pandoc / lua-filters

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

minted: doesn't handle framebreaks in beamer #115

Open balsoft opened 3 years ago

balsoft commented 3 years ago

Consider the following document:

---
header-includes:
  - \usepackage[outputdir=/tmp/pandoc]{minted}
---

# Hello world
## foo
~~~~~~~
foo bar
~~~~~~~

------ 

~~~~~~~
baz goo
~~~~~~~

When compiled to beamer pdf with

pandoc --standalone --pdf-engine=xelatex --pdf-engine-opt=-shell-escape --pdf-engine-opt=-output-directory=/tmp/pandoc --slide-level=2 --to beamer --no-highlight -o test.pdf test.md

It works (frame "foo" is split into two)

However, when compiled with minted filter like this:

pandoc --standalone --pdf-engine=xelatex --pdf-engine-opt=-shell-escape --pdf-engine-opt=-output-directory=/tmp/pandoc --slide-level=2 --to beamer --no-highlight --lua-filter minted.lua -o test.pdf test.md

It fails with an obscure error:

Error producing PDF.
! FancyVerb Error:
  Extraneous input ` baz goo \end {minted} \end {beamer@frameslide}\ifbeamer@tw
oscreenstext \beamer@dosecondscreennow {\begin {minted}[autogobble]{text} baz g
oo \end {minted} }\fi \ifbeamer@anotherslide \advance \beamer@slideinframe by 1
\relax \relax \expandafter \iterate \fi \let \iterate \relax \beamer@writeslide
ntry \beamer@reseteecodes ' between \begin{minted}[<key=value>] and line end
.
\FV@Error ...ncyVerb Error:^^J\space \space #1^^J}

l.107 \end{frame}

This error changes a lot depending on relative positions of code blocks, frames and line breaks, so I wasn't able to determine the exact cause or suggest a fix.

CC @svenevs

svenevs commented 3 years ago

Do you get reliable behavior if you follow the suggested approach of md -> tex then tex -> pdf (do not use pandoc to go md -> pdf)?

https://github.com/pandoc/lua-filters/blob/master/minted/README.md#pdf-compilation

The linked issue was closed, but I don't think this is actually fixed. Presumably the unreliable / changing error is directly related to this, especially if you reuse the same directory each time without deleting it. It would be great if there was a better fix, but I'm not going to be able to fix it myself and I don't think the filter side can either.

balsoft commented 3 years ago

The behavior is reproducible with md -> tex -> pdf too:

$ pandoc --standalone --pdf-engine=xelatex --pdf-engine-opt=-shell-escape --pdf-engine-opt=-output-directory=/tmp/pandoc --slide-level=2 --to beamer --no-highlight --lua-filter minted.lua -o test.tex test.md

$ xelatex -shell-escape -output-directory=/tmp/pandoc test
<...>
! FancyVerb Error:
  Extraneous input ` baz goo \end {minted} \end {beamer@frameslide}\ifbeamer@tw
oscreenstext \beamer@dosecondscreennow {\begin {minted}[autogobble]{text} baz g
oo \end {minted} }\fi \ifbeamer@anotherslide \advance \beamer@slideinframe by 1
\relax \relax \expandafter \iterate \fi \let \iterate \relax \beamer@writeslide
ntry \beamer@reseteecodes ' between \begin{minted}[<key=value>] and line end
.
\FV@Error ...ncyVerb Error:^^J\space \space #1^^J}

l.107 \end{frame}

?

The full tex file: https://0x0.st/i0KQ.tex

For every given md file, the error is always the same, however it changes a lot with some changes to the file.

Also, I don't have any issues with md -> pdf on my presentation (apart from this one, but it is reproducible with md -> tex -> pdf too).