I started to use the excellent PythonTex package to write reproducible reports but can't seem to get it to evaluate Python code inside a LaTeX command.
R has Sweave & knitr which provide the \Sexpr{} command that lets you access variables declared in R chunks inside a LaTeX command. This works in R with Sweave/knitr:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
<<read, engine='R'>>=
y = 4
@
The value of y is $\SI{\Sexpr{y}}{\metre}$.
\end{document}
However, the following does not seem to work in PythonTex:
\documentclass{article}
\usepackage{siunitx}
\usepackage{pythontex}
\begin{document}
\pyc{y = 4}
The value of y is $\SI{\py{y}}{\metre}$.
\end{document}
Am I missing something? Is there a way to achieve \Sexpr{} functionality in PythonTex?
Thanks for your help!