Math macro with \left can only be used in math mode error

errorsmacrosmath-mode

I use \eq{} and \eq*{} instead of \begin and \end equation.

\def\eq{\@ifstar\@eq\@eeq}
\def\@eq#1{\begin{equation*}\begin{split}#1\end{split}\end{equation*}}
\def\@eeq#1{\begin{equation}\begin{split}#1\end{split}\end{equation}}

It works well, however, when I try to use

\eq{\left( .... \right)}   % no error
\eq*{\left( .... \right)}   % \left can only be used in math mode

The editor warns me that left can only be used in math mode.

How do I make the editor think that my input is 100% math?

...
\def\@eq#1{\begin{equation*}\begin{split}\ensuremath{#1}\end{split}\end{equation*}}
...

does yield same error, but,

\eq*{\ensuremath{\left(...\right)}}

This works without error.

*When I say error, Its not that It fails to compile, but has red x mark on the left.. both method compiles as expected..

*Other maths (\frac{}{}, x_s,... ) work without error…

Best Answer

Your editor knows that

\[ ... \]
\begin{equation} ... \end{equation}
\begin{equation*} ... \end{equation*}

(not necessarily with the initial and terminal marks on the same line) and other environments are math, so it won't signal math specific commands inside them.

Instead, it apparently seems to be wanting to help you in avoiding common errors, like using math specific commands out of context.

You don't say which editor you're using, but the answer is independent of the editor. You have two choices:

  1. teach the editor that the argument of \eq or \eq* is math;

  2. avoid using “abbreviations” such as \eq and \eq*.

The second strategy is preferable: you perhaps gain a few keystrokes at the expense of input clarity and flexibility. I have no doubt what input is clearer in the following code.

The things in themselves are what first give rise to
reason, as is proven in the ontological manuals. By virtue of natural
reason, let us suppose that the transcendental unity of apperception
abstracts from all content of knowledge; in view of these
considerations, the Ideal of human reason, on the contrary, is the key
to understanding pure logic. Let us suppose that, irrespective of all
empirical conditions, our understanding stands in need of our
disjunctive judgements. As is shown in the writings of Aristotle, pure
logic, in the case of the discipline of natural reason, abstracts from
all content of knowledge
\begin{equation}\label{abc}
\int_{-\infty}^{\infty} \exp(-x^2)\,dx=\sqrt{\pi}
\end{equation}
Our understanding is a representation of, in accordance with the principles 
of the employment of the paralogisms, time. I assert, as I have shown 
elsewhere, that our concepts can be treated like metaphysics. By means of 
the Ideal, it must not be supposed that the objects in space and time are 
what first give rise to the employment of pure reason
\eq{\label{abc}\int_{-\infty}^{\infty} \exp(-x^2)\,dx=\sqrt{\pi}}
Thus, the Antinomies exclude the possibility of, on the other hand, natural 
causes, as will easily be shown in the next section.  Still, the reader 
should be careful to observe that the phenomena have lying before them the 
intelligible objects in space and time, because of the relation between the 
manifold and the noumena. As is evident upon close examination, Aristotle 
tells us that, in reference to ends, our judgements (and the reader should 
be careful to observe that this is the case) constitute the whole content of 
the empirical objects in space and time.
Related Question