# HG changeset patch # User Michael D. Godfrey # Date 1436300731 -3600 # Node ID b9d4ccf4291cd93c8943e41e9fef89041a90926a # Parent 9e361ecea8788263ff645209e1ec4cab685a862c Use FLTK for creating plots for Manual. * plot.txi: Add explanation of standalone printing modes to work around lack of 'interpreter' property for OpenGL toolkits. * plotimages.m: Rework example using text and 'interpreter' to use standalone printing. diff -r 9e361ecea878 -r b9d4ccf4291c doc/interpreter/plot.txi --- a/doc/interpreter/plot.txi Tue Jul 07 22:00:06 2015 -0400 +++ b/doc/interpreter/plot.txi Tue Jul 07 21:25:31 2015 +0100 @@ -205,6 +205,7 @@ @example polar (0:0.1:10*pi, 0:0.1:10*pi); +set (gca, "rtick", [0:10:40]); @end example @noindent @@ -914,31 +915,6 @@ @end tex @end float -A complete example showing the capabilities of the extended text is - -@example -@group -x = 0:0.01:3; -plot (x, erf (x)); -hold on; -plot (x,x,"r"); -axis ([0, 3, 0, 1]); -text (0.65, 0.6175, strcat ('\leftarrow x = @{2/\surd\pi', -' @{\fontsize@{16@}\int_@{\fontsize@{8@}0@}^@{\fontsize@{8@}x@}@}', -' e^@{-t^2@} dt@} = 0.6175')) -@end group -@end example - -@ifnotinfo -@noindent -The result of which can be seen in @ref{fig:extendedtext} - -@float Figure,fig:extendedtext -@center @image{extended,4in} -@caption{Example of inclusion of text with the @TeX{} interpreter} -@end float -@end ifnotinfo - @node Printing and Saving Plots @subsection Printing and Saving Plots @cindex plotting, saving and printing plots @@ -963,12 +939,48 @@ saves the current figure to an encapsulated PostScript file called @file{foo.eps}. -The different graphic toolkits have different print capabilities. In -particular, the OpenGL based toolkits such as @code{fltk} do not support -the @qcode{"interpreter"} property of text objects. This means special -symbols drawn with the @qcode{"tex"} interpreter will appear correctly -on-screen but will be rendered with interpreter @qcode{"none"} when printing. -Switch graphics toolkits for printing if this is a concern. +The current graphic toolkits have differing print capabilities. In particular, +the OpenGL based toolkits such as @code{fltk} and @code{qt} do not support the +@qcode{"interpreter"} property of text objects. This means that when using +OpenGL toolkits special symbols drawn with the @qcode{"tex"} interpreter will +appear correctly on-screen but will be rendered with interpreter @qcode{"none"} +when printing unless one of the @qcode{standalone} (see below) modes is used. +These modes provide access to the pdflatex processor and therefore allow full +use of LaTeX commands. + +A complete example showing the capabilities of text printing using the +@code{-dpdflatexstandalone} option is + +@example +@group +x = 0:0.01:3; +hf = figure (); +plot (x, erf (x)); +hold on; +plot (x, x, "r"); +axis ([0, 3, 0, 1]); +text (0.65, 0.6175, ['$\leftarrow x = @{2/\sqrt@{\pi@}' ... + '@{\int_@{0@}^@{x@}@}e^@{-t^2@} dt@} = 0.6175$']); +xlabel ("x"); +ylabel ("erf (x)"); +title ("erf (x) with text annotation"); +set (hf, "visible", "off") +print (hf, "plot15_7.pdf", "-dpdflatexstandalone") +set (hf, "visible", "on") +system ("pdflatex plot15_7"); +system ("acroread plot15_7.pdf &"); +@end group +@end example + +@ifnotinfo +@noindent +The result of which can be seen in @ref{fig:extendedtext} + +@float Figure,fig:extendedtext +@center @image{extended,4in} +@caption{Example of inclusion of text with use of @code{-dpdflatexstandalone}} +@end float +@end ifnotinfo @DOCSTRING(print) diff -r 9e361ecea878 -r b9d4ccf4291c doc/interpreter/plotimages.m --- a/doc/interpreter/plotimages.m Tue Jul 07 22:00:06 2015 -0400 +++ b/doc/interpreter/plotimages.m Tue Jul 07 21:25:31 2015 +0100 @@ -17,7 +17,7 @@ ## . function plotimages (d, nm, typ) - graphics_toolkit ("gnuplot"); + graphics_toolkit ("qt"); set_print_size (); hide_output (); outfile = fullfile (d, strcat (nm, ".", typ)); @@ -31,7 +31,7 @@ endif if (strcmp(typ , "txt")) - image_as_txt(d, nm); + image_as_txt (d, nm); elseif (strcmp (nm, "plot")) x = -10:0.1:10; plot (x, sin (x)); @@ -60,6 +60,7 @@ print (outfile, d_typ); elseif (strcmp (nm, "polar")) polar (0:0.1:10*pi, 0:0.1:10*pi); + set (gca, "rtick", [0:10:40]); title ("Example polar plot from 0 to 10*pi"); print (outfile, d_typ); elseif (strcmp (nm, "mesh")) @@ -85,16 +86,27 @@ print (outfile, d_typ); elseif (strcmp (nm, "extended")) x = 0:0.01:3; - plot (x,erf(x)); + plot (x, erf (x)); hold on; - plot (x,x,"r"); + plot (x, x, "r"); axis ([0, 3, 0, 1]); - text (0.65, 0.6175, ['\leftarrow x = {2/\surd\pi {\fontsize{16}' ... - '\int_{\fontsize{8}0}^{\fontsize{8}x}} e^{-t^2} dt} = 0.6175']); + if (strcmp (typ, "pdf")) + text (0.65, 0.6175, ['$\leftarrow x = {2/\sqrt{\pi}' ... + '{\int_{0}^{x}}e^{-t^2} dt} = 0.6175$']); + else + text (0.65, 0.6175, ['\leftarrow x = {2/\surd\pi {\fontsize{16}' ... + '\int_{\fontsize{8}0}^{\fontsize{8}x}} e^{-t^2} dt} = 0.6175']); + endif xlabel ("x"); ylabel ("erf (x)"); title ("erf (x) with text annotation"); - print (outfile, d_typ); + if (strcmp (typ, "pdf")) + print ([nm ".pdf"], "-dpdflatexstandalone"); + system (["pdflatex " nm]); + delete ([nm ".aux"], [nm "-inc.pdf"], [nm ".log"], [nm ".tex"]); + else + print ([nm "." typ], d_typ); + endif else error ("unrecognized plot requested"); endif @@ -111,7 +123,7 @@ endfunction ## Use this function before plotting commands and after every call to -## print since print() resets output to stdout (unfortunately, gnpulot +## print since print() resets output to stdout (unfortunately, gnuplot ## can't pop output as it can the terminal type). function hide_output () f = figure (1); @@ -119,7 +131,7 @@ endfunction ## generate something for the texinfo @image command to process -function image_as_txt(d, nm) +function image_as_txt (d, nm) fid = fopen (fullfile (d, strcat (nm, ".txt")), "wt"); fputs (fid, "\n"); fputs (fid, "+---------------------------------+\n");