Operators missing in TLatex.cxx

Hi there,

Operators “\tilde{” & “\slash{” were not present in method TLatex::CheckLatexSyntax() whereas operators “#tilde{” & “#slash{” were. So I added them and as I’m interested in undestanding how this function works for reasons I’ll explain in a later post, I made a bit of cleaning, namely:

  • several comments were added
  • some variables were renamed for consistency
  • some variables were added for consistency and to avoid “floating” hardcoded numbers (see lmaxkLeftRight and lmaxkWords)
  • some variables were removed because they were (then) useless (nOfSquareBracket, nOfExtraCurly, nOfExtraSquare)
  • some statements were removed because they were useless (nOfExtra* in/decrementation, nOfSquareBracket tests at the end, buf[1]=0)
  • the size and length of each element in keyword arrays is now computed automatically to avoid hardcoded errors.
    Those changes were validated against all $ROOTSYS/tutorials/graphics/latex*.C (visual inspection and diff against .ps output files).
    Attached’s the diff file against master and patch branch (same file).
    Could you please commit this in order not to make tens of different changes in various parts of the code in one go?

Cheers,
Z
TLatex.cxx.diff.txt (14.9 KB)

I will check but in principal the \ control os for TMathText … not TLatex …
(sorry for the late answer I was away)

Hi Olivier,
Glad you’re back :wink:
Actually all operators (except tilde & slash) are currently doubled in TLatex.cxx
("#frac{" & “\frac{”, …).
M

Hello Mathieu,

Yes you are right in CheckLatexSyntax both are checked. But I am afraid that now the \ control is useless because in TLatex::PaintLatex we have:

[...]
   // Paint the text using TMathText if contains a "\"
   if (strstr(text1,"\\")) {
      TMathText tm;
      tm.SetTextAlign(GetTextAlign());
      tm.SetTextFont(GetTextFont());
      tm.PaintMathText(x, y, angle, size, text1);
      if (saveps) gVirtualPS = saveps;
      return;
   }
[...]

Hi Olivier,

As I understand it (browsing the code and reading the user’s guide), histogram and graph axes are drawn using TGaxis::PaintAxis() which calls TLatex::PaintLatex().
So IMHO “\xxx{” operators should be kept and “\tilde{” & “\slash{” should be added.

Did you have time to look at the patch above?

Cheers,
M

PS: By the way, as this was not clear to me: TMathText is not an alternative to TLatex (see [url=https://root-forum.cern.ch/t/latex-in-histogram-titles/16902/14
PPS: [url=https://root-forum.cern.ch/t/tmathtext-further-limitations/18259/1 are some limitations I found on the way.

TMathText is the Latex Math mode. It is not a replacement of TLatex. But it render the Math formulae in a closer look and feel to what LaTeX would do. Also it implements some character TLatex does not have like \ell. Also it implements Japenese and Russian. As I said the convention is now that when TLatex is called with \ inside the string, then TMathText is called. I saw your patch, but seems to me it is not really useful. I would rather remove the support of \ in TLatex as it would be confusing now. Unless you can show me a case where your change is needed.
I will look at you other post.

[quote]I saw your patch, but seems to me it is not really useful[/quote]If adding comments is useless, why not remove them all?
Let me say it again:

[quote][quote]As I [was] interested in undestanding how this function works […], I made a bit of cleaning, namely:

  • several comments were added
  • some variables were renamed for consistency
  • some variables were added for consistency and to avoid “floating” hardcoded numbers (see lmaxkLeftRight and lmaxkWords)
  • some variables were removed because they were (then) useless (nOfSquareBracket, nOfExtraCurly, nOfExtraSquare)
  • some statements were removed because they were useless (nOfExtra* in/decrementation, nOfSquareBracket tests at the end, buf[1]=0)
  • the size and length of each element in keyword arrays is now computed automatically to avoid hardcoded errors.[/quote][/quote]IMHO, making a code more readable IS useful!
    Besides, as it is said in that first post, this first patch is not meant to provide any new functionalities. It is just a first step towards something else (namely adding new operators).

[quote]I would rather remove the support of \ in TLatex as it would be confusing now.[/quote]Wouldn’t you break backward compatibility then?

Cheers,
M

Is it ok to apply it on the trunk only (ie ROOT 6) ?