Add LaTeX command improvements and new packages #3

Merged
aniva merged 3 commits from emacs into main 2023-09-19 21:19:52 -07:00
1 changed files with 22 additions and 25 deletions
Showing only changes of commit 95932db545 - Show all commits

View File

@ -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 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 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 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 #+begin_src emacs-lisp
(defun custom/TeX-compile-in-root () (defun custom/TeX-root-directory (start)
"Execute ~TeX-command-run-all~ in the nearest ~.latexmkrc~ directory or (let* (
projectile project root." (dir-latexmkrc (projectile-locate-dominating-file start ".latexmkrc"))
(interactive) (dir-projectile (projectile-project-root))
(let* (is-latexmk-child-of-projectile (and dir-projectile dir-latexmkrc
((dir-latexmkrc (string-match-p (regexp-quote dir-projectile) dir-latexmkrc))))
(projectile-locate-dominating-file default-directory ".latexmkrc")) (cond
(dir-projectile (projectile-project-root)) ((and dir-latexmkrc is-latexmk-child-of-projectile) dir-latexmkrc)
(is-latexmk-child-of-projectile (string-match-p (regexp-quote dir-projectile) dir-latexmkrc)) (dir-projectile dir-projectile)
(dir-work (cond (t start))))
((and dir-latexmkrc is-latexmk-child-of-projectile) dir-latexmkrc) (defun custom/TeX-master-directory-filter (dir-master)
(dir-projectile dir-projectile) (custom/TeX-root-directory dir-master))
(t default-directory))) (defun custom/TeX-master-file-filter (file-master)
(dir-current-rel (string-remove-prefix dir-work default-directory)) (concat
(file-current-rel (concat dir-current-rel (TeX-master-file)))) (string-remove-prefix (custom/TeX-root-directory default-directory) default-directory)
; Execute in shadowed ~default-directory~ file-master
(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) (advice-add 'TeX-master-directory :filter-return #'custom/TeX-master-directory-filter)
(TeX-command-run-all nil) (advice-add 'TeX-master-file :filter-return #'custom/TeX-master-file-filter)
(advice-remove 'TeX-master-file #'replace-file)
(advice-remove 'TeX-master-directory #'replace-pwd)
)))
#+end_src #+end_src
@ -502,7 +500,6 @@ introduced.
:desc "View Compilation Log" "l" #'TeX-recenter-output-buffer :desc "View Compilation Log" "l" #'TeX-recenter-output-buffer
:desc "Next Error" "e" #'TeX-next-error :desc "Next Error" "e" #'TeX-next-error
:desc "Close Environment" "]" #'LaTeX-close-environment :desc "Close Environment" "]" #'LaTeX-close-environment
:desc "Compile in root" "." #'custom/TeX-compile-in-root
(:prefix ("f" . "Fold") (:prefix ("f" . "Fold")
:desc "Fold Mode" "f" #'TeX-fold-mode :desc "Fold Mode" "f" #'TeX-fold-mode
:desc "Environment" "e" #'TeX-fold-env :desc "Environment" "e" #'TeX-fold-env