I am using psfrag
for figures quite often and generating my figures in eps
format. I would like to set up my AUCTeX to use latex->dvips->ps2pdf
automatically. And at the end view the pdf file from inside Emacs with the help of AUCTeX view button.
I looked into this thread
How to replace AUCTeX's "LaTeX" command with latex->dvips->ps2pdf chain?
but I guess the options should be a bit different since I upgraded to the latest version of AUCTeX.
Any ideas on how to enable this and make it my default compile process by using my init file?
EDIT: Here is the updated part from my side. I guess I made quite some progress with the input of Arash in the below answer but there is a very small thing that is not clear. The below code is a minimal example which also uses psfrag and does what I would like to perform if I set C-c C-t C-p
explicitly after saving this code in a file, say, simple.tex, namely, the steps followed are as follows,
- Save the below code in a file called simple.tex:
\documentclass{article} \usepackage{psfrag} \usepackage{graphicx} \usepackage[sc,osf]{mathpazo} % With old-style figures and real smallcaps. \linespread{1.025} % Palatino leads a little more leading % \begin{document} \begin{figure} \centering % \psfrag{X}[][]{$x$} \psfrag{Y}[][]{$y$} \psfrag{Z}[][]{$z$} % \psfrag{0}[][]{$0$} \psfrag{0}[][]{$0$} \psfrag{0.6}[][]{$0.65$} \psfrag{1.2}[][]{$1.2$} \psfrag{0.25}[][cl]{$0.25$} \psfrag{0.5}[][cl]{$0.5$} % get the image from imagebin: % test.eps location, https://imagebin.ca/v/3x1gUN0CmKbo % save it as test.eps \includegraphics[width=\textwidth]{test} \end{figure} \end{document}
Extra info: I have this line
(setq-default TeX-master nil)
in my init file as the AUCTeX manual suggests. To ask for the master file for each file that is open
If after step 1, I do C-c C-c then emacs asks for the master file, default is to set the above file as master, just typed return
After typing return, these 4 new lines are added to the file to show that it is the master file:
%%% Local Variables: %%% mode: latex %%% TeX-master: t %%% End:
and asks to save the file, ok, pressed y and saved it.
Then it jumped to Command (default LaTeX): which is followed by enter. Latex succesfully compiled the document to dvi format.
Now if I perform one more C-c C-c, I am getting
Cannot find "dvips and gv" viewer. Select another one in 'TeX-view-program-selection'
This was the part that was not working for viewing the output file as a pdf output although I had the following in my init file which were added after performing M-x customize variable for
TeX-PDF-mode -> setting it to on
Tex-PDF-from-DVI -> setting it to dvips - ps2pdf under Value Menu
And the exact settings added to the init file after these are turned on from inside emacs are as follows:
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(TeX-PDF-mode t)
'(TeX-PDF-from-DVI "Dvips"))
At this point, I can not view the pdf output because it is compiled in the latex mode(just for dvi output, I believe), although the TeX-PDF-mode is set to true(t) above in the init file(which is strange).
After the above error message, as mentioned above, if I explicitly switch to pdf mode with C-c C-t C-p
, then C-c C-a
gives me the correct output with all the psfrag substitutions. But I still did not understand why it is not set by default as I open the document since TeX-PDF-mode is set to true.
In the end, I get what I want but I did not totally understand why the file does not open in pdf-mode while "TeX-PDF-mode t" is in the init file.