2

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.
<read *> 

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. – egreg Sep 3 '13 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. – DigNative Sep 3 '13 at 12:51
  • I believe it has to do with the multiple passes tabu does on cell entries. – egreg Sep 3 '13 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. – DigNative Sep 3 '13 at 13:04
  • 1
    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. – egreg Sep 3 '13 at 13:06
1

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}
\let\originalinput\input
\newcommand{\newinput}[1]{\InputIfFileExists{#1}{}{}}
\AtBeginEnvironment{tabu*}{\let\input\newinput}
  • Thank you very much! I am now able to compile my document without any errors. – DigNative Sep 6 '13 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.