1

I never use \( \). How do I redefine them to mean \begin{equation} \end{equation}?

(I know that many of you will think this is a bad idea.)

JPi
  • 13,595
  • 7
    It is a bad idea! \DeclareRobustCommand\({\begin{equation}} and the equivalent for the \end part should do... (you could also do with \def\({\begin{equation}}; I used \DeclareRobustCommand to keep the definition robust, as the original.) – Phelype Oleinik Jun 07 '19 at 19:25
  • Ha, I hadn't clued in that a simple construct like that would in fact work. Frame it as an answer and I'll accept. – JPi Jun 07 '19 at 19:30
  • I think it is rather an editor problem, to be configured so that with a shortcut it displays begin{equation} \end{equation} and the cursor in-between. – Bernard Jun 07 '19 at 19:49

1 Answers1

9

Don't!


If you do, don't blame me ;-)

TeX macros can (under normal circumstances, no \csname, not \catcode involved) be of two basic types: control sequences and control characters. A control sequence is formed by an escape character (normally \) followed by a sequence of "letter" tokens (normally a-z and A-Z), for example \begin. A control character is formed by an escape character and one single non-letter token (every other character that doesn't fit as "letter"). TeX allows you to define/access both control sequences and control characters in the same way, so \def\mymacro{something} is as valid as \def\({something}.

In latex.ltx, \( and \) are defined as:

\DeclareRobustCommand\({%
  \relax\ifmmode\@badmath\else$\fi}%
\DeclareRobustCommand\){%
  \relax\ifmmode\ifinner$\else\@badmath\fi\else \@badmath\fi}%

The extra code checks for nested usage of \(...\), which is invalid. You can replace $ by the proper environment delimiters (and move the \end{equation} to the \else branch of \ifinner):

\makeatletter
\DeclareRobustCommand\({%
  \relax\ifmmode\@badmath\else\begin{equation}\fi}%
\DeclareRobustCommand\){%
  \relax\ifmmode\ifinner\@badmath\else\end{equation}\fi\else\@badmath\fi}%
\makeatother

As egreg said in the comment below, if you load amsmath (which you usually should), then you can leave the nesting check to equation:

\DeclareRobustCommand\({\begin{equation}}
\DeclareRobustCommand\){\end{equation}}
  • 2
    I somehow feel like the "Don't" should be much larger. ;-) – schtandard Jun 07 '19 at 21:54
  • 5
    In amsmath.sty (that should be used for any document containing an equation environment) we read \DeclareRobustCommand{\[}{\begin{equation*}} and \DeclareRobustCommand{\]}{\end{equation*}}. No need to add the checks, because \begin{equation} already takes care of them. But of course I agree with *DON'T*. :-) – egreg Jun 07 '19 at 21:56
  • @schtandard There :-) I was trying to be not too shouty – Phelype Oleinik Jun 07 '19 at 22:03
  • @egreg Thanks. I knew I was forgetting something slightly important :-) – Phelype Oleinik Jun 07 '19 at 22:06