Subject: Re: bug#59638: 13.0.9; reftex-toc counts incorrectly if section is commented out

From: Arash Esbati <[email-masked]>
Date: Mon, 28 Nov 2022 09:13:13 +0100

Hi Tassilo,

Tassilo Horn <[email-masked]> writes:

> I'd call it a feature.  I mean, when you have commented out sections,
> you'll most probably intend to uncomment them again.  Otherwise, you
> could just delete them, no?

This feature was introduced with commit 1e8bb313ea in reftex.el.  The
change was good to make RefTeX recognize sectioning macros in .dtx file,
but I'd consider the behavior in regular .tex files as wrong.  What do
you think about this change:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/textmodes/reftex.el b/lisp/textmodes/reftex.el
index e72576cdc7..c72dd5fa07 100644
--- a/lisp/textmodes/reftex.el
+++ b/lisp/textmodes/reftex.el
@@ -1005,9 +1005,13 @@ reftex-compile-variables

     ;; Calculate the regular expressions
     (let* (
-;          (wbol "\\(\\`\\|[\n\r]\\)[ \t]*")
-           (wbol "\\(^\\)%?[ \t]*") ; Need to keep the empty group because
-                                    ; match numbers are hard coded
+           ;; (wbol "\\(\\`\\|[\n\r]\\)[ \t]*")
+           ;; Need to keep the empty group because match numbers are
+           ;; hard coded
+           (wbol (concat "\\(^\\)"
+                         (when (string-suffix-p ".dtx" (buffer-file-name) t)
+                           "%")
+                         "[ \t]*"))
            (label-re (concat "\\(?:"
                             (mapconcat #'identity reftex-label-regexps "\\|")
                             "\\)"))
--8<---------------cut here---------------end--------------->8---

@Uwe: Meanwhile, you can try to comment out your sections like this:

%% \section{foo}

and you should get a correct TOC.

Best, Arash