Author Topic: How I do graphics  (Read 15896 times)

Victor Ivrii

  • Administrator
  • Elder Member
  • *****
  • Posts: 2607
  • Karma: 0
    • View Profile
    • Personal website of Victor Ivrii
How I do graphics
« on: October 09, 2015, 05:29:48 PM »
How am I producing graphics? Usually I am using latex with package pdf/tikz which is one of two TeX graphical superbundles (the second one is pstricks). If you have TeXLive distribution (which is a sure but for non-Windows machines) just type on the terminal prompt
Code: [Select]
% texdoc pgfand enjoy 1161 pp manual (v. 3.0.1.a). What is more: pdf can use gnuplot to produce data for drawing plots. There are also several 3rd party packages built on the top of pgf (I use tkz-euclide for high-school geometry drawings).

After LaTeX produces pdf I use either
Code: [Select]
% convert foo.pdf foo.pngor
Code: [Select]
% pdf2svg foo.pdf foo.svg(do not use convert for the second task as it rasterizes vector-graphics). convert is a part of the standard suite ImageMagick while pd2svg I compiled from the source; alternatively one can use Inkscape (which is also can fix bad svg).

Finally I attach png files but  svg I do not attach as they would not be displayed on forum in this case: I upload them on my web server and put URL between img tags (the bottom-left button)
« Last Edit: March 18, 2018, 10:51:14 AM by Victor Ivrii »

Victor Ivrii

  • Administrator
  • Elder Member
  • *****
  • Posts: 2607
  • Karma: 0
    • View Profile
    • Personal website of Victor Ivrii
Re: How I do graphics
« Reply #1 on: March 25, 2018, 08:23:37 AM »
How to plot functions using LaTeX? There are two "superpackages" (and some based on them packages)––pstricks and pgf/tikz. pgf/tikz, however, can draw, but cannot produce data, so it asks gnuplot for a data. Thus

1) You need to install gnuplot http://gnuplot.info/ which is a great free s/w on it's own

2) You need to allow latex to talk to shell (I am discussing mainly UNIX, in particular MacOSX). Thus latex should be executed with --shell-escape option (it is a security problem if you running malicious code). If you running latex from terminal, you just use this switch. If you running latex from frontend, you need to configure it's Preferences. F.e. TeXShop (for MacOSX) in Preferences>Engine put

in LaTeX "pdflatex --shell-escape -file-line-error -synctex=1"

(-file-line-error -synctex=1 allows debugging and synchronization source<->pdf )

Example (standalone picture):

Code: [Select]
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[scale=0.8]
\draw[thin, ->] (pi/2-.1,0) -- (11,0) node[right] {$x$};
\draw[thin,->] (pi/2,-3.7) -- (pi/2,3.7);% node[above] {$\textbf{Y}$};

\clip (pi/2-.1,-4) rectangle (11,4);
\draw[thick, red](pi/2,0)--(11,3.5);
\draw[thick, brown](pi/2,0)--(11,-3.5);
\foreach \i in { 0, 1, 2, 3}{
    \pgfmathsetmacro{\start}{\i*pi-1.3}
    \pgfmathsetmacro{\left}  {(\i-0.5)*pi}
    \pgfmathsetmacro{\end}  {\i*pi+1.3}
    \draw[dashed] (\left,-3.5) -- (\left,3.5);
    \draw[ultra thick, color=blue] plot [domain=\start:\end, smooth, samples=25] (\x, -{tan(\x r)} );
}
\fill[white] (0,0) circle (.05);
\end{tikzpicture}

\end{document}

In the paper you use tikzpicture as a graphics (so, usually put it inside of figure:)

Code: [Select]
\begin{figure}[h]
\centering
\begin{tikzpicture}
.......
\end{tikzpicture}
\caption{blah blah}
\end{figure}