Thanks for spotting the alt-title handling ;-) Apply this on top of my last
patch.

Best, /PA

On Thu, 20 Feb 2025 at 19:13, Ihor Radchenko <yanta...@posteo.net> wrote:

> Pedro Andres Aranda Gutierrez <paag...@gmail.com> writes:
>
> > Final version... got the wrong file... sorry /PA
>
> Thanks!
> You still did not address all the earlier suggestions.
> I will repeat the missing ones below for your convenience.
>
> > modified   doc/org-manual.org
> > @@ -14852,6 +14852,41 @@ *** Quote blocks in LaTeX export
> >  \end{foreigndisplayquote}
> >  #+end_example
> >
> > +#+cindex: LaTeX ToC export a la ~org~
> > +#+cindex: @samp{org-latex-toc-include-unnumbered-style}
> > +If you want the LaTeX exporter to behave like other exporters,
> > +customise the variable ~org-latex-toc-include-unnumbered-style~ and
> > +set it to ~t~:
>
> When I was suggesting this customization, what I had in mind is not
> t/nil values but 'latex and 'org (style: latex or style: org).
> For t/nil, a better name would be simply
> org-latex-toc-include-unnumbered.
>
> > +*** ox-latex: Table of contents generation has been fixed and augmented
> > +
> > +The LaTeX exporter differs from other exporters in that it *does not*
> > +export unnumbered sections by default.
> > +
> > +The LaTeX exporter will use the new property =:UNNUMBERED: toc= to
> > +include unnumbered sections in the table of contents.
>
> New property value. UNNUMBERED is the existing property.
>
> > +(defcustom org-latex-toc-include-unnumbered-style nil
> > +  "Set this variable to true to include unnumbered headings in the
> > +table of contents as other exporters do.
> > +
> > +The default behaviour is to include numbered headings only.
> > +To include an unnumbered heading, set the `:UNNUMBERED:'
> > +property to `toc'"
> > +  :group 'org-export-latex
> > +  :package-version '(Org . "9.8")
> > +  :type 'boolean
> > +  :safe #'booleanp)
>
> I am wondering if we need to accompany this with an export option
> keyword to be set per-buffer.
>
> > +            (when need-alternative
> > +              (if (string-suffix-p "*" section-kw)
> > +                  (progn ;; unnumbered sections
> > +                    ;; Then we need to obey what the :UNNUMBERED:
> property says
> > +                    (if org-latex-toc-include-unnumbered-style ;;
> legacy or new behavior ?
> > +                        ;; new behavior (á la org)
>
> May you not use "new" and "legacy" here? Instead, use LaTeX/Org style.
> "new" only makes sense for people familiar with the old version of the
> code, but not for people reading ox-latex afresh.
>
> > +            ;; In all cases
> > +            ;; Get rid of the footnotes in opt-title
> > +            (unless (equal full-text-no-footnote full-text)
> > +              (setq opt-title full-text-no-footnote))
>
> What if ALT_TITLE is specified explicitly in the headline?
>
> --
> 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
Year 1 of the New Koprocracy
From 18944194a38f1d7449fe640b17d4f5c39113d16b Mon Sep 17 00:00:00 2001
From: "Pedro A. Aranda" <paag...@gmail.com>
Date: Fri, 21 Feb 2025 09:09:44 +0100
Subject: [PATCH 2/2] Ihor's comments and fix alternative title handling

---

* doc/org-manual.org: fix variable name: use
org-latex-toc-include-unnumbered to make it a boolean
* etc/ORG-NEWS: reflect changes in variable names
and minor quirks.
* lisp/ox-latex.el: rename variable to
org-latex-toc-include-unnumbered and fix alternative
title handling for titles with footnotes
* testing/lisp/test-ox-latex.el: Add tests for footnotes
in section titles with alternative title for the ToC

 doc/org-manual.org            |  8 ++++----
 etc/ORG-NEWS                  |  4 ++--
 lisp/ox-latex.el              | 19 ++++++++++---------
 testing/lisp/test-ox-latex.el | 12 ++++++------
 4 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 2edb74986..dcc9a6dec 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -14867,13 +14867,13 @@ contents, use the property =UNNUMBERED= and set it to =toc=:
 #+end_example

 #+cindex: LaTeX ToC export a la ~org~
-#+cindex: @samp{org-latex-toc-include-unnumbered-style}
+#+cindex: @samp{org-latex-toc-include-unnumbered}
 If you want the LaTeX exporter to behave like other exporters,
-customise the variable ~org-latex-toc-include-unnumbered-style~ and
+customise the variable ~org-latex-toc-include-unnumbered~ and
 set it to ~t~:

 #+begin_example
-(setq org-latex-toc-include-unnumbered-style t)
+(setq org-latex-toc-include-unnumbered t)
 #+end_example

 or add this setting in the local variables.
@@ -23546,7 +23546,7 @@ configuration.  See [[LaTeX specific export settings]].
 [fn:43] At the moment, some export backends do not obey this
 specification.  For example, LaTeX export excludes by default
 every unnumbered headline from the table of contents, unless you set
-the custom variable =org-latex-toc-include-unnumbered-style= to =t= or add
+the custom variable =org-latex-toc-include-unnumbered= to =t= or add
 =:UNNUMBERED: toc= to the section's properties.

 [fn:44] Note that ~org-link-search-must-match-exact-headline~ is
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index c14f7fc72..b4170336d 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -300,11 +300,11 @@ This text will be displayed on animation step 2 and later.
 The LaTeX exporter differs from other exporters in that it *does not*
 export unnumbered sections by default.

-The LaTeX exporter will use the new property =:UNNUMBERED: toc= to
+The LaTeX exporter will use the new property value =:UNNUMBERED: toc= to
 include unnumbered sections in the table of contents.

 Additionally, a new custom variable
-~org-latex-toc-include-unnumbered-style~ has been introduced. It
+~org-latex-toc-include-unnumbered~ has been introduced. It
 enables including unnumbered sections in the ToC aligned with the
 behaviour of other exporters. In this case, to exclude a section from
 the table of contents, mark it as =:UNNUMBERED: notoc= in its
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 326a65167..de682e27c 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1539,7 +1539,7 @@ calling `org-latex-compile'."
 	   (string :tag "Message"))))


-(defcustom org-latex-toc-include-unnumbered-style nil
+(defcustom org-latex-toc-include-unnumbered nil
   "Set this variable to true to include unnumbered headings in the
 table of contents as other exporters do.

@@ -2427,27 +2427,28 @@ holding contextual information."
           ;; This applies to anything that may go into the ToC.
           ;; Specifically for paragraphs, see first answer of
           ;; https://tex.stackexchange.com/questions/288072/footnotes-within-paragraph
-          (let ((need-alternative (string-match "\\`\\\\\\(.+?\\){" section-fmt))
+          (let ((need-alternative (not (null (string-match "\\`\\\\\\(.+?\\){" section-fmt))))
                 (section-kw (match-string 1 section-fmt)))
             (when need-alternative
               (if (string-suffix-p "*" section-kw)
                   (progn ;; unnumbered sections
                     ;; Then we need to obey what the :UNNUMBERED: property says
-                    (if org-latex-toc-include-unnumbered-style ;; legacy or new behavior ?
-                        ;; new behavior (á la org)
+                    (if org-latex-toc-include-unnumbered
+                        ;; Treat the ToC closer to what other exporters do
                         (when (string= unnumbered-type "notoc")
                           (setq need-alternative nil))
-                      ;; legacy behavior (á la LaTeX)
+                      ;; Treat the ToC as it has been originally
                       (unless (string= unnumbered-type "toc")
                         (setq need-alternative nil))))
                 ;; numbered sections
-                (if (and (equal full-text full-text-no-footnote)  ;; no footnotes
-                         (equal full-text opt-title)) ;; same alternative title
+                (if (and (string= full-text full-text-no-footnote)  ;; no footnotes
+                         (string= full-text opt-title)) ;; same alternative title
                     (setq need-alternative nil))))
             ;; In all cases
             ;; Get rid of the footnotes in opt-title
-            (unless (equal full-text-no-footnote full-text)
-              (setq opt-title full-text-no-footnote))
+            (when (and (not (string= full-text-no-footnote full-text)) ;; when we have footnotess
+                       (string= full-text-no-footnote opt-title))      ;; And we do not impose an alternative title
+                (setq opt-title full-text-no-footnote))
 	    (if need-alternative
                 (let ((new-format section-fmt)
                       (new-extra  "")) ;; put the addcontentsline here
diff --git a/testing/lisp/test-ox-latex.el b/testing/lisp/test-ox-latex.el
index 90f447eea..4918a473c 100644
--- a/testing/lisp/test-ox-latex.el
+++ b/testing/lisp/test-ox-latex.el
@@ -179,7 +179,7 @@ is suppressed
 :ALT_TITLE: Alternative
 :END:

-* Section 2
+* Section 2[fn::Test]
 :PROPERTIES:
 :ALT_TITLE: SECTION 2
 :END:
@@ -207,14 +207,14 @@ is suppressed
 \\label{"))
   (should (search-forward "}
 \\addcontentsline{toc}{subsection}{Alternative}
-\\section[SECTION 2]{Section 2}
+\\section[SECTION 2]{Section 2\\footnote{Test}}
 \\label{"))
   (should (search-forward "}
 \\end{document}"))))

 (ert-deftest test-ox-latex/new-toc-as-org ()
-  "test toc treatment with `org-latex-toc-include-unnumbered-style' set to `t'"
-  (let ((org-latex-toc-include-unnumbered-style t))
+  "test toc treatment with `org-latex-toc-include-unnumbered' set to `t'"
+  (let ((org-latex-toc-include-unnumbered t))
     (org-test-with-exported-text
      'latex
      "#+TITLE: num: fix
@@ -235,7 +235,7 @@ is suppressed
 :ALT_TITLE: Alternative
 :END:

-* Section 2
+* Section 2[fn::Test]
 :PROPERTIES:
 :ALT_TITLE: SECTION 2
 :END:
@@ -264,7 +264,7 @@ is suppressed
 \\label{"))
    (should (search-forward "}
 \\addcontentsline{toc}{subsection}{Alternative}
-\\section*{Section 2}
+\\section*{Section 2\\footnote{Test}}
 \\label{"))
    (should (search-forward "}
 \\addcontentsline{toc}{section}{SECTION 2}")))))
--
2.34.1

Reply via email to