root icon indicating copy to clipboard operation
root copied to clipboard

TLatex interpreter bug

Open edbird opened this issue 4 years ago • 8 comments

  • [X] Checked for duplicates

Describe the bug

The following string fails to be interpreted by TLatex

#frac{#int^{5}_{0} dX}{#int^{5}_{0} dX}

Expected behavior

Should not crash

To Reproduce

int latextest()
{

    TCanvas *c = new TCanvas();

    TLatex latex;
    latex.SetNDC();
    latex.SetTextFont(43);
    latex.SetTextSize(20);

    TString latexstring2;
    latexstring2.Form("#frac{#int dX}{#int dX}");
    latex.DrawLatex(0.1, 0.3, latexstring2);

    TString latexstring3;
    latexstring3.Form("#frac{#int^{5}_{0} dX}{#int^{5}_{0} dX}");
    latex.DrawLatex(0.1, 0.5, latexstring3);

    return 0;
}

Setup

ROOT Version: 6.18/04 Built for linuxx8664gcc on Sep 11 2019, 15:38:23 From tags/v6-18-04@v6-18-04

Debian 10, Linux

Obtained from homebrew fork / distribution (SuperNEMO collaboration)

Additional context

See also issue in example with integral symbols overlaying fraction line.

edbird avatar Nov 20 '20 17:11 edbird

Command line error:

*ERROR<TLatex>: Missing denominator for #frac
==> #frac{#int^{5}_{0} dX}{#int^{5}_{0} dX}

image

edbird avatar Nov 20 '20 17:11 edbird

This bug Edward reports was described at the ROOT forum two years ago by me in this thread. The MWE from that thread of mine can be further simplified down to just three lines of code actually:

void drawl()
{
        TLatex l;
        l.DrawLatex(0.5, 0.3, "#frac{#int_{0} v dt}{2}");
}

This snippet crashes (when ran in 6.14/04) with the same

*ERROR<TLatex>: Missing denominator for #frac
==> #frac{@{#int_{0}} v dt}{2@}

YuryYury avatar Nov 21 '20 18:11 YuryYury

I see the error with the 6.23 also:

root [1]  TLatex l;  l.DrawLatex(0.5, 0.3, "#frac{a}{#int^{5}_{0}}");
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
Error in <TLatex::Analyse>: It seems there is a syntax error in the TLatex string
Error in <TLatex::Analyse>: It seems there is a syntax error in the TLatex string

and the plot generated is wrong.

couet avatar Feb 12 '21 09:02 couet

The following code:

{
   auto l1 = new TLatex(0.4, 0.3, "#frac{a}{#int^{5}_{0}}");  l1->Draw();
   auto l2 = new TLatex(0.5, 0.3, "#frac{a}{#sum^{5}_{0}}");  l2->Draw();
   auto l3 = new TLatex(0.6, 0.3, "#frac{a}{#prod^{5}_{0}}"); l3->Draw();
}

gives:

Screenshot 2021-02-12 at 12 52 41

so prod is ok and it has the same structure as int and sum which are not. That may help to find the bug.

couet avatar Feb 12 '21 11:02 couet

I found the culprit. Now we need to understand why this was done.

couet avatar Feb 12 '21 15:02 couet

If we revert the changes done in this commit The fraction with integral is fine, but the limits of the integral are misplaced in case a greek character appears in front of the #int.

{
   TLatex l;
   l.DrawLatex(0.2,0.5,"#nuabc#int^{1-x}_{2#pi}");
   l.DrawLatex(0.5,0.5,"#sigma^{C}_{T}");
   l.DrawLatex(0.8,0.5,"#frac{a}{#int^{5}_{0}}");

}
Screenshot 2021-02-22 at 16 56 30

couet avatar Feb 22 '21 15:02 couet

@couet what is the state of this item? Can you propose a path to the solution and implement it?

dpiparo avatar Apr 25 '24 07:04 dpiparo

I am afraid there is no fix. I spent a lot of time on it. If we fix something then something else breaks... I am afraid we should leave it as it is and use TMathText for such formulae.

couet avatar Apr 25 '24 07:04 couet