# Output graphics code Error

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{amsmath}
\usepackage{pst-plot,pst-node}
\psset{algebraic,plotpoints=100,labelsep=3pt}

\def\f[#1,#2]{2*2^(-2.5*(#1-#2)^2)}

\begin{document}
\begin{pspicture}[showgrid=false](-3,0)(3.5,3)
\psaxes[axesstyle=frame,tickstyle=bottom,ticks=x,ticksize=0 4pt,xsubticks=5,xsubticksize=.5,labels=none](0,0)(-3,0)(3,3)
\uput[d](-1,0){$\omega_{\text{nl}}$}
\uput[d](1.5,0){$\omega_{\text{lin}}$}
\uput[d](0,0){\tiny Frequency}
\psline{<-}(0,2)(1,2)
\psset{linecolor=gray}
\psline[linestyle=dashed](0,0)(0,3)
\psplot[linecolor=red,linestyle=dashed]{-3}{1}{\f[x,-1]}
\psplot[linecolor=red]{-.5}{3}{\f[x,1.5]}
\pcline{<->}(*-1.5 {\f[x,-1]})(*-.5 {\f[x,-1]})\nbput{$\Gamma_{\text{nl}}$}
\pcline{<->}(*1 {\f[x,1.5]})(*2 {\f[x,1.5]})\nbput{$\Gamma_{\text{lin}}$}
\end{pspicture}
\end{document}


I have requested someone to draw a graph and he did this by the code I have shown. I am trying to run this in my Latex file but it is not working. What can I do? Moreover, Can you give any tips so i can draw graph by using LaTeX code.

EDIT:

-
Run with latex->ps or latex->ps->pdf. – azetina Nov 10 '13 at 21:01
What compiler and distribution are you using? – azetina Nov 10 '13 at 21:12
It didn't work for me either until I updated pstricks. After that, latex+dvips+ps2pdf worked fine. By the way, the screen shot seems to be of a different file than is quoted at the start of this answer. – Dan Nov 11 '13 at 4:19
@dan: Yes. The screenshot is different from the code posted at the start of this question. The code posted at the start of this question must be compiled with latex-dvips-ps2pdf sequence. But, the code I posted in my answer wraps latex-dvips-ps2pdf sequence in a host input file (named main.tex) that must be compiled with pdflatex -shell-escape main.tex. – kiss my armpit Nov 11 '13 at 7:14
@Marienplatz, then what else I have to do to compile the latex code. I just copied the code to one of my latex file and then followed dvi->ps ps pdf dvi- pdf – Complex Guy Nov 11 '13 at 7:22

## Important Notes

The following complete code wraps latex-dvips-ps2pdf compilation for the diagram.tex in a host input file (named as main.tex) and this main.tex must be compiled with

pdflatex -shell-escape main.tex


rather than

latex main.tex
dvips main.dvi
ps2pdf -dAutoRotatePages=/None main.ps


## Complete Code

% the name of this file is main.tex
% compile it with
% pdflatex -shell-escape main.tex

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{diagram.tex}
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{amsmath}
\usepackage{pst-plot,pst-node}
\psset{algebraic,plotpoints=100,labelsep=3pt}

\def\f[#1,#2]{2*2^(-2.5*(#1-#2)^2)}

\begin{document}
\begin{pspicture}[showgrid=false](-3,0)(3.5,3)
\psaxes[axesstyle=frame,tickstyle=bottom,ticks=x,ticksize=0 4pt,xsubticks=5,xsubticksize=.5,labels=none](0,0)(-3,0)(3,3)
\uput[d](-1,0){$\omega_{\text{nl}}$}
\uput[d](1.5,0){$\omega_{\text{lin}}$}
\uput[d](0,0){\tiny Frequency}
\psline{<-}(0,2)(1,2)
\psset{linecolor=gray}
\psline[linestyle=dashed](0,0)(0,3)
\psplot[linecolor=red,linestyle=dashed]{-3}{1}{\f[x,-1]}
\psplot[linecolor=red]{-.5}{3}{\f[x,1.5]}
\pcline{<->}(*-1.5 {\f[x,-1]})(*-.5 {\f[x,-1]})\nbput{$\Gamma_{\text{nl}}$}
\pcline{<->}(*1 {\f[x,1.5]})(*2 {\f[x,1.5]})\nbput{$\Gamma_{\text{lin}}$}
\end{pspicture}
\end{document}
\end{filecontents*}

\immediate\write18{latex diagram && dvips diagram && ps2pdf -dAutoRotatePages=/None diagram.ps}

\usepackage{graphicx}
\begin{document}

\begin{figure}[hbtp]
\centering
\caption{Spectrum}\label{fig:diagram}
\includegraphics{diagram}
\end{figure}
Beauty without intelligence is a masterpiece painted on a toilet paper.
\end{document}


## More detailed explanation

In main.tex as a host input file, there is

\immediate\write18{latex diagram && dvips diagram && ps2pdf -dAutoRotatePages=/None diagram.ps}


which will compile diagram.tex with latex-dvips-ps2pdf on the fly.

The diagram.tex is prepared on the fly via filecontents environment as follows.

\usepackage{filecontents}
\begin{filecontents*}{diagram.tex}
\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{amsmath}
\usepackage{pst-plot,pst-node}
\psset{algebraic,plotpoints=100,labelsep=3pt}

\def\f[#1,#2]{2*2^(-2.5*(#1-#2)^2)}

\begin{document}
\begin{pspicture}[showgrid=false](-3,0)(3.5,3)
\psaxes[axesstyle=frame,tickstyle=bottom,ticks=x,ticksize=0 4pt,xsubticks=5,xsubticksize=.5,labels=none](0,0)(-3,0)(3,3)
\uput[d](-1,0){$\omega_{\text{nl}}$}
\uput[d](1.5,0){$\omega_{\text{lin}}$}
\uput[d](0,0){\tiny Frequency}
\psline{<-}(0,2)(1,2)
\psset{linecolor=gray}
\psline[linestyle=dashed](0,0)(0,3)
\psplot[linecolor=red,linestyle=dashed]{-3}{1}{\f[x,-1]}
\psplot[linecolor=red]{-.5}{3}{\f[x,1.5]}
\pcline{<->}(*-1.5 {\f[x,-1]})(*-.5 {\f[x,-1]})\nbput{$\Gamma_{\text{nl}}$}
\pcline{<->}(*1 {\f[x,1.5]})(*2 {\f[x,1.5]})\nbput{$\Gamma_{\text{lin}}$}
\end{pspicture}
\end{document}
\end{filecontents*}


And the last step is to consume the diagram.pdf as illustrated in the host body as follows.

\usepackage{graphicx}
\begin{document}

\begin{figure}[hbtp]
\centering
\caption{Spectrum}\label{fig:diagram}
\includegraphics{diagram}
\end{figure}
Beauty without intelligence is a masterpiece painted on a toilet paper.
\end{document}


If you still don't understand, please drop comments as many as you want!

-
I'm using Winedt how to run by this editor? – Complex Guy Nov 10 '13 at 21:28
@ComplexGuy: I don't use Winedt. I use TeXnicCenter. – kiss my armpit Nov 10 '13 at 21:29
At first I run your code in the tex file called main.tex. After I have got the diagram.tex file. What next? will I run DVI-PS – Complex Guy Nov 11 '13 at 7:47
@ComplexGuy: No. You don't need any other intervention as diagram.pdf will be generated on the fly via latex-dvips-ps2pdf that main.tex invokes silently behind the scene. – kiss my armpit Nov 11 '13 at 8:20
@azetina: To ease the newbie to do everything on the fly. – kiss my armpit Nov 11 '13 at 19:54

Running latex->ps yields the following .ps file:

Running latex->ps->pdf yields the same output but in pdf format. For example, in TeXnicCenter, you can find these options as seen in the diagram below:

Under WinEdt, the options are as follows:

1. Compile using LaTeX as shown.

2. Run dvi->ps. Click on the icon then

3. If pdf is necessary, click on

or after compilation just click on

-
I am using Kile and also Windt. How to run there? – Complex Guy Nov 10 '13 at 21:31
I have attached the image, what is showing the editor when I click Latex – Complex Guy Nov 10 '13 at 22:07
I have done the process, dvi->ps then ps pdf and then dvi pdf. But it showed >> i have edited in the question. please check. – Complex Guy Nov 11 '13 at 6:18