As LyX normally loads amsmath
automatically if you use one of its environments, I just had to redefine the environment, by adding the following to the preamble:
\renewenvironment{align*}{\align}{\endalign}
Example of result, having added a simple align
environment from the LyX menus:
I used the "command forms" \align
and \endalign
as I think I read somewhere on this site that those are recommended in definitions of environments. Please comment if I'm wrong.
If you still get the error message, try loading amsmath
explicitly, by either
- adding
\usepackage{amsmath}
the Document --> Settings --> LaTeX preamble, or
- going to Document --> Settings --> Math options, unchecking the box by "Use AMS math package automatically" and checking the box below, for "Use AMS math package".
A better option, in my opinion
Instead of redefining align*
to align
, you can add a keyboard shortcut to add a numbered align
. This is done in Tools --> Preferences --> Editing --> Shortcuts (see my answer on Shortcuts for Lemma, Claim, Theorem etc for some more detail, should that be needed). Add a new shortcut, and type
command-sequence math-mode on; math-mutate align;math-number-toggle
as the function. You could for example use Ctrl+Alt+Shift+A as the shortcut, in which case the dialog would look as follows:
Having done this, just hit the specified shortcut, and you have a numbered align
environment.
Similarly you can create a keyboard shortcut for a numbered equation. Just replace align
with equation
in the function above, making it
command-sequence math-mode on; math-mutate equation;math-number-toggle
Ctrl+Alt+Shift+M is free (unless you've defined it yourself), so then only the Alt is the difference between a numbered and an unnumbered. You could of course change these around, making Ctrl+Shift+M create a numbered equation.
I'm not sure why but you can't use \begin{align}
and \end{align}
in the definition of a new environment; you have to use the "lower-level" macros \align
and \endalign
instead. Edit: as pointed by alexwlchan in his comment, you can find more details about that in section 6 of Technical notes on the amsmath
package.
Here I've used the equivalent of an align*
environment (see Herbert's answer to Define a custom align, and align* environment).
Note that you will get an error if you try to reset your grammarcounter
at each chapter in the article
class, because the latter doesn't have chapters; \section
is the most high-level sectioning command in the article
class. Did you mean
\numberwithin{grammarcounter}{section}
instead?
\documentclass{article}
\usepackage{amsmath}
\newcounter{grammarcounter}[section]
\makeatletter
\newenvironment{grammar}
{%
\refstepcounter{grammarcounter}
\start@align\@ne\st@rredtrue\m@ne
\tag{$\Gamma_{\thegrammarcounter}$}
}{%
\endalign
}
\makeatother
\begin{document}
\section{Foo}
\begin{grammar}
\label{gr:label}
E &::= E + E \\
E &::= a \\
E &::= b
\end{grammar}
\begin{grammar}
\label{gr:label2}
E &::= E + E \\
E &::= a \\
E &::= b
\end{grammar}
\end{document}
Best Answer
The
align
environment is defined by theamsmath
package that you have not loaded.