0

I have defined commands \( and \) for \left( and \right). When I use them, it can cause the green from the math environment to overflow into the text following. For example, in the below example, there. \end{document} is also green. Any thoughts on how to fix this? I use these commands a lot. I just reinstalled Windows and Texmaker, but I don't remember this happening (as much at least) on my older version...

\documentclass[12pt]{article}
\renewcommand{\(}{\left(}
\renewcommand{\)}{\right)}
\begin{document}
Hello $a+\(b+c\)$ there.
\end{document}
4
  • 2
    Well, it's because you've defined over the primitive LaTeX commands \( and \). \( enters inline math mode and \) leaves it. \( ... \) is the LaTeX-y equivalent of $ ... $. Your editor knows this and therefore it applies the correct syntax highlighting. This is an obvious problem with defining over these commands, which is highly inadvisable. You should not do this. Not doing this will solve many problems. Beware the lure of overusing \left and \right tex.stackexchange.com/questions/173717/…
    – Au101
    Aug 6, 2016 at 0:13
  • By the way what I believe is happening is your editor is seeing your \) and ending the math mode syntax highlighting there. It then immediately sees your $ and starts it again, running through to the end, for it finds no "closing" $. But this kind of thing is liable to produce confusing and unpredictable syntax highlighting. I used to redefine the old deprecated commands like \it not as switches, I defined \it{...} as \textit{...} so I could use \it{...} without some of the associated problems. Emacs did not enjoy this. I elected to stop doing this. I think that was a good idea:P
    – Au101
    Aug 6, 2016 at 0:17
  • @Au101 Ah I wasn't aware \( and \) had that behavior by default...that makes sense as to why it's formatting it like that then. Thanks!
    – Hanmyo
    Aug 6, 2016 at 8:10
  • @Au101 -- that's an answer you've given in your comment. make it one, please. Aug 6, 2016 at 13:57

1 Answer 1

2

Well I can tell you what the problem is.

\( and \) are primitive LaTeX commands. \( enters inline math mode and \) leaves it. Or, in other words, \( ... \) is the modern, LaTeX equivalent of $ ... $. You might be more familiar with \[ ... \] being preferred over the old (and heavily discouraged in LaTeX) $$ ... $$.

Now, your editor knows these commands are for inline math mode and therefore it's applying the math mode syntax highlighting. At a guess, I'd say what's probably happening is that your editor is seeing your \) and ending the math mode syntax highlighting there. It then immediately sees your $ and starts it again, running through to the end, for it finds no "closing" $.

I'm not sure about this, though, and, indeed, the main point is that this kind of thing is liable to produce confusing and unpredictable syntax highlighting, because it's not at all what your editor is expecting.

This is an obvious problem with defining over primitive commands like \( and \), which is highly inadvisable. You should not do this. In general, you should be very careful about defining over LaTeX commands, especially fundamental ones like \( ... \) unless you're sure of what you're doing. You could get some highly unusual results which may not be that easy to troubleshoot. See for example this question.

In any case, beware the lure of overusing \left and \right. I know your question is an MWE, designed to be as stripped down as possible, but you certainly shouldn't use \left and \right as you did in your example. Quite possibly you already know this, and were just trying to make a minimal minimal working example, but I thought I'd underline it.

Quick demo:

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\verb|\( ... \)| can be used to enter inline math mode:
\(x^{2} + 2x + 1 = (x + 1)^{2}\). It is just like \verb|$ ... $|, as
you can see: $x^{2} + 2x + 1 = (x + 1)^{2}$.

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .