I would like to use latex symbols in my histogram titles and axis labels, but I have run into a few issues.
First, how do I simply display a # sign without it being interpreted as the escape character for TLatex? Using two ## gives me back two ## signs.
Secondly, I would like to export this to a tex output and often have something written in latex as:
This would render only the $\Delta E$ in math mode and the rest in normal mode. I do not know how to accomplish this in ROOT. I can write the label in ROOT as
but this causes in error in latex as the outputed latex label is
$Energy Difference (\DeltaE) and \DeltaE is an unknown control sequence. If I then change the ROOT label to
Energy Difference (#Delta E) the error about \DeltaE is avoided, but the label is rendered entirely in math mode removing all the spacing even that which was anticipated between Energy and Difference.
Of course this can easily be corrected by adjusting the resultant tex output, but the idea is to minimize this type of editing. Would this be considered a bug or ignorance of TLatex on my part?
The single # sign does not always work. For example the following will not display a # sign:
I realize if I wrap the #4 in an mbox then it will appear again, but this solution is not immediately apparent.
The issue I seem to have trouble understanding is why ROOT renders latex in what appears to be opposite to what one would expect. Usually you would need to initiate math mode to make symbols with the $, but it appears ROOT defaults to math mode and you have to escape it with mbox. Does TLatex recognize the math mode escape character, $ ? Is there a way to make TLatex follow the latex standard more closely?
It would be simpler and clearer if one code write the Latex titles as
As soon as you use a \ in a text then the TMathText tool is used.
TMathText, as its name indicates, enter the Math mode of TeX
Which means it is like having virtual $ $ around your text.
So you are in math mode always. therefore if you want text with space you enclose with mbox.
So I guess there is nothing to fix. I can mark this issue as solved.
Why is it treated this way? I would have expected TLatex to handle math mode as well with the $ characters.
The only bug I could see then would be when exort the following label to latex:
It does not invoke TMathText as there is no , but causes error in latex since the control sequence \DeltaE is written in the tex file. Also the text “Energy Difference” is rendered in math mode in the tex file.
So the end result is that whenever using latex titles and exporting to tex one has to wrap normal text in mbox?
[quote=“couet”][quote]
Why is it treated this way? I would have expected TLatex to handle math mode as well with the $ characters.
[/quote]
The Class TMathText is meant to render LaTeX Math mod … See the help of this class. That’s not LAtex Text, That’s Latex Text in MAth mod[/quote]
My point here is that I feel ROOT is treating the Latex rendering in a sort of strange way. I would expect TLatex to be a class that can handle any latex even math mode. Instead of automatically switching to use TMathText when \ is in the label and rendering the entire label why can’t only a portion be rendered in that way? I would like to use the $ to evoke math mode as one does in Latex and then render everything outside in a normal text mode.
To summarize I would expect TLatex to see the $$ and render that portion with TMathText and render the rest as normal Latex.
That’s not how it is … TLatex is the old TLatex class which is in ROOT since the beginning. It did not have a very good quality to render math formulae. A new Class written by a ROOT user: TMathtex has been introduced recently. It is math mod !!! it assumes …To facilitate the migration TLatex call TMathtex if there is \ in the string. Then I have implemented the Tex output … That is really TeX now … Also it encloses the output with $$ as soon as there is Math character like Greek …
I understand there are many projects that need attention and I appreciate your discussion so far.
Of course I can do as you suggest, but I still believe that this is fundamentally just a hack around a bug. I will continue to just correct the labels in the tex output, but I believe this issue should be tracked and taken care of at some point in the future. The implementation of latex labels in ROOT should follow the latex syntax more closely and only render in math mode when it is indicated by the user with the $ symbol.
Looking closer it seems not realistic to pretend that TLatex will match exactly Latex in TTexDump. The control character # is one thing, but there is many other TLatex extension which do not have equivalent in the normal Latex (#kern, #splitline, etc …). So it is better to leave it as it is right now.