Additional List of TOC generated when publishing from doctree

Thomas Krug via Docutils-users <[email protected]> Mon, 30 Nov 2020 13:49:02 +0100
Newsgroups gmane.text.docutils.user
Message-ID <[email protected]>
Hi there,

I'm using docutils to generate latex which works great.
But I stumbled upon a problem with TOC generation.

If I use publish_string() the generated tex is correct.
If I use publish_doctree() then publish_from_doctree() the generated tex
contains an additional list containing the TOC.

I'm not sure if I'm missing something here.

I attached a minimal working example and the diff of the generated tex
files.

Greetings,
Thomas
texexport.py (text/x-python, 447 B)
#!/usr/bin/env python3


import docutils
import docutils.core



rst = """

.. contents:: TOC

foo
---

bar
---

"""

dtree = docutils.core.publish_doctree(rst)
tex = docutils.core.publish_from_doctree(dtree, writer_name="latex")
tex = tex.decode()

with open("test_via_dtree.tex", "w") as f:
    f.write(tex)



tex = docutils.core.publish_string(rst, writer_name="latex")
tex = tex.decode()

with open("test.tex", "w") as f:
    f.write(tex)
test.diff (text/x-patch, 305 B)
--- test.tex	2020-11-30 02:24:58.082659035 +0100
+++ test_via_dtree.tex	2020-11-30 02:24:58.075992446 +0100
@@ -31,6 +31,12 @@
 \renewcommand{\contentsname}{TOC}
 \tableofcontents
 
+\begin{itemize}
+\item \hyperref[foo]{foo}
+
+\item \hyperref[bar]{bar}
+\end{itemize}
+
 
 \section{foo%
   \label{foo}%