# How do I include PSTricks pictures in a LaTeX document?

I use LaTeX regularly, and several times I have included .eps images. I am learning how to use PSTricks. I have used it to create .ps and .pdf files with images. There is plenty of free information on the web, but I haven't seen the answer to this question: how do you include the pictures that PSTricks produces in your LaTeX file?

-

If you have image files (EPS or PDF) you can include them with the graphicx package and \includegraphic{<filename>}. latex needs an EPS and pdflatex a PDF file. If you put both in your folder and omit the suffix in the including macro the package decied which file to use automatically.

If you want to include the PSTricks code directly you may use the {pspicture}environment.

-

If you write each PSTricks diagram in a separate TeX input file and compile it with latex-dvips-ps2pdf (much faster) or xelatex (slower) to obtain a PDF output, you might need the PDF output without white spaces around it.

To obtain the tight PDF output, use the following template for each diagram you want to make.

\documentclass[pstricks,border=12pt]{standalone}

\begin{document}
\begin{pspicture}[showgrid=true](-3,-3)(3,3)
% your drawing code goes here!
\end{pspicture}
\end{document}


It will be better if you put all your TeX input files for creating diagrams in a special folder outside other projects you have. This method will make your diagrams consumable to many projects easily. My directory structures look like below.

All my TeX input file for creating diagrams are placed in Diagrams. The PDF outputs associated with the input files are also in Diagrams for sure.

Another project, namely ProjectA, might use the diagrams you have made before. For example, let Main.tex be the input file in ProjectA folder. You can import the diagrams easily as follows.

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{../Diagrams/}}

\begin{document}
\begin{figure}
\centering
\includegraphics[scale=1.5]{Template}
\caption{This is my PSTricks template.}
\label{fig:Template}
\end{figure}
\end{document}


The important points are:

• Load graphicx and set the graphics path. Adjust the scale to meet your preference.
• Compile it with pdflatex or xelatex. You cannot use latex-dvips-ps2pdf unless you have EPS equivalent for each PDF output.
-
In case anyone is interested, I ended up using \documentclass[12pt]{standalone} in the file where the picture was drawn. It worked fine. –  bogus Mar 25 '12 at 19:41
@user20520: standalone internally uses preview package. –  stalking is prohibited Mar 25 '12 at 19:47
@bogus: I updated the template in my answer, now it uses standalone class you prefer. –  stalking is prohibited Sep 7 '13 at 2:57

Say your PSTricks figure file looks like this:

\begin{pspicture}(0,-2.4)(7.72,2.4)
\psframe[linewidth=0.04,dimen=outer](7.72,2.4)(0.0,-2.4)
\end{pspicture}


saved by the name picture_file.tex in the same folder as your main latex file.

In your latex main file, saved by the name main_file.tex, add

\usepackage{pstricks}    %for embedding pspicture.
\usepackage{graphicx}    %for figure environment.


Now, the picture_file.tex can be included in the main_file.tex as:

%=========================
\begin{figure}[h]
\centering{
\resizebox{0.5\textwidth}{!}{\input{picture_file.tex}}}

Only the main_file.tex needs be compiled.
2. Make sure the \documentclass[...]{...} does not have minimal or letter as the type, in which case, the figure environment would not be recognized.