# LaTeX mode: How to select “pdflatex” instead of “latex” for a file automatically?

I have a LaTeX file using lots of PDF figures (mostly because converting figures to EPS is a waste of disk space), so it requires to use pdflatex.

I added there lines to the end of my main file:

%% Local Variables:
%% latex-run-command: pdflatex
%% End:


Whenever when I open the file, Emacs asks me whether to evaluate these settings, and I confirm. However, C-c C-f still runs latex \\nonstopmode\\input input.tex.

Why doesn't it work? (this is the question I should point out clearly)

Also in Customize the setting of latex-run-command still is Standard.

After a significant waste of time, I wrote a Makefile that builds my document (keeping the PDF open in evince). So I use compile to build the file now.

Details:

When I run C-c C-f, the output starts like this:

latex \\nonstopmode\\input Farbe.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/TeX Live for SUSE Linux) (preloaded format=latex)


When I run pdflatex manually, the output starts like this:

pdflatex Farbe
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/TeX Live for SUSE Linux) (preloaded format=pdflatex)


So the preloaded format is different, causing errors like

! LaTeX Error: Cannot determine size of graphic in RGB-Cube-3D.pdf (no Bounding
Box).


Also, using latex-run-command: "pdflatex" makes no difference: pdflatex is not being used.

More details:

When I load the file (having changed the settings to the following)

%% Local Variables:
%% latex-run-command: "pdflatex"
%% End:


and then do C-h v latex-run-command, I get:

latex-run-command’s value is "pdflatex"
Original value was "latex"
Local in buffer Farbe.tex; global value is "latex"

This variable’s value is file-local.
This variable may be risky if used as a file-local variable.

Documentation:
Command used to run LaTeX subjob.
LaTeX Mode sets ‘tex-command’ to this string.
See the documentation of that variable.


But still, the command run is not pdflatex, but latex!

• @Drew: Please just read the whole question, especially the part about "C-c C-f". Actually I don't understand your comment. – U. Windl Apr 8 at 19:55
• I tried a tex file of mine with emacs -Q and your local variables. After C-c C-f it does say \$ latex \\nonstopmode\\input tvFellerprobe.tex This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018/Arch Linux) (preloaded format=latex). Is it the same for you or not, when starting the things with emacs -Q – andrej Apr 8 at 20:16
• @andrej: Yes, it's the same. I'll update the question with more details. – U. Windl Apr 8 at 20:31
• Have you tried auctex? It is a much richer mode than the native latex mode and might have something to accommodate your needs. – NickD Apr 8 at 22:20
• I'm pretty sure I provided the answer: the mode function which sets tex-command from latex-run-command runs before the latter is given its file-local value. – NickD Apr 9 at 0:00

## 1 Answer

One problem is the syntax: the value is a string so you need to say so by surrounding it with double quotes. However I could not get this to work with the latex-run-command variable. However tex-command seems to work (for some value of "work"):

%% Local Variables:
%% tex-command: "pdflatex"
%% End:


EDIT: The problem with latex-run-command may be a sequencing problem: when the file is opened, does the mode function get run and then local vars are set? or the other way round? If the mode function is run first, that would explain why the latex-run-comand setting is ineffective: the mode function does

(setq-local tex-command latex-run-command)


so it is probably setting it to the old value, before the local variable setting takes effect. You can try customizing latex-run-command and restarting emacs: I suspect that that would work.

• However customize says for latex-run-command: "LaTeX Mode sets ‘tex-command’ to this string." – U. Windl Apr 8 at 20:42
• It sounds like a bug. Consider the above as a possible workaround. – NickD Apr 8 at 20:52
• Maybe not a bug: see my EDIT. – NickD Apr 8 at 20:57
• On "You can try customizing latex-run-command and restarting emacs": That was not the question: I want to select LaTeX mode for a particular file, not for all LaTeX files. – U. Windl Apr 8 at 21:06
• ... or rather you cannot do it by setting latex-run-command locally in the file. As I demonstrated above, you can set tex-command locally: that works fine. – NickD Apr 8 at 23:59