[Tex/LaTex] How to export the eps file from the .tex file using pdfLaTex

epstexstudiotikz-pgf

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?

Best Answer

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