reddit / emacs

Noob question about compiling + viewing pdf

acidoglutammico · 2022-08-06 21:42
Preface: I don't have AUCTeX installed. I have all setup so that a makefile compiles a latex file and creates a pdf. I also setup pdf-tools and synctex. I would like to bind to a key a functions that start to compile, wait for the result, if there is no error from make then it displays in a separate buffer the pdf, else it displays the buffer with the error (which are on stdout because I redirect them and grep the important bits). The makefile is important because there are other scripts that modify the latex before actual rendering. It also makes the setup more friendly with only the terminal. My experience with lisp is unfortunately very small, any suggestions for resources to read are welcome.
junderdown · 2022-08-07 00:43
If you have a Makefile, then `M-x compile` should work. You could bind it to F10 function key via: (define-key tex-mode-map (kbd “<f10>”) `compile) See: [https://www.gnu.org/software/emacs/manual/html\_node/emacs/Compilation.html](https://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation.html) Also, you should be aware that Emacs has a built-in mode for TeX and LaTeX documents that is really bare bones. Since every file has a major mode associated with it, the above line of Elisp adds that F10 key binding to the built-in mode's keymap. If you want to learn more about the built-in mode, you can read:[https://www.gnu.org/software/emacs/manual/html\_node/emacs/TeX-Mode.html](https://www.gnu.org/software/emacs/manual/html_node/emacs/TeX-Mode.html) Getting emacs to open a PDF buffer upon successful compilation is not something I know how to do in Elisp. I use AUCTeX and it does that automatically for me via pdf-tools. In AUCTeX you type `C-c C-c` to compile and then `C-c C-v` to view, or you can do both in one chord: `C-c C-a`.
acidoglutammico · 2022-08-07 13:55
Alright, after many tribulations I discovered that `compile` runs asynchronously so I opted for `shell-command`. Here is my little script: (defun tex-compile-and-view () "Compile and show pdf created by make rule." (interactive) (shell-command "make" "*make*") (find-file "*.pdf" t) ) (eval-after-load 'tex-mode '(define-key latex-mode-map (kbd "C-c C-a") 'tex-compile-and-view)) I would like to be able to detect if there is only one window open in the frame and use `find-file-other-window` to display the pdf. Also error handling is absent. `shell-command` seems to make emacs unresponsive, which is weird.
HM0880 · 2022-08-07 21:29
I just open the PDF manually: .tex on the right and .pdf on the left and use `g` to refresh the pdf (if needed).