How to write prime in TLatex

Hi, I want to write S’_{L} in the legend of my histogram, how can I put the prime symbol using TLatex in ROOT ?

ROOT Version: 5.34/09
Platform: Scientific Linux

root [0] auto t = new TLatex(.5,.5,"this is prime: '")
root [1] t->Draw()

Screenshot 2022-09-27 at 14.53.31

But, this is the same as apostrophe.
I want like this S^\prime_L
Is there anyway to write this in TLatex ?

auto t = new TLatex(.5,.5,"S^{'}_{L}")

Screenshot 2022-09-27 at 15.03.53


auto t = new TLatex(.5,.5,"S^{\\prime}_{L}")

Screenshot 2022-09-27 at 15.31.50


auto t = new TLatex(.5,.5,"S_{L}\\prime")

Screenshot 2022-09-27 at 15.35.06
indeed simply use what you would use in LaTex.

Can β€œS^{\prime}_{L}” be written inside legend->AddEntry() ?

Yes sure. Note you need 2 β€œ\”:

  TCanvas *c2 = new TCanvas("c2","c2",500,300);

  TLegend* leg = new TLegend(0.2, 0.2, .8, .8);

  TH1* h = new TH1F("", "", 1, 0, 1);

  leg->AddEntry(h, "Histogram \"h\"", "l");
  leg->AddEntry((TObject*)0, "", "");
  leg->AddEntry((TObject*)0, "Some text", "");
  leg->AddEntry((TObject*)0, "", "");
  leg->AddEntry(h, "Histogram \"h\" again", "l");
  leg->AddEntry(h, "TMathText: S^{\\prime}_{L}", "l");


Screenshot 2022-09-28 at 09.51.18

Note the TMathText limitation: TMathText rendering is not implemented for the PDF output. PostScript output should be used instead.

Thanks for the showing the command to write prime in the the legend of the histogram.
But, there is one problem I am facing with this command is that - the statement that is written prior to S^{\\prime}_{L} gets printed in italics format and without any spaces like the one in the following picture. Is there a way to mitigate this problem ?

TMathText renders text as Latex Math formulae. So it follows the Latex Math formulae rules (see a Latex manual). So yes, it is always italic, and yes the spaces are ignored. To make spaces you can for instance do:

  leg->AddEntry(h, "After\\;Mass\\;Cut, S^{\\prime}_{L}", "l");

As a suggestion/alternative idea:

When I want full latex control, what I usually follow is Saving Canvas as TeX - ROOT

For the β€˜italics’ issue, what I would do in that case is something like

1 Like

Instead of β€œS_{L}^{\\prime}”, you may like β€œS_{L}{\\!\\!\\prime}” or β€œS_{L}{\\!\\!\\'}”.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.