Pandoc: Label figure and centering not converted from latex to markdown

Created on 12 Jun 2018  路  5Comments  路  Source: jgm/pandoc

I used

pandoc -f latex -t markdown | pandoc -f markdown -t latex

with the input

\begin{figure}
  \centering
  \includegraphics{figures/fig1.pdf}
  \caption{blablabla}
  \label{fig1}
\end{figure}

gives the output

\centering

\begin{figure}
\centering
\includegraphics{figures/fig1.pdf}
\caption{blablabla{}}
\end{figure}

for information, the markdown intermediary output is

\centering
![blablabla[]{label="fig1"}](figures/fig1.pdf)

My problem is that the label is not converted, it should do something like

![blablabla\label{fig1}](figures/fig1.pdf)

You can observe that \centering is used twice too.

LaTeX reader

All 5 comments

The LaTeX reader could parse the \label{foo} to the id attribute on the image in the AST, which would allow round-tripping.

The centering, however is a layouting instruction which pandoc doesn't aim to preserve.

I'm not sure to understand your answer.

The centering doesn't bother me, it is just not useful in markdown.

The label is the real issue.

@mb21 is making a suggestion (a sensible one) about how the parser's code could be changed to solve your problem.

I'm still not quite sure about the proposed fix. Conceptually, labels are different from ids. Ids serve as link anchors, while labels affect automatic numbering.
Since we're already parsing the latex above as

Para [Image ("",[],[]) [Str "blablabla",Span ("",[],[("label","fig1")]) []] ("figures/fig1.pdf","fig:")]

why not have the LaTeX writer transform Span ("",[],[("label","fig1")]) [] into \label{fig1}, instead of populating the id attribute?

Well, since we're already creating \label from a markdown image id, I guess this makes a certain amount of sense, and I'll merge the PR, but I wanted to raise this question.

Conceptually, labels are different from ids. Ids serve as link anchors, while labels affect automatic numbering.

I wasn't really aware of that. how do they affect automatic numbering?

Was this page helpful?
0 / 5 - 0 ratings