[Tex/LaTex] Setting up LaTeX -> DVIPS -> PS2PDF with Shell-Escape (in TeXStudio)

shell-escapetexstudio

I am trying to set up a "user command" on TeXStudio with the purpose of compiling with shell-escape and the LaTeX -> DviPs -> Ps2Pdf cycle.

This is what I have done to get shell-escape to work and produce PDF output. [Edit: This section edited: see explanation below]

Method 1. In TeXStudio preferences -> Build -> User Commands:

latexmk --shell-escape
latexmk -synctex=1 -interaction=nonstopmode --shell-escape %.tex

See screenshot: top user command, the two lines above are entered from left to right.

enter image description here

Method 2. At the top of my document insert the line:

% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape] 

This line induces TeXStudio to request authorization to compile with shell-escape. This setup has so far worked for me to invoke shell-escape and produce PDF output "on the fly".

By analogy, I tried the following:

Method 1b. User Command:

latex --shell-escape: dvips : ps2pdf : view-pdf
latex -synctex=1 -interaction=nonstopmode --shell-escape %.tex: dvips -o %.ps %.dvi: ps2pdf %.ps

Method 2b. Top of document:

% !TeX TXS-program:compile = txs:///latex/[--shell-escape]

But that does not work. Am I on the right track?

To provide context: my purpose is to be able to compile the code shown here: Recreating a guilloche with TikZ. The code relies on the tkz-fct package and apparently requires the use of shell-escape but does not support pdflatex, suggesting that the latex -> dvips -> ps2pdf route is a natural one to try. And it is the route recommended in the tkz-fct manual.

How to set user commands in TexStudio? is a tex-stackexchange question with a link to the TeXStudio doc, which addresses related problems, but not this particular one head-on.

The TeXStudio documentation is here:

http://svn.code.sf.net/p/texstudio/code/trunk/utilities/usermanual_en.html#SECTION02a

Edit: Explanation about my first edit. I initially wrote that I had been succesful with the following settings:

pdflatex --shell-escape
pdflatex -synctex=1 -interaction=nonstopmode --shell-escape %.tex

However, I had been running this command on documents that had this at the top:

% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape] 

And it turns out that this line overrules my user commands. This is stated explicitly in Harish Kumar's answer (thanks Harish!). Without this overruling line, my user command does not succesfully invoke shell-escape. However, replacing pdflatex with latexmk did invoke shell-escape without the overruling line. I have therefore edited my incorrect claim. Having said that, I do not know much about latexmk other than it seems to be working.

Epilogue: Read Harish Kumar's answer to see how to properly enter the commands. Another thing I have since discovered is that the spanner-shaped button allows you to select among existing commands and to combine several commands, in that way the proper separator will be added between commands. Lastly, if you read the various comments here you will see that one reason why I had a hard time getting this to work was because the LaTeX file I was trying to compile needs gnuplot and I didn't have gnuplot installed on my system, giving me the impression that my commands were not working when they were (after Harish's corrections they were working properly).

Best Answer

If you use the line

% !TeX TXS-program:compile = txs:///latex/[--shell-escape]

at the top of the document, then you don't need any extra user command. Just compile it. Then texstudio will compile it with latex with --shell-escape (of course it will ask your permission) (even if the default build has pdflatex as the compiler) and dvi file is produced. Then you can run DVI2PS and in turn PS2PDF.

Now the question is - whether you would like to compile the document with three clicks or one click. If the latter, then define a new user command like the following:

  1. Type the name of the command in the first box (mine is user2: LaTex.DVIPS.PS2PDF) ( (user2: may be different for you).
  2. Type the command:

    latex --synctex=1 -interaction=nonstopmode --shell-escape %.tex | dvips -o %.ps %.dvi| ps2pdf %.ps
    

in the second box as in this picture:

enter image description here

Note that command separator is |, not :.

Now if you use user2: LaTex.DVIPS.PS2PDF to compile, you won't need that first line: % !TeX TXS-p....

I get this:

enter image description here