Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\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.

enter image description here

EDIT:

enter image description here

share|improve this question
    
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. –  Who is crazy first 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

2 Answers 2

up vote 4 down vote accepted

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

Please read carefully my note above!

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!

share|improve this answer
    
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. –  Who is crazy first 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. –  Who is crazy first Nov 11 '13 at 8:20
1  
@azetina: To ease the newbie to do everything on the fly. –  Who is crazy first Nov 11 '13 at 19:54

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

enter image description here

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:

enter image description here

Under WinEdt, the options are as follows:

  1. Compile using LaTeX as shown.

    enter image description here

  2. Run dvi->ps. Click on the icon enter image description herethen

  3. If pdf is necessary, click on enter image description here

or after compilation just click on enter image description here

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.