emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ox-latex: Replace \verb instances in headings with \texttt
@ 2021-03-31 15:14 Timothy
  2021-03-31 17:03 ` Timothy
  0 siblings, 1 reply; 6+ messages in thread
From: Timothy @ 2021-03-31 15:14 UTC (permalink / raw)
  To: org-mode-email

[-- Attachment #1: Type: text/plain, Size: 448 bytes --]

Hello again,

This time with a smaller patch that works around LaTeX peculiarities.
When LaTeX encounters \verb inside another command it's expanding, it
can panic and compilation fails.
This occurs inside \section commands, and so it's worth modifying the
default header format function to convert any instances of \verb to
\texttt, as that can actually compile successfully.

See https://www.texfaq.org/FAQ-verbwithin for more info.

--
Timothy


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-latex-convert-verbatim-text-in-headings-to-tt.patch --]
[-- Type: text/x-patch, Size: 1572 bytes --]

From b15af4ac23fabe501121e0fd45de603367cb12ed Mon Sep 17 00:00:00 2001
From: TEC <tec@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 | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index da3c3f815..8a2787a62 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2055,6 +2055,18 @@ (defun org-latex-format-headline-default-function
    (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)))))))
    (and tags
 	(format "\\hfill{}\\textsc{%s}"
 		(mapconcat #'org-latex--protect-text tags ":")))))
-- 
2.30.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-02 16:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31 15:14 [PATCH] ox-latex: Replace \verb instances in headings with \texttt Timothy
2021-03-31 17:03 ` Timothy
2021-03-31 18:09   ` Timothy
2021-04-02 15:04     ` Nicolas Goaziou
2021-04-02 15:15       ` Timothy
2021-04-02 15:26       ` Timothy

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).