The Pandoc documentation says that cross references can be made to section headers in a number of ways. For example, you can create your own ID and reference that ID. For example:
# This is my header {#header}
Will create an ID with value '#header' that can be refenced in the text, as such:
[Link to header](#header)
Which will display the text 'Link to header' with a link to the header.
I couldn't find anywhere how to make the text of the link be the section number when compiled as a LaTeX document.
For example, if my header is compiled to '1.2.3 Section Header', I want my cross-reference to text to display as '1.2.3'.
Authoring Books and Technical Documents with R Markdown In fact, you can also reference sections using the same syntax \@ref(label) , where label is the section ID. By default, Pandoc will generate an ID for all section headers, e.g., a section # Hello World will have an ID hello-world .
An extension can be enabled by adding +EXTENSION to the format name and disabled by adding -EXTENSION . For example, --from markdown_strict+footnotes is strict Markdown with footnotes enabled, while --from markdown-footnotes-pipe_tables is pandoc's Markdown without footnotes or pipe tables.
pandoc-crossref is a filter that adds support for figure, table, and equation numbers and cross-references. pandoc-xnos is a suite of filters supporting numbering and cross-referencing figures, equations, tables, and sections.
Pandoc can convert between numerous markup and word processing formats, including, but not limited to, various flavors of Markdown, HTML, LaTeX and Word docx.
This can be achieved by defining the ID as done previously. eg:
# This is my header {#header}
Then in the text, the cross reference can be written as:
\ref{header}
When this compiles to LaTeX, the cross-reference text will be the section number of the referenced heading.
You can use the pandoc-secnos filter, which is part of the pandoc-xnos filter suite.
The header
# This is my header {#sec:header}
is referenced using @sec:header
. Alternatively, you can reference
# This is my header
using @sec:this-is-my-header
.
Markdown documents coded in this way can be processed by adding --filter pandoc-secnos
to the pandoc
call. The --number-sections
option should be used as well. The output uses LaTeX's native commands (i.e., \label
and \ref
or \cref
).
The benefit to this approach is that output in other formats (html, epub, docx, ...) is also possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With