Subject: bug#74009: 14.0.6.2024-10-22_10:04:26; LaTeX-fill-environment does strange things when % is present

From: Arash Esbati <[email-masked]>
Date: Tue, 29 Oct 2024 18:23:32 +0100

Uwe Brauer via bug-auctex via Bug reporting list for AUCTeX <[email-masked]> writes:

> running LaTeX-fill-environment results in 
> formatting environment 41% I have to interrupt with C-g and obtain
>
> \begin{definition}[homotopy relation on
>   1-simplices]\label{defn:1-simplex-htpy}
>   \uses{defn:simplicial-set} A parallel pair of 1-sim\-plices $f,g$ in
>   a simplicial set $X$ are \textbf{homotopic} if there exists a
>   2-simplex whose boundary takes either of the following
>   forms\footnote{The symbol ``$=$'' is used in diagrams to denote a
>     degenerate simplex or an identity arrow.}
>   % \footnote{The symbol
> [...]
>   % ``$\!\!\!\!\!\begin{tikzcd}[ampersand replacement=\&, sep=small] ~\arrow[r, equals] \& ~ \end{tikzcd}\!\!\!\!\!$'' is used in diagrams to denote a degenerate simplex or an identity arrow.}
>    \begin{center}
>    \begin{tikzcd}[row sep=small, column sep=small]
>    & y \arrow[dr, equals] & && &  x \arrow[dr, "f"]  \\ x \arrow[ur, "f"] \arrow[rr, "g"'] & & y & & x \arrow[ur, equals] \arrow[rr, "g"'] & & y
>    \end{tikzcd}
>   \end{center}
>    or if $f$ and $g$ are in the same equivalence class generated by this relation.
> \end{definition}
>
> It could have been much longer because I think emacs entered a infinite
> loop.
>
> Any ideas?

I didn't look closely, but slightly re-writting the code like this:

--8<---------------cut here---------------start------------->8---
\begin{definition}[homotopy relation on 1-simplices]\label{defn:1-simplex-htpy}
  \uses{defn:simplicial-set} A parallel pair of 1-sim\-plices $f,g$ in a simplicial set $X$ are \textbf{homotopic} if there exists a 2-simplex whose boundary takes either of the following forms\footnote{The symbol ``$=$'' is used in diagrams to denote a degenerate simplex or an identity arrow.}
   % \footnote{%
   % The symbol ``$\!\!\!\!\!%
   % \begin{tikzcd}[ampersand replacement=\&, sep=small]
   %   ~\arrow[r, equals] \& ~
   % \end{tikzcd}%
   % \!\!\!\!\!$'' is used in diagrams to denote a degenerate simplex or an identity arrow.}
   \begin{center}
   \begin{tikzcd}[row sep=small, column sep=small]
   & y \arrow[dr, equals] & && &  x \arrow[dr, "f"]  \\ x \arrow[ur, "f"] \arrow[rr, "g"'] & & y & & x \arrow[ur, equals] \arrow[rr, "g"'] & & y
   \end{tikzcd}
  \end{center}
   or if $f$ and $g$ are in the same equivalence class generated by this relation.
\end{definition}
--8<---------------cut here---------------end--------------->8---

and running `LaTeX-fill-environment' on this gives:

--8<---------------cut here---------------start------------->8---
\begin{definition}[homotopy relation on
    1-simplices]\label{defn:1-simplex-htpy}
  \uses{defn:simplicial-set} A parallel pair of 1-sim\-plices $f,g$ in
  a simplicial set $X$ are \textbf{homotopic} if there exists a
  2-simplex whose boundary takes either of the following
  forms\footnote{The symbol ``$=$'' is used in diagrams to denote a
    degenerate simplex or an identity arrow.}
  % \footnote{% The symbol ``$\!\!\!\!\!%
  % \begin{tikzcd}[ampersand replacement=\&, sep=small]
  %   ~\arrow[r, equals] \& ~
  % \end{tikzcd}%
  % \!\!\!\!\!$'' is used in diagrams to denote a degenerate simplex
  % or an identity arrow.}
  \begin{center}
    \begin{tikzcd}[row sep=small, column sep=small]
      & y \arrow[dr, equals] & && & x \arrow[dr, "f"] \\ x \arrow[ur,
        "f"] \arrow[rr, "g"'] & & y & & x \arrow[ur, equals]
      \arrow[rr, "g"'] & & y
    \end{tikzcd}
  \end{center}
  or if $f$ and $g$ are in the same equivalence class generated by
  this relation.
\end{definition}
--8<---------------cut here---------------end--------------->8---

So I suspect it has something to do with the placement of
\begin/\end{tikzcd} in the comment.

Best, Arash