Skip to content

Consider having option to label sympy expressions with their python name #37

Description

@gutow

This would require adding another option to output formatting (e.g. sympy_expr_labels). When requested sympy expressions would be labeled with the python name for the expressions just as equations are by default.

The operation to extract equation labels could be used more generically and not be a part of the expression object. Rough code to get the necessary string for the label would be:

def _get_eqn_name(expr):
    """
    Tries to find the python string name that refers to a sympy object. In
    IPython environments (IPython, Jupyter, etc...) looks in the user_ns.
    If not in an IPython environment looks in __main__.
    :return: string value if found or empty string.
    """
    import __main__ as shell
    for k in dir(shell):
        item = getattr(shell, k)
        if isinstance(item, Basic):
            if item == expr and not k.startswith('_'):
                return k
    return ''

This could also take over for the similar function currently embedded in the equation type, further removing output tweaking from sympy proper.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions