pythontex icon indicating copy to clipboard operation
pythontex copied to clipboard

Sympy latex formatting in \pycon

Open reckoner opened this issue 8 years ago • 3 comments

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!

reckoner avatar Oct 04 '15 17:10 reckoner

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.

gpoore avatar Oct 04 '15 23:10 gpoore

Will using this temp file method interfere with later depythontex processing?

reckoner avatar Oct 06 '15 14:10 reckoner

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.

gpoore avatar Oct 06 '15 15:10 gpoore