Latexmk -pvc: Automating the Edit-Compile Cycle Without Editor Plugins
Latexmk's preview-continuous mode watches your LaTeX sources and rebuilds the PDF on every save. Here is how to set it up, what it costs, and how to verify it is working.
18 Aug 2026, 09:15 UTC

The edit-compile-view loop in LaTeX is a tax on concentration. You adjust an equation, save, switch to a terminal, run pdflatex, switch back, and inspect the PDF. Do that a few dozen times while tuning a figure or debugging a cross-reference, and the context switching costs more than the typing. latexmk -pvc removes that friction by watching your source tree and rebuilding the output automatically whenever a file changes. It is editor-agnostic, needs no plugins, and works with any editor that writes to disk.
Why Manual Rebuilds Interrupt Technical Writing
LaTeX projects rarely compile in one pass. Bibliographies, cross-references, glossaries, and included figures often require multiple runs before the PDF is correct. Running the compiler by hand after every save means you are also manually managing that dependency chain. latexmk already solves the dependency problem by tracking which files need another pass; the -pvc (preview continuous) flag extends that by turning the tool into a file watcher. Instead of you initiating the build, the build initiates itself.
A Minimal Continuous Build
You need a TeX distribution that ships latexmk—TeX Live and MiKTeX both include it. The following example assumes a normal user account with write access to the working directory; no elevated permissions are required.
Create a file named demo.tex with this content:
\documentclass{article}
\begin{document}
Hello $x^2$
\end{document}
In a terminal, change to the directory containing demo.tex and run:
latexmk -pvc -pdf demo.tex
The command stays in the foreground. Open demo.tex in any text editor, change the text inside the document environment, and save. latexmk should detect the write event and start a new compilation, updating demo.pdf on disk. To stop the watcher, return to the terminal and press Ctrl+C.
If your project uses a master file with many \include or \input statements, point the command at that master file instead:
latexmk -pvc -pdf main.tex
Trade-offs: CPU, Editors, and Project Size
Continuous compilation is not free. The watcher keeps a process alive in the background, and every save triggers a full build. On a large document with heavy graphics or a slow bibliography tool, that rebuild can take enough time to make the loop feel laggy. More importantly, some editors auto-save or run formatting and linting hooks on a timer. If your editor rewrites the file every few seconds, latexmk -pvc will recompile just as often, turning a convenience into a CPU heater.
Version assumptions matter here. Robust -pvc behavior depends on the file-watching backend available to latexmk. Older releases—particularly those before the 4.50 series—may miss events on certain file systems or exhibit bugs with network-mounted directories. If you are on an older version and see missed recompiles, upgrading is the first thing to try.
Editor integration is another axis. If you already use an editor with built-in auto-compilation—Overleaf is the obvious example—running latexmk -pvc alongside it is redundant and risks two processes writing the same PDF simultaneously. In that environment, let the platform handle the build.
Verifying the Loop Before You Rely On It
Before adopting -pvc for a real project, confirm that saves actually trigger builds. A practical check is to watch the terminal output: after each save, latexmk should report that it is running a compilation step. You can also inspect latexmk.log in the working directory; it should contain entries corresponding to the new run.
For a stricter test, compare timestamps. Note the modification time of demo.tex immediately after saving, then check the modification time of demo.pdf. If the PDF is newer, causality is likely. On Linux, you can log file events with a utility such as inotifywait and correlate them with PDF updates:
inotifywait -m demo.tex
Run that in a second terminal while latexmk -pvc is active. Each save should produce a MODIFY event, followed shortly by PDF activity.
Adoption Checklist
- Confirm
latexmkis installed and note its version. - Run
latexmk -pvc -pdf main.texin a dedicated terminal. - Configure your PDF viewer to reload the file automatically, or use a viewer that watches for changes.
- Test with a small edit and verify the PDF timestamp updates.
- Disable editor auto-save if it causes excessive recompiles.
- Skip
-pvcon platforms that already auto-compile, such as Overleaf.
Used deliberately, latexmk -pvc collapses the edit-compile gap into a single step: save, and look. The cost is a resident process and some background CPU; the benefit is that your attention stays on the document instead of the build system.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.