Skip to content

Make \py check for ._repr_latex_ #54

Open

Description

@Cadair

Some objects I have encountered have a _repr_latex method, like the _repr_html_ method for IPython notebook display. (https://github.com/astropy/astropy/blob/master/astropy/units/quantity.py#L942)

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.

edit: wrong link

Activity

  1. gpoore commented on Feb 5, 2015

    @gpoore
    Owner

    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.

  2. Cadair commented on Feb 5, 2015

    @Cadair
    Author

    Where is the default pytex.formatter code located?

  3. gpoore commented on Feb 5, 2015

    @gpoore
    Owner

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions