Logo ROOT   6.12/07
Reference Guide
TTeXDump.cxx
Go to the documentation of this file.
1 // @(#)root/postscript:$Id$
2 // Author: Olivier Couet
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifdef WIN32
13 #pragma optimize("",off)
14 #endif
15 
16 #include <stdlib.h>
17 #include <string.h>
18 #include <ctype.h>
19 
20 #include "Riostream.h"
21 #include "TROOT.h"
22 #include "TColor.h"
23 #include "TVirtualPad.h"
24 #include "TPoints.h"
25 #include "TTeXDump.h"
26 #include "TStyle.h"
27 #include "TMath.h"
28 #include "TObjString.h"
29 #include "TObjArray.h"
30 #include "TClass.h"
31 
33 
34 /** \class TTeXDump
35 \ingroup PS
36 
37 Interface to TeX.
38 
39 This class allow to generate <b>PGF/TikZ</b> vector graphics output
40 which can be included in TeX and LaTeX documents.
41 
42 PGF is a TeX macro package for generating graphics. It is platform
43 and format-independent and works together with the most important TeX
44 backend drivers, including pdftex and dvips. It comes with a
45 user-friendly syntax layer called TikZ.
46 
47 To generate a such file it is enough to do:
48 ~~~ {.cpp}
49  gStyle->SetPaperSize(10.,10.);
50  hpx->Draw();
51  gPad->Print("hpx.tex");
52 ~~~
53 
54 Then, the generated file (`hpx.tex`) can be included in a
55 LaTeX document (`simple.tex`) in the following way:
56 ~~~ {.cpp}
57 \documentclass{article}
58 \usepackage{tikz}
59 \usetikzlibrary{patterns}
60 \usetikzlibrary{plotmarks}
61 \title{A simple LaTeX example}
62 \date{July 2013}
63 \begin{document}
64 \maketitle
65 The following image as been generated using the TTeXDump class:
66 \par
67 \input{hpx.tex}
68 \end{document}
69 ~~~
70 
71 Note the three directives needed at the top of the LaTeX file:
72 ~~~ {.cpp}
73 \usepackage{tikz}
74 \usetikzlibrary{patterns}
75 \usetikzlibrary{plotmarks}
76 ~~~
77 
78 Then including the picture in the document is done with the
79 `\input` directive.
80 
81  The command `pdflatex simple.tex` will generate the
82 corresponding pdf file `simple.pdf`.
83 */
84 
85 ////////////////////////////////////////////////////////////////////////////////
86 /// Default TeX constructor
87 
89 {
90  fStream = 0;
91  fType = 0;
92  gVirtualPS = this;
94  fRange = kFALSE;
95  fXsize = 0.;
96  fYsize = 0.;
97  fCurrentRed = -1.;
98  fCurrentGreen = -1.;
99  fCurrentBlue = -1.;
100  fCurrentAlpha = 1.;
101  fLineScale = 0.;
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// Initialize the TeX interface
106 ///
107 /// --fname : TeX file name
108 /// - wtype : TeX workstation type. Not used in the TeX driver. But as TTeXDump
109 /// inherits from TVirtualPS it should be kept. Anyway it is not
110 /// necessary to specify this parameter at creation time because it
111 /// has a default value (which is ignore in the TeX case).
112 
113 TTeXDump::TTeXDump(const char *fname, Int_t wtype) : TVirtualPS(fname, wtype)
114 {
115  fStream = 0;
116  fType = 0;
117  gVirtualPS = this;
119  fRange = kFALSE;
120  fXsize = 0.;
121  fYsize = 0.;
122  fCurrentRed = -1.;
123  fCurrentGreen = -1.;
124  fCurrentBlue = -1.;
125  fCurrentAlpha = 1.;
126  fLineScale = 0.;
127 
128  Open(fname, wtype);
129 }
130 
131 ////////////////////////////////////////////////////////////////////////////////
132 /// Open a TeX file
133 
134 void TTeXDump::Open(const char *fname, Int_t wtype)
135 {
136  if (fStream) {
137  Warning("Open", "TeX file already open");
138  return;
139  }
140 
142  fLenBuffer = 0;
143  fType = abs(wtype);
144 
146 
147  Float_t xrange, yrange;
148  if (gPad) {
149  Double_t ww = gPad->GetWw();
150  Double_t wh = gPad->GetWh();
151  ww *= gPad->GetWNDC();
152  wh *= gPad->GetHNDC();
153  Double_t ratio = wh/ww;
154  xrange = fXsize;
155  yrange = fXsize*ratio;
156  if (yrange > fYsize) { yrange = fYsize; xrange = yrange/ratio;}
157  fXsize = xrange; fYsize = yrange;
158  }
159 
160  // Open OS file
161  fStream = new std::ofstream(fname,std::ios::out);
162  if (fStream == 0 || !fStream->good()) {
163  printf("ERROR in TTeXDump::Open: Cannot open file:%s\n",fname);
164  if (fStream == 0) return;
165  }
166 
167  gVirtualPS = this;
168 
169  for (Int_t i=0;i<fSizBuffer;i++) fBuffer[i] = ' ';
170 
172  fRange = kFALSE;
173 
174  // Set a default range
175  Range(fXsize, fYsize);
176 
177  NewPage();
178 }
179 
180 ////////////////////////////////////////////////////////////////////////////////
181 /// Default TeX destructor
182 
184 {
185  Close();
186 }
187 
188 ////////////////////////////////////////////////////////////////////////////////
189 /// Close a TeX file
190 
192 {
193  if (!gVirtualPS) return;
194  if (!fStream) return;
195  if (gPad) gPad->Update();
196  PrintStr("@");
197  PrintStr("\\end{tikzpicture}@");
198 
199  // Close file stream
200  if (fStream) { fStream->close(); delete fStream; fStream = 0;}
201 
202  gVirtualPS = 0;
203 }
204 
205 ////////////////////////////////////////////////////////////////////////////////
206 /// Activate an already open TeX file
207 
209 {
210  // fType is used to know if the TeX file is open. Unlike TPostScript, TTeXDump
211  // has no "workstation type". In fact there is only one TeX type.
212 
213  if (!fType) {
214  Error("On", "no TeX file open");
215  Off();
216  return;
217  }
218  gVirtualPS = this;
219 }
220 
221 ////////////////////////////////////////////////////////////////////////////////
222 /// Deactivate an already open TeX file
223 
225 {
226  gVirtualPS = 0;
227 }
228 
229 ////////////////////////////////////////////////////////////////////////////////
230 /// Draw a Box
231 
233 {
234  Float_t x1c = XtoTeX(x1);
235  Float_t y1c = YtoTeX(y1);
236  Float_t x2c = XtoTeX(x2);
237  Float_t y2c = YtoTeX(y2);
238 
239  Int_t fillis = fFillStyle/1000;
240  Int_t fillsi = fFillStyle%1000;
241 
242  if (fillis==1) {
244  PrintStr("@");
245  PrintStr("\\draw [color=c, fill=c");
246  if (fCurrentAlpha != 1.) {
247  PrintStr(", fill opacity=");
249  }
250  PrintStr("] (");
251  WriteReal(x1c, kFALSE);
252  PrintFast(1,",");
253  WriteReal(y1c, kFALSE);
254  PrintStr(") rectangle (");
255  WriteReal(x2c, kFALSE);
256  PrintFast(1,",");
257  WriteReal(y2c, kFALSE);
258  PrintStr(");");
259  }
260  if (fillis>1 && fillis<4) {
262  PrintStr("@");
263  PrintStr("\\draw [pattern=");
264  switch (fillsi) {
265  case 1 :
266  PrintStr("crosshatch dots");
267  break;
268  case 2 :
269  case 3 :
270  PrintStr("dots");
271  break;
272  case 4 :
273  PrintStr("north east lines");
274  break;
275  case 5 :
276  PrintStr("north west lines");
277  break;
278  case 6 :
279  PrintStr("vertical lines");
280  break;
281  case 7 :
282  PrintStr("horizontal lines");
283  break;
284  case 10 :
285  PrintStr("bricks");
286  break;
287  case 13 :
288  PrintStr("crosshatch");
289  break;
290  }
291  PrintStr(", draw=none, pattern color=c");
292  if (fCurrentAlpha != 1.) {
293  PrintStr(", fill opacity=");
295  }
296  PrintStr("] (");
297  WriteReal(x1c, kFALSE);
298  PrintFast(1,",");
299  WriteReal(y1c, kFALSE);
300  PrintStr(") rectangle (");
301  WriteReal(x2c, kFALSE);
302  PrintFast(1,",");
303  WriteReal(y2c, kFALSE);
304  PrintStr(");");
305  }
306  if (fillis == 0) {
307  if (fLineWidth<=0) return;
309  PrintStr("@");
310  PrintStr("\\draw [c");
311  PrintStr(",line width=");
313  if (fCurrentAlpha != 1.) {
314  PrintStr(", opacity=");
316  }
317  PrintStr("] (");
318  WriteReal(x1c, kFALSE);
319  PrintFast(1,",");
320  WriteReal(y1c, kFALSE);
321  PrintStr(") -- (");
322  WriteReal(x1c, kFALSE);
323  PrintFast(1,",");
324  WriteReal(y2c, kFALSE);
325  PrintStr(") -- (");
326  WriteReal(x2c, kFALSE);
327  PrintFast(1,",");
328  WriteReal(y2c, kFALSE);
329  PrintStr(") -- (");
330  WriteReal(x2c, kFALSE);
331  PrintFast(1,",");
332  WriteReal(y1c, kFALSE);
333  PrintStr(") -- (");
334  WriteReal(x1c, kFALSE);
335  PrintFast(1,",");
336  WriteReal(y1c, kFALSE);
337  PrintStr(");");
338  }
339 }
340 
341 ////////////////////////////////////////////////////////////////////////////////
342 /// Draw a Frame around a box
343 ///
344 /// mode = -1 the box looks as it is behind the screen
345 /// mode = 1 the box looks as it is in front of the screen
346 /// border is the border size in already pre-computed TeX units dark is the
347 /// color for the dark part of the frame light is the color for the light
348 /// part of the frame
349 
351  Int_t, Int_t, Int_t, Int_t)
352 {
353  Warning("DrawFrame", "not yet implemented");
354 }
355 
356 ////////////////////////////////////////////////////////////////////////////////
357 /// Draw a PolyLine
358 ///
359 /// Draw a polyline through the points xy.
360 /// - If NN=1 moves only to point x,y.
361 /// - If NN=0 the x,y are written in the TeX file
362 /// according to the current transformation.
363 /// - If NN>0 the line is clipped as a line.
364 /// - If NN<0 the line is clipped as a fill area.
365 
367 {
368  Warning("DrawPolyLine", "not yet implemented");
369 }
370 
371 ////////////////////////////////////////////////////////////////////////////////
372 /// Draw a PolyLine in NDC space
373 ///
374 /// Draw a polyline through the points xy.
375 /// - If NN=1 moves only to point x,y.
376 /// - If NN=0 the x,y are written in the TeX file
377 /// according to the current transformation.
378 /// - If NN>0 the line is clipped as a line.
379 /// - If NN<0 the line is clipped as a fill area.
380 
382 {
383  Warning("DrawPolyLineNDC", "not yet implemented");
384 }
385 
386 ////////////////////////////////////////////////////////////////////////////////
387 /// Paint PolyMarker
388 
390 {
391  Warning("DrawPolyMarker", "not yet implemented");
392 }
393 
394 ////////////////////////////////////////////////////////////////////////////////
395 /// Paint PolyMarker
396 
398 {
399  Float_t x, y;
400 
402 
403  PrintStr("@");
404  PrintStr("\\foreach \\P in {");
405 
406  x = XtoTeX(xw[0]);
407  y = YtoTeX(yw[0]);
408 
409  PrintStr("(");
410  WriteReal(x, kFALSE);
411  PrintFast(1,",");
412  WriteReal(y, kFALSE);
413  PrintStr(")");
414 
415  for (Int_t i=1;i<n;i++) {
416  x = XtoTeX(xw[i]);
417  y = YtoTeX(yw[i]);
418  PrintFast(3,", (");
419  WriteReal(x, kFALSE);
420  PrintFast(1,",");
421  WriteReal(y, kFALSE);
422  PrintFast(1,")");
423  }
424 
425  if (fMarkerStyle == 23 || fMarkerStyle == 32) {
426  PrintStr("}{\\draw[mark options={color=c,fill=c,rotate=180},mark size=");
427  } else {
428  PrintStr("}{\\draw[mark options={color=c,fill=c},mark size=");
429  }
430  PrintStr(Form("%fpt,mark=",8./3.33*fMarkerSize));
431  switch (fMarkerStyle) {
432  case 1 :
433  PrintStr("*");
434  PrintStr(",mark size=1pt");
435  break;
436  case 2 :
437  PrintStr("+");
438  break;
439  case 3 :
440  PrintStr("asterisk");
441  break;
442  case 4 :
443  PrintStr("o");
444  break;
445  case 5 :
446  PrintStr("x");
447  break;
448  case 20 :
449  PrintStr("*");
450  break;
451  case 21 :
452  PrintStr("square*");
453  break;
454  case 22 :
455  PrintStr("triangle*");
456  break;
457  case 23 :
458  PrintStr("triangle*");
459  break;
460  case 24 :
461  PrintStr("o");
462  break;
463  case 25 :
464  PrintStr("square");
465  break;
466  case 26 :
467  PrintStr("triangle");
468  break;
469  case 27 :
470  PrintStr("diamond");
471  break;
472  case 28 :
473  PrintStr("cross");
474  break;
475  case 29 :
476  PrintStr("newstar*");
477  break;
478  case 30 :
479  PrintStr("newstar");
480  break;
481  case 31 :
482  PrintStr("10-pointed star");
483  break;
484  case 32 :
485  PrintStr("triangle");
486  break;
487  case 33 :
488  PrintStr("diamond*");
489  break;
490  case 34 :
491  PrintStr("cross*");
492  break;
493  }
494  PrintStr("] plot coordinates {\\P};}");
495 }
496 
497 ////////////////////////////////////////////////////////////////////////////////
498 /// This function defines a path with xw and yw and draw it according the
499 /// value of nn:
500 ///
501 /// - If nn>0 a line is drawn.
502 /// - If nn<0 a closed polygon is drawn.
503 
505 {
506  Int_t n = TMath::Abs(nn);;
507  Float_t x, y;
508 
509  if( n <= 1) {
510  Error("DrawPS", "Two points are needed");
511  return;
512  }
513 
514  x = XtoTeX(xw[0]);
515  y = YtoTeX(yw[0]);
516 
517  Int_t fillis = fFillStyle/1000;
518  Int_t fillsi = fFillStyle%1000;
519 
520  if (nn>0) {
521  if (fLineWidth<=0) return;
523  PrintStr("@");
524  PrintStr("\\draw [c");
526  TString tikzSpec;
527  TString stripped = TString{spec.Strip(TString::kBoth)};
528  if (stripped.Length()) {
529  tikzSpec.Append(",dash pattern=");
530  Ssiz_t i{0}, j{0};
531  bool on{true}, iterate{true};
532 
533  while (iterate){
534  j = stripped.Index(" ", 1, i, TString::kExact);
535  if (j == kNPOS){
536  iterate = false;
537  j = stripped.Length();
538  }
539 
540  if (on) {
541  tikzSpec.Append("on ");
542  on = false;
543  } else {
544  tikzSpec.Append("off ");
545  on = true;
546  }
547  int num = TString{stripped(i, j - i)}.Atoi();
548  float pt = 0.2*num;
549  tikzSpec.Append(TString::Format("%.2fpt ", pt));
550  i = j + 1;
551  }
552  PrintStr(tikzSpec.Data());
553  }
554  PrintStr(",line width=");
556  } else {
558  if (fillis==1) {
559  PrintStr("@");
560  PrintStr("\\draw [c, fill=c");
561  } else if (fillis==0) {
562  PrintStr("@");
563  PrintStr("\\draw [c");
564  } else {
565  PrintStr("\\draw [pattern=");
566  switch (fillsi) {
567  case 1 :
568  PrintStr("crosshatch dots");
569  break;
570  case 2 :
571  case 3 :
572  PrintStr("dots");
573  break;
574  case 4 :
575  PrintStr("north east lines");
576  break;
577  case 5 :
578  PrintStr("north west lines");
579  break;
580  case 6 :
581  PrintStr("vertical lines");
582  break;
583  case 7 :
584  PrintStr("horizontal lines");
585  break;
586  case 10 :
587  PrintStr("bricks");
588  break;
589  case 13 :
590  PrintStr("crosshatch");
591  break;
592  }
593  PrintStr(", draw=none, pattern color=c");
594  }
595  if (fCurrentAlpha != 1.) {
596  PrintStr(", fill opacity=");
598  }
599  }
600  PrintStr("] (");
601  WriteReal(x, kFALSE);
602  PrintFast(1,",");
603  WriteReal(y, kFALSE);
604  PrintStr(") -- ");
605 
606  for (Int_t i=1;i<n;i++) {
607  x = XtoTeX(xw[i]);
608  y = YtoTeX(yw[i]);
609  PrintFast(1,"(");
610  WriteReal(x, kFALSE);
611  PrintFast(1,",");
612  WriteReal(y, kFALSE);
613  PrintFast(1,")");
614  if (i<n-1) PrintStr(" -- ");
615  else PrintStr(";@");
616  }
617 }
618 
619 ////////////////////////////////////////////////////////////////////////////////
620 /// Start the TeX page. This function starts the tikzpicture environment
621 
623 {
624  // Compute pad conversion coefficients
625  if (gPad) {
626  Double_t ww = gPad->GetWw();
627  Double_t wh = gPad->GetWh();
628  fYsize = fXsize*wh/ww;
629  } else {
630  fYsize = 27;
631  }
632 
633  if(!fBoundingBox) {
634  PrintStr("\\begin{tikzpicture}@");
635  DefineMarkers();
637  }
638 }
639 
640 ////////////////////////////////////////////////////////////////////////////////
641 /// Set the range for the paper in centimetres
642 
643 void TTeXDump::Range(Float_t xsize, Float_t ysize)
644 {
645  fXsize = xsize;
646  fYsize = ysize;
647 
648  fRange = kTRUE;
649 }
650 
651 ////////////////////////////////////////////////////////////////////////////////
652 /// Set color index for fill areas
653 
655 {
656  fFillColor = cindex;
657  if (gStyle->GetFillColor() <= 0) cindex = 0;
658 }
659 
660 ////////////////////////////////////////////////////////////////////////////////
661 /// Set color index for lines
662 
664 {
665  fLineColor = cindex;
666 }
667 
668 ////////////////////////////////////////////////////////////////////////////////
669 /// Change the line style
670 ///
671 /// - linestyle = 2 dashed
672 /// - linestyle = 3 dotted
673 /// - linestyle = 4 dash-dotted
674 /// - linestyle = else solid (1 in is used most of the time)
675 
677 {
678  fLineStyle = linestyle;
679 }
680 
681 ////////////////////////////////////////////////////////////////////////////////
682 /// Set the lines width.
683 
685 {
686  fLineWidth = linewidth;
687 }
688 
689 ////////////////////////////////////////////////////////////////////////////////
690 /// Set size for markers.
691 
693 {
694  fMarkerSize = msize;
695 }
696 
697 ////////////////////////////////////////////////////////////////////////////////
698 /// Set color index for markers.
699 
701 {
702  fMarkerColor = cindex;
703 }
704 
705 ////////////////////////////////////////////////////////////////////////////////
706 /// Set color with its color index
707 
709 {
710  if (color < 0) color = 0;
711  TColor *col = gROOT->GetColor(color);
712 
713  if (col) {
714  SetColor(col->GetRed(), col->GetGreen(), col->GetBlue());
715  fCurrentAlpha = col->GetAlpha();
716  } else {
717  SetColor(1., 1., 1.);
718  fCurrentAlpha = 1.;
719  }
720 }
721 
722 ////////////////////////////////////////////////////////////////////////////////
723 /// Set color with its R G B components
724 ///
725 /// - r: % of red in [0,1]
726 /// - g: % of green in [0,1]
727 /// - b: % of blue in [0,1]
728 
730 {
731  if (fCurrentRed == r && fCurrentGreen == g && fCurrentBlue == b) return;
732 
733  fCurrentRed = r;
734  fCurrentGreen = g;
735  fCurrentBlue = b;
736  PrintStr("@");
737  PrintStr("\\definecolor{c}{rgb}{");
738  WriteReal(r, kFALSE);
739  PrintFast(1,",");
740  WriteReal(g, kFALSE);
741  PrintFast(1,",");
742  WriteReal(b, kFALSE);
743  PrintFast(2,"};");
744 }
745 
746 ////////////////////////////////////////////////////////////////////////////////
747 /// Set color index for text
748 
750 {
751  fTextColor = cindex;
752 }
753 
754 ////////////////////////////////////////////////////////////////////////////////
755 /// Draw text
756 ///
757 /// - xx: x position of the text
758 /// - yy: y position of the text
759 /// - chars: text to be drawn
760 
761 void TTeXDump::Text(Double_t x, Double_t y, const char *chars)
762 {
763  Double_t wh = (Double_t)gPad->XtoPixel(gPad->GetX2());
764  Double_t hh = (Double_t)gPad->YtoPixel(gPad->GetY1());
765  Float_t tsize, ftsize;
766  if (wh < hh) {
767  tsize = fTextSize*wh;
768  Int_t sizeTTF = (Int_t)(tsize+0.5);
769  ftsize = (sizeTTF*fXsize*gPad->GetAbsWNDC())/wh;
770  } else {
771  tsize = fTextSize*hh;
772  Int_t sizeTTF = (Int_t)(tsize+0.5);
773  ftsize = (sizeTTF*fYsize*gPad->GetAbsHNDC())/hh;
774  }
775  ftsize *= 2.22097;
776  if (ftsize <= 0) return;
777 
778  TString t(chars);
779  if (t.Index("\\")>=0 || t.Index("^{")>=0 || t.Index("_{")>=0) {
780  t.Prepend("$");
781  t.Append("$");
782  } else {
783  t.ReplaceAll("<","$<$");
784  t.ReplaceAll(">","$>$");
785  t.ReplaceAll("_","\\_");
786  }
787  t.ReplaceAll("&","\\&");
788  t.ReplaceAll("#","\\#");
789  t.ReplaceAll("%","\\%");
790 
791  Int_t txalh = fTextAlign/10;
792  if (txalh <1) txalh = 1; else if (txalh > 3) txalh = 3;
793  Int_t txalv = fTextAlign%10;
794  if (txalv <1) txalv = 1; else if (txalv > 3) txalv = 3;
796  PrintStr("@");
797  PrintStr("\\draw");
798  if (txalh!=2 || txalv!=2) {
799  PrintStr(" [anchor=");
800  if (txalv==1) PrintStr("base");
801  if (txalv==3) PrintStr("north");
802  if (txalh==1) PrintStr(" west");
803  if (txalh==3) PrintStr(" east");
804  PrintFast(1,"]");
805  }
806  PrintFast(2," (");
807  WriteReal(XtoTeX(x), kFALSE);
808  PrintFast(1,",");
809  WriteReal(YtoTeX(y), kFALSE);
810  PrintStr(") node[scale=");
811  WriteReal(ftsize, kFALSE);
812  PrintStr(", color=c, rotate=");
814  PrintFast(2,"]{");
815  PrintStr(t.Data());
816  PrintFast(2,"};");
817 }
818 
819 ////////////////////////////////////////////////////////////////////////////////
820 /// Write a string of characters in NDC
821 
822 void TTeXDump::TextNDC(Double_t u, Double_t v, const char *chars)
823 {
824  Double_t x = gPad->GetX1() + u*(gPad->GetX2() - gPad->GetX1());
825  Double_t y = gPad->GetY1() + v*(gPad->GetY2() - gPad->GetY1());
826  Text(x, y, chars);
827 }
828 
829 ////////////////////////////////////////////////////////////////////////////////
830 /// Convert U from NDC coordinate to TeX
831 
833 {
834  Double_t cm = fXsize*(gPad->GetAbsXlowNDC() + u*gPad->GetAbsWNDC());
835  return cm;
836 }
837 
838 ////////////////////////////////////////////////////////////////////////////////
839 /// Convert V from NDC coordinate to TeX
840 
842 {
843  Double_t cm = fYsize*(gPad->GetAbsYlowNDC() + v*gPad->GetAbsHNDC());
844  return cm;
845 }
846 
847 ////////////////////////////////////////////////////////////////////////////////
848 /// Convert X from world coordinate to TeX
849 
851 {
852  Double_t u = (x - gPad->GetX1())/(gPad->GetX2() - gPad->GetX1());
853  return UtoTeX(u);
854 }
855 
856 ////////////////////////////////////////////////////////////////////////////////
857 /// Convert Y from world coordinate to TeX
858 
860 {
861  Double_t v = (y - gPad->GetY1())/(gPad->GetY2() - gPad->GetY1());
862  return VtoTeX(v);
863 }
864 
865 ////////////////////////////////////////////////////////////////////////////////
866 /// Begin the Cell Array painting
867 
869  Double_t)
870 {
871  Warning("CellArrayBegin", "not yet implemented");
872 }
873 
874 ////////////////////////////////////////////////////////////////////////////////
875 /// Paint the Cell Array
876 
878 {
879  Warning("CellArrayFill", "not yet implemented");
880 }
881 
882 ////////////////////////////////////////////////////////////////////////////////
883 /// End the Cell Array painting
884 
886 {
887  Warning("CellArrayEnd", "not yet implemented");
888 }
889 
890 ////////////////////////////////////////////////////////////////////////////////
891 /// Not needed in TeX case
892 
894 {
895  Warning("DrawPS", "not yet implemented");
896 }
897 
898 ////////////////////////////////////////////////////////////////////////////////
899 /// add additional pgfplotmarks
900 
902 {
903  // open cross
904  PrintStr("\\pgfdeclareplotmark{cross} {@");
905  PrintStr("\\pgfpathmoveto{\\pgfpoint{-0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
906  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
907  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
908  PrintStr("\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
909  PrintStr("\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
910  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
911  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
912  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
913  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
914  PrintStr("\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
915  PrintStr("\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
916  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
917  PrintStr("\\pgfpathclose@");
918  PrintStr("\\pgfusepathqstroke@");
919  PrintStr("}@");
920 
921  // filled cross
922  PrintStr("\\pgfdeclareplotmark{cross*} {@");
923  PrintStr("\\pgfpathmoveto{\\pgfpoint{-0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
924  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{\\pgfplotmarksize}}@");
925  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
926  PrintStr("\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
927  PrintStr("\\pgfpathlineto{\\pgfpoint{+1\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
928  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
929  PrintStr("\\pgfpathlineto{\\pgfpoint{+0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
930  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-1.\\pgfplotmarksize}}@");
931  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
932  PrintStr("\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{-0.3\\pgfplotmarksize}}@");
933  PrintStr("\\pgfpathlineto{\\pgfpoint{-1.\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
934  PrintStr("\\pgfpathlineto{\\pgfpoint{-0.3\\pgfplotmarksize}{0.3\\pgfplotmarksize}}@");
935  PrintStr("\\pgfpathclose@");
936  PrintStr("\\pgfusepathqfillstroke@");
937  PrintStr("}@");
938 
939  // open star
940  PrintStr("\\pgfdeclareplotmark{newstar} {@");
941  PrintStr("\\pgfpathmoveto{\\pgfqpoint{0pt}{\\pgfplotmarksize}}@");
942  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{44}{0.5\\pgfplotmarksize}}@");
943  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{18}{\\pgfplotmarksize}}@");
944  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-20}{0.5\\pgfplotmarksize}}@");
945  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-54}{\\pgfplotmarksize}}@");
946  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-90}{0.5\\pgfplotmarksize}}@");
947  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{234}{\\pgfplotmarksize}}@");
948  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{198}{0.5\\pgfplotmarksize}}@");
949  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{162}{\\pgfplotmarksize}}@");
950  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{134}{0.5\\pgfplotmarksize}}@");
951  PrintStr("\\pgfpathclose@");
952  PrintStr("\\pgfusepathqstroke@");
953  PrintStr("}@");
954 
955  // filled star
956  PrintStr("\\pgfdeclareplotmark{newstar*} {@");
957  PrintStr("\\pgfpathmoveto{\\pgfqpoint{0pt}{\\pgfplotmarksize}}@");
958  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{44}{0.5\\pgfplotmarksize}}@");
959  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{18}{\\pgfplotmarksize}}@");
960  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-20}{0.5\\pgfplotmarksize}}@");
961  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-54}{\\pgfplotmarksize}}@");
962  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{-90}{0.5\\pgfplotmarksize}}@");
963  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{234}{\\pgfplotmarksize}}@");
964  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{198}{0.5\\pgfplotmarksize}}@");
965  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{162}{\\pgfplotmarksize}}@");
966  PrintStr("\\pgfpathlineto{\\pgfqpointpolar{134}{0.5\\pgfplotmarksize}}@");
967  PrintStr("\\pgfpathclose@");
968  PrintStr("\\pgfusepathqfillstroke@");
969  PrintStr("}@");
970 }
void CellArrayBegin(Int_t W, Int_t H, Double_t x1, Double_t x2, Double_t y1, Double_t y2)
Begin the Cell Array painting.
Definition: TTeXDump.cxx:868
void Close(Option_t *opt="")
Close a TeX file.
Definition: TTeXDump.cxx:191
Float_t GetLineScalePS() const
Definition: TStyle.h:272
char * fBuffer
Definition: TVirtualPS.h:42
int iterate(rng_state_t *X)
Definition: mixmax.icc:34
void DrawPolyLine(Int_t n, TPoints *xy)
Draw a PolyLine.
Definition: TTeXDump.cxx:366
void SetMarkerSize(Size_t msize=1)
Set size for markers.
Definition: TTeXDump.cxx:692
Float_t GetRed() const
Definition: TColor.h:56
short Style_t
Definition: RtypesCore.h:76
Float_t fCurrentRed
Current Red component.
Definition: TTeXDump.h:28
float Float_t
Definition: RtypesCore.h:53
float Size_t
Definition: RtypesCore.h:83
const char Option_t
Definition: RtypesCore.h:62
void SetLineColor(Color_t cindex=1)
Set color index for lines.
Definition: TTeXDump.cxx:663
const Ssiz_t kNPOS
Definition: RtypesCore.h:111
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:638
Float_t GetAlpha() const
Definition: TColor.h:62
R__EXTERN TStyle * gStyle
Definition: TStyle.h:402
void SetLineStyle(Style_t linestyle=1)
Change the line style.
Definition: TTeXDump.cxx:676
void GetPaperSize(Float_t &xsize, Float_t &ysize) const
Set paper size for PostScript output.
Definition: TStyle.cxx:810
Float_t UtoTeX(Double_t u)
Convert U from NDC coordinate to TeX.
Definition: TTeXDump.cxx:832
Size_t fMarkerSize
Marker size.
Definition: TAttMarker.h:24
Float_t fLineScale
Line width scale factor.
Definition: TTeXDump.h:32
void DrawPS(Int_t n, Float_t *xw, Float_t *yw)
Not needed in TeX case.
Definition: TTeXDump.cxx:893
void DefineMarkers()
add additional pgfplotmarks
Definition: TTeXDump.cxx:901
#define gROOT
Definition: TROOT.h:402
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:585
static constexpr double cm
void Text(Double_t x, Double_t y, const char *string)
Draw text.
Definition: TTeXDump.cxx:761
Basic string class.
Definition: TString.h:125
virtual ~TTeXDump()
Default TeX destructor.
Definition: TTeXDump.cxx:183
int Int_t
Definition: RtypesCore.h:41
Float_t fCurrentAlpha
Current Alpha value.
Definition: TTeXDump.h:31
Float_t VtoTeX(Double_t v)
Convert V from NDC coordinate to TeX.
Definition: TTeXDump.cxx:841
TString & Prepend(const char *cs)
Definition: TString.h:607
Float_t GetBlue() const
Definition: TColor.h:58
Short_t Abs(Short_t d)
Definition: TMathBase.h:108
virtual void WriteReal(Float_t r, Bool_t space=kTRUE)
Write a Real number to the file.
Definition: TVirtualPS.cxx:185
Float_t fCurrentBlue
Current Blue component.
Definition: TTeXDump.h:30
static const double x2[5]
Double_t x[n]
Definition: legend1.C:17
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Definition: TString.cxx:2365
virtual void PrintStr(const char *string="")
Output the string str in the output buffer.
Definition: TVirtualPS.cxx:72
Float_t GetGreen() const
Definition: TColor.h:57
TString & Append(const char *cs)
Definition: TString.h:495
Float_t fYsize
Page size along Y.
Definition: TTeXDump.h:24
Float_t XtoTeX(Double_t x)
Convert X from world coordinate to TeX.
Definition: TTeXDump.cxx:850
short Color_t
Definition: RtypesCore.h:79
Style_t fMarkerStyle
Marker style.
Definition: TAttMarker.h:23
void Off()
Deactivate an already open TeX file.
Definition: TTeXDump.cxx:224
Float_t fTextAngle
Text angle.
Definition: TAttText.h:21
TTeXDump()
Default TeX constructor.
Definition: TTeXDump.cxx:88
Style_t fLineStyle
Line style.
Definition: TAttLine.h:22
Float_t fXsize
Page size along X.
Definition: TTeXDump.h:23
void Open(const char *filename, Int_t type=-111)
Open a TeX file.
Definition: TTeXDump.cxx:134
TPaveText * pt
ROOT::R::TRInterface & r
Definition: Object.C:4
Float_t fCurrentGreen
Current Green component.
Definition: TTeXDump.h:29
SVector< double, 2 > v
Definition: Dict.h:5
Bool_t fBoundingBox
True when the Tex header is printed.
Definition: TTeXDump.h:26
Int_t fSizBuffer
Definition: TVirtualPS.h:39
void SetFillColor(Color_t cindex=1)
Set color index for fill areas.
Definition: TTeXDump.cxx:654
const char * GetLineStyleString(Int_t i=1) const
Return line style string (used by PostScript).
Definition: TStyle.cxx:792
Color_t fLineColor
Line color.
Definition: TAttLine.h:21
Bool_t fRange
True when a range has been defined.
Definition: TTeXDump.h:27
void NewPage()
Start the TeX page. This function starts the tikzpicture environment.
Definition: TTeXDump.cxx:622
void On()
Activate an already open TeX file.
Definition: TTeXDump.cxx:208
Width_t fLineWidth
Line width.
Definition: TAttLine.h:23
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition: TObject.cxx:880
char * Form(const char *fmt,...)
Float_t YtoTeX(Double_t y)
Convert Y from world coordinate to TeX.
Definition: TTeXDump.cxx:859
Ssiz_t Length() const
Definition: TString.h:386
void SetTextColor(Color_t cindex=1)
Set color index for text.
Definition: TTeXDump.cxx:749
TSubString Strip(EStripType s=kTrailing, char c=' ') const
Return a substring of self stripped at beginning and/or end.
Definition: TString.cxx:1080
std::ofstream * fStream
Definition: TVirtualPS.h:41
short Width_t
Definition: RtypesCore.h:78
void SetLineScale(Float_t scale=1)
Definition: TTeXDump.h:66
const Bool_t kFALSE
Definition: RtypesCore.h:88
int Ssiz_t
Definition: RtypesCore.h:63
2-D graphics point (world coordinates).
Definition: TPoints.h:19
Interface to TeX.
Definition: TTeXDump.h:20
void Range(Float_t xrange, Float_t yrange)
Set the range for the paper in centimetres.
Definition: TTeXDump.cxx:643
static const double x1[5]
#define ClassImp(name)
Definition: Rtypes.h:359
double Double_t
Definition: RtypesCore.h:55
virtual void PrintFast(Int_t nch, const char *string="")
Fast version of Print.
Definition: TVirtualPS.cxx:103
Double_t y[n]
Definition: legend1.C:17
virtual Color_t GetFillColor() const
Return the fill area color.
Definition: TAttFill.h:30
void TextNDC(Double_t u, Double_t v, const char *string)
Write a string of characters in NDC.
Definition: TTeXDump.cxx:822
The color creation and management class.
Definition: TColor.h:19
Float_t fTextSize
Text size.
Definition: TAttText.h:22
void SetLineWidth(Width_t linewidth=1)
Set the lines width.
Definition: TTeXDump.cxx:684
Int_t fLenBuffer
Definition: TVirtualPS.h:38
void SetColor(Int_t color=1)
Set color with its color index.
Definition: TTeXDump.cxx:708
void CellArrayEnd()
End the Cell Array painting.
Definition: TTeXDump.cxx:885
void CellArrayFill(Int_t r, Int_t g, Int_t b)
Paint the Cell Array.
Definition: TTeXDump.cxx:877
Color_t fFillColor
Fill area color.
Definition: TAttFill.h:22
void SetMarkerColor(Color_t cindex=1)
Set color index for markers.
Definition: TTeXDump.cxx:700
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
R__EXTERN TVirtualPS * gVirtualPS
Definition: TVirtualPS.h:81
void DrawPolyMarker(Int_t n, Float_t *x, Float_t *y)
Paint PolyMarker.
Definition: TTeXDump.cxx:389
#define gPad
Definition: TVirtualPad.h:285
Int_t Atoi() const
Return integer value of string.
Definition: TString.cxx:1975
void DrawBox(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw a Box.
Definition: TTeXDump.cxx:232
TVirtualPS is an abstract interface to Postscript, PDF, SVG.
Definition: TVirtualPS.h:30
Color_t fMarkerColor
Marker color.
Definition: TAttMarker.h:22
const Bool_t kTRUE
Definition: RtypesCore.h:87
Color_t fTextColor
Text color.
Definition: TAttText.h:24
void DrawFrame(Double_t xl, Double_t yl, Double_t xt, Double_t yt, Int_t mode, Int_t border, Int_t dark, Int_t light)
Draw a Frame around a box.
Definition: TTeXDump.cxx:350
const Int_t n
Definition: legend1.C:16
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition: TObject.cxx:866
Style_t fFillStyle
Fill area style.
Definition: TAttFill.h:23
Short_t fTextAlign
Text alignment.
Definition: TAttText.h:23
const char * Data() const
Definition: TString.h:345
void DrawPolyLineNDC(Int_t n, TPoints *uv)
Draw a PolyLine in NDC space.
Definition: TTeXDump.cxx:381
static constexpr double g
Int_t fType
Workstation type used to know if the Tex is open.
Definition: TTeXDump.h:25