SaveAs(.pdf) cannot handle TMathText

It appears that TCanvas::SaveAs(.pdf) converts all escaped TMathText symbols to TLatex, which, of course, fails when TLatex encounters a symbol it doesn’t know, resulting in literal strings of LaTeX code displayed in the file. This seems to only happen with .pdf files; .eps and .png files, for example, work fine. Reproducer below.


can = ROOT.TCanvas()
df = ROOT.RDataFrame(10).Define('e', 'rdfentry_')
h = df.Histo1D('e')
h.SetTitle(r'\mathcal{B}_\text{foo}')  # example of TMathText that cannot be TLatex
h.Draw()
can.SaveAs('example.pdf')  # displays Title as "#mathcal{B}_#text{foo}"
can.SaveAs('example.png')  # displays Title properly

example.pdf|attachment


ROOT Version: 6.18.04
Platform: x86_64-centos7-gcc8-opt
Compiler: Not Provided


This is known. The TMathText is not implemented for the pdf format. Use PS instead.

There are publication requirements mandating that I produce .pdf files. Currently, I work around this by converting to .pdf after the fact, but I cannot simply use .ps files.

I will make a pull request adding this known limitation to the documentation.

Yes thanks. But I can do it. It can be added on the TMathText class doc. I will do it.

I made a PR

Let me know if that’s what you had in mind.

Ah, thank you. I made an independent pull request adding the documentation to TPad::SaveAs, TPad::Print as well. I think both are important. Thanks again.

Yes better put it in several places. I will push both .
Thanks.

@couet can you please write “short summary” about difference between EPS, PS and PDF files produced by ROOT ? Do we need something like: ROOT.SaveAs (“ps or ?eps?”) => ps2pdf => publication ? Which option is best for publication in journal ?

Thanks

PS is PostScript, one can have several pages in the same file. It supports TMathText. EPS does also support it. It is Encapsulated PostScript and only one page is allowed in it. It is meant to be included in LaTex documents (for instance). PDF is classic PDF and does not support TMathText. You can also generate TeX natives file to be included in LaTeX documents and of course full LaTeX is supported there.

1 Like

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