... and somehow I forgot to remove the old `text' :facepalm:

Third time's the charm.

>From ee6ec00145c442804d945bae292c199689f626ed Mon Sep 17 00:00:00 2001
From: TEC <t...@tecosaur.com>
Date: Wed, 31 Mar 2021 23:06:14 +0800
Subject: [PATCH] ox-latex: convert verbatim text in headings to tt

* lisp/ox-latex.el (org-latex-format-headline-default-function): Convert
any instances of \verb text with \texttt.  This is required to work
around LaTeX peculiarities that would otherwise cause compilation to
fail (see the code comment for more information).
---
 lisp/ox-latex.el | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index da3c3f815..13de07728 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2054,7 +2054,19 @@ (defun org-latex-format-headline-default-function
   (concat
    (and todo (format "{\\bfseries\\sffamily %s} " todo))
    (and priority (format "\\framebox{\\#%c} " priority))
-   text
+   ;; LaTeX isn't happy when you try to use \verb inside the argument of other
+   ;; commands (like \section, etc.), and this causes compilation to fail.
+   ;; So, within headings it's a good idea to replace any instances of \verb
+   ;; with \texttt.
+   (replace-regexp-in-string
+    "\\\\verb\\(.\\).+?\\1"
+    (lambda (verb-string)
+      (replace-regexp-in-string
+       "\\\\" "\\\\\\\\"
+       (org-latex--text-markup (substring verb-string 6 -1)
+                               'code
+                               '(:latex-text-markup-alist ((code . protectedtexttt))))))
+    text)
    (and tags
 	(format "\\hfill{}\\textsc{%s}"
 		(mapconcat #'org-latex--protect-text tags ":")))))
-- 
2.30.1

Reply via email to