emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Timothy <tec@tecosaur.com>
To: org-mode-email <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] ox-latex: Replace \verb instances in headings with \texttt
Date: Thu, 01 Apr 2021 02:09:09 +0800	[thread overview]
Message-ID: <878s63fb5m.fsf@tecosaur.com> (raw)
In-Reply-To: <87blazfe6i.fsf@tecosaur.com>

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


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

Third time's the charm.


[-- 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: 1610 bytes --]

From ee6ec00145c442804d945bae292c199689f626ed 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 | 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	other threads:[~2021-04-02 11:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-31 15:14 Timothy
2021-03-31 17:03 ` Timothy
2021-03-31 18:09   ` Timothy [this message]
2021-04-02 15:04     ` Nicolas Goaziou
2021-04-02 15:15       ` Timothy
2021-04-02 15:26       ` Timothy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878s63fb5m.fsf@tecosaur.com \
    --to=tec@tecosaur.com \
    --cc=emacs-orgmode@gnu.org \
    --subject='Re: [PATCH] ox-latex: Replace \verb instances in headings with \texttt' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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).