Make engrave handle this org file and apply some cosmetics

This commit is contained in:
Gerard Vermeulen 2022-08-21 13:48:09 +02:00
parent 083ff19f16
commit 27401f8c4b
2 changed files with 118 additions and 53 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@
*.log *.log
*.lol *.lol
*.lot *.lot
*.lst
*.out *.out
*.pdf *.pdf
*.run.xml *.run.xml

View File

@ -901,20 +901,22 @@ variable in section are compatible. The local variable ~compile-command~ in the
=pdf= files) shows how to use the =latexmkrc= file. =pdf= files) shows how to use the =latexmkrc= file.
#+attr_latex: :options breaklines #+attr_latex: :options breaklines
#+caption[Tangle the Latexmk resource file]: #+caption[Tangle the =Latexmk= resource file]:
#+caption: Tangle the Latexmk resource file. #+caption: Tangle the =Latexmk= resource file.
#+name: lst:latexmkrc #+name: lst:latexmkrc
#+begin_src perl :tangle latexmkrc :comments none #+begin_src perl :tangle latexmkrc :comments none
# pdf creator # pdf creator
$pdf_mode = 4; # 4 means lualatex $pdf_mode = 4; # 4 means lualatex
# pdf previewer and update pdf previewer # pdf previewer and update pdf previewer
$pdf_previewer = "emacsclient -e '(find-file-other-window %S)'"; $pdf_previewer = "emacsclient -e '(find-file-other-window %S)'";
$pdf_update_method = 4; # 4 runs a command to force the update $pdf_update_method = 4; # 4 runs $pdf_update_command to force the update
$pdf_update_command = "emacsclient -e '(with-current-buffer (find-buffer-visiting %S) (pdf-view-revert-buffer nil t))'"; $pdf_update_command = "emacsclient -e '(with-current-buffer (find-buffer-visiting %S) (pdf-view-revert-buffer nil t))'";
# see for instance glossary.latexmkrc # see for instance glossary.latexmkrc
add_cus_dep( 'acn', 'acr', 0, 'makeglossaries' ); add_cus_dep( 'acn', 'acr', 0, 'makeglossaries' );
add_cus_dep( 'glo', 'gls', 0, 'makeglossaries' ); add_cus_dep( 'glo', 'gls', 0, 'makeglossaries' );
$clean_ext .= " acr acn alg bbl dvi glo gls glg ist lol nav run.xml snm synctex.gz"; # use ".=" to append to $clean_ext
$clean_ext .= " acr acn alg bbl dvi glo gls glg ist lol lst";
$clean_ext .= " nav run.xml snm synctex.gz";
sub makeglossaries { sub makeglossaries {
my ($name, $path) = fileparse( $$Psource ); my ($name, $path) = fileparse( $$Psource );
return system "makeglossaries -d '$path' '$name'"; return system "makeglossaries -d '$path' '$name'";
@ -1940,7 +1942,8 @@ backward compatibility. See table [[tab:org-latex-class-tag-placeholder]] and ty
(custom-set-variables (custom-set-variables
'(org-latex-pdf-process '(org-latex-pdf-process
;; https://tecosaur.github.io/emacs-config/#compiling ;; https://tecosaur.github.io/emacs-config/#compiling
("latexmk -f -pdf -%latex -interaction=nonstopmode -shell-escape -outdir=%o %f")) `(,(concat "latexmk -f -pdf -%latex"
" -interaction=nonstopmode -shell-escape -outdir=%o %f")))
'(org-latex-compiler "lualatex") '(org-latex-compiler "lualatex")
'(org-latex-hyperref-template "\\hypersetup{ '(org-latex-hyperref-template "\\hypersetup{
pdfauthor={%a}, pdfauthor={%a},
@ -2124,24 +2127,32 @@ valid directories and files. In an [[https://orgmode.org/][Org-mode]] buffer th
This package aims to produce a versatile generic core which can process a This package aims to produce a versatile generic core which can process a
fontified buffer and pass the data to any number of backends to deal with fontified buffer and pass the data to any number of backends to deal with
specific output formats and it should work with =org-mode=. *However*, specific output formats and it should work with =org-mode=. *Thanks to the
[[https://github.com/tecosaur/engrave-faces#readme][Engrave Faces]] and [[info:org#Source blocks in LaTeX export][Org source block export to LaTeX (info)]] *are sofar incapable listings below*, [[https://github.com/tecosaur/engrave-faces#readme][Engrave Faces]] and [[info:org#Source blocks in LaTeX export][Org source block export to LaTeX (info)]] *are
of handling this [[file:README.org]] file.* capable of handling this [[file:README.org]] file:*
1. Listing [[lst:ensure-engrave-faces-with-latex-face-mapper-fix]] ensures
Listing [[lst:ensure-and-fix-engrave-faces-installation]] ensures installation of installation of =engrave-faces= and makes =engrave-faces-latex-face-mapper=
=engrave-faces= and fixes =engrave-faces-latex= for multi-line documentation handle multi-line documentation strings.
strings. Listing [[lst:ox-latex-engraved-filter-emacs-lisp-setup]] and 2. Listing [[lst:ensure-engrave-faces-with-latex-face-apply-fix]] ensures
[[lst:smart-latex-engrave-org-source-blocks]] allow to engrave =org-mode= source installation of =engrave-faces= and makes =engrave-faces-latex-face-apply=
blocks to "floating unbreakable" or "non-floating breakable" LaTeX environments. handle symbolic color name strings (in addition to the hexadecimal strings).
3. The =org-latex-engraved-source-block-filter= in listing
[[lst:ox-latex-engraved-filter-emacs-lisp-setup]] and the
=org-latex-engraved-preamble= customization in listing
[[lst:smart-latex-engrave-org-source-blocks]] allow to engrave =org-mode= source
blocks to "floating unbreakable" or "non-floating breakable" LaTeX
environments.
Listing [[lst:ox-latex-engraved-emacs-lisp-setup]] is shows how to use this
configuration.
#+caption[Ensure =engrave-faces= installation and fix multiline docstrings]: #+caption[Ensure =engrave-faces= installation and fix multiline docstrings]:
#+caption: Ensure =engrave-faces= installation and fix multiline docstrings. #+caption: Ensure =engrave-faces= installation and fix multiline docstrings.
#+name: lst:ensure-and-fix-engrave-faces-installation #+name: lst:ensure-engrave-faces-with-latex-face-mapper-fix
#+begin_src emacs-lisp #+begin_src emacs-lisp
(when (ensure-package-installation 'engrave-faces) (when (ensure-package-installation 'engrave-faces)
(require 'engrave-faces-latex nil t)
(defun engrave-faces-latex-face-mapper-override (faces content) (defun engrave-faces-latex-face-mapper-override (faces content)
"Create a LaTeX representation of CONTENT With FACES applied." "Create a LaTeX representation of CONTENT With FACES applied."
(autoload 'engrave-faces-latex-mathescape "engrave-faces-latex" nil t)
(let* ((style (engrave-faces-preset-style faces)) (let* ((style (engrave-faces-preset-style faces))
(protected-content (protected-content
(funcall (funcall
@ -2179,6 +2190,46 @@ blocks to "floating unbreakable" or "non-floating breakable" LaTeX environments.
(toggle-engrave-faces-latex-face-mapper-override)) (toggle-engrave-faces-latex-face-mapper-override))
#+end_src #+end_src
#+caption[Ensure =engrave-faces= installation and fix symbolic colors]:
#+caption: Ensure =engrave-faces= installation and fix symbolic colors.
#+name: lst:ensure-engrave-faces-with-latex-face-apply-fix
#+begin_src emacs-lisp
(when (ensure-package-installation 'engrave-faces)
(require 'engrave-faces-latex nil t)
(defun engrave-faces-latex--html-color (color)
"Convert COLOR loosely to a string of six hexadecimal digits."
(if (char-equal ?# (aref color 0))
(substring color 1 7)
(apply 'format "%02x%02x%02x"
(mapcar (lambda (c) (ash c -8))
(color-values color)))))
(defun engrave-faces-latex-face-apply-override (faces content)
"Convert each compatible parameter of FACES to a LaTeX command applied to CONTENT."
(let ((attrs (engrave-faces-merge-attributes faces)))
(let ((bg (plist-get attrs :background))
(fg (plist-get attrs :foreground))
(it (eql (plist-get attrs :slant) 'italic))
(bl (member (plist-get attrs :weight) '(bold extra-bold)))
(st (plist-get attrs :strike-through)))
(concat
(when bg (concat "\\colorbox[HTML]{"
(engrave-faces-latex--html-color bg) "}{"))
(when fg (concat "\\textcolor[HTML]{"
(engrave-faces-latex--html-color fg) "}{"))
(when st "\\sout{") (when bl "\\textbf{") (when it "\\textit{")
content
(when bg "}") (when fg "}") (when st "}") (when bl "}") (when it "}")))))
(defun toggle-engrave-faces-latex-face-apply-override ()
"Toggle `engrave-faces-latex-face-apply' advice."
(interactive)
(toggle-advice 'engrave-faces-latex-face-apply
:override #'engrave-faces-latex-face-apply-override))
(toggle-engrave-faces-latex-face-apply-override))
#+end_src
#+caption[Engrave to floating unbreakable or non-floating breakable environments]: #+caption[Engrave to floating unbreakable or non-floating breakable environments]:
#+caption: Define an =org-export= filter function to engrave =org-src-mode= #+caption: Define an =org-export= filter function to engrave =org-src-mode=
#+caption: blocks to floating unbreakable LaTeX environments or non-floating #+caption: blocks to floating unbreakable LaTeX environments or non-floating
@ -2225,41 +2276,51 @@ blocks to "floating unbreakable" or "non-floating breakable" LaTeX environments.
[FVEXTRA-SETUP] [FVEXTRA-SETUP]
% Make code and line numbers normalsize. Make line numbers grey. % Make code and line numbers normalsize. Make line numbers grey.
\\renewcommand\\theFancyVerbLine{\\normalsize\\color{black!40!white}\\arabic{FancyVerbLine}} \\renewcommand\\theFancyVerbLine{
\\normalsize\\color{black!40!white}\\arabic{FancyVerbLine}}
% In case engrave-faces-latex-gen-preamble has not been run. % In case engrave-faces-latex-gen-preamble has not been run.
\\providecolor{EfD}{HTML}{f7f7f7} \\providecolor{EfD}{HTML}{f7f7f7}
\\providecolor{EFD}{HTML}{28292e} \\providecolor{EFD}{HTML}{28292e}
% To use \\DeclareTColorBox from the tcolorbox package: % To use \\DeclareTColorBox from the tcolorbox package:
\\usepackage[breakable,xparse]{tcolorbox} \\usepackage[breakable,xparse]{tcolorbox}
% Define a Breakable environment to wrap the fontified code outside floats. % Define a Breakable environment to fontify code outside floats.
\\DeclareTColorBox[]{Breakable}{o}% \\DeclareTColorBox[]{Breakable}{o}{
{ colback=EfD, colframe=EFD, colupper=EFD,
colback=EfD,
colframe=EFD,
fontupper=\\normalsize\\setlength{\\fboxsep}{0pt}, fontupper=\\normalsize\\setlength{\\fboxsep}{0pt},
colupper=EFD, IfNoValueTF={#1}{
IfNoValueTF={#1}% boxsep=1pt, arc=1pt, outer arc=1pt, boxrule=0.5pt,
{boxsep=1pt, arc=2.5pt, outer arc=1pt, boxrule=0.5pt, left=2pt}% }{
{boxsep=2.5pt, arc=0pt, outer arc=0pt, boxrule=0pt, leftrule=1.5pt, left=0.5pt}, boxsep=1pt, arc=0pt, outer arc=0pt, boxrule=0pt, leftrule=1pt
right=2pt, top=1pt, bottom=1pt, },
breakable left=2pt, right=2pt, top=1pt, bottom=1pt, breakable
} }
% Define an unbreakable Code environment to wrap the fontified code inside floats. % Define an unbreakable Code environment to fontify code inside floats.
\\DeclareTColorBox[]{Code}{o}% \\DeclareTColorBox[]{Code}{o}{
{ colback=EfD, colframe=EFD, colupper=EFD,
colback=EfD,
colframe=EFD,
fontupper=\\normalsize\\setlength{\\fboxsep}{0pt}, fontupper=\\normalsize\\setlength{\\fboxsep}{0pt},
colupper=EFD, IfNoValueTF={#1}{
IfNoValueTF={#1}% boxsep=1pt, arc=1pt, outer arc=1pt, boxrule=0.5pt
{boxsep=1pt, arc=1pt, outer arc=1pt, boxrule=0.5pt, left=2pt}% }{
{boxsep=2.5pt, arc=0pt, outer arc=0pt, boxrule=0pt, leftrule=1.5pt, left=0.5pt}, boxsep=1pt, arc=0pt, outer arc=0pt, boxrule=0pt, leftrule=1pt
right=2pt, top=1pt, bottom=1pt, },
left=2pt, right=2pt, top=1pt, bottom=1pt,
} }
[LISTINGS-SETUP]")) [LISTINGS-SETUP]"))
#+end_src #+end_src
#+caption[Emacs setup to use =engrave-faces-latex= in =org-mode= smartly]:
#+caption: Emacs setup to use =engrave-faces-latex= in =org-mode= smartly.
#+name: lst:ox-latex-engraved-emacs-lisp-setup
#+begin_src emacs-lisp :tangle no
(with-eval-after-load 'ox-latex
(make-variable-buffer-local 'org-export-filter-src-block-functions)
(add-to-list 'org-export-filter-src-block-functions
'org-latex-engraved-source-block-filter)
(when (fboundp 'smart-latex-engrave-org-source-blocks)
(smart-latex-engrave-org-source-blocks)))
#+end_src
*** [[info:org#Adding Hyperlink Types][Making Org hyperlink types (info)]] *** [[info:org#Adding Hyperlink Types][Making Org hyperlink types (info)]]
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: sec:making-org-hyperlink-types :CUSTOM_ID: sec:making-org-hyperlink-types
@ -2400,15 +2461,17 @@ variables in order to export the =info-org-link= types in this document to
(setq org-info-emacs-documents (delete "org" org-info-emacs-documents)) (setq org-info-emacs-documents (delete "org" org-info-emacs-documents))
(make-variable-buffer-local 'org-info-other-documents) (make-variable-buffer-local 'org-info-other-documents)
(setq org-info-other-documents (setq org-info-other-documents
(cl-union '(("consult" . "https://github.com/minad/consult") (cl-union
("embark" . "https://github.com/oantolin/embark") '(("consult" . "https://github.com/minad/consult")
("marginalia" . "https://github.com/minad/marginalia") ("embark" . "https://github.com/oantolin/embark")
("maxima" . "https://maxima.sourceforge.io/docs/manual/maxima_singlepage.html") ("marginalia" . "https://github.com/minad/marginalia")
("org" . "https://orgmode.org/org.html") ("maxima" .
("orderless" . "https://github.com/oantolin/orderless") "https://maxima.sourceforge.io/docs/manual/maxima_singlepage.html")
("sly" . "https://joaotavora.github.io/sly/") ("org" . "https://orgmode.org/org.html")
("vertico" . "https://github.com/minad/vertico")) ("orderless" . "https://github.com/oantolin/orderless")
org-info-other-documents :test #'equal))) ("sly" . "https://joaotavora.github.io/sly/")
("vertico" . "https://github.com/minad/vertico"))
org-info-other-documents :test #'equal)))
#+end_src #+end_src
*** [[https://tecosaur.github.io/emacs-config/#translate-capital-keywords][Translate capital keywords (old) to lower case (new)]] *** [[https://tecosaur.github.io/emacs-config/#translate-capital-keywords][Translate capital keywords (old) to lower case (new)]]
@ -2755,8 +2818,8 @@ Listing [[lst:use-latex-header-1]], [[lst:use-latex-header-2]], [[lst:use-latex-
headheight=20mm, headheight=20mm,
top=40mm, top=40mm,
bottom=20mm, bottom=20mm,
left=60pt, left=0.1\paperwidth,
right=60pt, right=0.1\paperwidth,
heightrounded, heightrounded,
verbose, verbose,
]{geometry} ]{geometry}
@ -2881,8 +2944,8 @@ exporting from Org-mode to LaTeX.
(make-variable-buffer-local 'org-latex-toc-command) (make-variable-buffer-local 'org-latex-toc-command)
(setq org-latex-toc-command " (setq org-latex-toc-command "
\\tableofcontents\\label{toc} \\tableofcontents\\label{toc}
\\listoflistings
\\listoftables \\listoftables
\\listoffigures
\\newpage \\newpage
") ")
@ -3936,7 +3999,7 @@ Structural editing keeps character pairs (for instance parentheses, curly and
square brackets as well as single and double quotes) balanced to leave code (for square brackets as well as single and double quotes) balanced to leave code (for
instance Lisp and Python) and text (for instance LaTeX and Org) structure instance Lisp and Python) and text (for instance LaTeX and Org) structure
intact. I use [[https://github.com/Fuco1/smartparens][smartparens]] which offers a normal mode (=smartparens-mode=) and a intact. I use [[https://github.com/Fuco1/smartparens][smartparens]] which offers a normal mode (=smartparens-mode=) and a
a strict mode (=smartparens-strict-mode=). Although both modes insert character strict mode (=smartparens-strict-mode=). Although both modes insert character
pairs, the normal mode allows to delete one of the paired characters easily pairs, the normal mode allows to delete one of the paired characters easily
while the strict mode does not. Therefore, the strict mode is more for code while the strict mode does not. Therefore, the strict mode is more for code
editing since it never breaks programming language rules and the normal mode is editing since it never breaks programming language rules and the normal mode is
@ -4150,7 +4213,7 @@ point movements visually.
;; to prevent the warning triggered by lazy loading. ;; to prevent the warning triggered by lazy loading.
(when (require 'pulse nil 'noerror) (when (require 'pulse nil 'noerror)
;; https://karthinks.com/software/batteries-included-with-emacs/ ;; https://karthinks.com/software/batteries-included-with-emacs/
;; https://www.reddit.com/r/emacs/comments/jwhr6g/batteries_included_with_emacs/ ;; https://github.com/karthink/.emacs.d/blob/master/init.el#L2077
(defun flash-line-around-point (&rest _) (defun flash-line-around-point (&rest _)
"Flash the line around point." "Flash the line around point."
(let ((pulse-iterations 16) (let ((pulse-iterations 16)
@ -4447,7 +4510,8 @@ enable =emms=.
'(("http://www.howardism.org/index.xml" h-abrams) '(("http://www.howardism.org/index.xml" h-abrams)
("https://emacshorrors.com/feed.atom" v-schneidermann) ("https://emacshorrors.com/feed.atom" v-schneidermann)
("https://emacsninja.com/emacs.atom" v-schneidermann) ("https://emacsninja.com/emacs.atom" v-schneidermann)
("https://feeds.feedburner.com/InterceptedWithJeremyScahill" j-scahill) ("https://feeds.feedburner.com/InterceptedWithJeremyScahill"
j-scahill)
("https://frame.work/fr/fr/blog.rss" framework) ("https://frame.work/fr/fr/blog.rss" framework)
("https://nullprogram.com/feed/" c-wellons) ("https://nullprogram.com/feed/" c-wellons)
("https://oremacs.com/atom.xml" o-krehel) ("https://oremacs.com/atom.xml" o-krehel)