Giter VIP home page Giter VIP logo

Comments (8)

gpoore avatar gpoore commented on August 14, 2024

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.

from minted.

emeth69 avatar emeth69 commented on August 14, 2024

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.

from minted.

gpoore avatar gpoore commented on August 14, 2024

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.

from minted.

emeth69 avatar emeth69 commented on August 14, 2024

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?

from minted.

gpoore avatar gpoore commented on August 14, 2024

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.

from minted.

emeth69 avatar emeth69 commented on August 14, 2024

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.

from minted.

gpoore avatar gpoore commented on August 14, 2024

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.

from minted.

emeth69 avatar emeth69 commented on August 14, 2024

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.

from minted.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.