pythontex
pythontex copied to clipboard
Sympy latex formatting in \pycon
Hi,
I have defined several sympy variables in a pycon
environment.
\begin{pyconcode}
from sympy.abc import a,b
\end{pyconcode}
and I want to do this later in the document \pycon{a/b}
and get this formatted using latex as a fraction, something like $\frac{a}{b}$.
Is this possible?
Thanks!
There isn't currently a built-in way to do this; \pyconc
always gives literal console output, and there isn't an easy way to have output interpreted as LaTeX code. Ultimately, this is similar to #55--you're running into limitations of the current treatment of console code.
In this case, my suggestion would be to run the code in both pycode
and pyconcode
, perhaps using the same tempfile trick from #55. Then you could access what you want using \py
plus the latex()
function from SymPy. Or you could use the sympycode
environment and \sympy
command to automate the LaTeX conversion.
I plan to add functionality that will make this sort of thing much simpler, but unfortunately progress on the next release is slow.
Will using this temp file method interfere with later depythontex processing?
Currently, depythontex only works with the built-in commands and environments. So it wouldn't work with my proposed solution, not because of the temp file, but just because of the fact that a new environment would be defined.