I'm able to create a nice table of contents with pandoc's --toc
option. But I was wondering, if there is any way of linking the header or a symbol near the heading back to the table of contents.
For example, when you create a footnote in pandoc, it links the subscript number to the bottom of the page. At the end of the note, there is this little sign (↩︎) with a link for going back to the line where the footnote was.
I'd like to do this with my table of contents for each header. I don't mind not using --toc
, and instead writing out the table of contents manually, but I'm not sure whether this particular feature is available.
A Lua filter can be used to add a link back to the TOC.
local link_to_toc = pandoc.Link({pandoc.Str '↑'}, '#TOC')
function Header (h)
h.content = h.content .. {pandoc.Space(), link_to_toc}
return h
end
Save the above into a file and pass it to pandoc via the --lua-filter
(or -L
) command line option.
Linking to a specific line in the TOC is not possible though.