root-project / root

The official repository for ROOT: analyzing, storing and visualizing big data, scientifically
https://root.cern
Other
2.53k stars 1.24k forks source link

TLatex interpreter bug #6851

Open edbird opened 3 years ago

edbird commented 3 years ago

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 commented 3 years ago

Command line error:

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

image

YuryYury commented 3 years ago

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@}
couet commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

couet commented 3 years ago

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
dpiparo commented 2 months ago

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

couet commented 2 months ago

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.