ox-latex: Support mathescape'd code with engraved

* lisp/ox-latex.el (org-latex-src-block--engraved,
org-latex-src--engrave-mathescape-p): Using the mathescape functionality
in engrave-faces-latex v0.3.1, we can support the mathescape option of
fvextra well.  Along the way, we fix a minor issue with the localoptions
list in `org-latex-src-block--engraved`.
This commit is contained in:
TEC 2022-05-11 23:18:19 +08:00
parent af4ca40eae
commit faa5c1887c
Signed by: tec
GPG Key ID: 779591AFDB81F06C
1 changed files with 41 additions and 5 deletions

View File

@ -3385,6 +3385,40 @@ and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
nil (and retain-labels (cdr code-info)))))))
(concat (car float-env) body (cdr float-env))))
(defun org-latex-src--engrave-mathescape-p (info options)
"From the export INFO plist, and the per-block OPTIONS, determine mathescape."
(let ((default-options (plist-get info :latex-engraved-options))
(mathescape-status
(lambda (opts)
(cl-some
(lambda (opt)
(or (and
(null (cdr opt))
(cond
((string-match-p
"\\(?:^\\|,\\)mathescape=false\\(?:,\\|$\\)"
(car opt))
'no)
((or (string-match-p
"\\(?:^\\|,\\)mathescape\\(?:=true\\)?\\(?:,\\|$\\)"
(car opt))
(string= "mathescape" (car opt)))
'yes)))
(and
(string= (car opt) "mathescape")
(cond
((or (and (stringp (cdr opt)) (string= (cdr opt) "true"))
(equal '("true") (cdr opt)))
'yes)
((or (and (stringp (cdr opt)) (string= "false" (cdr opt)))
(equal '("false") (cdr opt)))
'no)))))
opts))))
(if-let ((mathescape (or (funcall mathescape-status default-options)
(funcall mathescape-status options))))
(when (eq mathescape 'yes)
(or engrave-faces-latex-mathescape t)))))
(defun org-latex-src--engrave-code (content lang &optional theme options inline)
"Engrave CONTENT to LaTeX in a LANG-mode buffer, and give the result.
When the THEME symbol is non-nil, that theme will be used.
@ -3464,7 +3498,7 @@ and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
(when (and num-start (not (assoc "linenos" engraved-options)))
`(("linenos")
("firstnumber" ,(number-to-string (1+ num-start)))))
(and local-options (list local-options)))))
(and local-options `((,local-options))))))
(engraved-theme (plist-get attributes :engraved-theme))
(content
(let* ((code-info (org-export-unravel-code src-block))
@ -3487,10 +3521,12 @@ and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'."
(format "(%s)" ref)))))
nil (and retain-labels (cdr code-info)))))
(body
(org-latex-src--engrave-code
content lang
(when engraved-theme (intern engraved-theme))
options)))
(let ((engrave-faces-latex-mathescape
(org-latex-src--engrave-mathescape-p info options)))
(org-latex-src--engrave-code
content lang
(when engraved-theme (intern engraved-theme))
options))))
(concat (car float-env) body (cdr float-env))))
(cl-defun org-latex-src-block--listings