flumglum · 2022-09-12 04:38
I have been using vimtex plugin of vim which has this nice feature that every time I save the Tex file, the PDF file updates itself. I have recently switched to Emacs and now using Autex package for latex compilation. To update the PDF, it requires C-c C-c each time. I am wondering there might be a way to set it up such that it updates the PDF file when the file is saved without requiring C-c C-c. By the way I am using evil mode.
lebensterben · 2022-09-12 04:57
you can use https://github.com/latex-lsp/texlab
and set https://github.com/latex-lsp/texlab/blob/master/docs/options.md#texlabbuildonsave
TunaCowboy · 2022-09-12 05:08
[`after-save-hook`](https://www.gnu.org/software/emacs/manual/html_node/elisp/Saving-Buffers.html#index-after_002dsave_002dhook)
ninjaguppy · 2022-09-12 05:29
I’m on mobile so I can’t provide the whole setup right now, but if you compile with `latexmk`you can set that to continuously compile whenever the saved file is updated!
[deleted] · 2022-09-12 05:36
[deleted]
franburstall · 2022-09-12 06:13
Auctex solution:
;; revert pdf-view after compilation
(add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer)
fieldri1 · 2022-09-12 07:06
I second latexmk. Create the latex file, and put in the bare minimum to create a document, then open command line in that directory and run latexmk - pvc filename.tex. The file will be compiled and displayed. Make edits and save to see the changes. The only foible is that if the file isn't valid then the compilation fails and you have to nudge it to get it going again.
I usually prefer to just hammer out the text and revisit appearance afterwards, but modern machines are so powerful this is a practical way of working, even on longer and more complex docs.
[deleted] · 2022-09-12 07:28
[deleted]
PhantomSeahorse · 2022-09-12 12:59
This is a good tip but doesn’t really answer the question tho
franburstall · 2022-09-12 18:43
Yeah---didn't read the question correctly. My bad.
flumglum · 2022-09-13 00:38
Thank you! This is the exact thing I am looking for.
Aminumbra · 2022-09-13 12:16
Just to add another perspective on that: setting `TeX-save-query` to `nil` will do something "similar".
What is you ask for is "Press the 'save' buttons and have LaTeX automatically recompile" (which means that you cannot save without recompiling, but can compile without saving), this would give you the following workflow: "Press compile and auto-save". Of course, you can do both (use this variable, and `after-save-hook` too).
Personnally, I would advise against automatic recompilation when saving:
\- you typically want to save often, sometimes in a "dirty" state, and compiling this would not really make sense
\- compiling a document can take a long time. You typically don't want to do it as often as you save.
\- If you ever try to re-compile while the process is already running (e.g. you re-save the document after a minor change, just after having already saved), you would have conflicts, an annoying prompt to kill the already-running process, etc.
On the other hand, using `C-c C-a` to recompile (and save) when you \*really\* want to spend time recompiling gives the best of both world, in my opinion. But you do you !