When writing LaTeX using latex-mode
, I often want to write "half-open intervals" in my text. For instance, [0,1)
, which refers to the set of all numbers x
with 0 <= x < 1
.
Unfortunately, these "unbalanced delimiters" seem to confuse the indentation parser, causing following text to be indented inappropriately, usually drifting to the right.
Here's an example document. The text below is the result after doing C-x h M-x indent-region
. The correct behavior would be to have all of both paragraphs indented by 0 spaces.
\documentclass{article}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam volutpat
at dui et mattis. Here is a half open interval $[0,1)$. Proin
fringilla lectus nec mi tincidunt aliquet. Vestibulum fermentum eu
neque id egestas. Here is another $[1,2)$. Nullam et lectus
convallis, placerat neque non, vehicula nisi. Fusce imperdiet
dignissim ante, eget fringilla nisi.
Integer fermentum nunc eget purus molestie commodo. Integer
tristique tincidunt odio, vel rutrum diam commodo quis. Fusce a
aliquet quam. Cras suscipit est et nisl sollicitudin
iaculis. Aliquam erat volutpat. Phasellus sapien arcu, aliquet ut
hendrerit in, lobortis nec ante.
\end{document}
Currently I am working around this with an ugly hack: I define a LaTeX macro that expands to nothing, and write the "matching" delimiters inside an invocation of this macro. This gets the indenter back in sync.
\documentclass{article}
\newcommand{\ugh}[1]{}
\begin{document}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam volutpat
at dui et mattis. Here is a half open interval $[0,1)$. Proin
fringilla lectus nec mi tincidunt aliquet. Vestibulum fermentum eu
neque id egestas. \ugh{(]} Now on the next line we are back in sync.
Nullam et lectus convallis, placerat neque non, vehicula nisi. Fusce
imperdiet dignissim ante, eget fringilla nisi.
\end{document}
But this is really unpleasant. Is there a better solution?
I'm using GNU Emacs 24.4.1.