Closed emeth69 closed 9 months ago
minted
is intended for typesetting code, not running code. escapeinside
allows small snippets of LaTeX code to be included within computer code that is otherwise typeset verbatim. It is not intended for \input{|...}
or \write18
.
I'd suggest saving the output of each of your \input{|...}
or \write18
in a file, and then \inputminted
those files individually.
Unfortunately to write to a file doesn't work in my scenario. I'd like to keep the version of a REPL that I'm showing aligned with the version of the REPL installed. So most of the code will be the same but just few characters depends on where the document is compiled.
What I'm suggesting is extending what you are doing in
\immediate\write18{ocamlc -version > /tmp/ocaml-version.txt}
\input /tmp/ocaml-version.txt
to the other programs. That is, use \input{|...}
or \write18
to run your external program, but then save/redirect the output into a file. Then \inputminted
that file (if you really need some kind of minted
formatting). This should get you current version info without running into incompatibilities with trying to run code within minted
. For \input{|...}
, you could probably use some shell scripting to wrap your version number with \mint
or \mintinline
like \mint{<lang>}{<version>}
and skip the temp file altogether.
Hi, this doesn't work but maybe I didn't got you hint correctly:
\documentclass[9pt,xcolor=svgnames]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[scaled=.90]{beramono}
\usepackage{filecontents} % to overwrite generated files
\usepackage[cachedir=.\jobname-cache]{minted}
\setminted{fontfamily=tt,fontsize=\footnotesize,encoding=utf8,style=trac,escapeinside=``}
\begin{filecontents*}[overwrite]{/tmp/escapeinside-bug.txt}
`\immediate\write18{scalac -version > /tmp/ocaml-version.txt}
\input /tmp/ocaml-version.txt`
\end{filecontents*}
\begin{document}
\textcolor{red}{In Minted}
\inputminted{shell-session}{/tmp/escapeinside-bug.txt}%
\end{document}
It compiles but it prints:
%%%% This is file `.tex',%% generated with the docstrip utility.%%%% The original source files were:%%%% fil...
even if the included files contains 4.12.0
Furthermore if I try to pipe the result of the command to grep some specific portions (as in | grep -o '[[:digit:]]*[.][[:digit:]]*[.][[:digit:]]*'
) I get:
! TeX capacity exceeded, sorry [input stack size=10000].
\curr@fontshape ->\f@encoding
/\f@family /\f@series /\f@shape
l.2 ...*[.][[:digit:]]*'> /tmp/ocaml-version.txt}}
! ==> Fatal error occurred, no output PDF file produced!
I did something wrong?
That is still trying to mix minted
with executable code.
Why not just use
\immediate\write18{scalac -version > /tmp/ocaml-version.txt}
\input /tmp/ocaml-version.txt
or something similar directly? If you want a different font or text color, you can always add a \textcolor
or texttt
command around the inputed version.
Because my MWE shows just the critical part of the what I'm passing to minted. In the real case I'm passing to minted a complete program (a REPL session transcript to be honest) where only a small portion is changed by my command. In my view to put the whole transcript in the post was too much but if you think it can help I can post it. Sorry for the confusion.
I don't have any more suggestions for this. minted
can't really emulate a REPL by mixing in \write18
, so you'll have to find another way to do what you want.
This message is just for those coming here with the same problem. I have solved it:
\documentclass[9pt,xcolor=svgnames]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[scaled=.90]{beramono}
\usepackage{filecontents} % to overwrite generated files
\usepackage[cachedir=.\jobname-cache]{minted}
\setminted{fontfamily=tt,fontsize=\footnotesize,encoding=utf8,style=trac,escapeinside=``}
\begin{filecontents*}[overwrite]{/tmp/escapeinside-bug.txt}
`!/tmp/version.txt!`
\end{filecontents*}
\immediate\write18{scalac -version | grep -o '[[:digit:]]*[.][[:digit:]]*[.][[:digit:]]*'> /tmp/version.txt}
\begin{document}
\begingroup
\catcode`\!=\active
\def!#1!{\input #1}
\inputminted{shell-session}{/tmp/escapeinside-bug.txt}%
\endgroup
\end{document}
There are few limitations in this solution, e.g., the file name can't contain a -, you have to enable pdflatex to write out of the current dir,... but this is a good starting point.
Dear Minted Experts, I'm trying to run some (linux) commands insides a minted piece of code without success.
This is a MWE
The MWE shows different ways to run linux commands both in plain LaTeX and through a minted piece of code.
When I compile it with:
openout_any=a pdflatex --enable-pipes --shell-escape MWE.tex
I get:All the approaches work perfectly when in normal LaTeX (in spite of the error message about --enable-pipes) but they fail when I escape from \inputminted. I have tried different escape characters without any lucky.
I'm using pygmentize 2.16.1, minted v2.7, pdfTeX 3.141592653-2.6-1.40.24 and kpathsea version 6.3.4.
Any help is appreciated.
Thank you