# SaveAs(.pdf) cannot handle TMathText

**URL:** <https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905>\
**Category:** ROOT\
**Tags:** graphics, bug, root\
**Created:** [April 15, 2020, 8:08pm UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905 "2020-04-15T20:08:16Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [April 15, 2020, 8:08pm UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/1 "2020-04-15T20:08:16Z")

</div>

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.

* * *

```python
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](https://root-forum.cern.ch/uploads/default/original/3X/d/9/d9d18ebf6fd9ff71d2565f3d7c249f87c26021c3.pdf)

 ![example](https://root-forum.cern.ch/uploads/default/original/3X/4/d/4d8015c8bf58e41c0830549205bd89a9b444554c.png)

* * *

_ROOT Version:_ 6.18.04  
_Platform:_ x86\_64-centos7-gcc8-opt  
_Compiler:_ Not Provided

* * *

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 16, 2020, 6:19am UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/2 "2020-04-16T06:19:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [April 16, 2020, 12:18pm UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/3 "2020-04-16T12:18:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 16, 2020, 12:24pm UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/4 "2020-04-16T12:24:39Z")

</div>

> [@mwilkins](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 16, 2020, 1:23pm UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/5 "2020-04-16T13:23:50Z")

</div>

I made a PR

> <https://github.com/root-project/root/pull/5372/files>

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

---

<div class="post-metadata">

**Author:** ![mwilkins](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mwilkins/32/28332_2.png) [@mwilkins](https://root-forum.cern.ch/u/mwilkins)\
**Post date:** [April 16, 2020, 1:47pm UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/6 "2020-04-16T13:47:03Z")

</div>

Ah, thank you. I made an independent [pull request](https://github.com/root-project/root/pull/5374) adding the documentation to `TPad::SaveAs`, `TPad::Print` as well. I think both are important. Thanks again.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 16, 2020, 1:50pm UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/7 "2020-04-16T13:50:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![otnikuda](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/o/9fc348/32.png) [@otnikuda](https://root-forum.cern.ch/u/otnikuda)\
**Post date:** [April 18, 2020, 6:33am UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/8 "2020-04-18T06:33:15Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [April 20, 2020, 7:51am UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/9 "2020-04-20T07:51:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [May 4, 2020, 7:51am UTC](https://root-forum.cern.ch/t/saveas-pdf-cannot-handle-tmathtext/38905/10 "2020-05-04T07:51:31Z")

</div>

Closed on May 4, 2020, 7:51am UTC

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