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?
luatexis an option for you. Instead of usingpythonyou can useluaand pass the output directly into the TeX document:\directlua{tex.print("Hello Pi: "..math.pi)}– Feb 16 '16 at 10:32