Closed amine-aboufirass closed 1 year ago
Try using pandoc's native listings maybe? pandoc ... -Mlistings --listings ...
Pandoc-crossref does some horrible hacks with listings in LaTeX, if you're going to process the file further, you'll want to avoid those.
I did:
pandoc -s -Mlistings --listings -L include-code-files.lua -F pandoc-crossref -L minted.lua --from markdown --to latex test-combined.md -o test.tex
latexmk --shell-escape -pdflatex test.tex
But that just results in:
That's not exactly what I'm looking for.
I see. Well, I've taken a look at what minted.lua
does, and it just unconditionally strips the code block identifier altogether. As far as I'm concerned, that's an issue with minted.lua
, but there is a relatively straightforward bodge I believe:
replace https://github.com/pandoc/lua-filters/blob/40a1a0b6e3c5b3347aaecb0ad697368e16289f86/minted/minted.lua#L408 with something like
"\\label{%s}\\begin{minted}[%s]{%s}\n%s\n\\end{minted}",
block.identifier,
This won't work in general, as in general you'd have to check that identifier is not empty and only then add the label. And I'm not sure whether it's better to put the label inside or outside minted
environment.
Disclaimer: I'm not familiar with minted
and I didn't test any of this, but on paper it seems like it should work.
@lierdakil sounds good. The adjustment you propose to the Lua file does work. I made a pull request in the official repo for minted.lua
https://github.com/pandoc/lua-filters/pull/264
Hopefully the maintainers can see the value of making these two filters play nice with each other and accept the change.
As a follow up to my comment to https://github.com/lierdakil/pandoc-crossref/issues/29 I'm now trying very hard to combine three filters into my workflow:
include-code-files.lua
pandoc-crossref
minted
The reason I need to combine these filters is that
pandoc-crossref
does not provide the following capabilities for listings:I've already had an extensive discussion with Bastien Dumont from the pandoc google group and was not able to find a solution. I was however able to boil down my problem a bit further.
Here are the files I'm working with:
test.md
test.py
Compilation
I found out that if I run the filters in specific order and I include the
header-includes
shown intest.md
I can at the very least get the LaTeX file to compile with no errors.pandoc -s -L include-code-files.lua -F pandoc-crossref -L minted.lua --from markdown --to latex test-combined.md -o test.tex
latexmk --shell-escape -pdflatex test.tex
Result
The reference is not recognized, it looks like
minted.lua
removes the\label
associated with thecodelisting
environment defined bypandoc-crossref
.Question
How do I get the reference to still work when adding
minted.lua
to the Pandoc call?