I found this post by the creator of PythonTeX himself. However, running the below code doesn't work for me; I get an error "Something's wrong--perhaps a missing \item. \end{pyblock}". I'm not convinced that the \pyc command is actually having the macro expanded.
Where am I going wrong? I'm trying to use package keyval to provide a nice interface to some TeX commands which pass the values on to Python, but in order to do that I need to be able to expand the TeX macros which are the key-values so that Python may consume them.
\documentclass{standalone}
\usepackage{pythontex}
\usepackage{lipsum}
\begin{document}
\pyc{mytext = """\lipsum[4]"""}
\begin{pyblock}
print(mytext)
\end{pyblock}
\end{document}
I've created an even simpler example below.
\documentclass{standalone}
\usepackage{pythontex}
\def\x{2}
\begin{document}
\pyc{print(\x)}
\end{document}
- PythonTeX stderr - error on line 8:
File "C:\Users\aosborne\AppData\Local\Temp<outputdir>\py_default_default.py", line 50
print(\x)
SyntaxError: unexpected character after line continuation character
\printpythontexafter thepyblockenvironment which apparently is not intended to produce output. – Don Hosek Dec 22 '20 at 22:19standalonereplaced witharticle, and packagepythontexloaded with optiongobble=auto, it works. – muzimuzhi Z Dec 22 '20 at 23:15