# Is there a way to define a shorter command macro instead of $$\label{}$$?

So instead of using the whole

$${body} \label{}$$

I could simply type something like

\inserteq{{x+y=1}{eq1}}

That would be very helpful. Thanks on advance!

• Welcome to TeX.SX! You won't gain profit from this in the long term – user31729 Jan 25 '15 at 13:02
• This is discussed in the amsmath documentation, but is generally not advisible. It is better to use an editor than inserts such constructs for you. – Andrew Swann Jan 25 '15 at 13:02
• why is it not advisable if it saves time in the writing? (seriously asking..). Also, didn't find it in the documentation, can you guys please provide an xeample for how 2 do it? – user1611107 Jan 25 '15 at 13:04
• it isn't recommended as for larger structures the environment syntax is helpful (which is why latex chooses to define some commands taking arguments and some as environments) also as the begin/end syntax is understood by many editors you are more likely to get correct math syntax highlighting and context sensitive help if you do not hide the syntax. But \newcommand is there specifically to make personal macros so it's purely personal preference, not exactly wrong. – David Carlisle Jan 25 '15 at 13:24
• It may be efficient while typing, it's not when revising, for instance because you can't simply look for \label if there is some problem with them. It's also inconvenient if you need to transform the single equation into a multiline display (say because the document turns out to need two column typesetting). – egreg Jan 25 '15 at 13:33

I've used these for years with no ill effects (other than tohecz [aka yo'] complaining about my typography :^)) This doesn't convert the environments into macros, but merely creates a shorthand syntax for getting into and out of the equation environments, with or without labels and/or punctuation.

%       BEGIN EQUATION MODE
\newcommand{\beq}{}
%       BEGIN EQUATION MODE WITH LABEL
\newcommand{\beql}[1]{\label{#1}}
%       END EQUATION MODE
\newcommand{\eeq}{}
%       END EQUATION MODE WITH A PERIOD
\newcommand{\eeqp}{\;\;\;.}
%       END EQUATION MODE WITH A COMMA
\newcommand{\eeqc}{\;\;\;,}

Typical usage might be

\documentclass{article}
%       BEGIN EQUATION MODE
\newcommand{\beq}{}
%       BEGIN EQUATION MODE WITH LABEL
\newcommand{\beql}[1]{\label{#1}}
%       END EQUATION MODE
\newcommand{\eeq}{}
%       END EQUATION MODE WITH A PERIOD
\newcommand{\eeqp}{\;\;\;.}
%       END EQUATION MODE WITH A COMMA
\newcommand{\eeqc}{\;\;\;,}
\begin{document}
Here is one equation,
\beql{eq:lbl}
y = mx+b
\eeqc
while here is another,
\beq
y = mx+b
\eeqp
\end{document}

Actually, what worked for me is an answer suggested by @eudoxos (he wrote it in the comments on my question) :

\def\inserteq#1#2{$${#1}\label{#2}$$}

I think this way is the simplest.

Than you use it as:

\inserteq{x+y=1}{eq1}

I usually use a eq macro:

\makeatletter
\def\eq{\@ifstar\@eq\@@eq}
\def\@eq#1{\begin{equation*}#1 \end{equation*}}
\def\@@eq#1#2{$$\label{#1}#2$$}
\makeatother

The eq macro takes the label as first argument and the equation as a second one. The starred version only takes the equation. However, no syntactic coloration, and some editors notice labels and serve them up when writing\ref, that won't work here. Use example:

\eq{b-a:ba}{1+1=2}
\eq*{2+2+=4}

Similarly, I find the parenthesis/bracket shortcuts useful:

\def$${\left(} \def$${\right)}
\def${\left[} \def${\right]}

Example:

\eq{eq:ex-parenthesis}{$$t+3$$\times9-2=0}
• Maybe you can find redefining  useful. I can't recommend it and you're bound to get surprising results if you load packages that assume those commands have their default meaning. – egreg Jan 26 '15 at 8:32
• Honestly, I didn't come up with those, but I have been using them since I encountered them. I had my doubts at first for the reason you evoke, but so far so good. Particularly in my current phd thesis where I use a lot packages I expected some mayhem there. Keeping fingers crossed though ;) – luneart Jan 26 '15 at 19:39