emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Max Nikulin <manikulin@gmail.com>
Cc: Eric Anderson <kluwak@gmail.com>,
	Timothy <orgmode@tec.tecosaur.net>,
	emacs-orgmode@gnu.org
Subject: Re: [BUG] Footnotes in section titles
Date: Fri, 26 Jan 2024 12:09:52 +0000	[thread overview]
Message-ID: <878r4cfg8f.fsf@localhost> (raw)
In-Reply-To: <691643eb-49d0-45c3-ab7f-a1edbd093bef@gmail.com>

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

Max Nikulin <manikulin@gmail.com> writes:

> On 24/01/2024 19:11, Ihor Radchenko wrote:
>> The \section[...]{...} approach may work, but it is tricky - it is
>> completely up to the `org-latex-classes'. So, we may have to use regexp
>> replacement, which might be fragile.
>
> ox supports the ALT_TITLE property and ox-latex already adds it using 
> regexp. So it should possible to define this property with stripped 
> footnote by an export filter. I have not tested it, but ALT_TITLE and 
> @@latex:\protect@@ might be a workaround.

Good point.
See the attached tentative patch.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-latex-headline-Prevent-footnotes-in-TOC-footers.patch --]
[-- Type: text/x-patch, Size: 3667 bytes --]

From b4d896f7daf5e7b2cf8dabfba5b9dbf212f0c54c Mon Sep 17 00:00:00 2001
Message-ID: <b4d896f7daf5e7b2cf8dabfba5b9dbf212f0c54c.1706270932.git.yantar92@posteo.net>
From: Ihor Radchenko <yantar92@posteo.net>
Date: Fri, 26 Jan 2024 13:07:13 +0100
Subject: [PATCH] org-latex-headline: Prevent footnotes in TOC/footers

* lisp/ox-latex.el (org-latex-headline): When headline contains
footnotes and does not have ALT_TITLE, arrange alternative title that
will appear in TOC and footers to not have any footnotes.

Reported-by: Eric Anderson <kluwak@gmail.com>
Link: https://orgmode.org/list/691643eb-49d0-45c3-ab7f-a1edbd093bef@gmail.com
---
 lisp/ox-latex.el | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index df20345f8..4f5258ea1 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2312,9 +2312,22 @@ (defun org-latex-headline (headline contents info)
                ;; with \texttt.
                (code . (lambda (o _ _) (org-latex--protect-texttt (org-element-property :value o))))
                (verbatim . (lambda (o _ _) (org-latex--protect-texttt (org-element-property :value o)))))))
+           ;; Create a temporary export backend that strips footnotes from title.
+           ;; Footnotes are not allowed in \section and similar
+           ;; commands that contribute to TOC and footers.
+           ;; See https://orgmode.org/list/691643eb-49d0-45c3-ab7f-a1edbd093bef@gmail.com
+           ;; https://texfaq.org/FAQ-ftnsect
+           (section-no-footnote-backend
+            (org-export-create-backend
+             :parent section-backend
+             :transcoders
+             `((footnote-reference . ignore))))
 	   (text
 	    (org-export-data-with-backend
 	     (org-element-property :title headline) section-backend info))
+           (text-no-footnote
+            (org-export-data-with-backend
+	     (org-element-property :title headline) section-no-footnote-backend info))
 	   (todo
 	    (and (plist-get info :with-todo-keywords)
 		 (let ((todo (org-element-property :todo-keyword headline)))
@@ -2328,6 +2341,9 @@ (defun org-latex-headline (headline contents info)
 	   ;; The latter is required to remove tags from toc.
 	   (full-text (funcall (plist-get info :latex-format-headline-function)
 			       todo todo-type priority text tags info))
+           (full-text-no-footnote
+            (funcall (plist-get info :latex-format-headline-function)
+		     todo todo-type priority text-no-footnote tags info))
 	   ;; Associate \label to the headline for internal links.
 	   (headline-label (org-latex--label headline info t t))
 	   (pre-blanks
@@ -2385,10 +2401,14 @@ (defun org-latex-headline (headline contents info)
 				  (string-match-p "\\<local\\>" v)
 				  (format "\\stopcontents[level-%d]" level)))))
 		    info t)))))
-	  (if (and opt-title
-		   (not (equal opt-title full-text))
+	  (if (and (or (and opt-title (not (equal opt-title full-text)))
+                       ;; Heading contains footnotes.  Add optional title
+                       ;; version without footnotes to avoid footnotes in
+                       ;; TOC/footers.
+                       (and (not (equal full-text-no-footnote full-text))
+                            (setq opt-title full-text-no-footnote)))
 		   (string-match "\\`\\\\\\(.+?\\){" section-fmt))
-	      (format (replace-match "\\1[%s]" nil nil section-fmt 1)
+              (format (replace-match "\\1[%s]" nil nil section-fmt 1)
 		      ;; Replace square brackets with parenthesis
 		      ;; since square brackets are not supported in
 		      ;; optional arguments.
-- 
2.43.0


[-- Attachment #3: Type: text/plain, Size: 224 bytes --]


-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

  parent reply	other threads:[~2024-01-26 12:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-22 20:42 Possible LaTeX export bug: Footnotes in items Eric Anderson
2024-01-24 12:11 ` [BUG] Footnotes in section titles Ihor Radchenko
2024-01-24 14:14   ` Max Nikulin
2024-01-24 15:23     ` Juan Manuel Macías
2024-01-24 15:31       ` Colin Baxter
2024-01-24 15:41         ` Juan Manuel Macías
2024-01-26 12:53           ` Ihor Radchenko
2024-01-26 13:17             ` Juan Manuel Macías
2024-01-26 16:43             ` Max Nikulin
2024-02-01 14:44               ` [DISCUSSION] Allowing footnote-references inside parsed keywords (#+AUTHOR, #+TITLE, etc) (was: [BUG] Footnotes in section titles) Ihor Radchenko
2024-02-01 17:44                 ` [DISCUSSION] Allowing footnote-references inside parsed keywords (#+AUTHOR, #+TITLE, etc) Juan Manuel Macías
2024-02-01 17:57                   ` Marvin Gülker
2024-02-02 17:00                   ` Ihor Radchenko
2024-02-02 17:12                     ` Marvin Gülker
2024-02-02 17:49                       ` Ihor Radchenko
2024-02-02 18:10                     ` Juan Manuel Macías
2024-02-02 20:21                       ` Exporting multiple #+AUTHOR keywords (was: [DISCUSSION] Allowing footnote-references inside parsed keywords (#+AUTHOR, #+TITLE, etc)) Ihor Radchenko
2024-02-02 22:26                         ` Exporting multiple #+AUTHOR keywords Juan Manuel Macías
2024-02-04 15:21                           ` Ihor Radchenko
2024-02-04 16:16                             ` Max Nikulin
2024-02-04 22:13                               ` Juan Manuel Macías
2024-02-05 14:57                               ` Ihor Radchenko
2024-01-26 12:09     ` Ihor Radchenko [this message]
2024-02-09 16:41       ` [BUG] Footnotes in section titles Ihor Radchenko

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=878r4cfg8f.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    --cc=kluwak@gmail.com \
    --cc=manikulin@gmail.com \
    --cc=orgmode@tec.tecosaur.net \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).