jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.39k stars 3.37k forks source link

Markdown to LaTeX: image referencing #6847

Closed nico-bachner closed 3 years ago

nico-bachner commented 3 years ago

Feature request

Using Pandoc 2.10.1

Issue

I haven't been able to reference images using the standard Markdown syntax:

![Image Caption](path/to/image.format)

Because this converts to the following:

\begin{figure}
\centering
\includegraphics{path/to/image.format}
\caption{Image Caption}
\end{figure}

However, if I were to reference the figure like so:

\ref{image-reference}

Then latex is unable to recognise the reference.

Solution

To me, there seems to be a solution that wouldn't change all that much:

If we were to add \label{image-reference} to the latex output, referencing the image would be possible.

Referencing using the Markdown method

Markdown's referencing method (for table of contents, etc.) should make the referencing even easier for the user, since they could reference the image using the caption. Thus, the markdown image syntax from above, ![Image Caption](path/to/image.format), could be referenced by the following:

\cite{image-caption}

I'm not quite sure how easy the implementation of this part is though, since there will likely be edge cases where the caption includes exotic symbols.

Final Output

The final output would then look like so:

Input

![Image Caption](path/to/image.format)

Output

\begin{figure}
\centering
\includegraphics{path/to/image.format}
\caption{Image Caption}
\label{image-caption}
\end{figure}

Referencing

\cite{image-caption}

Sadly, I am lost in the codebase of pandoc since I don't know Haskell, so I'm not sure how easy this change actually is to implement.

To the people reviewing this

  1. Please feel free to ask me to reformulate any part of the feature proposal if it's not clear enough
  2. If anyone would like to give me a very brief explanation of how the Markdown to LaTeX converter works, I'd be happy to try and tackle the issue myself. I have found the Text.Pandoc.Writers.LaTeX module to contain the functionality starting at line 575, but am unable to understand how exactly it functions
mb21 commented 3 years ago

Try:

![Image Caption](path/to/image.format){#foo}

see https://pandoc.org/MANUAL.html#images

nico-bachner commented 3 years ago

Try:

![Image Caption](path/to/image.format){#foo}

see https://pandoc.org/MANUAL.html#images

Thank you, for some reason missed that part of the docs.