Ask Your Question

How to change _latex_ of log to \ln ?

asked 2011-06-03 01:23:33 -0500

And also more changes, for example: tan to \tg, sin to \sen etc. It's very common to use this small differences in classes in Portugal.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2011-06-03 08:30:34 -0500

kcrisman gravatar image

updated 2011-06-03 08:42:57 -0500

You'd have to probably change the code slightly. Of course, in the long run this sort of thing should be fully localizable, but for now it's not done so easily.

sage: sage.functions.trig.Function_tan??
GinacFunction.__init__(self, "tan", latex_name=r"\tan")

So if you changed that to latex_name=r"\tg" you might be in business! That would work for the name as well to some extent, though one might have to be careful with making sure one actually got it back to Ginac - the code for sage.symbolic.function.Function should have much info.

You'd have to build your changes, of course.

I'll try to see if one can do this in a running session; one might have to reinitialize it, but the init signature is different for Function_tan than for GinacFunction.

No matter how many ways I try to do things like

sage: tan.__setattr__('_latex_name',r"\tg")
sage: tan._latex_name
sage: latex(tan)

it doesn't seem to quite work. I just can't get it it initialize this.

edit flag offensive delete link more


If I am not mistaken, the attribute _latex_name is a cdef attribute, so, not easily overridden. So, it looks like a missing feature to me: There *should* be methods set_name() and set_latex_name(), that can be used to determine how a function is printed on screen resp. how it appears in LaTeX. Shall I open a ticket for it?

Simon King gravatar imageSimon King ( 2011-06-03 21:58:15 -0500 )edit

That's a great idea.

kcrisman gravatar imagekcrisman ( 2011-06-04 02:17:49 -0500 )edit

Related to this: ; And in particular this comment: "...there should be a class _latex_() method to override, I just can't find it at the moment. Maybe someone with more familiarity can chime in. - benjaminfjones (May 09)"

Pedro Cruz gravatar imagePedro Cruz ( 2011-06-04 03:26:41 -0500 )edit

It is a bit disappointing that the latex name (or the name) are not used when evaluating the function: Using a new method set_name() and set_latex_name(), I changed the names of tan such that it is printed `tg` on screen and `\tg` in latex. But when I did `tan(x)` or `latex(tan(x))`, the new name "tg" was not used. Does someone have an idea how that can be solved?

Simon King gravatar imageSimon King ( 2011-06-04 04:03:56 -0500 )edit

The ticket is #11428. I didn't upload a patch, because I can only make latex(tan) customizable, but then latex(tan(x)) won't change, sadly.

Simon King gravatar imageSimon King ( 2011-06-04 06:54:35 -0500 )edit

answered 2011-06-03 06:59:49 -0500

I'm not exactly sure how this is a Sage question but in your LaTeX preamble you can write


so that whenever you write "\tg" in the LaTeX code is will appear as "tan" in the document.

edit flag offensive delete link more


Thank you for the tex declaration. This is a good solution. The other could be something changing the _latex_ method but I don't know how to do it avoiding changes in latex "preamble". I seems to me that one has to forget \log and then redefine it. \let\tan\undefined \DeclareMathOperator*{\tan}{tg}

Pedro Cruz gravatar imagePedro Cruz ( 2011-06-03 07:06:43 -0500 )edit

No worries. I think kcrisman's answer is at least starting to head in the direction of what you're looking for.

cswiercz gravatar imagecswiercz ( 2011-06-03 08:44:58 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools


Asked: 2011-06-03 01:23:33 -0500

Seen: 628 times

Last updated: Jun 03 '11