I use Pythontex for formatting Python source code. I store code in a macro. I need to pass this code to one of the Pythontex commands (e.g. \pyv) and get the formatted code.
Code:
\documentclass{article}
\usepackage{pythontex}
\begin{document}
\def\foo{x = 3}
\pyv{\foo}
\end{document}
Result:
\foo
The macro \pys does this, but doesn't format the code.
\expandafter\pyv\expandafter{\foo}. This causes the\foomacro to be expanded before\pyv. – frougon Jan 22 '20 at 18:47