Split ox-chameleon out into its own package

This commit is contained in:
TEC 2021-08-30 04:48:08 +08:00
parent 31ff2c4750
commit f5d6c5765e
Signed by: tec
GPG Key ID: 779591AFDB81F06C
3 changed files with 15 additions and 202 deletions

3
.gitmodules vendored
View File

@ -19,6 +19,9 @@
[submodule "emacs-everywhere"]
path = lisp/emacs-everywhere
url = https://github.com/tecosaur/emacs-everywhere.git
[submodule "ox-chameleon"]
path = lisp/ox-chameleon
url = https://github.com/tecosaur/ox-chameleon.git
[submodule "ob-julia"]
path = lisp/ob-julia
url = https://github.com/nico202/ob-julia.git

View File

@ -9355,211 +9355,20 @@ tempfile, this can provide a caching mechanism.
(org-latex--inline-image link info))))
#+end_src
**** Chameleon --- aka. match theme
Once I had the idea of having the look of the LaTeX document produced match the
current Emacs theme, I was enraptured. The result is the pseudo-class ~chameleon~.
#+begin_src emacs-lisp
(after! ox
(defvar ox-chameleon-base-class "scr-article"
"The base class that chameleon builds on")
current Emacs theme, I was enraptured. The result is the pseudo-class ~chameleon~,
which I have implemented in the package =ox-chameleon=.
(defvar ox-chameleon--p nil
"Used to indicate whether the current export is trying to blend in. Set just before being accessed.")
;; (setf (alist-get :filter-latex-class
;; (org-export-backend-filters
;; (org-export-get-backend 'latex)))
;; 'ox-chameleon-latex-class-detector-filter)
;; (defun ox-chameleon-latex-class-detector-filter (info backend)
;; ""
;; (setq ox-chameleon--p (when (equal (plist-get info :latex-class)
;; "chameleon")
;; (plist-put info :latex-class ox-chameleon-base-class)
;; t)))
;; TODO make this less hacky. One ideas was as follows
;; (map-put (org-export-backend-filters (org-export-get-backend 'latex))
;; :filter-latex-class 'ox-chameleon-latex-class-detector-filter))
;; Never seemed to execute though
(defadvice! ox-chameleon-org-latex-detect (orig-fun info)
:around #'org-export-install-filters
(setq ox-chameleon--p (when (equal (plist-get info :latex-class)
"chameleon")
(plist-put info :latex-class
(if (plist-get info :beamer-theme) "beamer"
ox-chameleon-base-class))
t))
(funcall orig-fun info))
(defadvice! ox-chameleon-org-latex-export (orig-fn info &optional template snippet?)
:around #'org-latex-make-preamble
(setq .info info)
(if (and ox-chameleon--p (not snippet?))
(let ((engrave-faces-preset-styles (engrave-faces-generate-preset)))
(concat (funcall orig-fn info template snippet?)
(ox-chameleon-generate-colourings info)))
(funcall orig-fn info template snippet?)))
(defun ox-chameleon-generate-colourings (info)
(concat
"\n%% make document follow Emacs theme\n"
(ox-chameleon--generate-fgbg-colours)
(if (plist-get info :beamer-theme)
(concat (ox-chameleon--generate-beamer-colourings)
(ox-chameleon--generate-beamer-list-colourings))
(concat "\n\\pagecolor{obg}\n\\color{ofg}\n"
(ox-chameleon--generate-list-colourings)
(ox-chameleon--generate-koma-structural-colourings)))
(ox-chameleon--generate-text-colourings)
(ox-chameleon--generate-src-colourings)
"\n%% end customisations\n\n"))
(defun ox-chameleon--generate-fgbg-colours ()
(apply #'format
"\n\\definecolor{obg}{HTML}{%s}\n\\definecolor{ofg}{HTML}{%s}\n"
(mapcar (doom-rpartial #'substring 1)
(list
(face-attribute 'default :background)
(face-attribute 'default :foreground)))))
(defun ox-chameleon--generate-text-colourings ()
(apply #'format
"
%% textual elements
\\definecolor{link}{HTML}{%s}
\\definecolor{cite}{HTML}{%s}
\\definecolor{itemlabel}{HTML}{%s}
\\definecolor{code}{HTML}{%s}
\\definecolor{verbatim}{HTML}{%s}
\\renewcommand{\\labelitemi}{\\textcolor{itemlabel}{\\textbullet}}
\\renewcommand{\\labelitemii}{\\textcolor{itemlabel}{\\normalfont\\bfseries \\textendash}}
\\renewcommand{\\labelitemiii}{\\textcolor{itemlabel}{\\textasteriskcentered}}
\\renewcommand{\\labelitemiv}{\\textcolor{itemlabel}{\\textperiodcentered}}
\\renewcommand{\\labelenumi}{\\textcolor{itemlabel}{\\theenumi.}}
\\renewcommand{\\labelenumii}{\\textcolor{itemlabel}{(\\theenumii)}}
\\renewcommand{\\labelenumiii}{\\textcolor{itemlabel}{\\theenumiii.}}
\\renewcommand{\\labelenumiv}{\\textcolor{itemlabel}{\\theenumiv.}}
\\DeclareTextFontCommand{\\texttt}{\\color{code}\\ttfamily}
\\makeatletter
\\def\\verbatim@font{\\color{verbatim}\\normalfont\\ttfamily}
\\makeatother
"
(mapcar (doom-rpartial #'substring 1)
(list
(face-attribute 'link :foreground)
(face-attribute 'org-cite :foreground)
(face-attribute 'org-list-dt :foreground)
(face-attribute 'org-code :foreground)
(face-attribute 'org-verbatim :foreground)))))
(defun ox-chameleon--generate-list-colourings ()
(format "
%% list labels
\\definecolor{itemlabel}{HTML}{%s}
\\renewcommand{\\labelitemi}{\\textcolor{itemlabel}{\\textbullet}}
\\renewcommand{\\labelitemii}{\\textcolor{itemlabel}{\\normalfont\\bfseries \\textendash}}
\\renewcommand{\\labelitemiii}{\\textcolor{itemlabel}{\\textasteriskcentered}}
\\renewcommand{\\labelitemiv}{\\textcolor{itemlabel}{\\textperiodcentered}}
\\renewcommand{\\labelenumi}{\\textcolor{itemlabel}{\\theenumi.}}
\\renewcommand{\\labelenumii}{\\textcolor{itemlabel}{(\\theenumii)}}
\\renewcommand{\\labelenumiii}{\\textcolor{itemlabel}{\\theenumiii.}}
\\renewcommand{\\labelenumiv}{\\textcolor{itemlabel}{\\theenumiv.}}
"
(substring (face-attribute 'org-list-dt :foreground) 1)))
(defun ox-chameleon--generate-src-colourings ()
(apply #'format
"
%% code blocks
\\definecolor{codebackground}{HTML}{%s}
\\colorlet{EFD}{ofg}
\\definecolor{codeborder}{HTML}{%s}
"
(mapcar (doom-rpartial #'substring 1)
(list
(face-attribute 'solaire-default-face :background)
(doom-blend (face-attribute 'solaire-default-face :background)
(face-attribute 'default :foreground)
0.95)))))
(defun ox-chameleon--generate-koma-structural-colourings ()
(apply #'format
"
%% structural elements
\\definecolor{documentTitle}{HTML}{%s}
\\definecolor{documentInfo}{HTML}{%s}
\\definecolor{level1}{HTML}{%s}
\\definecolor{level2}{HTML}{%s}
\\definecolor{level3}{HTML}{%s}
\\definecolor{level4}{HTML}{%s}
\\definecolor{level5}{HTML}{%s}
\\definecolor{level6}{HTML}{%s}
\\definecolor{level7}{HTML}{%s}
\\definecolor{level8}{HTML}{%s}
\\addtokomafont{title}{\\color{documentTitle}}
\\addtokomafont{author}{\\color{documentInfo}}
\\addtokomafont{date}{\\color{documentInfo}}
\\addtokomafont{section}{\\color{level1}}
\\newkomafont{sectionprefix}{\\color{level1}}
\\addtokomafont{subsection}{\\color{level2}}
\\newkomafont{subsectionprefix}{\\color{level2}}
\\addtokomafont{subsubsection}{\\color{level3}}
\\newkomafont{subsubsectionprefix}{\\color{level3}}
\\addtokomafont{paragraph}{\\color{level4}}
\\newkomafont{paragraphprefix}{\\color{level4}}
\\addtokomafont{subparagraph}{\\color{level5}}
\\newkomafont{subparagraphprefix}{\\color{level5}}
"
(mapcar (doom-rpartial #'substring 1)
(list
(face-attribute 'org-document-title :foreground)
(face-attribute 'org-document-info :foreground)
(face-attribute 'outline-1 :foreground)
(face-attribute 'outline-2 :foreground)
(face-attribute 'outline-3 :foreground)
(face-attribute 'outline-4 :foreground)
(face-attribute 'outline-5 :foreground)
(face-attribute 'outline-6 :foreground)
(face-attribute 'outline-7 :foreground)
(face-attribute 'outline-8 :foreground)))))
(defun ox-chameleon--generate-beamer-colourings ()
(format
"
%% beamer
\\definecolor{builtin}{HTML}{%s}
\\NewCommandCopy{\\oldusetheme}{\\usetheme}
\\renewcommand*{\\usetheme}[2][]{\\oldusetheme[#1]{#2}
\\setbeamercolor{normal text}{fg=ofg, bg=obg}
\\setbeamercolor{alerted text}{fg=builtin}
\\setbeamercolor{progress bar}{fg=builtin}
\\setbeamercolor{title separator}{fg=builtin}
\\setbeamercolor{progress bar in head/foot}{fg=builtin}
\\setbeamercolor{progress bar in section page}{fg=builtin}}
"
(substring (face-attribute 'font-lock-builtin-face :foreground) 1)))
(defun ox-chameleon--generate-beamer-list-colourings ()
(format "
%% beamer list labels
\\definecolor{itemlabel}{HTML}{%s}
\\setbeamercolor*{item}{fg=itemlabel}
"
(substring (face-attribute 'org-list-dt :foreground) 1))))
#+begin_src emacs-lisp :noweb-ref none :tangle packages.el
(package! ox-chameleon :recipe (:local-repo "lisp/ox-chameleon"))
#+end_src
#+begin_src emacs-lisp :noweb-ref none :tangle yes
(use-package! ox-chameleon
:after ox)
#+end_src
**** Make verbatim different to code
Since have just gone to so much effort above let's make the most of it by making
=verbatim= use ~verb~ instead of ~protectedtexttt~ (default).

1
lisp/ox-chameleon Submodule

@ -0,0 +1 @@
Subproject commit afcd7fc4f92303b735e63eae65968ae3ba65e661