3

I'm trying to call shell commands that contain multiple (nested) quotation marks. This is, for instance, what I would write on the shell:

$ python -c "print \"Hello World\""

which produces Hello World. I found here that \input can read from the standard output when started with a |. However, it is not surprising that the following produces not what I want:

\input{|"python -c "print \"Hello World\"""} 

Similar to this question, the following works fine:

\immediate\write18{python -c "print \string\"Hello World\string\"" > \jobname.pyout}
\input{\jobname.pyout}

but requires a temporary file. Also, using \detokenize seems to work with \write18:

\immediate\write18{\detokenize{python -c "print \"Hello World\""} > \jobname.pyout}
\input{\jobname.pyout}

Is there a solution that doesn't need to write a file?

  • There is a python package that enables one to use python in TeX. Perhaps it's what you want to achieve? – Romain Picot Feb 16 '16 at 10:14
  • maybe luatex is an option for you. Instead of using python you can use lua and pass the output directly into the TeX document: \directlua{tex.print("Hello Pi: "..math.pi)} – user2478 Feb 16 '16 at 10:32
  • I look rather for a minimal solution. Ultimately, I want to call this from within tikz figures and use it with tikz's externalize library to generate pdf's from the figures. Then I could share my tex sources with people that don't have, say python, nor the files that I used in the scripts. – Philipp Feb 16 '16 at 11:00

Your Answer

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

Browse other questions tagged or ask your own question.