* LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
@ 2024-12-25 17:45 Rudolf Adamkovič
2024-12-26 15:08 ` Ihor Radchenko
0 siblings, 1 reply; 13+ messages in thread
From: Rudolf Adamkovič @ 2024-12-25 17:45 UTC (permalink / raw)
To: emacs-orgmode
REPRODUCTION:
1. Create a file containing:
#+OPTIONS: num:nil
* Test
:PROPERTIES:
:ALT_TITLE: alt
:END:
This is a test.
2. Open the file.
3. Export to a PDF file with LaTeX.
EXPECTED:
Test
This is a test.
ACTUAL:
[
alt]Test This is a test.
Rudy
--
"Programming reliably -- must be an activity of an undeniably
mathematical nature […] You see, mathematics is about thinking, and
doing mathematics is always trying to think as well as possible."
--- Edsger W. Dijkstra, 1981
Rudolf Adamkovič <rudolf@adamkovic.org> [he/him]
http://adamkovic.org
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
2024-12-25 17:45 LaTeX export is broken with 'num:nil` and 'ALT_TITLE` Rudolf Adamkovič
@ 2024-12-26 15:08 ` Ihor Radchenko
0 siblings, 0 replies; 13+ messages in thread
From: Ihor Radchenko @ 2024-12-26 15:08 UTC (permalink / raw)
To: Rudolf Adamkovič; +Cc: emacs-orgmode
Rudolf Adamkovič <rudolf@adamkovic.org> writes:
> REPRODUCTION:
>
> 1. Create a file containing:
>
> #+OPTIONS: num:nil
>
> * Test
> :PROPERTIES:
> :ALT_TITLE: alt
> :END:
>
> This is a test.
>
> 2. Open the file.
> 3. Export to a PDF file with LaTeX.
Confirmed.
This is because [<alt-title>] is inserted into the sectioning command
unconditionally, regardless whether sectioning command supports such an
optional argument.
I suspect that the proper way to handle this problem is changing
structure of `org-latex-classes' to explicitly specify alt-title
placeholder.
--
Ihor Radchenko // yantar92,
Org mode maintainer,
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>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
@ 2024-12-26 17:08 Pedro Andres Aranda Gutierrez
2024-12-26 17:15 ` Pedro Andres Aranda Gutierrez
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-12-26 17:08 UTC (permalink / raw)
To: rudolf; +Cc: Org Mode List
Hi Rudolf,
After playing around with the generated LaTeX in overleaf, I have to conclude that the problem is that ALT_TITLE should be not generated for unnumbered chapters, sections, etc. As far as my LaTeX goes, you use the [alt_title] to get something different in the TOC, so it makes no sense and LaTeX doesn’t cater for it.
Solutions from the org-mode side:
1. You don’t use ALT_TITLE if section is unnumbered (easier)
2. We make org-mode throw an error in this case (???)
Discussion open ;-)
Seasons greetings,
/PA
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
2024-12-26 17:08 LaTeX export is broken with 'num:nil` and 'ALT_TITLE` Pedro Andres Aranda Gutierrez
@ 2024-12-26 17:15 ` Pedro Andres Aranda Gutierrez
2024-12-27 6:59 ` Pedro Andres Aranda Gutierrez
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-12-26 17:15 UTC (permalink / raw)
To: rudolf; +Cc: Org Mode List, Ihor Radchenko
A MWE:
——
\documentclass{article}
\title{test}
\author{paranda }
\date{December 2024}
\begin{document}
\maketitle
\tableofcontents
\section{Introduction}
\subsection[Sub - shown 1]{Sub intro - shown}
This section shows up with a modified heading
\subsection*{Sub intro - hidden}
This subsection doesn't show up in the ToC
\subsection{Sub intro - shown 2}
This subsection shows up as is in the ToC
\end{document}
——
> El 26 dic 2024, a las 18:08, Pedro Andres Aranda Gutierrez <paaguti@gmail.com> escribió:
>
> Hi Rudolf,
>
> After playing around with the generated LaTeX in overleaf, I have to conclude that the problem is that ALT_TITLE should be not generated for unnumbered chapters, sections, etc. As far as my LaTeX goes, you use the [alt_title] to get something different in the TOC, so it makes no sense and LaTeX doesn’t cater for it.
>
> Solutions from the org-mode side:
> 1. You don’t use ALT_TITLE if section is unnumbered (easier)
> 2. We make org-mode throw an error in this case (???)
>
> Discussion open ;-)
>
> Seasons greetings,
> /PA
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
2024-12-26 17:15 ` Pedro Andres Aranda Gutierrez
@ 2024-12-27 6:59 ` Pedro Andres Aranda Gutierrez
2024-12-27 17:43 ` Ihor Radchenko
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-12-27 6:59 UTC (permalink / raw)
To: rudolf; +Cc: Org Mode List, Ihor Radchenko
[-- Attachment #1.1: Type: text/plain, Size: 2064 bytes --]
Hi,
A quick fix (on main) attached. With this ALT_TITLE is ignored in the
document with #+OPTIONS: num:nil and if #+OPTIONS: num:t and :PROPERTIES:
:UNNUMBERED: t
MWE:
----
#+OPTIONS: num:t
* Test
:PROPERTIES:
:UNNUMBERED: t
:ALT_TITLE: alt
:END:
This is a test.
* Numbered test
:PROPERTIES:
:alt_title: alt numbered
:END:
This is the second part of the test.
----
PS: maybe a rework of this part to make it more readable could be
desirable....
Seasons greetings, /PA
On Thu, 26 Dec 2024 at 18:15, Pedro Andres Aranda Gutierrez <
paaguti@gmail.com> wrote:
> A MWE:
>
> ——
> \documentclass{article}
>
> \title{test}
> \author{paranda }
> \date{December 2024}
>
> \begin{document}
>
> \maketitle
> \tableofcontents
>
> \section{Introduction}
>
> \subsection[Sub - shown 1]{Sub intro - shown}
> This section shows up with a modified heading
> \subsection*{Sub intro - hidden}
> This subsection doesn't show up in the ToC
> \subsection{Sub intro - shown 2}
> This subsection shows up as is in the ToC
> \end{document}
> ——
> > El 26 dic 2024, a las 18:08, Pedro Andres Aranda Gutierrez <
> paaguti@gmail.com> escribió:
> >
> > Hi Rudolf,
> >
> > After playing around with the generated LaTeX in overleaf, I have to
> conclude that the problem is that ALT_TITLE should be not generated for
> unnumbered chapters, sections, etc. As far as my LaTeX goes, you use the
> [alt_title] to get something different in the TOC, so it makes no sense and
> LaTeX doesn’t cater for it.
> >
> > Solutions from the org-mode side:
> > 1. You don’t use ALT_TITLE if section is unnumbered (easier)
> > 2. We make org-mode throw an error in this case (???)
> >
> > Discussion open ;-)
> >
> > Seasons greetings,
> > /PA
>
>
--
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler
Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet
[-- Attachment #1.2: Type: text/html, Size: 2944 bytes --]
[-- Attachment #2: fix.diff --]
[-- Type: text/x-patch, Size: 899 bytes --]
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 4b2e797d0..6507a1c42 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2402,10 +2402,10 @@ holding contextual information."
(string-match-p "\\<local\\>" v)
(format "\\stopcontents[level-%d]" level)))))
info t)))))
- (if (and (or (and opt-title (not (equal opt-title full-text)))
+ (if (and numberedp (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.
+ ;; TOC/footers for numbered sections *only*
(and (not (equal full-text-no-footnote full-text))
(setq opt-title full-text-no-footnote)))
(string-match "\\`\\\\\\(.+?\\){" section-fmt))
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
2024-12-27 6:59 ` Pedro Andres Aranda Gutierrez
@ 2024-12-27 17:43 ` Ihor Radchenko
2024-12-27 17:56 ` Pedro Andres Aranda Gutierrez
0 siblings, 1 reply; 13+ messages in thread
From: Ihor Radchenko @ 2024-12-27 17:43 UTC (permalink / raw)
To: Pedro Andres Aranda Gutierrez; +Cc: rudolf, Org Mode List
Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
> A quick fix (on main) attached. With this ALT_TITLE is ignored in the
> document with #+OPTIONS: num:nil and if #+OPTIONS: num:t and :PROPERTIES:
> :UNNUMBERED: t
Thanks!
I am slightly concerned about generality of dropping ALT_TITLE from
unnumbered sectioning command.
From LaTeX2e reference manual, I see
Structure your text into divisions: parts, chapters, sections, etc. All sectioning commands
have the same form, one of:
sectioning-command{title}
sectioning-command*{title}
sectioning-command[toc-title]{title}
But can we assume that unnumbered entries never appear in the table of
contents?
> MWE:
> ----
> #+OPTIONS: num:t
>
> * Test
> :PROPERTIES:
> :UNNUMBERED: t
> :ALT_TITLE: alt
> :END:
>
> This is a test.
>
> * Numbered test
> :PROPERTIES:
> :alt_title: alt numbered
> :END:
>
> This is the second part of the test.
> ----
>
> PS: maybe a rework of this part to make it more readable could be
> desirable....
Even better would be a test and a proper patch with commit message.
Do you have time for that?
--
Ihor Radchenko // yantar92,
Org mode maintainer,
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>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
2024-12-27 17:43 ` Ihor Radchenko
@ 2024-12-27 17:56 ` Pedro Andres Aranda Gutierrez
2024-12-27 18:01 ` Ihor Radchenko
0 siblings, 1 reply; 13+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-12-27 17:56 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: rudolf, Org Mode List
[-- Attachment #1: Type: text/plain, Size: 2429 bytes --]
Hi
On Fri, 27 Dec 2024 at 18:42, Ihor Radchenko <yantar92@posteo.net> wrote:
> Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
>
> > A quick fix (on main) attached. With this ALT_TITLE is ignored in the
> > document with #+OPTIONS: num:nil and if #+OPTIONS: num:t and :PROPERTIES:
> > :UNNUMBERED: t
>
> Thanks!
> I am slightly concerned about generality of dropping ALT_TITLE from
> unnumbered sectioning command.
>
> From LaTeX2e reference manual, I see
>
> Structure your text into divisions: parts, chapters, sections, etc.
> All sectioning commands
> have the same form, one of:
>
> sectioning-command{title}
> sectioning-command*{title}
> sectioning-command[toc-title]{title}
>
> But can we assume that unnumbered entries never appear in the table of
> contents?
>
I do think we can. Unnumbered sectioning commands never appear in the ToC...
Unless you use additional magic like, for example,
https://tex.stackexchange.com/questions/11668/adding-unnumbered-sections-to-toc
.
So I suppose the quick fix is what I sent and then we can try to implement
something like:
```
\section*{Introduction}\addcontentsline{toc}{section}{Introduction}
```
or
```
% Package 'hyperref' needed for command
'\nameref'\section*{Introduction}\label{sec:intro}
\addcontentsline{toc}{section}{\nameref{sec:intro}}
```
Although it goes quite against the \section vs \section* philosophy and it
would need more that a quick fix.
Best, /PA
> > MWE:
> > ----
> > #+OPTIONS: num:t
> >
> > * Test
> > :PROPERTIES:
> > :UNNUMBERED: t
> > :ALT_TITLE: alt
> > :END:
> >
> > This is a test.
> >
> > * Numbered test
> > :PROPERTIES:
> > :alt_title: alt numbered
> > :END:
> >
> > This is the second part of the test.
> > ----
> >
> > PS: maybe a rework of this part to make it more readable could be
> > desirable....
>
> Even better would be a test and a proper patch with commit message.
> Do you have time for that?
>
> --
> Ihor Radchenko // yantar92,
> Org mode maintainer,
> 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>
>
--
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler
Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet
[-- Attachment #2: Type: text/html, Size: 8442 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
2024-12-27 17:56 ` Pedro Andres Aranda Gutierrez
@ 2024-12-27 18:01 ` Ihor Radchenko
2024-12-27 18:07 ` Pedro Andres Aranda Gutierrez
2024-12-30 12:44 ` [PATCH]: ox-latex.eel: handle unnumbered sections in TOC correctly Pedro Andres Aranda Gutierrez
0 siblings, 2 replies; 13+ messages in thread
From: Ihor Radchenko @ 2024-12-27 18:01 UTC (permalink / raw)
To: Pedro Andres Aranda Gutierrez; +Cc: rudolf, Org Mode List
Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
>> I am slightly concerned about generality of dropping ALT_TITLE from
>> unnumbered sectioning command.
> ...
> I do think we can. Unnumbered sectioning commands never appear in the ToC...
> Unless you use additional magic like, ...
Good. I am not concerned about hacks, I am concerned about users who
customized `org-latex-classes' to use something non-standard for
sectioning.
But if doing so is not expected in general, I'd rather accept your fix
until someone comes and complains. Fixing the existing bug with default
settings is more important than fixing possible bug (affecting less
users) with custom sectioning.
--
Ihor Radchenko // yantar92,
Org mode maintainer,
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>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
2024-12-27 18:01 ` Ihor Radchenko
@ 2024-12-27 18:07 ` Pedro Andres Aranda Gutierrez
2024-12-30 7:17 ` Pedro Andres Aranda Gutierrez
2024-12-30 12:44 ` [PATCH]: ox-latex.eel: handle unnumbered sections in TOC correctly Pedro Andres Aranda Gutierrez
1 sibling, 1 reply; 13+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-12-27 18:07 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: rudolf, Org Mode List
[-- Attachment #1: Type: text/plain, Size: 1396 bytes --]
@Rudolf, WDYT?
How can I phrase it? It looks like you were trying something that LaTeX
doesn't allow...
Best, /PA
On Fri, 27 Dec 2024 at 19:00, Ihor Radchenko <yantar92@posteo.net> wrote:
> Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
>
> >> I am slightly concerned about generality of dropping ALT_TITLE from
> >> unnumbered sectioning command.
> > ...
> > I do think we can. Unnumbered sectioning commands never appear in the
> ToC...
> > Unless you use additional magic like, ...
>
> Good. I am not concerned about hacks, I am concerned about users who
> customized `org-latex-classes' to use something non-standard for
> sectioning.
>
> But if doing so is not expected in general, I'd rather accept your fix
> until someone comes and complains. Fixing the existing bug with default
> settings is more important than fixing possible bug (affecting less
> users) with custom sectioning.
>
> --
> Ihor Radchenko // yantar92,
> Org mode maintainer,
> 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>
>
--
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler
Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet
[-- Attachment #2: Type: text/html, Size: 2397 bytes --]
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: LaTeX export is broken with 'num:nil` and 'ALT_TITLE`
2024-12-27 18:07 ` Pedro Andres Aranda Gutierrez
@ 2024-12-30 7:17 ` Pedro Andres Aranda Gutierrez
0 siblings, 0 replies; 13+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-12-30 7:17 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: rudolf, Org Mode List
[-- Attachment #1.1: Type: text/plain, Size: 2010 bytes --]
Hi,
just an MWE to show how this can be done without ALT_TITLE. The first part
is close to what Rudolf was looking for, so it might be something we could
see to include in org-mode, right?
Happy New Year,
/PA
On Fri, 27 Dec 2024 at 19:07, Pedro Andres Aranda Gutierrez <
paaguti@gmail.com> wrote:
> @Rudolf, WDYT?
> How can I phrase it? It looks like you were trying something that LaTeX
> doesn't allow...
>
> Best, /PA
>
> On Fri, 27 Dec 2024 at 19:00, Ihor Radchenko <yantar92@posteo.net> wrote:
>
>> Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
>>
>> >> I am slightly concerned about generality of dropping ALT_TITLE from
>> >> unnumbered sectioning command.
>> > ...
>> > I do think we can. Unnumbered sectioning commands never appear in the
>> ToC...
>> > Unless you use additional magic like, ...
>>
>> Good. I am not concerned about hacks, I am concerned about users who
>> customized `org-latex-classes' to use something non-standard for
>> sectioning.
>>
>> But if doing so is not expected in general, I'd rather accept your fix
>> until someone comes and complains. Fixing the existing bug with default
>> settings is more important than fixing possible bug (affecting less
>> users) with custom sectioning.
>>
>> --
>> Ihor Radchenko // yantar92,
>> Org mode maintainer,
>> 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>
>>
>
>
> --
> Fragen sind nicht da, um beantwortet zu werden,
> Fragen sind da um gestellt zu werden
> Georg Kreisler
>
> Headaches with a Juju log:
> unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
> a leader-deposed hook here, but we can't yet
>
>
--
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler
Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet
[-- Attachment #1.2: Type: text/html, Size: 3590 bytes --]
[-- Attachment #2: test.org --]
[-- Type: application/octet-stream, Size: 867 bytes --]
#+TITLE: Unnumbered sections in ToC - MWE
#+OPTIONS: num:nil
* This is a test
@@latex: \addcontentsline{toc}{section}{Test}@@
With this you can control what appears in the ToC:
#+BEGIN_EXAMPLE
* This is a test
@@latex: \addcontentsline{toc}{section}{Test}@@
#+END_EXAMPLE
* <<sec:mysec>>This is another test
@@latex: \addcontentsline{toc}{section}{\nameref{sec:mysec}}@@
And you can also use ~nameref~ to get the full title into the ToC, since ~org~
calls the ~hyperref~ package:
#+BEGIN_EXAMPLE
* <<sec:mysec>>This is another test
@@latex: \addcontentsline{toc}{section}{\nameref{sec:mysec}}@@
#+END_EXAMPLE
Although for this, you'll need, for example, to add the following to your local variables:
#+BEGIN_EXAMPLE
# org-latex-prefer-user-labels: t
#+END_EXAMPLE
# Local variables:
# org-latex-prefer-user-labels: t
# spell-check-lang: "en_GB"
# End:
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH]: ox-latex.eel: handle unnumbered sections in TOC correctly
2024-12-27 18:01 ` Ihor Radchenko
2024-12-27 18:07 ` Pedro Andres Aranda Gutierrez
@ 2024-12-30 12:44 ` Pedro Andres Aranda Gutierrez
2024-12-30 16:53 ` Ihor Radchenko
1 sibling, 1 reply; 13+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2024-12-30 12:44 UTC (permalink / raw)
To: Ihor Radchenko; +Cc: rudolf, Org Mode List
[-- Attachment #1: Type: text/plain, Size: 147 bytes --]
Hi,
In some traditions, Xmas presents come on New Years Eve… so here you are.
I hope this covers most use cases.
Happy New Year,
/PA
[-- Attachment #2: 0001-ox-latex.el-Fix-adding-unnumbered-sections-to-the-To.patch --]
[-- Type: application/octet-stream, Size: 3302 bytes --]
From d4dd85679939ff5b1e0dfb2cfedf3d59258c6a85 Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <paranda@it.uc3m.es>
Date: Mon, 30 Dec 2024 13:09:43 +0100
Subject: [PATCH] ox-latex.el: Fix adding unnumbered sections to the ToC
* etc/ORG-NEWS: Announce the fix
* lisp/ox-latex.el: (org-latex-headline): Add the logic to create the
~\\addcontentsline{toc}...~ for unnumbered section headings. This
generates correct LaTeX code that handles including unnumbered
sections in the ToC
---
etc/ORG-NEWS | 5 +++++
lisp/ox-latex.el | 18 +++++++++++++++---
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index b43db549d..7c882b96b 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -436,6 +436,11 @@ For example, given =H:3= and =toc:2= in =#+OPTIONS:=, all headings at
the 1st and 2nd level appear in the table of contents and those at the
3rd level do not.
+*** LaTeX exporter now correctly adds unnumbered sections to the ToC
+
+If you add the =:ALT_TITLE:= property to an unnumbered section, it will
+be added to the Table of Contents correctly.
+
* Version 9.7
** Important announcements and breaking changes
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 4b2e797d0..a4cfe2f2c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2402,7 +2402,7 @@ holding contextual information."
(string-match-p "\\<local\\>" v)
(format "\\stopcontents[level-%d]" level)))))
info t)))))
- (if (and (or (and opt-title (not (equal opt-title full-text)))
+ (if (and numberedp (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.
@@ -2419,8 +2419,20 @@ holding contextual information."
(concat headline-label pre-blanks contents))
;; Impossible to add an alternative heading. Fallback to
;; regular sectioning format string.
- (format section-fmt full-text
- (concat headline-label pre-blanks contents))))))))
+ (save-match-data
+ ;; Try to extract the section command from section-fmt
+ ;; This should givee us some protection against unexpeted stuff
+ (let ((matched (string-match "\\\\\\([a-z]+\\)[^a-z]" section-fmt)))
+ (if (or numberedp (not matched))
+ ;; Just in case the section header is not a standard \\xyz*{}
+ (format section-fmt full-text
+ (concat headline-label pre-blanks contents))
+ (let* ((section-label (match-string 1 section-fmt))
+ (add-contents (format "\\addcontentsline{toc}{%s}{%s}\n" section-label opt-title)))
+ ;; prepend the addcontentsline as the first element in the generated section
+ ;; this assures that it will go directly after the section command
+ (format section-fmt full-text
+ (concat add-contents headline-label pre-blanks contents))))))))))))
(defun org-latex-format-headline-default-function
(todo _todo-type priority text tags _info)
--
2.37.1 (Apple Git-137.1)
[-- Attachment #3: Type: text/plain, Size: 1060 bytes --]
> El 27 dic 2024, a las 19:01, Ihor Radchenko <yantar92@posteo.net> escribió:
>
> Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
>
>>> I am slightly concerned about generality of dropping ALT_TITLE from
>>> unnumbered sectioning command.
>> ...
>> I do think we can. Unnumbered sectioning commands never appear in the ToC...
>> Unless you use additional magic like, ...
>
> Good. I am not concerned about hacks, I am concerned about users who
> customized `org-latex-classes' to use something non-standard for
> sectioning.
>
> But if doing so is not expected in general, I'd rather accept your fix
> until someone comes and complains. Fixing the existing bug with default
> settings is more important than fixing possible bug (affecting less
> users) with custom sectioning.
>
> --
> Ihor Radchenko // yantar92,
> Org mode maintainer,
> 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>
^ permalink raw reply related [flat|nested] 13+ messages in thread
* Re: [PATCH]: ox-latex.eel: handle unnumbered sections in TOC correctly
2024-12-30 12:44 ` [PATCH]: ox-latex.eel: handle unnumbered sections in TOC correctly Pedro Andres Aranda Gutierrez
@ 2024-12-30 16:53 ` Ihor Radchenko
[not found] ` <CAO48Bk8dXigB0qbXzCuKZK9X4=Woy2+4xpA2QtC4O8Lx_224BA@mail.gmail.com>
0 siblings, 1 reply; 13+ messages in thread
From: Ihor Radchenko @ 2024-12-30 16:53 UTC (permalink / raw)
To: Pedro Andres Aranda Gutierrez; +Cc: rudolf, Org Mode List
Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
> In some traditions, Xmas presents come on New Years Eve… so here you are.
> I hope this covers most use cases.
Thanks!
May you also add a test?
--
Ihor Radchenko // yantar92,
Org mode maintainer,
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>
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: [PATCH]: ox-latex.eel: handle unnumbered sections in TOC correctly
[not found] ` <CAO48Bk8dXigB0qbXzCuKZK9X4=Woy2+4xpA2QtC4O8Lx_224BA@mail.gmail.com>
@ 2025-01-01 6:43 ` Pedro Andres Aranda Gutierrez
0 siblings, 0 replies; 13+ messages in thread
From: Pedro Andres Aranda Gutierrez @ 2025-01-01 6:43 UTC (permalink / raw)
To: Ihor Radchenko, Org Mode List
[-- Attachment #1.1: Type: text/plain, Size: 1561 bytes --]
Attached is a patch that fixes adding an unnumbered section to the TOC with
test cases. You will need to add the Title you want to appear in the ToC in
:ALT_TITLE: I'm looking at a new property to copy the section title.
Something like
:ALT_TITLE_COPY: t
But I'm open to suggestions.
Happy New Year,
/PA
On Mon, 30 Dec 2024 at 18:39, Pedro Andres Aranda Gutierrez <
paaguti@gmail.com> wrote:
> I'll do my best...
> /PA
>
> On Mon, 30 Dec 2024 at 17:51, Ihor Radchenko <yantar92@posteo.net> wrote:
>
>> Pedro Andres Aranda Gutierrez <paaguti@gmail.com> writes:
>>
>> > In some traditions, Xmas presents come on New Years Eve… so here you
>> are.
>> > I hope this covers most use cases.
>>
>> Thanks!
>> May you also add a test?
>>
>> --
>> Ihor Radchenko // yantar92,
>> Org mode maintainer,
>> 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>
>>
>
>
> --
> Fragen sind nicht da, um beantwortet zu werden,
> Fragen sind da um gestellt zu werden
> Georg Kreisler
>
> Headaches with a Juju log:
> unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
> a leader-deposed hook here, but we can't yet
>
>
--
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler
Headaches with a Juju log:
unit-basic-16: 09:17:36 WARNING juju.worker.uniter.operation we should run
a leader-deposed hook here, but we can't yet
[-- Attachment #1.2: Type: text/html, Size: 3023 bytes --]
[-- Attachment #2: 0001-Fix-unnumbered-sections-in-ToC.patch --]
[-- Type: text/x-patch, Size: 5414 bytes --]
From 17dd1cb3c624c5b685fab7bc901678b16fba5cd2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20A=2E=20Aranda=20Guti=C3=A9rrez?= <paaguti@gmail.com>
Date: Wed, 1 Jan 2025 07:30:28 +0100
Subject: [PATCH] Fix unnumbered sections in ToC
* etc/ORG-NEWS: Announce fix
* lisp/ox-latex.el: (org-latex-headline): Fix adding unnumbered sections
to ToC. Insert `\\addcontentsline{toc}{section}{section title}' to add
unnumbered sections to ToC.
* testing/lisp/test-ox-latex.el: Add two tests: one for a document with num:nil
and one for a document with num:t and an unnumbered section.
---
etc/ORG-NEWS | 5 +++
lisp/ox-latex.el | 18 ++++++++--
testing/lisp/test-ox-latex.el | 64 +++++++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 3 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 2d4616fab..7ed71c63c 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -437,6 +437,11 @@ For example, given =H:3= and =toc:2= in =#+OPTIONS:=, all headings at
the 1st and 2nd level appear in the table of contents and those at the
3rd level do not.
+*** LaTeX exporter now correctly adds unnumbered sections to the ToC
+
+If you add the =:ALT_TITLE:= property to an unnumbered section, it will
+be added to the Table of Contents correctly.
+
* Version 9.7
** Important announcements and breaking changes
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 4b2e797d0..a4cfe2f2c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -2402,7 +2402,7 @@ holding contextual information."
(string-match-p "\\<local\\>" v)
(format "\\stopcontents[level-%d]" level)))))
info t)))))
- (if (and (or (and opt-title (not (equal opt-title full-text)))
+ (if (and numberedp (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.
@@ -2419,8 +2419,20 @@ holding contextual information."
(concat headline-label pre-blanks contents))
;; Impossible to add an alternative heading. Fallback to
;; regular sectioning format string.
- (format section-fmt full-text
- (concat headline-label pre-blanks contents))))))))
+ (save-match-data
+ ;; Try to extract the section command from section-fmt
+ ;; This should givee us some protection against unexpeted stuff
+ (let ((matched (string-match "\\\\\\([a-z]+\\)[^a-z]" section-fmt)))
+ (if (or numberedp (not matched))
+ ;; Just in case the section header is not a standard \\xyz*{}
+ (format section-fmt full-text
+ (concat headline-label pre-blanks contents))
+ (let* ((section-label (match-string 1 section-fmt))
+ (add-contents (format "\\addcontentsline{toc}{%s}{%s}\n" section-label opt-title)))
+ ;; prepend the addcontentsline as the first element in the generated section
+ ;; this assures that it will go directly after the section command
+ (format section-fmt full-text
+ (concat add-contents headline-label pre-blanks contents))))))))))))
(defun org-latex-format-headline-default-function
(todo _todo-type priority text tags _info)
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 892ac4437..8fcc0a810 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -28,6 +28,69 @@
(signal 'missing-test-dependency '("org-export-latex")))
\f
+(ert-deftest test-ox-latex/unnumbered-toc ()
+ "Test unnumbered toc elements"
+ (org-test-with-exported-text
+ 'latex
+ "#+OPTIONS: num:nil
+
+* Test
+:PROPERTIES:
+:ALT_TITLE: alt
+:END:
+
+This is a test.
+"
+ (goto-char (point-min))
+ (should
+ (search-forward "\\begin{document}"))
+ (should
+ (search-forward "\\tableofcontents"))
+ (should
+ (search-forward "\\section*{Test}"))
+ (should
+ (search-forward "\\addcontentsline{toc}{section}{alt}"))
+ (should
+ (search-forward "\\label{"))
+ (should
+ (search-forward "This is a test."))))
+
+(ert-deftest test-ox-latex/unnumbered-toc-mixed ()
+ "Test unnumbered toc elements"
+ (org-test-with-exported-text
+ 'latex
+ "* Introduction: a test
+:PROPERTIES:
+:ALT_TITLE: Introduction
+:END:
+
+A shorter test for alt title
+
+** State of the Art
+:PROPERTIES:
+:UNNUMBERED: t
+:ALT_TITLE: SOTA
+:END:
+
+And now an unnumbered section in the ToC
+"
+ (goto-char (point-min))
+ (should
+ (search-forward "\\begin{document}
+
+\\tableofcontents
+
+\\section[Introduction]{Introduction: a test}
+\\label{sec:org"))
+ (should
+ (search-forward "}
+A shorter test for alt title
+\\subsection*{State of the Art}
+\\addcontentsline{toc}{subsection}{SOTA}
+\\label{sec:"))
+ (should
+ (search-forward "}
+And now an unnumbered section in the ToC"))))
(ert-deftest text-ox-latex/protect-square-brackets ()
"Test [foo] being interpreted as plain text even after LaTeX commands."
@@ -127,5 +190,6 @@ Column & Column \\\\
(search-forward
"\\href{https://orgmode.org/worg/images/orgmode/org-mode-unicorn.svg}{\\includegraphics[width=.9\\linewidth]{/wallpaper.png}}"))))
+
(provide 'test-ox-latex)
;;; test-ox-latex.el ends here
--
2.47.1
^ permalink raw reply related [flat|nested] 13+ messages in thread
end of thread, other threads:[~2025-01-01 8:16 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-26 17:08 LaTeX export is broken with 'num:nil` and 'ALT_TITLE` Pedro Andres Aranda Gutierrez
2024-12-26 17:15 ` Pedro Andres Aranda Gutierrez
2024-12-27 6:59 ` Pedro Andres Aranda Gutierrez
2024-12-27 17:43 ` Ihor Radchenko
2024-12-27 17:56 ` Pedro Andres Aranda Gutierrez
2024-12-27 18:01 ` Ihor Radchenko
2024-12-27 18:07 ` Pedro Andres Aranda Gutierrez
2024-12-30 7:17 ` Pedro Andres Aranda Gutierrez
2024-12-30 12:44 ` [PATCH]: ox-latex.eel: handle unnumbered sections in TOC correctly Pedro Andres Aranda Gutierrez
2024-12-30 16:53 ` Ihor Radchenko
[not found] ` <CAO48Bk8dXigB0qbXzCuKZK9X4=Woy2+4xpA2QtC4O8Lx_224BA@mail.gmail.com>
2025-01-01 6:43 ` Pedro Andres Aranda Gutierrez
-- strict thread matches above, loose matches on Subject: below --
2024-12-25 17:45 LaTeX export is broken with 'num:nil` and 'ALT_TITLE` Rudolf Adamkovič
2024-12-26 15:08 ` Ihor Radchenko
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).