Simplify `org-latex-engraved-source-block-filter'

This commit is contained in:
Gerard Vermeulen 2024-02-10 10:20:10 +01:00
parent e7c4bbbe6d
commit c943430f8d

View File

@ -3494,21 +3494,13 @@ environment and an unbreakable Code (floating) environment."
org-latex-engraved-preamble) org-latex-engraved-preamble)
(user-error "`org-latex-engraved-preamble' defines no `Breakable' environment")) (user-error "`org-latex-engraved-preamble' defines no `Breakable' environment"))
(when (eq org-latex-src-block-backend 'engraved) (when (eq org-latex-src-block-backend 'engraved)
(let ((enter "^\\\\begin{Code}\n\\\\begin{Verbatim}") ;; Transform only blocks matching at position 0. Therefore, do
(leave "^\\\\end{Verbatim}\n\\\\end{Code}")) ;; not transform blocks that are listing environments.
;; Transform only blocks matching the enter regexp at position 0. (when (string-match "\\`\\\\begin{Code}\n" data)
;; Do not transform blocks that are listing environments. (setq data (replace-match "\\begin{Breakable}\n" t 'literal data))
(when (and (string-match enter data) (eql 0 (match-beginning 0))) (if (string-match "^\\\\end{Code}\n" data)
(setq data (replace-match (setq data (replace-match "\\end{Breakable}\n" t 'literal data))
"\\begin{Breakable}\n\\begin{Verbatim}" t t data)) (error "Match `^\\\\end{Code}' failure")))))
(when (string-match leave data (match-end 0))
(setq data (replace-match
"\\end{Verbatim}\n\\end{Breakable}" t t data))
(when (string-match enter data)
(user-error "The `enter' regexp `%s' should not match" enter))
(when (string-match leave data)
(user-error "The `leave' regexp `%s' should not match" leave))
data)))))
#+end_src #+end_src
#+caption[Smart LaTeX engraving of =org-src-mode= blocks]: #+caption[Smart LaTeX engraving of =org-src-mode= blocks]: