Fix engraving of whitespace in LaTeX export

To prevent LaTeX's undesirable folding of whitespace, it's good to
ensure the styling commands wrap around whitespace conservatively.
This commit is contained in:
Gerard Vermeulen 2022-10-23 12:54:51 +02:00 committed by TEC
parent 2b107c9357
commit 2c72619195
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
1 changed files with 21 additions and 5 deletions

View File

@ -150,11 +150,27 @@ When THEME is given, the style used is obtained from `engrave-faces-get-theme'."
#'engrave-faces-latex--protect-content-mathescape
#'engrave-faces-latex--protect-content)
content)))
(if (string-match-p "\\`[\n[:space:]]+\\'" content)
protected-content
(if (and style (eq engrave-faces-latex-output-style 'preset))
(concat "\\EF" (plist-get (cdr style) :slug) "{" protected-content "}")
(engrave-faces-latex-face-apply faces protected-content)))))
;; Wrap groups of "words joined by blank characters" in LaTeX commands.
;; Do not wrap newlines and other whitespace between those groups.
(let ((contains-blank-re
(rx (or (group (+ graph ) (* (+ blank) (+ graph)))
(group (+ (any "\n" space))))))
(slug (and style
(eq engrave-faces-latex-output-style 'preset)
(plist-get (cdr style) :slug))))
(with-temp-buffer
(insert protected-content)
(goto-char (point-min))
(while (re-search-forward contains-blank-re nil t)
(replace-match
(concat
(and (match-string 1)
(if (stringp slug)
(format "\\EF%s{%s}" slug (match-string 1))
(engrave-faces-latex-face-apply faces (match-string 1))))
(match-string 2))
t t))
(buffer-string)))))
(defun engrave-faces-latex--post-processing ()
"Set the initial text color and curly paren positioning.