# Autonumber orgmode headings

**URL:** <https://discourse.gohugo.io/t/autonumber-orgmode-headings/37723>\
**Category:** support\
**Created:** [March 17, 2022, 9:09pm UTC](https://discourse.gohugo.io/t/autonumber-orgmode-headings/37723 "2022-03-17T21:09:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradesigner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pradesigner/32/15713_2.png) [@pradesigner](https://discourse.gohugo.io/u/pradesigner)\
**Post date:** [March 17, 2022, 9:09pm UTC](https://discourse.gohugo.io/t/autonumber-orgmode-headings/37723/1 "2022-03-17T21:09:10Z")

</div>

i would like

- heading 1
- heading 2

to show up something like

1. heading 1
2. heading 2

none of the following make this happen:

1. adding to config.yaml

```auto
[markup]
  [markup.tableOfContents]
    endLevel = 3
    ordered = false
    startLevel = 2

```

or

1. coding `#+startup: num` to the file

or

1. activating org-num-mode

a numbered html file can be exported through emacs, but not through hugo.

**how can i get hugo to produce numbered headings from an org file?**

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [March 17, 2022, 10:08pm UTC](https://discourse.gohugo.io/t/autonumber-orgmode-headings/37723/2 "2022-03-17T22:08:08Z")

</div>

> [@pradesigner](#):
>
> coding `#+startup: num` to the file

If you need Hugo to understand the export options, the [go-org](https://github.com/niklasfasching/go-org) module needs to implement that i.e. it needs to parse the `#+options:` keyword. Try asking this question on that repo.

* * *

_PS: This is supported if you export the Org file using `ox-hugo` – ([related tests](https://ox-hugo.scripter.co/test/tags/num))._

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [March 17, 2022, 10:10pm UTC](https://discourse.gohugo.io/t/autonumber-orgmode-headings/37723/3 "2022-03-17T22:10:30Z")

</div>

> [@pradesigner](#):
>
> would like
> 
> - heading 1
> - heading 2
> 
> to show up something like
> 
> 1. heading 1
> 2. heading 2

Alternatively, look into CSS counters and/or render hooks for headings to implement the same.

* * *

**Edit** : Example:

> **[Automatically numbering headings via CSS](https://2ality.com/2012/01/numbering-headingshtml.html)**
>
> This post shows you how to number HTML headings with CSS. That is, given the following HTML. My Article Introduction Rationale Background With the proper CSS, the above will be displayed as My Article 1. Introduction 1.1. Rationale 2....

---

<div class="post-metadata">

**Author:** ![pradesigner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pradesigner/32/15713_2.png) [@pradesigner](https://discourse.gohugo.io/u/pradesigner)\
**Post date:** [March 19, 2022, 7:31pm UTC](https://discourse.gohugo.io/t/autonumber-orgmode-headings/37723/4 "2022-03-19T19:31:08Z")

</div>

thx @kaushalmodi for this info and taking the trouble to provide the links.

i haven’t tried ox-hugo yet, because hugo has been working really nicely for me, but may give it a try at some point.

my attempts at css modification didn’t work:

```auto
<style>
body {counter-reset: h1;}
h1 {counter-reset: h2}
h2 {counter-reset: h3}

h2:before {counter-increment: h2; content: counter(h2) ". "}
h3:before {counter-increment: h3; content: counter(h2) "." counter(h3) " "}
</style>

```

various other efforts including copying the actual code in the examples provided such as the link you provided and here:

> **[HTML / CSS autonumber headings?](https://newbedev.com/html-css-autonumber-headings)**
>
> Definitely possible using css counters - just make sure you watch out for browser compatibility...: This will make h2 get 1., 2., h3 gets 1.1, 2.1, 2.2 etc... \<

led to the same thing. the h2 didn’t increment, but the h3 did.

not sure why other than the html coding hugo produces is too complex for this to work because of the id=“headline-X”?

```auto
<h2 id="headline-1">
Animal Rights
</h2>

```

i haven’t really experimented further with this though beyond the hugo produced html (using a seperate stylesheet as well as placing code into baseof.html).

i also realized that the css solution wouldn’t produce the TOC i wanted so i wrote a little script which autonumbers the headings much in the way that org-num-mode does. The script can also remove the headings, if i want to work further on the file and then renumber things again.

i’m including below in case it is of use to someone else:

```auto
#!/usr/bin/env zsh

# [un]numbers the headings
# usage: org-numberer.sh <FILE>.org [+-]

fn=$1 #filename
op=$2 #operation [+-] numbers

h=(0 0 0 0 0 0) #initialize heading array to depth of 6

case $op in
    
    "+")
        echo "adding numbering ..."
        while read l
        do
            itm=${l%% *} #isolate the itm before the first space
            len=${#itm} #get length of the itm
            txt=${l#* } #isolate the text following *

            if [[$itm =~ ^\\*]];
            then #if itm begins with * it is a heading, so process numbering
                (( h[len]++ ))

                #build the section numbers sn
                sn=''
                for i in {1..$len};do
                    sn="$sn$h[i]."
                done
                sn=${sn%.}
                h[i+1]=0
                l="$itm $sn $txt"
            fi

            echo $l >> TMP #append line (heading or not)to TMP file
            
        done < $fn
        mv TMP $fn
        ;;
    
    "-")
        echo "removing numbering ..."
        sed -i 's/^\(\**\) [0-9.]* /\1 /' $fn
        ;;

    *)
        echo "LIKE THIS: orgnum.sh <FILE>.org [+-]"
        exit
        
esac
    
exit

```

thx again for your help!
