unofficial mirror of emacs-orgmode@gnu.org
 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

* Re: [PATCH] ox-latex: Replace \verb instances in headings with \texttt
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Timothy @ 2021-03-31 17:03 UTC (permalink / raw)
  To: org-mode-email

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


Ooops, I spotted a minor in my patch.
Try this instead.


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

From 1065e1ee71c1f169ca419f5cbfc94409088c44e6 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 | 13 +++++++++++++
 1 file changed, 13 insertions(+)

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


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

* Re: [PATCH] ox-latex: Replace \verb instances in headings with \texttt
  2021-03-31 17:03 ` Timothy
@ 2021-03-31 18:09   ` Timothy
  2021-04-02 15:04     ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Timothy @ 2021-03-31 18:09 UTC (permalink / raw)
  To: org-mode-email

[-- 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


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

* Re: [PATCH] ox-latex: Replace \verb instances in headings with \texttt
  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
  0 siblings, 2 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2021-04-02 15:04 UTC (permalink / raw)
  To: Timothy; +Cc: org-mode-email

Hello,

Timothy <tec@tecosaur.com> writes:

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

This is not the appropriate location for the fix.

In `section-back-end' variable within `org-latex-headline', you can
extend the local export back-end to handle correctly verbatim markup.

Regards,
-- 
Nicolas Goaziou


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

* Re: [PATCH] ox-latex: Replace \verb instances in headings with \texttt
  2021-04-02 15:04     ` Nicolas Goaziou
@ 2021-04-02 15:15       ` Timothy
  2021-04-02 15:26       ` Timothy
  1 sibling, 0 replies; 6+ messages in thread
From: Timothy @ 2021-04-02 15:15 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode-email


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

>> * 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).
>
> This is not the appropriate location for the fix.
>
> In `section-back-end' variable within `org-latex-headline', you can
> extend the local export back-end to handle correctly verbatim markup.
>
> Regards,

Thanks Nicolas, I'll take a look at that and send over a revised patch
:)

--
Timothy


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

* Re: [PATCH] ox-latex: Replace \verb instances in headings with \texttt
  2021-04-02 15:04     ` Nicolas Goaziou
  2021-04-02 15:15       ` Timothy
@ 2021-04-02 15:26       ` Timothy
  1 sibling, 0 replies; 6+ messages in thread
From: Timothy @ 2021-04-02 15:26 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: org-mode-email


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Timothy <tec@tecosaur.com> writes:
>
>> * 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).
>
> This is not the appropriate location for the fix.
>
> In `section-back-end' variable within `org-latex-headline', you can
> extend the local export back-end to handle correctly verbatim markup.
>
> Regards,

I've just had a look; I don't feel that confident with my usage after
checking the docstring for `org-export-create-backend'. Would you mind
giving the below a quick look and letting me know if it looks right to
you?

#+begin_src diff
@@ -1960 +1960,3 @@ (defun org-latex-headline (headline contents info)
-	     '((underline . (lambda (o c i) (format "\\underline{%s}" c))))))
+	     '((underline . (lambda (o c i) (format "\\underline{%s}" c))))
+        :options
+        '((:latex-text-markup-alist ((code . protectedtexttt))))))
#+end_src diff

--
Timothy


^ 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

unofficial mirror of emacs-orgmode@gnu.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/orgmode/0 orgmode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 orgmode orgmode/ https://yhetil.org/orgmode \
		emacs-orgmode@gnu.org
	public-inbox-index orgmode

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


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

	orgmode.git.git (no URL configured)

AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git