@@ -44,6 +44,7 @@ to the Latex's one. It provides several functionalities:
4444- [Italic and Boldface](\ref L12)
4545- [Examples](\ref L13)
4646- [Interface to TMathText](\ref L14)
47+ - [URL links](\ref L15)
4748
4849When the font precision (see `TAttText`) is low (0 or 1), TLatex is
4950painted as a normal TText, the control characters are not interpreted.
@@ -393,6 +394,21 @@ TeX syntax and uses "\\" as control instead of "#". If a piece of text containin
393394"\\" is given to `TLatex` then `TMathText` is automatically invoked.
394395Therefore, as histograms' titles, axis titles, labels etc ... are drawn using
395396`TLatex`, the `TMathText` syntax can be used for them also.
397+
398+ \anchor L15
399+ ## URL links
400+ JSROOT and standard SVG output support the syntax '#url[link]{label}'.
401+ This can be combined with other LaTeX commands, such as color or font settings.
402+ Begin_Macro(source)
403+ {
404+ auto cl = new TCanvas("cl", "Use of #url in TLatex", 1200, 800);
405+ auto latex = new TLatex(0.5, 0.5, "Link on #color[4]{#url[https://root.cern]{root.cern}} web site");
406+ latex->SetTextSize(0.1);
407+ latex->SetTextAlign(22);
408+ latex->Draw();
409+ cl->Print("cl.svg");
410+ }
411+ End_Macro
396412*/
397413
398414// //////////////////////////////////////////////////////////////////////////////
@@ -647,6 +663,7 @@ TLatex::TLatexFormSize TLatex::Analyse(Double_t x, Double_t y, const TextSpec_t
647663 Int_t opSquareCurly = -1 ; // Position of first ]{
648664 Int_t opCloseCurly = -2 ; // Position of first }
649665 Int_t opColor = -1 ; // Position of first #color
666+ Int_t opUrl = -1 ; // Position of first #url
650667 Int_t opFont = -1 ; // Position of first #font
651668 Int_t opScale = -1 ; // Position of first #scale
652669 Int_t opGreek = -1 ; // Position of a Greek letter
@@ -863,6 +880,11 @@ TLatex::TLatexFormSize TLatex::Analyse(Double_t x, Double_t y, const TextSpec_t
863880 if (i>0 && opCloseCurly==-2 ) opCloseCurly=i-1 ;
864881 continue ;
865882 }
883+ if (strncmp (buf," url[" ,4 )==0 || strncmp (buf," url{" ,4 )==0 ) {
884+ opUrl=i; opFound = kTRUE ;
885+ if (i>0 && opCloseCurly==-2 ) opCloseCurly=i-1 ;
886+ continue ;
887+ }
866888 }
867889 if (length>i+3 ) {
868890 Char_t buf[4 ];
@@ -1738,6 +1760,25 @@ TLatex::TLatexFormSize TLatex::Analyse(Double_t x, Double_t y, const TextSpec_t
17381760 Analyse (x,y,newSpec,text+opSquareCurly+1 ,length-opSquareCurly-1 );
17391761 }
17401762 }
1763+ else if (opUrl>-1 ) { // \url found
1764+ if (opSquareCurly==-1 ) {
1765+ // url is not specified
1766+ fError = " Missing url. Syntax is #url[http://...]{ ... }" ;
1767+ delete[] text;
1768+ return TLatexFormSize (0 ,0 ,0 );
1769+ }
1770+ TextSpec_t newSpec = spec;
1771+ Char_t *url = new Char_t[opSquareCurly-opUrl-4 ];
1772+ strncpy (url,text+opUrl+5 ,opSquareCurly-opUrl-5 );
1773+ fName = url;
1774+ delete[] url;
1775+ if (!fShow ) {
1776+ result = Anal1 (newSpec,text+opSquareCurly+1 ,length-opSquareCurly-1 );
1777+ } else {
1778+ Analyse (x,y,newSpec,text+opSquareCurly+1 ,length-opSquareCurly-1 );
1779+ }
1780+ fName = " " ;
1781+ }
17411782 else if (opFont>-1 ) { // \font found
17421783 if (opSquareCurly==-1 ) {
17431784 // font number is not specified
@@ -1927,7 +1968,8 @@ TLatex::TLatexFormSize TLatex::Analyse(Double_t x, Double_t y, const TextSpec_t
19271968 // paint the Latex sub-expression per sub-expression
19281969 Double_t xx, yy;
19291970 Rotate (gPad , spec.fAngle , x, y, xx, yy);
1930- gPad ->PaintText (xx, yy, text);
1971+ if (fName .Length () > 0 ) gPad ->PaintTextUrl (xx, yy, text, fName .Data ());
1972+ else gPad ->PaintText (xx, yy, text);
19311973 } else {
19321974 GetTextExtent (w,h,text);
19331975 Double_t width = w;
@@ -2310,19 +2352,19 @@ Int_t TLatex::PaintLatex1(Double_t x, Double_t y, Double_t angle, Double_t size,
23102352
23112353Int_t TLatex::CheckLatexSyntax (TString &text)
23122354{
2313- const Char_t *kWord1 [] = {" {}^{" ," {}_{" ," ^{" ," _{" ," #scale{" ," #color{" ," #font{" ," #sqrt{" ," #[]{" ," #{}{" ," #||{" ,
2355+ const Char_t *kWord1 [] = {" {}^{" ," {}_{" ," ^{" ," _{" ," #scale{" ," #color{" ," #url{ " , " # font{" ," #sqrt{" ," #[]{" ," #{}{" ," #||{" ,
23142356 " #bar{" ," #vec{" ," #dot{" ," #hat{" ," #ddot{" ," #acute{" ," #grave{" ," #check{" ," #tilde{" ," #slash{" ," #bf{" ," #it{" ," #mbox{" ,
23152357 " \\ scale{" ," \\ color{" ," \\ font{" ," \\ sqrt{" ," \\ []{" ," \\ {}{" ," \\ ||{" ," #(){" ," \\ (){" ,
23162358 " \\ bar{" ," \\ vec{" ," \\ dot{" ," \\ hat{" ," \\ ddot{" ," \\ acute{" ," \\ grave{" ," \\ check{" ," \\ bf{" ," \\ it{" ," \\ mbox{" }; // check for }
2317- const Char_t *kWord2 [] = {" #scale[" ," #color[" ," #font[" ," #sqrt[" ," #kern[" ," #lower[" ," \\ scale[" ," \\ color[" ," \\ font[" ," \\ sqrt[" ," \\ kern[" ," \\ lower[" }; // check for ]{ + }
2359+ const Char_t *kWord2 [] = {" #scale[" ," #color[" ," #url[ " , " # font[" ," #sqrt[" ," #kern[" ," #lower[" ," \\ scale[" ," \\ color[" ," \\ font[" ," \\ sqrt[" ," \\ kern[" ," \\ lower[" }; // check for ]{ + }
23182360 const Char_t *kWord3 [] = {" #frac{" ," \\ frac{" ," #splitline{" ," \\ splitline{" }; // check for }{ then }
23192361 const Char_t *kLeft1 [] = {" #left[" ," \\ left[" ," #left{" ," \\ left{" ," #left|" ," \\ left|" ," #left(" ," \\ left(" };
23202362 const Char_t *kLeft2 [] = {" #[]{" ," #[]{" ," #{}{" ," #{}{" ," #||{" ," #||{" ," #(){" ," #(){" };
23212363 const Char_t *kRight [] = {" #right]" ," \\ right]" ," #right}" ," \\ right}" ," #right|" ," \\ right|" ," #right)" ," \\ right)" };
2322- const Int_t lkWord1[] = {4 ,4 ,2 ,2 ,7 ,7 ,6 ,6 ,4 ,4 ,4 ,5 ,5 ,5 ,5 ,6 ,7 ,7 ,7 ,7 ,7 ,4 ,4 ,6 ,7 ,7 ,6 ,6 ,4 ,4 ,4 ,4 ,4 ,5 ,5 ,5 ,5 ,6 ,7 ,7 ,7 ,4 ,4 ,6 };
2323- const Int_t lkWord2[] = {7 ,7 ,6 ,6 ,6 ,7 ,7 ,7 ,6 ,6 ,6 ,7 } ;
2364+ const Int_t lkWord1[] = {4 ,4 ,2 ,2 ,7 ,7 ,5 , 6 ,6 ,4 ,4 ,4 ,5 ,5 ,5 ,5 ,6 ,7 ,7 ,7 ,7 ,7 ,4 ,4 ,6 ,7 ,7 ,6 ,6 ,4 ,4 ,4 ,4 ,4 ,5 ,5 ,5 ,5 ,6 ,7 ,7 ,7 ,4 ,4 ,6 };
2365+ const Int_t lkWord2[] = {7 ,7 ,5 , 6 ,6 ,6 ,7 ,7 ,7 ,6 ,6 ,6 ,7 } ;
23242366 const Int_t lkWord3[] = {6 ,6 ,11 ,11 } ;
2325- Int_t nkWord1 = 44 , nkWord2 = 12 , nkWord3 = 4 ;
2367+ Int_t nkWord1 = 45 , nkWord2 = 13 , nkWord3 = 4 ;
23262368 Int_t i,k ;
23272369 Int_t nLeft1 , nRight , nOfLeft, nOfRight;
23282370 Int_t lLeft1 = 6 ;
0 commit comments