Skip to content

Incorrect caching of variables' latex_name attribute #17559

@sagetrac-wonder

Description

@sagetrac-wonder

Saving and loading variables apparently doesn't reload the latex_name attribute:

┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.4.1, Release Date: 2014-11-23                       │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: xhat = SR.symbol( 'xhat', latex_name='\hat{x}' )
sage: latex(xhat)
\hat{x}
sage: save_session( 'xhat' )
sage: l = load( 'xhat.sobj' )
sage: latex( l['xhat'] )
\hat{x}
sage: 
Exiting Sage (CPU time 0m0.20s, Wall time 2m49.25s).
┌────────────────────────────────────────────────────────────────────┐
│ Sage Version 6.4.1, Release Date: 2014-11-23                       │
│ Type "notebook()" for the browser-based notebook interface.        │
│ Type "help()" for help.                                            │
└────────────────────────────────────────────────────────────────────┘
sage: l = load( 'xhat.sobj' )
sage: latex( l['xhat'] )
\mathit{xhat}

It looks as if it tries to keep these objects unique, and load() will leave an existing variable's latex_name in place, but won't set it when creating a variable.

I can see arguments for and against considering SR.symbol('x', latex_name='y') a different variable from SR.symbol('x'). It seems reasonable to consider them the same, in which case the latex name should be discarded if there's already a variable of the same name. But it should use the saved latex name when loading a variable that isn't already defined.

Seems possibly related: #5466

Update: I think this report, posted to sage-support today, is the same issue:

If you do something like this

sage: a = var('a',latex_name='BLAH')

and then
sage: a = var('a') 
sage: latex(a) 
BLAH 
So the first a=var(...) did have an impact on the second one, no?

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/17559

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions