# dblatex generated output does not play nice with minted

I have a large LaTeX file generated with dblatex. When I replace lstlisting environment with minted it fails to process it. XeLaTeX produces following errror:

``````! Missing \endcsname inserted.
\global
l.2 ...de \PYGdefaultZlt{}stdio.h\PYGdefaultZgt{}}
``````

Has anyone tried using dblatex with minted? https://github.com/sciactive/2be-extras/blob/master/documentation/doc-pdf.sh git repository has integration of dblatex with minted but even that does not work.

A sample xml can be

``````<article xmlns="http://docbook.org/ns/docbook"
<title>Test article</title>

<para>
<application xl:href="http://www.gnu.org/software/emacs/">Emacs</application>
is my favourite text editor.</para>
...
<programlisting language="c">#include &lt;stdio.h&gt;</programlisting>
</article>
``````

The TeX file can be generated via command `dblatex -bxetex -p dblatex.xsl -t tex test.xml`.

Then minted can be included and processed with XeLaTeX for the error.

• Welcome to TeX.SX! Do you think you can give an MWE of what you are trying to do and what causes the error? It would also be good if you could explain your work flow if it involves more than just running XeLaTeX on your file. – moewe Oct 20 '15 at 12:57
• I have edited the question to contain github repository. – Bugbugbuggerbuggered Oct 20 '15 at 13:18
• Please try giving us a minimal example that we can try out. It is also preferred to add paste the code directly to your question, so we can simply copy it to our machines and have a go. – moewe Oct 20 '15 at 13:21
• I have created an MWE. – Bugbugbuggerbuggered Oct 20 '15 at 13:33

`fancybox` and `fancyvrb` conflict. For things to work correctly, `fancyvrb` must be loaded last. Both of these packages are loaded by the `db2latex` package, so neither of them are needed in your output`.tex` file.
The package `db2latex` attempts to load the two packages in the correct order, but overlooks the fact that it has already loaded `fancyvrb` in the subpackage `dbk_verbatim`, which loads `listings` which loads `fancyvrb`. Even if that wasn't the case, `dbk_misc` would load `fancyvrb` explicitly. So `db2latex` ultimately ends up loading `fancybox` last, which is wrong. You would need to comment out the `\usepackage{fancybox}` in `db2latex.sty`, or move it to before `\usepackage{dbk_verbatim}`.
If `fancybox` is loaded anywhere by `db2latex`, then `minted` must be loaded after `db2latex`, because `minted` will load `fancyvrb`, and thus `fancyvrb` wouldn't be loaded last. If `fancybox` isn't ever loaded, then `minted` can be loaded anywhere.
Once that is done, there is still a problem because `dbk_misc.sty` uses `\lstset{fancyvrb=true}`, which overwrites the `fancyvrb` internals with `listings` versions. You would need to comment that out, or have `\lstset{fancyvrb=false}` in your output document somewhere after loading `db2latex`.