Wandmalfarbe / pandoc-latex-template

A pandoc LaTeX template to convert markdown files to PDF or LaTeX.
BSD 3-Clause "New" or "Revised" License
6.09k stars 959 forks source link

custom highlighting-style conflicts with --listings #209

Closed sfc-gh-kcox closed 3 years ago

sfc-gh-kcox commented 3 years ago

I am using a custom highlight-style and syntax-definition template for my Markdown files. Everything is stored in a Docker container which I then run as follows:

docker run --volume $BASEDIR:/data \
  --user `id -u`:`id -g` edu_pandoc \
    --template=/data/templates/eisvogel.tex \
    --filter=pandoc-include-code \
    --filter=pandoc-latex-environment \
    --highlight-style=/data/templates/sql.theme \
    --syntax-definition=/data/templates/sql.xml \
    --number-sections \
    --toc-depth=2 \
    --metadata=date:$3 \
    $LIST_OF_MD \
    -o output/$1_$2_workbook_$3.pdf

My problem is that periodically I need to add longer stretches of inline code that uses backticks to highlight the text background. Anything longer than 4-5 words does not wrap.

My solution to this was to enable --listings in the pandoc execution. This solved the wrapping issue, but then all other words of phrases that were previously highlighted using single backticks no longer had a gray background.

Is it possible to use --listings in conjunction with custom highlight-style and syntax-definition formats? The former cancels out the two latter versions.

Apologies if this is not the correct forum.

Wandmalfarbe commented 3 years ago

My problem is that periodically I need to add longer stretches of inline code that uses backticks to highlight the text background. Anything longer than 4-5 words does not wrap.

This is a known pandoc problem (see https://github.com/jgm/pandoc/issues/4302) that I tried to solve for Eisvogel (see https://github.com/Wandmalfarbe/pandoc-latex-template/issues/2) but the changes don't work as expected (see https://github.com/Wandmalfarbe/pandoc-latex-template/issues/176).

My solution to this was to enable --listings in the pandoc execution. This solved the wrapping issue, but then all other words of phrases that were previously highlighted using single backticks no longer had a gray background.

This is also a known issue (see https://github.com/Wandmalfarbe/pandoc-latex-template/issues/42).

Is it possible to use --listings in conjunction with custom highlight-style and syntax-definition formats?

This is not possible because these options work with the default pandoc built-in highlighting which is done by skylighting. When using --listings everything like tokenization, coloring, formatting and such is done by the listings package. Listings has very limited options regarding syntax definitions. I've included an example definition in Eisvogel for Java. But the listings syntax highlighting will always be inferior to the pandoc built-in highlighting.

You could work around this by using the minted package for highligting. Please keep in mind that the setup might be a little more work than just specifying a command line option. Unfortunately pandoc has no native support for syntax highlighting with minted (see https://github.com/jgm/pandoc/issues/4117). There is however a pandoc supported filter to use minted for syntax highlighting (see https://github.com/pandoc/lua-filters/tree/master/minted).