diff --git a/doom/config.org b/doom/config.org index 650c28b..ebd3201 100644 --- a/doom/config.org +++ b/doom/config.org @@ -452,31 +452,29 @@ The target indentation style of ~LaTeX~ is as follows: The ~SPC m c~ command which by default binds to ~TeX-command-run-all~ is modified so it runs in the directory of the nearest ~.latexmkrc~ file or the projectile root, whichever is closer. If a ~.latexmkrc~ file is not found, we -fall back to the current directory. +fall back to the current directory. We improve this below by decreeing that all +compilation has to happen with the ~.latexmkrc~ file's directory as PWD. #+begin_src emacs-lisp -(defun custom/TeX-compile-in-root () - "Execute ~TeX-command-run-all~ in the nearest ~.latexmkrc~ directory or - projectile project root." - (interactive) - (let* - ((dir-latexmkrc - (projectile-locate-dominating-file default-directory ".latexmkrc")) - (dir-projectile (projectile-project-root)) - (is-latexmk-child-of-projectile (string-match-p (regexp-quote dir-projectile) dir-latexmkrc)) - (dir-work (cond - ((and dir-latexmkrc is-latexmk-child-of-projectile) dir-latexmkrc) - (dir-projectile dir-projectile) - (t default-directory))) - (dir-current-rel (string-remove-prefix dir-work default-directory)) - (file-current-rel (concat dir-current-rel (TeX-master-file)))) - ; Execute in shadowed ~default-directory~ - (cl-labels ((replace-pwd () dir-work) (replace-file (&optional extension nondirectory ask) file-current-rel)) - (advice-add 'TeX-master-directory :override #'replace-pwd) - (advice-add 'TeX-master-file :override #'replace-file) - (TeX-command-run-all nil) - (advice-remove 'TeX-master-file #'replace-file) - (advice-remove 'TeX-master-directory #'replace-pwd) - ))) +(defun custom/TeX-root-directory (start) + (let* ( + (dir-latexmkrc (projectile-locate-dominating-file start ".latexmkrc")) + (dir-projectile (projectile-project-root)) + (is-latexmk-child-of-projectile (and dir-projectile dir-latexmkrc + (string-match-p (regexp-quote dir-projectile) dir-latexmkrc)))) + (cond + ((and dir-latexmkrc is-latexmk-child-of-projectile) dir-latexmkrc) + (dir-projectile dir-projectile) + (t start)))) +(defun custom/TeX-master-directory-filter (dir-master) + (custom/TeX-root-directory dir-master)) +(defun custom/TeX-master-file-filter (file-master) + (concat + (string-remove-prefix (custom/TeX-root-directory default-directory) default-directory) + file-master + )) + +(advice-add 'TeX-master-directory :filter-return #'custom/TeX-master-directory-filter) +(advice-add 'TeX-master-file :filter-return #'custom/TeX-master-file-filter) #+end_src @@ -502,7 +500,6 @@ introduced. :desc "View Compilation Log" "l" #'TeX-recenter-output-buffer :desc "Next Error" "e" #'TeX-next-error :desc "Close Environment" "]" #'LaTeX-close-environment - :desc "Compile in root" "." #'custom/TeX-compile-in-root (:prefix ("f" . "Fold") :desc "Fold Mode" "f" #'TeX-fold-mode :desc "Environment" "e" #'TeX-fold-env