How to Make Emacs and AUCTeX Use MiKTeX on Windows
At a glance
- 1. Find MiKTeX’s bin folder
Locate the directory containing pdflatex.exe, latex.exe, and other MiKTeX command-line tools.
- 2. Put it on PATH
Add that directory to Windows PATH, then restart Emacs so it inherits the updated environment.
- 3. Check the compiler
Run where pdflatex and pdflatex --version in Command Prompt to confirm MiKTeX is found.
- 4. Compile from Emacs
Open a .tex file, press C-c C-c, and choose PDFLaTeX or the engine you need.
Emacs does not need a special connection to MiKTeX. AUCTeX starts TeX programs such as pdflatex or latex as external commands, so the key is making MiKTeX’s command-line programs discoverable to Emacs. Once that works, you can compile from the editor with AUCTeX’s usual command.
1. Find MiKTeX’s executable directory
Locate the MiKTeX installation folder that contains pdflatex.exe. Common locations for a 64-bit installation include:
C:\Program Files\MiKTeX\miktex\bin\x64C:\Users\your-name\AppData\Local\Programs\MiKTeX\miktex\bin\x64
The exact folder depends on the MiKTeX version and whether it was installed for all users or just your Windows account. Look for the directory containing pdflatex.exe, latex.exe, and often xelatex.exe; do not add the parent folder unless that is where the executable files are.
2. Add the directory to Windows PATH
Windows PATH is a list of folders searched when a program is started by name. Add the MiKTeX bin directory to PATH:
- Open Start and search for Edit the system environment variables.
- Open Environment Variables.
- Under your user variables, select
Pathand choose Edit. Adding it to your user PATH is usually sufficient. - Choose New, enter the directory containing
pdflatex.exe, and save the dialogs. - Close and reopen Emacs. If Emacs was launched from a terminal, close and reopen that terminal too.
Restarting matters: an Emacs process that was already running generally keeps the environment it received when it started. If you have more than one TeX distribution installed, put the MiKTeX bin directory before other TeX directories in PATH if you want MiKTeX to be the one found first.
3. Verify MiKTeX from Windows
Open a new Command Prompt and run:
where pdflatex
pdflatex --version
where pdflatex should list a path inside your MiKTeX installation. The version command should print MiKTeX’s pdfTeX information. If it reports that the command cannot be found, check that you added the correct bin folder and opened a new Command Prompt.
If where pdflatex lists multiple paths, Windows uses the first matching executable. Reorder PATH if the first one is from a different TeX distribution.
4. Compile with AUCTeX
Open a .tex file in Emacs and press C-c C-c (hold Control and press c twice). AUCTeX asks which command to run. Choose PDFLaTeX to produce a PDF directly, or choose another engine such as XeLaTeX when the document needs it. AUCTeX will run that program using the environment available to Emacs.
For documents that should normally produce PDF output, you can enable AUCTeX’s PDF mode in your Emacs initialization file:
(setq TeX-PDF-mode t)
Restart Emacs or evaluate that line, then use C-c C-c and select the appropriate PDF-producing command if it is offered. The mode controls AUCTeX’s PDF workflow; it does not install MiKTeX or fix a missing PATH entry.
If Command Prompt works but Emacs does not
First fully quit and restart Emacs. If it still cannot find the program, check Emacs’s view of PATH by evaluating M-: (getenv "PATH") and confirm that it includes the MiKTeX bin directory. You can also add the directory to Emacs’s executable search path in your initialization file, replacing the example with your actual folder:
(let ((miktex-bin "C:/Program Files/MiKTeX/miktex/bin/x64"))
(setenv "PATH" (concat miktex-bin ";" (getenv "PATH")))
(add-to-list 'exec-path miktex-bin))
Forward slashes are accepted in Emacs Lisp paths on Windows. This adjustment is useful when Emacs is launched by a desktop shortcut that does not inherit the PATH you expect. Prefer fixing Windows PATH when possible, so other applications can find MiKTeX too.
Common mistakes
- Adding the wrong directory: PATH must contain the folder holding
pdflatex.exe, not the executable’s filename and not just the MiKTeX installation’s top-level folder. - Forgetting to restart Emacs: updating Windows PATH does not retroactively change the environment of an already-running Emacs process.
- Choosing the wrong engine:
latexnormally produces DVI output; choose PDFLaTeX when you want a PDF from a conventional LaTeX document. XeLaTeX and LuaLaTeX are alternatives for documents that need their features. - Assuming AUCTeX installs TeX: AUCTeX provides editing and command integration. MiKTeX supplies the compiler and packages. If compilation starts but reports a missing package, manage packages through MiKTeX Console or its package installation prompts.
A quick diagnosis is to compare where pdflatex in Command Prompt with the PATH visible inside Emacs. If the command is unavailable in both, fix the Windows PATH or MiKTeX installation; if it works only in Command Prompt, restart Emacs or adjust Emacs’s environment.
References
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.