8

If I export the following document as a PDF through C-c C-e l p I get a PDF with a table of contents as expected:

* Hello                                                                                                                                      

  This is a test.                                                                                                                            

* World                                                                                                                                      

  Of org mode section numbering.

but if I add num:nil to the options (to disable section numbering) like so:

#+OPTIONS: num:nil                                                                                                                           
* Hello                                                                                                                                      

  This is a test.                                                                                                                            

* World                                                                                                                                      

  Of org mode section numbering.

my table of contents becomes empty.

I'd like to have a table of contents but without all the section numbers. Is there any way to do that? I've tried adding toc:2 as well but that didn't help.


The first one (without the num:nil) looks like this:

enter image description here

and the second one (with the num:nil) looks like this:

enter image description here

(a rather useless table of contents...)

2 Answers 2

4

The num:nil option tells org to export your headings as unnumbered sections, which look like \section* in LaTeX. The normal handling of these sections in LaTeX is to exclude them from the table of contents. To over-ride this, you have to explicitly add them with \addcontentsline, as @Dox has indicated in his answer.

As an alternative, instead of setting the num:nil option, you can use a LaTeX macro to turn of section numbering entirely:

\setcounter{secnumdepth}{0}

If you do this, you only need this one line at the top of your org document, you don't need to add it for every section.

The resulting LaTeX produced by the org-exporter will use normal sections, i.e., \section (without an asterix). These sections show up in your TOC, but will not have numbers.

Using the setcounter macro will only work for LaTeX output, so it's no help if you export to html or other formats.

5
  • Unfortunately clicking on the toc links also doesn't work in this case, they navigate to the first page. Jul 29, 2023 at 15:53
  • 1
    @user2609980: with the \setcounter case, or the \addcontentsline case? It's working for me with the former.
    – lindes
    Dec 8, 2023 at 2:42
  • 1
    Alas, this isn't an ideal solution for me, because I still have to leave out the num:nil in #+OPTIONS, and that means that while the LaTeX/PDF export looks OK, the numbers are still there in the HTML export, which I don't want. It's helpful, though, inasmuch as if I leave HTML aside, I can get what I want with the LaTeX/PDF export using a line near the top of my file with these contents: #+LATEX_HEADER: \setcounter{secnumdepth}{0}
    – lindes
    Dec 8, 2023 at 2:43
  • @lindes I was running into another issue: tex.stackexchange.com/a/693852/70734, I am not sure the workaround I describe there works for your HTML export use case, I don't think so if the HTML export is not based on LaTeX. Dec 12, 2023 at 15:23
  • @user2609980 yeah, I'm just using org-html-export-to-html, so, not LaTeX based, as far as I know. So, would be nice to be able to have things that work in one exporter also work in another. I'm failing to find easily (I admit to not trying terribly hard) the source code for the exporter, but maybe I or someone could at least file a bug, and/or better, submit a pull request or whatever equivalent to make the latex exporter do appropriate things (whatever that takes, even if it means setting num to non-nill, and just adding a pre-amble like listed here) with #+OPTIONS: num:nil.
    – lindes
    Dec 13, 2023 at 3:03
2

Of course, that happen also in LaTeX. You could use the option toc:nil to disable the table of contents. Otherwise you can trick it using the LaTeX code which forces the sections to appear in the table of contents

* Hello @@latex: \addcontentsline{toc}{section}{Hello}@@
  This is a test 
* World @@latex: \addcontentsline{toc}{section}{World}@@
  Of =org-mode= section numbering

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.