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?

ShreevatsaR
  • 45,428
  • 10
  • 117
  • 149
DigNative
  • 1,255
  • 1
  • 16
  • 29
  • 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 03 '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 03 '13 at 12:51
  • I believe it has to do with the multiple passes tabu does on cell entries. – egreg Sep 03 '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 03 '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 03 '13 at 13:06
  • You might be interested in the matlab-prettifier package; see this answer. – jub0bs Apr 28 '14 at 17:12
  • @Jubobs: Looks interesting, however, I will wait until the package is published on CTAN for compatibility reasons. – DigNative Apr 28 '14 at 17:18
  • @DigNative The package has just been released on CTAN :) However, you might have to wait a few days for all the CTAN mirrors to catch up before being able to install the package directly through your package manager. – jub0bs Apr 28 '14 at 17:20
  • @Jubobs: Ahh, fine. Then I will have a look on the package the next time I need to display MATLAB code. Thanks! – DigNative Apr 28 '14 at 17:23

1 Answers1

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}
G. Poore
  • 12,417