Remove two work-arounds for `engrave-faces' bugs
This commit is contained in:
parent
3a54b3fa4b
commit
682b825b8d
149
README.org
149
README.org
@ -680,24 +680,6 @@ and [[lst:3rd-window-management]] implement a selection of his recommendations.
|
||||
#+name: lst:toggle-specific-advice
|
||||
#+begin_src emacs-lisp
|
||||
(with-eval-after-load 'emacs
|
||||
(defun toggle-engrave-faces-attribute-values-around ()
|
||||
"Toggle `engrave-faces-attribute-values-around' advice."
|
||||
(interactive)
|
||||
(advice-toggle 'engrave-faces-attribute-values
|
||||
:around #'engrave-faces-attribute-values-around))
|
||||
|
||||
(defun toggle-engrave-faces-latex-face-apply-override ()
|
||||
"Toggle `engrave-faces-latex-face-apply' advice."
|
||||
(interactive)
|
||||
(advice-toggle 'engrave-faces-latex-face-apply
|
||||
:override #'engrave-faces-latex-face-apply-override))
|
||||
|
||||
(defun toggle-engrave-faces-latex-face-mapper-override ()
|
||||
"Toggle `engrave-faces-latex-face-mapper' advice."
|
||||
(interactive)
|
||||
(advice-toggle 'engrave-faces-latex-face-mapper
|
||||
:override #'engrave-faces-latex-face-mapper-override))
|
||||
|
||||
(defun toggle-eww-display-pdf-around ()
|
||||
"Toggle `eww-display-advice' advice."
|
||||
(interactive)
|
||||
@ -930,9 +912,6 @@ defined in this Org file.
|
||||
(define-short-documentation-group init
|
||||
"Advice"
|
||||
(advice-toggle :no-manual t)
|
||||
(toggle-engrave-faces-attribute-values-around :no-manual t)
|
||||
(toggle-engrave-faces-latex-face-apply-override :no-manual t)
|
||||
(toggle-engrave-faces-latex-face-mapper-override :no-manual t)
|
||||
(toggle-eww-display-pdf-around :no-manual t)
|
||||
(toggle-ilog-timer-function-after :no-manual t)
|
||||
(toggle-keycast-log-update-buffer-override :no-manual t)
|
||||
@ -2536,11 +2515,10 @@ output into one of three back-ends for export to LaTeX, HTML and text with ANSI
|
||||
escape codes. It is an alternative to =minted= in case of LaTeX export or to
|
||||
=htmlized= in case of HTML export.
|
||||
|
||||
The listings below work around two issues with spacing in the =pdf= output
|
||||
The listings below work around one issue with spacing in the =pdf= output
|
||||
resulting from use of the =engraved= source block back-end during =LaTeX=
|
||||
export, and one isssue with symbolic color names in faces. They increase the
|
||||
quality of the export results of this [[file:README.org][README.org]] and the user-friendliness of
|
||||
this facility to a level acceptable for my workflow:
|
||||
export. They increase the quality of the export results of this [[file:README.org][README.org]] and
|
||||
the user-friendliness of this facility to a level acceptable for my workflow:
|
||||
1. The default Org export configuration for engraving listings produces =pdf=
|
||||
output with a non-equidistant interline spacing in floating listings (those
|
||||
with captions) and equidistant interline spacing in non-floating =tcolorbox=
|
||||
@ -2555,32 +2533,7 @@ this facility to a level acceptable for my workflow:
|
||||
blocks to "floating unbreakable with caption" or "non-floating breakable
|
||||
without caption" LaTeX environments. This is a partial work-around, but part
|
||||
of my workflow.
|
||||
2. Fixed in [[https://elpa.gnu.org/devel/engrave-faces.html][engrave-faces-0.3.1.0.20230115.70118]]: listing
|
||||
[[lst:ensure-engrave-faces-with-latex-face-apply-fix]] makes
|
||||
=engrave-faces-latex-face-apply= handle symbolic color name strings (in
|
||||
addition to the hexadecimal strings). Since faces in for instance
|
||||
src_emacs-lisp{(find-library "org-faces")} and src_emacs-lisp{(find-library
|
||||
"faces")} have symbolic color names (beware: Emacs themes may replace the
|
||||
symbolic color names with hexadecimal strings), this fix allows to engrave
|
||||
for instance org-mode source blocks during LaTeX export without any
|
||||
customization of =engrave-faces-themes=. Listing
|
||||
[[lst:ensure-engrave-faces-with-attribute-values-fix]] proposes another method to
|
||||
obtain the same result. Currently, I prefer to tangle listing
|
||||
[[lst:ensure-engrave-faces-with-attribute-values-fix]] to the =user-init-file=
|
||||
instead of listing [[lst:ensure-engrave-faces-with-latex-face-apply-fix]].
|
||||
3. Fixed in [[https://elpa.gnu.org/devel/engrave-faces.html][engrave-faces-0.3.1.0.20230115.70118]]: listing
|
||||
[[lst:ensure-engrave-faces-with-latex-face-mapper-fix]] makes
|
||||
=engrave-faces-latex-face-mapper= handle horizontal and vertical spacing in
|
||||
multiple line documentation strings correctly. For instance, without this fix
|
||||
the mishandling of vertical and horizontal spacing destroys the indentation
|
||||
in Python documentation strings. An Emacs lisp example of the bug is the
|
||||
disappearance of the empty line in the documentation string of
|
||||
=org-latex-engraved-source-block-filter= of listing
|
||||
[[lst:org-latex-engraved-source-block-filter]] in exported =pdf= files. The idea
|
||||
of the fix is to let the LaTeX face mapper wrap only groups of "words joined
|
||||
by blank characters" in LaTeX commands and pass "newlines and other
|
||||
whitespace between those groups" on without wrapping.
|
||||
4. Listing [[lst:ox-engraved-emacs-lisp-setup]] shows how to use this configuration.
|
||||
2. Listing [[lst:ox-engraved-emacs-lisp-setup]] shows how to use this configuration.
|
||||
|
||||
#+caption[Engrave to floating unbreakable or non-floating breakable environments]:
|
||||
#+caption: Define an =org-export= filter function to engrave =org-src-mode=
|
||||
@ -2667,100 +2620,6 @@ environments and non-floating breakable LaTeX environments by means of
|
||||
[LISTINGS-SETUP]")))
|
||||
#+end_src
|
||||
|
||||
#+caption[Fix engraving of symbolic color names in =engrave-faces-latex=]:
|
||||
#+caption: Fix engraving of symbolic colors names in =engrave-faces-latex=.
|
||||
#+name: lst:ensure-engrave-faces-with-latex-face-apply-fix
|
||||
#+begin_src emacs-lisp :tangle no
|
||||
(when (require 'engrave-faces-latex nil t)
|
||||
(defun engrave-faces-latex--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 attributes of FACES to LaTeX commands 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--color bg) "}{"))
|
||||
(when fg (concat "\\textcolor[HTML]{"
|
||||
(engrave-faces-latex--color fg) "}{"))
|
||||
(when st "\\sout{") (when bl "\\textbf{") (when it "\\textit{")
|
||||
content
|
||||
(when bg "}") (when fg "}") (when st "}") (when bl "}") (when it "}")))))
|
||||
|
||||
(advice-add 'engrave-faces-latex-face-apply
|
||||
:override #'engrave-faces-latex-face-apply-override))
|
||||
#+end_src
|
||||
|
||||
#+caption[Fix engraving of symbolic color names in =engrave-faces=]:
|
||||
#+caption: Fix engraving of symbolic colors names in =engrave-faces=.
|
||||
#+name: lst:ensure-engrave-faces-with-attribute-values-fix
|
||||
#+begin_src emacs-lisp :tangle no
|
||||
(when (require 'engrave-faces nil t)
|
||||
(defun engrave-faces-attribute-values-around (efav-fun &rest args)
|
||||
(let ((values (apply efav-fun args))
|
||||
(attribute (cadr args)))
|
||||
(if (not (member attribute '(:foreground :background)))
|
||||
values
|
||||
(mapcar (lambda (color)
|
||||
(if (char-equal ?# (aref color 0))
|
||||
color)
|
||||
(apply 'format "#%02x%02x%02x"
|
||||
(mapcar (lambda (c) (ash c -8))
|
||||
(color-values color))))
|
||||
values))))
|
||||
|
||||
(advice-add 'engrave-faces-attribute-values
|
||||
:around #'engrave-faces-attribute-values-around))
|
||||
#+end_src
|
||||
|
||||
#+caption[Fix engraving of horizontal/vertical spacing in multiline docstrings]:
|
||||
#+caption: Fix engraving of horizontal and vertical spacing in multiple line
|
||||
#+caption: documentation strings.
|
||||
#+name: lst:ensure-engrave-faces-with-latex-face-mapper-fix
|
||||
#+begin_src emacs-lisp :tangle no
|
||||
(when (require 'engrave-faces-latex nil t)
|
||||
(defun engrave-faces-latex-face-mapper-override (faces content)
|
||||
"Create a LaTeX representation of CONTENT with FACES applied."
|
||||
(let* ((style (engrave-faces-preset-style faces))
|
||||
(protected-content
|
||||
(funcall
|
||||
(if (and engrave-faces-latex-mathescape
|
||||
(eq 'font-lock-comment-face (car style)))
|
||||
#'engrave-faces-latex--protect-content-mathescape
|
||||
#'engrave-faces-latex--protect-content)
|
||||
content)))
|
||||
;; Wrap groups of "words joined by blank characters" in LaTeX commands.
|
||||
;; Do not wrap newlines and other whitespace between those groups.
|
||||
(let ((regexp (rx (or (group-n 1 (+ graph ) (* (+ blank) (+ graph)))
|
||||
(group-n 2 (+ (any "\n" space))))))
|
||||
(slug (when (and style
|
||||
(eq engrave-faces-latex-output-style 'preset))
|
||||
(plist-get (cdr style) :slug)))
|
||||
(start 0) (stack))
|
||||
(while (string-match regexp protected-content start)
|
||||
(setq start (match-end 0))
|
||||
(when-let ((pc (match-string 1 protected-content)))
|
||||
(if (stringp slug)
|
||||
(push (concat "\\EF" slug "{" pc "}") stack)
|
||||
(push (engrave-faces-latex-face-apply faces pc) stack)))
|
||||
(when-let ((pc (match-string 2 protected-content)))
|
||||
(push pc stack)))
|
||||
(apply #'concat (nreverse stack)))))
|
||||
|
||||
(advice-add 'engrave-faces-latex-face-mapper
|
||||
:override #'engrave-faces-latex-face-mapper-override))
|
||||
#+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-engraved-emacs-lisp-setup
|
||||
|
Loading…
Reference in New Issue
Block a user