lierdakil/pandoc-crossref

Fail to modiffy “Reference format” during convertion from .tex

Closed this issue · 4 comments

runck commented

I am trying to convert .tex to .docx, with the need of
continous single numbering for figure reference ( things like \ref{figlabel} ) , i.e., without chapter number ahead.

After reading the doc, I have tried figPrefixTemplate and refIndexTemplate, but got failed without effect. (Althogh figureTitle is working fine).
Thank you for pointing my mistake.

Here is a minimum example:

pandoc command:

pandoc -s -o t.docx ^
	--filter pandoc-crossref ^
	-M chapter=False ^
	-M "figPrefixTemplate=$$i$$" ^
	-M figureTitle=MYFIG ^
	--number-sections ^
	--verbose  ^
	t.tex

Source file:

\documentclass{book}
\usepackage{graphicx}
				

\begin{document}
\chapter{ch1}
text1

\chapter{ch2}

Fig~\ref{fig:f1}


\begin{figure}
	\includegraphics{t.png}
	\label{fig:f1} 
	\caption{caption}
\end{figure}


\end{document}

Expect in text for \ref{fig}: Fig 1
Actual result : Fig 2.1

Versions:

pandoc 3.1
Features: +server +lua
Scripting engine: Lua 5.4


pandoc-crossref v0.3.15.1 git commit b5fee658cfe22164e93608c1abe4468c9e09be1b (HEAD) built with Pandoc v3.1, pandoc-types v1.23 and GHC 9.0.2

See #250 TL;DR pandoc-crossref doesn't by itself support LaTeX as input format, but you can get 90% there by using a filter to massage LaTeX into what pandoc-crossref expects.

runck commented

Thank you. I am learning the filter way now.

Just to avoid silly start as a beginner: does it expected to convert \ref{fig:label} to @fig:label in a pre-filter before pandoc-crossref even for .tex? (since I thought this is what pandoc-crossref expects as a reference token from https://lierdakil.github.io/pandoc-crossref/#references).
I found just @fig:label in .tex is not recognized by pandoc-crossref, so I am not sure how to make pandoc-crossref take over it.

Although I have done my original purpose by dumbly replacing the output string in the filter without pandoc-crossref, but I thought this is probably not the expected way.

Pandoc parses @fig:label into a data structure, that pandoc-crossref then can use. But that works only in Markdown. So the Lua filter in the issue linked above massages \ref{...} into the data structure that pandoc would parse from @..., which pandoc-crossref can then use. Simply writing @... in TeX source won't work.

To clarify, TeX was never intended as an input format for pandoc-crossref, for many reasons, the primary being that it's generally impossible to parse TeX into a markup language, as TeX is technically Turing-complete. But it's possible to get most of the way there with typical TeX documents.

runck commented

Thank you for your kind explanation!