Use of Latex fonts ("mathcal") for axis labels in root

___Hi, how can I use different fonts, in this case the Latex font “mathcal” to label properly the axis of a histogram or plot ??

Welcome to the ROOT forum

What do you mean by “mathcal” ? that’s not a ROOT font.
Can you post the TLatex command you are using ?

Hi,
in Latex we write things like \mathcal{P}_{\tau}
The mathcal{P} font makes a more artistic “P”, similar to the “L” which is often used for Luminosity
The problem is precisely that the choice of fonts in ROOT is very limited

When you use a backslash (\) in TLatex, the class TMathText is automatically invoked. This class implements the LaTex math formulae which have one font only (see LaTeX Doc) That’s why in that case there is no possibility to change the font: It is a LaTex Math formula.

Thanks for your feedback; so my conclusion that is impossible to do what I wanted within ROOT is correct. My work around is to combine the text and the root figure with some other software…

Regards

I am not sure what you “wanted to do” is, so I can’t tell if it is impossible or not to do it with ROOT.

You could save your canvas as .tex and then fine tune the result by hand opening with a tex editor

The math formula will be fixed font again… As I said it is a LaTex feature.

See here what the user mentioned about mathcal: Mathematical fonts - Overleaf, Online LaTeX Editor

One could open the stored .tex and replace by hand the axes titles with any custom commands required.

Yes, tweaking is always possible. I am just telling that the standard Math formala LaTeX is fixed font.

Hi thanks for all the suggestions.
Yes I saved the canvas in Tex format and it somehoe executes in overleave with quite a few errors, because it does not understand all root syntax (scale[1.5]) commands and the font definitions of ROOT, so again you need again a lot of editing to get what you want.
So unless there is a script at CERN to reprocess the root.tex file exactly the way root is producing his plot, this did unfortunately not do what I wished for…
Thanks again anyway!

Can you provide the .tex as an example?
What are the errors you see?

When you save as .tex, you can directly write in your axis titles the latex code you want later to run.

A small reproducer (c++ macro) showing what you do will be useful.

Yes I see the lines in the Tex file and adding the mathcal{P} was easy, but then lots of other things dont work anymore as in ROOT.
Here some parts of the ROOT tex output :
I added the first lines to process in Overleaf:

\documentclass[crop,tikz]{standalone}
\usepackage{graphicx} % Required for inserting images
\usepackage{tikz}
\title{best_fit}
\author{ulrich.goerlach }
\date{June 2023}

\begin{document}
% here the ROOT output
\begin{tikzpicture}
\pgfdeclareplotmark{cross} {
\pgfpathmoveto{\pgfpoint{-0.3\pgfplotmarksize}{\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{+0.3\pgfplotmarksize}{\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{+0.3\pgfplotmarksize}{0.3\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{+1\pgfplotmarksize}{0.3\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{+1\pgfplotmarksize}{-0.3\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{+0.3\pgfplotmarksize}{-0.3\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{+0.3\pgfplotmarksize}{-1.\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{-0.3\pgfplotmarksize}{-1.\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{-0.3\pgfplotmarksize}{-0.3\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{-1.\pgfplotmarksize}{-0.3\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{-1.\pgfplotmarksize}{0.3\pgfplotmarksize}}
\pgfpathlineto{\pgfpoint{-0.3\pgfplotmarksize}{0.3\pgfplotmarksize}}
\pgfpathclose
\pgfusepathqstroke
}}

%problems occur with lines like this:
%\draw [anchor= east] (3.2949,4.81447) %node[scale=1.16991,color=c,rotate=0{\scale[1.8]{\rho\tau_{h}}};
%\draw [anchor= east] (3.2949,6.00839) node[scale=1.16991, color=c, %rotate=0{\scale[1.8]{a_{1}a_{1}}};

%doesn’t like the \scale[1.8] command

%also the line
\draw [anchor=base west] (4.2,18.7462) node[scale=1.79386, color=c, rotate=0]{\font[62]{\scale[1.5]{CMS }} \font[42]{ 36.3 fb^{-1} (13 TeV)}};
%does not work as expected, \font is not known… it does not plot CMS and the rest of the text is in math style (italic)
the line I wanted to change
\draw [anchor= east] (19.95,1.57226) node[scale=2.02784, color=c, rotate=0]{Average polarization <\mathcal{P}_{\tau}>};
% worked correctly after changing to
\draw [anchor= east] (19.95,1.57226) node[scale=2.02784, color=c, rotate=0]{\textrm{Average polarization} <\mathcal{P}_{\tau}>};

So unless there is a package which can process the root.tex file correctly, I will just merge two PDF files into one using Powerpoint or similar…

Thanks for your help

Did you include the required packages as explained in the instructions I linked above?

\usetikzlibrary{patterns}
\usetikzlibrary{plotmarks}

No I didn’t but doing so had no effect.

If you like you can look and edit the file at overleaf dot com
/7869854493kyrmzjwmrcps

why can’t I post a simple link

Hi @couet this seems like a bug in ROOT. The file exported as tex contains the commands scale and font which are not defined anywhere. ROOT should strip that part or define these commands in the beginning using mbox or sth like that.

I would like to have this (hopefully small) macro generating that .tex file so I can try myself to generate the .tex file and include it in a LateX doc to de visualized (as explained here)

@Goerlach can you please let us know what statement you use in your C++ or Python script for defining this:
36.3 fb^{-1} (13 TeV)

I use the following:

TPaveText *pt = new TPaveText(0,0,1,1,"brNDC");
   pt->SetBorderSize(0);
   pt->SetFillStyle(0);
   pt->SetTextAlign(12);
   pt->SetTextFont(42);
   pt->SetTextSize(0.04);
   TText *pt_LaTex = pt->AddText(0.2,0.93,"#font[62]{#scale[1.5]{CMS            }} #font[42]{     36.3 fb^{-1} (13 TeV)}");
   pt_LaTex->SetTextAlign(11);
   pt->Draw();

which runs in root.
It seems the #font and #scale do not get translated properly into the tex file…