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.

I am trying to:

  1. Export a gnuplot .gpl file to a .ps
  2. Get my .tex file to use the .ps file as an image
  3. Convert that .tex file to a pdf

I created the following gnuplot .gpl file which exports 'a03e02.ps' as its output:

set terminal postscript portrait
set title "Dirac Delta-Function"
set xrange[-.01:.01]
set yrange[*:*]
set xlabel 'Independent Variable'
set ylabel 'Dependent Variable'
plot sin(2500*x)/(pi*x)
set output 'a03e02.ps'

The .ps file successfully appears after I run "gnuplot a03e02.gpl" in the command line. My .tex file that I want to read the .ps file read as such:

\documentclass{article}
\begin{document}
\begin{equation}
$\delta_n(x)=\frac{sin(nx)}{{\pi}x}=\frac{1}{2\pi}\int_{-\pi}^{\pi}e^{ixt}dt$
\end{equation}
\\
\begin{figure}
\centerline{
\includegraphics[width=8cm,angle=270]{a03e02.ps}
}
\caption{This is the Dirac $\delta$-function graphed between $x=\pm.01$ for $n=2500$}
\end{figure}
\end{document}

It is quite simple and should be working fine, but when I try either of the following to my .tex file (dirac.tex) I get a pdf that has no image from the .ps file:

latex2e dirac.tex
dvipdf dirac.dvi

or

pdflatex dirac.tex

When I use the latex2e > dvipdf method, I even get a latex file that displays my entries out of order!

You can take a look at the output here to see what I am talking about:

http://www.physics.utah.edu/~u0459335/dirac.pdf

Thank you in advance for any direction, you guys are always helpful. :)

share|improve this question

migrated from stackoverflow.com Oct 2 '13 at 11:09

This question came from our site for professional and enthusiast programmers.

    
This may be too obvious, but did you try dvips and then ps2pdf as separate steps? –  luser droog Sep 17 '13 at 3:08
    
Perhaps you can elaborate on how dvips would help me (I thought it was for converting dvi to ps which is the opposite of the process here, but I could be wrong), but per your advice I tried using ps2pdf to change a03e02.ps to a03e02.pdf and changing the .tex file to read .pdf as the graphics output but it comes up blank. I am starting to think that it is just my school machines. I am using SSH to go into them and every week they seem to be missing plugins, programs, etc. Last week we had a problem because the systems administrator let the server fill up and we got Disk Quota errors. Fun :( –  Adam West Sep 17 '13 at 4:10
    
I've added more explanation as an answer. For Disk Quota problems, make sure you delete any *.core files that might have been created by crashed programs. HTH. :) –  luser droog Sep 17 '13 at 4:24

2 Answers 2

up vote 7 down vote accepted
+150

The main problem is, that you must set output before plotting!

set terminal postscript ps
set output 'a03e02.ps'
plot sin(2500*x)/(pi*x)

I tested with dvipdf, and it worked for me (TeXLive 2013), but personally I always use the latex -> dvips -> ps2pdf chain.

Some comments to the LaTeX-document:

  • You must include the graphicx package

  • You cannot use $ inside the equation-environment

  • figure is a floating environment, no need to place a \\ before it (BTW: This is also wrong for adding a new paragraph, this is done by an empty line or a \par).

  • An opened bracket { with a newline is prone for extra spacings.

  • Why do you rotate the image by 270?

  • I wouldn't set the width in the LaTeX-document but rather in the gnuplot script, so that you do not have different scalings for different images. Although you have vector images, the linewidth will change and the font size also.

  • You shouldn't set the image extension in the \includegraphics argument.

  • Use \sin instead of sin.

Here is how I would do it:

set terminal postscript eps size 8cm,6cm
set title "Dirac Delta-Function"
set xrange[-.01:.01]
set xlabel 'Independent Variable'
set ylabel 'Dependent Variable'
set samples 1000
set output 'a03e02.eps'
plot sin(2500*x)/(pi*x)

The LaTeX-document:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{equation}
\delta_n(x)=\frac{\sin(nx)}{{\pi}x}=\frac{1}{2\pi}\int_{-\pi}^{\pi}e^{ixt}dt
\end{equation}

\begin{figure}
\centering
\includegraphics{a03e02}
\caption{This is the Dirac $\delta$-function graphed between $x=\pm.01$ for $n=2500$.}
\end{figure}
\end{document}

This gives (using latex -> dvipdf):

enter image description here

You could also use the epslatex terminal to get the same fonts and enhanced math in you gnuplot image.

share|improve this answer
    
This worked! Thank you very much for also explaining the positioning of set output and the usepackage{graphicx} line in the LaTeX document. –  Adam West Sep 17 '13 at 16:43

Edit: The following may be of historical interest only, or useful only on older installations! It appears that recent versions dvipdf will invoke gs to convert the graphics to pdf automatically.

When you include a postscript graphic in your document, you will also need to include a postscript processor in the chain. Instead of

latex2e dirac.tex
dvipdf dirac.dvi

try

latex2e dirac.tex
dvips dirac.dvi
ps2pdf dirac.ps

dvipdf can convert the "dvi" (TeX's native output format) directly into pdf, but it cannot process the postscript program. dvips works just the same, but it outputs postscript, and your included graphic will be included in the output. Then, ps2pdf can convert the whole thing to pdf.

dvipdf is a more recent program that skips the postscript step. But if you need to insert postscript, it needs to be processed by a postscript interpreter.

share|improve this answer
    
I get less errors this time, but document still appears pretty much the same. You can view the output here still: physics.utah.edu/~u0459335/dirac.pdf That is a really good explanation about the need for dvips, though! :) –  Adam West Sep 17 '13 at 4:48
1  
I found one document that suggests converting to EPS (encapsulated postscript) first: kb.mit.edu/confluence/pages/viewpage.action?pageId=3907319 and another document that suggests adding \usepackage{graphicx} to the preamble: math.mun.ca/~edgar/includeps.html . Latex is a little out of my expertise. :( –  luser droog Sep 17 '13 at 4:57

Your Answer

 
discard

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