Autonumber orgmode headings

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
[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?

If you need Hugo to understand the export options, the 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).

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


Edit: Example:

https://2ality.com/2012/01/numbering-headingshtml.html

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:

<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:

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”?

<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:

#!/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!