Subject: bug#53390: 29.0.50; [PATCH] Don't look for invalid whitespaces

From: Arash Esbati <[email-masked]>
Date: Thu, 20 Jan 2022 14:28:16 +0100

Hi all,

I'd like to suggest a minor change to `ispell-tex-skip-alists' which
looks for valid code and doesn't fix an apparent bug:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index ae3b18ed17..6382b402c0 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -1673,14 +1673,13 @@ ispell-tex-skip-alists
      ("\\\\bibliographystyle"           ispell-tex-arg-end)
      ("\\\\makebox"                     ispell-tex-arg-end 0)
      ("\\\\e?psfig"                     ispell-tex-arg-end)
-     ("\\\\document\\(class\\|style\\)" .
-      "\\\\begin[ \t\n]*{[ \t\n]*document[ \t\n]*}"))
+     ("\\\\document\\(class\\|style\\)" . "\\\\begin[ \t\n]*{document}"))
     (;; delimited with \begin.  In ispell: displaymath, eqnarray, eqnarray*,
      ;; equation, minipage, picture, tabular, tabular* (ispell)
      ("\\(figure\\|table\\)\\*?"        ispell-tex-arg-end 0)
      ("list"                            ispell-tex-arg-end 2)
-     ("program"                . "\\\\end[ \t\n]*{[ \t\n]*program[ \t\n]*}")
-     ("verbatim\\*?"   . "\\\\end[ \t\n]*{[ \t\n]*verbatim\\*?[ \t\n]*}"))))
+     ("program"      . "\\\\end[ \t]*{program}")
+     ("verbatim\\*?" . "\\\\end[ \t]*{verbatim\\*?}"))))
   "Lists of regions to be skipped in TeX mode.
 First list is used raw.
 Second list has key placed inside \\begin{}.
--8<---------------cut here---------------end--------------->8---

Currently, the regexps would accept the following cases:

1.
\documentclass{article}
\begin{ document}
foo
\end{document}

Running LaTeX on the file gives:

! LaTeX Error: Environment  document undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.3 \begin{ document}

Note that space is significant in environment names.

2.
\documentclass{article}
\usepackage{program}
\begin{document}
\begin{program}
  foo bar
\end{ program}
\end{document}

Running LaTeX on the file above says:
! LaTeX Error: \begin{program} on input line 4 ended by \end{ program}.

3.
\documentclass{article}
\begin{document}
\begin{verbatim}
foo
\end {verbatim}

\end{document}

Running LaTeX on the file above says:
Runaway argument?
^^Mfoo^^M\end {verbatim}^^M^^M\end{document}^^M^^M^^M^^M^^M^^M^^M^^M^^M\ETC.
! File ended while scanning use of \@xverbatim.
<inserted text>
                \par

This one is delicate since vanilla LaTeX looks exactly for 14 characters
\end{verbatim} and packages like verbatim.sty lift this limitation and
allow a whitespace (and not a linebreak) between \end and {verbatim}.

Please let me know if I should install this change.

Best, Arash