You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A check to see if an object knows how to display itself under LaTeX would be pretty simple and have some very cool results. If you could point me to the section of code called by \py I might be able to take a shot at implementing this one.
Everything from \py is formatted by pytex.formatter(). By default, this is str() under Python 3 and unicode() under Python 2. All you would need to get this working is a function repr_latex_else_str(), and then pytex.formatter=repr_latex_else_str within the session before you use \py. If you want to write the function and post it here, I can think about the best way to add it into the package, either as a default or at least an option.
It's in pythontex_utils.py. There is a set_formatter() method called by the utils class __init__() that creates formatter(). The set_formatter() is mostly there to deal with the context-sensitive sympy_latex() method. There may be a better, more Pythonic way to do all this, though; that's very "old" code from very early in the project. It might be best to have formatter start off as repr_latex_else_str(), and then let it be changed by assignment (deprecate set_formatter).
Activity
gpoore commentedon Feb 5, 2015
Everything from
\pyis formatted bypytex.formatter(). By default, this isstr()under Python 3 andunicode()under Python 2. All you would need to get this working is a functionrepr_latex_else_str(), and thenpytex.formatter=repr_latex_else_strwithin the session before you use\py. If you want to write the function and post it here, I can think about the best way to add it into the package, either as a default or at least an option.Cadair commentedon Feb 5, 2015
Where is the default
pytex.formattercode located?gpoore commentedon Feb 5, 2015
It's in
pythontex_utils.py. There is aset_formatter()method called by the utils class__init__()that createsformatter(). Theset_formatter()is mostly there to deal with the context-sensitivesympy_latex()method. There may be a better, more Pythonic way to do all this, though; that's very "old" code from very early in the project. It might be best to haveformatterstart off asrepr_latex_else_str(), and then let it be changed by assignment (deprecateset_formatter).