Graphics, Figures & TablesProduce EPS from LaTeX File

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Produce EPS from LaTeX File

Post by ghostanime2001 »

How do you produce a .eps file from .tex file so that whatever is drawn in one .tex can be used in another .tex file to be included as a \includegraphics?

This is what I want to be exported as a .eps file:

Code: Select all

\documentclass{article} 
\usepackage{amsmath}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.3]
\draw (0,1.1) -- (10.5,1.1) node[midway,above] {B}; %top
\draw (0,-1.1) -- (10.5,-1.1); %bottom
\draw (0,-1) cos (10.5,0); %top curve
\draw (0,1) cos (10.5,0); %bottom curve
\draw (10.5,1.1) -- (10.5,-1.1) node[midway,anchor=west] {\;$n=1$ \quad $L=\dfrac{1}{4}\lambda_{1}$}; %right
\draw[fill=black] (10.5,0) circle (2.5pt); %circle
\end{tikzpicture} \par\medskip
\begin{tikzpicture}[scale=0.3]
\draw (0,1.1) -- (10.5,1.1) node[midway,above] {C}; %top
\draw (0,-1.1) -- (10.5,-1.1); %bottom
\draw (0,1) cos (3.5,0) sin (7,-1) cos (10.5,0); %top curve
\draw (0,-1) cos (3.5,0) sin (7,1) cos (10.5,0); %bottom curve
\draw (10.5,1.1) -- (10.5,-1.1) node[midway,anchor=west] {\;$n=3$ \quad $L=\dfrac{3}{4}\lambda_{3}$}; %right
\draw[fill=black] (3.5,0) circle (2.5pt); %circle
\draw[fill=black] (10.5,0) circle (2.5pt); %circle
\end{tikzpicture} \par\medskip
\begin{tikzpicture}[scale=0.3]
\draw (0,1.1) -- (10.5,1.1) node[midway,above] {D}; %top
\draw (0,-1.1) -- (10.5,-1.1); %bottom
\draw (0,1) cos (2.1,0) sin (4.2,-1) cos (6.3,0) sin (8.4,1) cos (10.5,0); %top curve
\draw (0,-1) cos (2.1,0) sin (4.2,1) cos (6.3,0) sin (8.4,-1) cos (10.5,0); %bottom curve
\draw (10.5,1.1) -- (10.5,-1.1) node[midway,anchor=west] {\;$n=5$ \quad $L=\dfrac{5}{4}\lambda_{5}$}; %right
\draw[fill=black] (2.1,0) circle (2.5pt); %circle
\draw[fill=black] (6.3,0) circle (2.5pt); %circle
\draw[fill=black] (10.5,0) circle (2.5pt); %circle
\end{tikzpicture} \par\medskip
\begin{tikzpicture}[scale=0.3]
\draw (0,1.1) -- (10.5,1.1) node[midway,above] {E}; %top
\draw (0,-1.1) -- (10.5,-1.1); %bottom
\draw (0,1) cos (1.5,0) sin (3,-1) cos (4.5,0) sin (6,1) cos (7.5,0) sin (9,-1) cos (10.5,0); %top curve
\draw (0,-1) cos (1.5,0) sin (3,1) cos (4.5,0) sin (6,-1) cos (7.5,0) sin (9,1) cos (10.5,0); %bottom curve
\draw (10.5,1.1) -- (10.5,-1.1) node[midway,anchor=west] {\;$n=7$ \quad $L=\dfrac{7}{4}\lambda_{7}$}; %right
\draw[fill=black] (1.5,0) circle (2.5pt); %circle
\draw[fill=black] (4.5,0) circle (2.5pt); %circle
\draw[fill=black] (7.5,0) circle (2.5pt); %circle
\draw[fill=black] (10.5,0) circle (2.5pt); %circle
\end{tikzpicture} 
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Produce EPS from LaTeX File

Post by shadgrind »

This is explained in the "Externalization Library" section of the TikZ manual. You add this to your preamble after loading the pgfplots package:

Code: Select all

\usetikzlibrary{external}
\tikzexternalize
\tikzset{external/system call={latex \tikzexternalcheckshellescape
 -halt-on-error -interaction=batchmode -jobname "\image" "\texsource";
 dvips -o "\image".eps "\image".dvi}}
If your example LaTeX source file is called file.tex, then you would get one .eps file for each tikzpicture, so in your case you'd get four: file-figure0.eps, file-figure1.eps, file-figure2.eps, file-figure3.eps. If instead you want all four tikzpictures to be exported together into a single .eps file, you'd have to modify your TikZ code to have everything in just one tikzpicture. For example, this worked for me:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\usetikzlibrary{external}
\tikzexternalize
\tikzset{external/system call={latex \tikzexternalcheckshellescape
 -halt-on-error -interaction=batchmode -jobname "\image" "\texsource";
 dvips -o "\image".eps "\image".dvi}}
\begin{document}
\begin{tikzpicture}[scale=0.3]
\draw (0,1.1) -- (10.5,1.1) node[midway,above] {B}; %top
\draw (0,-1.1) -- (10.5,-1.1); %bottom
\draw (0,-1) cos (10.5,0); %top curve
\draw (0,1) cos (10.5,0); %bottom curve
\draw (10.5,1.1) -- (10.5,-1.1) node[midway,anchor=west] {\;$n=1$ \quad $L=\dfrac{1}{4}\lambda_{1}$}; %right
\draw[fill=black] (10.5,0) circle (2.5pt); %circle
\begin{scope}[yshift=-5cm]
\draw (0,1.1) -- (10.5,1.1) node[midway,above] {C}; %top
\draw (0,-1.1) -- (10.5,-1.1); %bottom
\draw (0,1) cos (3.5,0) sin (7,-1) cos (10.5,0); %top curve
\draw (0,-1) cos (3.5,0) sin (7,1) cos (10.5,0); %bottom curve
\draw (10.5,1.1) -- (10.5,-1.1) node[midway,anchor=west] {\;$n=3$ \quad $L=\dfrac{3}{4}\lambda_{3}$}; %right
\draw[fill=black] (3.5,0) circle (2.5pt); %circle
\draw[fill=black] (10.5,0) circle (2.5pt); %circle
\end{scope}
\begin{scope}[yshift=-10cm]
\draw (0,1.1) -- (10.5,1.1) node[midway,above] {D}; %top
\draw (0,-1.1) -- (10.5,-1.1); %bottom
\draw (0,1) cos (2.1,0) sin (4.2,-1) cos (6.3,0) sin (8.4,1) cos (10.5,0); %top curve
\draw (0,-1) cos (2.1,0) sin (4.2,1) cos (6.3,0) sin (8.4,-1) cos (10.5,0); %bottom curve
\draw (10.5,1.1) -- (10.5,-1.1) node[midway,anchor=west] {\;$n=5$ \quad $L=\dfrac{5}{4}\lambda_{5}$}; %right
\draw[fill=black] (2.1,0) circle (2.5pt); %circle
\draw[fill=black] (6.3,0) circle (2.5pt); %circle
\draw[fill=black] (10.5,0) circle (2.5pt); %circle
\end{scope}
\begin{scope}[yshift=-15cm]
\draw (0,1.1) -- (10.5,1.1) node[midway,above] {E}; %top
\draw (0,-1.1) -- (10.5,-1.1); %bottom
\draw (0,1) cos (1.5,0) sin (3,-1) cos (4.5,0) sin (6,1) cos (7.5,0) sin (9,-1) cos (10.5,0); %top curve
\draw (0,-1) cos (1.5,0) sin (3,1) cos (4.5,0) sin (6,-1) cos (7.5,0) sin (9,1) cos (10.5,0); %bottom curve
\draw (10.5,1.1) -- (10.5,-1.1) node[midway,anchor=west] {\;$n=7$ \quad $L=\dfrac{7}{4}\lambda_{7}$}; %right
\draw[fill=black] (1.5,0) circle (2.5pt); %circle
\draw[fill=black] (4.5,0) circle (2.5pt); %circle
\draw[fill=black] (7.5,0) circle (2.5pt); %circle
\draw[fill=black] (10.5,0) circle (2.5pt); %circle
\end{scope}
\end{tikzpicture}
\end{document}
When I ran latex (not pdflatex) on that file, I got a single .eps file (file-figure0.eps) containing all four pictures.
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Produce EPS from LaTeX File

Post by ghostanime2001 »

How do I run just LaTeX ?
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Produce EPS from LaTeX File

Post by shadgrind »

ghostanime2001 wrote:How do I run just LaTeX ?

Code: Select all

latex file.tex
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Produce EPS from LaTeX File

Post by ghostanime2001 »

I still don't understand. I am using TexWorks. Do you mean just renaming the file to .tex ?
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Produce EPS from LaTeX File

Post by shadgrind »

No, just run that command in a terminal window.

If you want to do it through the TeXworks GUI, I'm not that familiar with it so I'm not the best person to ask. Maybe this guide will help. You need to setup "latex" as one of the Typeset commands.
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Produce EPS from LaTeX File

Post by ghostanime2001 »

What do you exactly want me to do with my .tex document. And where do I find and what do I do with a terminal window? Are u asking about cmd command window in windows 7 ?
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Re: Produce EPS from LaTeX File

Post by kaiserkarl13 »

I'd suggest you have a look at the Ghostscript utility "ps2epsi"; this will take your PostScript output (*.ps) and make an EPS out of it (the EPSI format is EPS vector graphics plus a low-resolution bitmapped "thumbnail" image, which is ignored by applications which understand EPS but used by those that don't, such as MS-Word).

If you need help with using command-line LaTeX (e.g., why a file might be called [name].tex and what it means to process this file with latex and dvips), I'd find someone locally who can help you. Using a shell (DOS, Bourne, or otherwise) is an integral part of understanding this post.
ghostanime2001
Posts: 402
Joined: Fri May 20, 2011 9:41 am

Re: Produce EPS from LaTeX File

Post by ghostanime2001 »

What if by taking the \tikzpicture environment and running pdflatex on it and making a PDF of just the diagram and crop it to include in another .tex document ? Is there a quality difference between making a encapsulated postscript of a diagram and using the plain PDF cropping way of including pictures ?
Post Reply