2

I have a document with a lot of listings that need to get written out to files, and I want those generated listing files to be in a subdirectory of my document's main directory. For example, if my main document is project/main.tex, I want all the listings to go into the directory project/generated.

I can't seem to make this work with tcolorbox and minted. MWE:

\documentclass{article}

% \usepackage[outputdir=mweout]{minted}

\usepackage{tcolorbox}

\tcbuselibrary{minted,raster,skins,xparse}

\NewTCBListing{mylisting}{ O{} }{
  listing only,
  #1,
}

\begin{document}

\begin{mylisting}[listing file=mweout/listing]
  \LaTeX is fun.
\end{mylisting}

\end{document}

Using lualatex and MacTeX 2017, I get:

$ mkdir mweout
$ lualatex --shell-escape mwe.tex 2>&1 </dev/null
This is LuaTeX, Version 1.0.4 (TeX Live 2017) 
 system commands enabled.
(./mwe.tex
LaTeX2e <2017-04-15>
[... snipping a bunch of files being loaded, I think...]
Library (tcolorbox): 'tcbminted.code.tex' version '4.10'
[... more snipping...]
/Users/dale/.vpy/default/bin/pygmentize

No file mwe.aux.
[... more snipping...]
(./_minted-mwe/default-pyg-prefix.pygstyle) (./_minted-mwe/default.pygstyle)Traceback (most recent call last):
  File "<string>", line 1, in <module>
OSError: [Errno 2] No such file or directory: 'mwe.pyg'
Error: cannot read infile: [Errno 2] No such file or directory: 'mwe.pyg'

! Package minted Error: Missing Pygments output; \inputminted was
probably given a file that does not exist--otherwise, you may need 
the outputdir package option, or may be using an incompatible build tool,
or may be using frozencache with a missing file.

See the minted package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.18 \end{mylisting}

? 
! Emergency stop.
 ...                                              

l.18 \end{mylisting}

 442 words of node memory still in use:
   2 hlist, 1 rule, 3 dir, 7 attribute, 59 glue_spec, 7 attribute_list, 2 temp,
 2 write, 1 pdf_colorstack nodes
   avail lists: 2:20,3:4,4:2,7:2,8:1,9:2
!  ==> Fatal error occurred, no output PDF file produced!
Transcript written on mwe.log.

If you take mweout out of listing file, it works, of course. Uncommenting the \usepackage[outputdir=mweout]{minted} doesn't help, I get a similar error.

How can I have listings in tcblisting output to a subdirectory and formatted by minted?

I'm not sure whether tcolorbox issues 9 and/or 12 may be relevant here but I couldn't discern any useful help from them.

3

If you look into the mweout directory, you'll find the file listing.tex. It's the file where your listing is temporarily saved by LaTeX. The .tex extension is added automagically. However, minted tries to find mweout/listing without any extension and fails. To make things work just add any extension to the listing file option. For example, the following code works fine:

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{minted,raster,skins,xparse}

\NewTCBListing{mylisting}{ O{} }{
  listing only,
  #1,
}

\begin{document}
\begin{mylisting}[listing file=mweout/listing.tex]
  \LaTeX is fun.
\end{mylisting}
\end{document}

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.