Do not include section in TOC in pandoc
Asked Answered
A

4

5

I am using this thesis template. It includes the abstract, acknowledgements, list of figures... in the table of contents. According to the university guidelines my TOC should start with Chapter 1 Introduction and not list abstract, acknowledgements... .

In latex you can just use \section* however using .unnumbered in pandoc results in that section still being included.

What is the cleanest way to exclude the sections before the introduction chapter from the TOC?

Azaria answered 30/3, 2018 at 11:38 Comment(0)
H
2

I'm using -H header.tex as an Pandoc option.

My workaround is appending:

\let\oldaddcontentsline\addcontentsline

to header.tex directly.

I wrote the same issue on GitHub: https://github.com/chdemko/pandoc-latex-unlisted/issues/1

Hammerhead answered 4/4, 2018 at 10:40 Comment(0)
I
4

You can use {.unlisted}.

Typically,

# Intro{.unlisted}

# Chapter 1

compiled with

pandoc test.md --toc -s -o test.html will give you

enter image description here

with the relevant html bit:

<body>
<nav id="TOC" role="doc-toc">
<ul>
<li><a href="#chapter-1">Chapter 1</a></li>
</ul>
</nav>
<h1 class="unlisted" id="intro">Intro</h1>
<h1 id="chapter-1">Chapter 1</h1>
</body>

Source, Doc

Izzy answered 29/10, 2021 at 16:38 Comment(0)
M
3

There's an open issue about this in pandoc.

To remove {.unnumbered} headers from the LaTeX TOC, you can meanwhile use the pandoc-latex-unlisted filter.

$ pip install pandoc-latex-unlisted
$ pandoc --filter pandoc-latex-unlisted input.md -o output.pdf
Mechanics answered 31/3, 2018 at 13:51 Comment(2)
Thanks for your help, however using your filter I get the following error: Chapter 1. ! Undefined control sequence. \addcontentsline #1#2#3->\oldaddcontentsline {#1}{#2}{#3} l.327 \chapter{Introduction}\label{introduction}} . Do you have an idea what the problem could be here? See here for my full build command.Azaria
not sure, I didn't write the filter myself... maybe helps inspecting the generated TeX with -s -t latex...Mechanics
H
2

I'm using -H header.tex as an Pandoc option.

My workaround is appending:

\let\oldaddcontentsline\addcontentsline

to header.tex directly.

I wrote the same issue on GitHub: https://github.com/chdemko/pandoc-latex-unlisted/issues/1

Hammerhead answered 4/4, 2018 at 10:40 Comment(0)
S
2

You need to combine .unlisted with .unnumbered to achieve this, as stated in Pandoc documentation.

Example:

# Abstract {.unnumbered .unlisted}

# Acknowledgements {.unnumbered .unlisted}

# Chapter 1
Saporous answered 5/10, 2022 at 14:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.