# Using minted environment inside a tabu table

I am trying to use a piece of highlighted code using the minted package inside a tabu table:

\documentclass{article}

\usepackage{minted}
\usepackage{longtable}
\usepackage{tabu}

\begin{document}
\begin{tabu*}{X[5,l]X[5,l]}
\begin{minted}{matlab}
function out = op(x, y)
out = x + y;
end
\end{minted}
& \\
\end{tabu*}
\end{document}


With the above MWE I tried to place a minted environment inside a tabu cell analogously to what was done with the Verbatim environment explained within the tabu package documentation in section 1.3 "Inserting Verbatim material (fancyvrb)". However, by compiling the above MWE I get the following error message:

Enter file name:
! Emergency stop.

l.15     \end{tabu*}
^^J
*** (cannot \read from terminal in nonstop modes)


If I try to compile the document in scroll mode (-interaction=scrollmode with XeLaTeX from MiKTeX), I just get a command prompt with Enter file name:.

How can the minted environment be used within a tabu table?

• minted is very different from Verbatim, because it has to write its contents in a file, then call an external program and input the resulting file. Sep 3, 2013 at 12:44
• @egreg Thank you for your comment. I know that minted uses these temporary files. What makes me curious is that if I just press my Enter key twice in scrollmode the output is generated as expected without an additional error. Sep 3, 2013 at 12:51
• I believe it has to do with the multiple passes tabu does on cell entries. Sep 3, 2013 at 12:58
• @egreg I don't know. I am not able to figure out where the problem is and I was also not able to find anything regarding the utilization of minted inside a tabu table on the web. Sep 3, 2013 at 13:04
• Usual caveat about tabu: the author has long promised a new version, stating it will have a number of incompatibilities with the current one. My advice is to contact the author. Sep 3, 2013 at 13:06

This is more of a hack than a real fix. minted correctly creates the highlighted content, and the content is correctly brought in. But at some point, minted's \minted@pygmentize macro tries to \input a file that "doesn't exist." I put "doesn't exist" in quotes because I've tried minted with all file deletion disabled, and still get the error--so it seems to be related to tabu's multiple passes. Anyway, the Enter file name: can be avoided by patching tabu*. Basically, replace every \input with an \InputIfFileExists. Insert the following in the preamble, after tabu is loaded, and you document will compile.
\usepackage{etoolbox}