1

How to export the image in .eps from the tex code using PdfLaTeX in TeXStudio.

\documentclass{article}
\usepackage{tikz-cd}
\begin{document}
    \begin{tikzcd}  
        A\arrow{d}\arrow{r}[near start]{\phi}[near end]{\psi}&B\arrow[red]{d}{\xi}\\
         C \arrow[red]{r}[blue]{\eta} & D 
    \end{tikzcd}
\end{document}

I have tried with the code given here

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{external}
\tikzexternalize
\begin{document}
  \begin{tikzcd}    
        A\arrow {d}\arrow{r}[near start]{\phi}[near end]{\psi}&B\arrow[red]{d}{\xi}\\
         C \arrow[red]{r}[ blue ]{\eta} & D 
  \end{tikzcd}
\end{document}

I got the following error File ended while scanning use of \tikzexternal@laTeX@collect@until@end@tikzpicture. Also adding the following code in the preamble didn't help me.

\usetikzlibrary{external}
\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape 
        -halt-on-error
        -interaction=batchmode 
        -jobname "\image" "\texsource"
        && pdftops -eps "\image.pdf"}}
\tikzexternalize[shell escape=-enable-write18]

I have found another help using pdftops here, which is helpful for the TeXWorks users. Can any one please help me to export the .eps file of the image using PdfLaTeX?

Litun
  • 3,295
  • 1
    Have you checked this out? http://tex.stackexchange.com/questions/25524/attempting-to-export-tikz-to-eps – Marco Jan 21 '16 at 10:06
  • @Macro That I tried and got the error File ended while scanning use of \tikzexternal@laTeX@collect@until@end@tikzpicture. But I didn't try the steps 1,2,3. – Litun Jan 21 '16 at 10:09

2 Answers2

4

standalone class can be used to create cropped figures but also to convert from pdf them to other formats like png, jpg, ... usually with imagemagick help. See, as example, Compile a LaTeX document into a PNG image that's as short as possible

OP wants to obtain an eps file using pdflatex from TeXstudio.

The idea is using standalone class to do all for us.

As I'm using MikTeX which has a pdftops converter (I don't know if its available on other systems), command

pdftops -eps file.pdf

can be used to convert a pdf file to encapsulated postscript. This command can be included as a standalone class option with:

\documentclass[convert={outext=.eps, command=\unexpanded{pdftops -eps \infile}}]{standalone}

\unexpanded is not mentioned in documentation but it's explained in Martin's answer

Therefore compiling with pdflatex a file like

\documentclass[convert={outext=.eps, command=\unexpanded{pdftops -eps \infile}}]{standalone}
\usepackage{tikz-cd}
\begin{document}
    \begin{tikzcd}  
        A\arrow{d}\arrow{r}[near start]{\phi}[near end]{\psi}&B\arrow[red]{d}{\xi}\\
         C \arrow[red]{r}[blue]{\eta} & D 
    \end{tikzcd}
\end{document}

will generate a pdf and eps results.

Important: -shell-escape must be added in configure options for pdflatex in TeXstudio

Ignasi
  • 136,588
  • It would be better to compile with LaTeX instead: latex -> dvips – pluton Jan 21 '16 at 13:44
  • @pluton Do you mean latex filename.tex and then pdftops -eps filename.pdf? If so, what is the difference? – Marco Jan 21 '16 at 16:00
  • @Ignasi I tried with your code using PdfLaTeX and got only .pdf file. Where to add -shell-escape in the configure options for pdflatex in TeXstudio? In my case the PdfLaTeX has configuration pdflatex.exe -synctex=1 -interaction=nonstopmode %.tex. – Litun Jan 21 '16 at 17:58
  • 1
    @LitunJohn insert it between pdflatex.exe and %.tex – Ignasi Jan 21 '16 at 18:18
  • 1
    @Marco The OP requests the use pdflatex (we do not really know why) but no, I was suggesting latex filename.tex and dvips filename.dvi – pluton Jan 22 '16 at 01:24
  • @pluton In my system, I am unable to get any .dvi output after running LaTeX due to the error Some PostScript specials could not be rendered. I don't know how to get rid of the error. So PdfLaTeX is my favorite. – Litun Jan 22 '16 at 04:30
  • @Ignasi Thank you. Configuring the PdfLaTeX command line to pdflatex.exe -shell-escape %.tex works for me. – Litun Jan 22 '16 at 04:34
0

As an alternative to using \tikzexternalize if the document is stable and you will make few modifications to tikzpicture, it is better to handle it in separate files and include them as an image (or with \input{test-tkz-1.tex}). The ltximg script you can do the following:

$ ltximg  --eps --subenv --imgdir=mypics --extrenv=tikzcd  --margin=10 --prefix=tkz -o test-out test.tex

Now you will have a new document test-out.tex with the tikzpicture environments converted into images (preserving the consistency of the fonts) and you will also have each tikzpicture environment in separate files (in case you need some extra modification) and one file test-all.tex with (only) all tikzpicture.

First check the documentation to see the options and conditions that the input file must meet.