Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference to figure and table numbers with Pandoc

I'm trying to make a document with Markdown/restructuredText which will be converted with pandoc to PDF using xelatex.

I would like to return reference to figure and tables numbers in the text body.

In both Markdown and reSt markup languages, the cross reference return a link to the figure but not the figure number.

for example [the figure](#myfig) with markdown or myfig_ with reST links to the figure but don't automaticly update the figure number.

Is it possible with Markdown or ReST markup languages to refer to figure and tables number?

like image 549
JeanJouX Avatar asked Aug 12 '18 13:08

JeanJouX


People also ask

What is Pandoc used for?

Pandoc is a tool that runs from the command window or Linux shell to convert a markdown file to another file format. For this workflow, with the use of an appropriate CSS is available to help convert HTML, PDF, DOCX, and EPUB. You can also use your own or discovered CSS as well.

How do you use extensions in Pandoc?

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.

Where are Pandoc templates?

Some Pandoc templates for an article in PDF (vita LaTeX), HTML, or Microsoft Word. These go in ~/. pandoc/templates . These can be be pointed to directly with the --template= switch as appropriate.

How do I convert markdown to PDF in Pandoc?

Generating PDF from Markdown with Pandoc There are actually two steps involved in converting a Markdown file to a PDF file: The Markdown source file is converted to a LaTeX source file. Pandoc invokes the pdflatex or xelatex or other TeX command and converts the . tex source file to a PDF file.


2 Answers

I suggest using the pandoc-crossref filter with pandoc. The demo gives you a good idea of the syntax. You invoke it by calling pandoc with --filter pandoc-crossref.

like image 180
John MacFarlane Avatar answered Nov 03 '22 18:11

John MacFarlane


The pandoc-fignos and pandoc-tablenos filters from the pandoc-xnos filters suite are good choices for cross-referencing in markdown with pandoc.

To mark a figure for numbering, add an identifier to its attributes:

![Caption.](image.png){#fig:id}

To reference the figure, use @fig:id.

Similarly, to mark a table for numbering, add an identifier to its attributes:

A B
- -
0 1

Table: Caption. {#tbl:id}

To reference the table, use @tbl:id.

When processing the markdown document, simply add --filter pandoc-fignos --filter pandoc-tablenos to the pandoc command.

like image 33
tjd Avatar answered Nov 03 '22 19:11

tjd