Asciidoc passthrough problem with Pandoc

Asciidoc passthrough problem with Pandoc

The idea

Use a passthrough to pass an includepdf instruction to LaTeX, so you can have full-page images in your text, using the LaTeX pdfpages package. The passthrough in the Asciidoc document looks like this:

++++
\includepdf{pics/eintagsfliegen-fullpage.pdf}
++++

The file is first converted to DocBook by Asciidoctor, then converted from DocBook to LaTeX with Pandoc. We have to first convert to DocBook because Pandoc can not work with Asciidoc yet. Finally, the file is rendered to PDF with pdflatex.

Of course the passthrough would have to be included into an ifeval that enables it only when the backend output format is DocBook, so it does’nt mess up other output formats like HTML or ePub.

The reality

But that does not work. In the resulting TeX document, we get this:

\textbackslash{}includepdf\{pics/eintagsfliegen-fullpage.pdf\}

Somebody escaped the backslash so that it shows up as a backslash when the TeX file is rendered. The intentions of the tool that did it are only the best, of course, but that escaping ruins the LaTeX includepdf command I intended to use.

At first I thought that Asciidoctor does that escape in the passthrough. I tried to switch all processing off with [subs="none"] right before the passthrough, but to no avail.[1]. But Asciidoctor is innocent, the passthrough ends up in the DocBook file unharmed, just as it was given in the Asciidoc document.

The substition was done by Pandoc. There may be ways to fix that. Maybe you could use Pandoc filters. But for now (March 2022), I don’t bother because I have a solution for including full pages images. I simply give them a filename that says that they are full page and do a Sed substition on the TeX file created by Pandoc in the Makefile:

sed -i 's/^\\includegraphics\({.*-fullpage.*}\)/\\includepdf\1/' pilze.tex

There may be more elegant ways to do this, but for now it’s all I need.


1. I always wanted to use that phrase. Now is the day.

links

social