pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
600 stars 165 forks source link

Fixing issue related to pandoc-crossref compatibility #264

Closed amine-aboufirass closed 1 year ago

amine-aboufirass commented 1 year ago

minted.lua unconditionally strips the code block identifier when processing with pandoc-crossref. This makes the current implementation of minted.lua incompatible with pandoc-crossref. Please see this thread for more details.

This change allows documents filtered by pandoc-crossref and then by minted.lua to preserve references. This combines the best of both worlds.

I was not able to run the tests to check if this is a breaking change, because of this issue in my WSL install. If someone can show me how to run the tests for minted.lua on a Windows machine and there are breaking changes I'd be glad to work through them or add new tests if necessary.

@tarleb

tarleb commented 1 year ago

I don't know much about the minted filter; maybe @svenevs as the author of that filter can help?

svenevs commented 1 year ago

Sure, I can try :upside_down_face: I've been out of touch with this stuff for years, wrote that filter during jury duty. @amine-aboufirass it would be helpful if you could share with me a quick minimal working example of a document that is using both minted and pandoc-crossref (edit: and how you are building things). I know I was using crossref at the time, vaguely remember filter order being a thing and that crossref always has to be first or something. But I should be able to run the tests this weekend if I can find a bootable linux system that's not my work computer.

Existing tests and were happy: https://github.com/pandoc/lua-filters/actions/runs/4375232713/jobs/7655760573#step:4:52

but maybe we should be adding to the test something that uses crossref? not sure if that's going to be easy

svenevs commented 1 year ago

oh sorry read too quick, https://github.com/lierdakil/pandoc-crossref/issues/379 looks like it has enough for me to work with

amine-aboufirass commented 1 year ago

@svenevs @lierdakil i've been looking at this stuff a bit more closely. Before I elaborate I think it's useful to note that my use case has the following requirements:

  1. Robust page-breaking for verbatim environments
  2. Robust line breaking for verbatim environments. That means line breaking anywhere (not just at spaces)
  3. Including external files in listings
  4. Cross-referencing listings in other parts of the document
  5. Captions.

This pull request was attempting to address the 5th item. However, it turns out pandoc-crossref also has difficulty with minted.lua because pandoc-crossref defines the following in header-includes:

\newcommand*\listoflistings{\listof{codelisting}{List of Listings}}

Since minted already defines a \listoflistings, LaTeX will crash. One workaround would be to undefine that command after \usepackage{minted} and before the header-include, but there's no telling whether that would impact someone trying to actually generate a list of listings.

To be more complete, this pull request would require one of the following items:

badumont commented 1 year ago

For your information, the minted package defines \listoflistings exactly as pandoc-crossref does, so it would be safe to reset it to @.*** after minted has been loaded (it would only prevent users from redefining the “List of listings” string via \listoflistingscaption, but pandoc-crossref provides the lolTitle metadata variable for that).

amine-aboufirass commented 1 year ago

@badumont in that case it might be better to update the README for minted.lua to reflect that. @svenevs any thoughts on that?