Add 'universal preamble' to org tex export

This commit is contained in:
TEC 2020-07-03 00:51:54 +08:00
parent 3f6dbd5e1f
commit 8396ceed74
1 changed files with 40 additions and 15 deletions

View File

@ -4984,20 +4984,9 @@ Now for a few more adjustments.
'("latexmk -shell-escape -interaction=nonstopmode -f -pdf -output-directory=%o %f")))
#+END_SRC
Instead of just loading doing the 'minted stuff' all the time, we can try to be
a bit cleverer.
#+NAME: org-latex-smart-minted
#+BEGIN_SRC emacs-lisp
(defadvice! org-latex-header-smart-minted (orig-fn tpl def-pkg pkg snippets-p &optional extra)
"Include minted config if src blocks are detected."
:around #'org-splice-latex-header
(let ((header (funcall orig-fn tpl def-pkg pkg snippets-p extra))
(src-p (when (save-excursion
(goto-char (point-min))
(search-forward-regexp "#\\+BEGIN_SRC\\|#\\+begin_src" nil t))
t)))
(concat header
(when src-p "
We also want a particular preamble when minted is used,
#+NAME: org-minted-preamble
#+BEGIN_SRC LaTeX
\\usepackage{minted}
\\usepackage[many]{tcolorbox}
\\setminted{
@ -5038,7 +5027,43 @@ a bit cleverer.
]
}
\\AfterEndEnvironment{minted}{\\end{tcolorbox}}
\\renewcommand\\theFancyVerbLine{\\color{black!60!white}\\arabic{FancyVerbLine}} % minted line numbering"))))
\\renewcommand\\theFancyVerbLine{\\color{black!60!white}\\arabic{FancyVerbLine}} % minted line numbering
#+END_SRC
We also always want some particular elements in the preamble, let's call this
the "universal preamble"
#+NAME: org-universal-preamble
#+BEGIN_SRC LaTeX
\\usepackage[main,input,include]{embedall}
\\IfFileExists{./\\jobname.org}{\\embedfile{\\jobname.org}}{}
#+END_SRC
Instead of just loading doing the 'minted stuff' all the time, we can try to be
a bit cleverer, and handle the "universal preamble" while we're at it.
#+NAME: org-latex-smart-minted
#+BEGIN_SRC emacs-lisp :noweb yes
(after! org
(defadvice! org-latex-header-smart-minted (orig-fn tpl def-pkg pkg snippets-p &optional extra)
"Include minted config if src blocks are detected."
:around #'org-splice-latex-header
(let ((header (funcall orig-fn tpl def-pkg pkg snippets-p extra))
(src-p (when (save-excursion
(goto-char (point-min))
(search-forward-regexp "#\\+BEGIN_SRC\\|#\\+begin_src" nil t))
t)))
(concat header
org-latex-universal-preamble
(when src-p org-latex-minted-preamble))))
(defvar org-latex-minted-preamble "
<<org-minted-preamble>>
"
"Preamble to be inserted when minted is used.")
(defvar org-latex-universal-preamble "
<<org-universal-preamble>>
"
"Preamble to be included in every export."))
#+END_SRC
***** Chameleon --- aka. match theme
Once the idea of having the look of the LaTeX document produced match the