# Auctex: bug in LaTeX-mark-environment?

Before I send this on to the developers, I'd like to know if others can confirm this problem. Consider these two environments:

\begin{flalign*}
sdfsdf
\end{flalign*}

\begin{flalign*}
&& A \rightarrow \End_{B}(M) && {; B=\End_{A}(M)}
\end{flalign*}


If I set the cursor in the first one and execute LaTeX-mark-environment (C-c .), then I get the expected result, i.e. marked the flalign* environment, including the \begin/end lines.

However if I do the same in the other one, it never covers the env. What ever is marked depends on where the cursor is. It is clearly having an issue with the \End, presumably because it is ignoring case.

Can others confirm?

(LaTeX-mark-environment together with narrow-to-region is a really nice feature to have when writing macros).

The problem is that the LaTeX-find-matching-end performs case insensitive searches. To make the search for the \end case sensitive, you have to bind the case-fold-search variable to nil. To do that you can advice the LaTeX-find-matching-end function. This will fix your problem but won't work if there is an \end inside the environment (think about a verbatim environment).

(defadvice LaTeX-find-matching-end
(around LaTeX-find-matching-end-case-sensitive activate)
"Perform case-sensitive search."
(let ((case-fold-search nil))


PS development version of AUCTeX has a new function to narrow to an environment (LaTeX-narrow-to-environment), so you'll need a single key binding (C-x n e) instead of C-c . C-x n r

(daleif addition), one also need to change add to LaTeX-find-matching-begin:

(defadvice LaTeX-find-matching-begin
(around LaTeX-find-matching-begin-case-sensitive activate)
"Perform case-sensitive search."
(let ((case-fold-search nil))

• They already mention thecverbatim in latex.el but nothing about case insensitivity. And \End is a perfectly reasonable mathematical operator – daleif Jan 10 '14 at 7:58
• I've added the corresponding fix for LaTeX-find-matching-begin without it C-u C-c C-e fails to find the start of the environment – daleif Jan 11 '14 at 10:29
• @daleif Regarding the post environment change hook, I advise you to suggest this improvement to the auctex-devel mailing list ;-). – giordano Jan 11 '14 at 13:49