[Tex/LaTex] way to define a shorter command macro instead of \begin{equation} \label{}\end{equation}

macros

So instead of using the whole

\begin{equation} 
{body}
\label{}
\end{equation}  

I could simply type something like

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

That would be very helpful. Thanks on advance!

Best Answer

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}}
%       BEGIN EQUATION MODE WITH LABEL
\newcommand{\beql}[1]{\begin{equation}\label{#1}}
%       END EQUATION MODE
\newcommand{\eeq}{\end{equation}}
%       END EQUATION MODE WITH A PERIOD
\newcommand{\eeqp}{\;\;\;.\end{equation}}
%       END EQUATION MODE WITH A COMMA
\newcommand{\eeqc}{\;\;\;,\end{equation}}

Typical usage might be

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

enter image description here

Related Question