Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to create automatic numbering of equations in LyX. when I entered

\renewcommand\[{\begin{equation}}
\renewcommand\]{\end{equation}} 

for the "equation" environment it worked. However, when trying to make the align* environment numbering

\renewcommand{\begin{align*}}{\begin{align}}
\renewcommand{\end{align*}}{\end{align}}

it produces errors, such as "LaTeX Error: \begin{align*}undefined".

how can I overcome this?

share|improve this question
1  
The align* environment is already defined to not produce numbered equations, and the align to produce numbered equations. Not sure exactly what you are trying to accomplish. Furthermore, \renewcommand is used to renew commands, not environments. –  Peter Grill May 31 '12 at 2:30
    
\renewcommand{<cmd>}[<arg>][<opt arg>]{<new cmd>} requires a macro as <cmd> and you're supplying "something else." Perhaps you could elaborate what you mean by "automatic equation numbering," since this seems like a XY Problem. –  Werner May 31 '12 at 2:30
    
I know that! Please read what I wrote more carefully. I am using LyX which automatically uses align* env. However, I want it to use align. So I am trying to redefine align* as align. –  PineApple May 31 '12 at 5:52
1  
I don't think LyX loads amsmath unless you actually use amsmath stuff, but you can force it to load amsmath in the document settings. (align is from amsmath.) Or you could add \usepackage{amsmath} to the preamble. Also, as mentioned above, you're trying to change an environment, so I suppose renewenvironment, not renewcommand should be used. –  Torbjørn T. May 31 '12 at 6:57
    
@PineApple: Welcome to TeX.SE. Apologies for not reading your question more carefully, but since there is another user on this site with the same user name I did not see that you were a new user. So you might want to consider changing your user name. –  Peter Grill May 31 '12 at 18:31
add comment

1 Answer

up vote 5 down vote accepted

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:

enter image description here

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

  1. adding \usepackage{amsmath} the Document --> Settings --> LaTeX preamble, or
  2. 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:

enter image description here

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.

share|improve this answer
    
Thank you! it works perfectly. However, sometimes I want it to number only the last equation in a certain "align" block (so that the block is numbered only once, and not in every row in it) do you know of a way to do that? –  PineApple May 31 '12 at 15:29
    
@PineApple There are two different answers to that question, depending on your intent. If you want to have a single number for the entire set of equations, then rather use a normal numbered equation and put either a split or aligned environment within it. The number will then be centered vertically with respect to the equations. If you want to have just one line of the set numbered, add \nonumber in an ERT to the lines that should not be numbered. I can add some info about this to my answer, or perhaps you can ask a follow up question. –  Torbjørn T. May 31 '12 at 20:09
    
@Torbjørn Thanks. I want to automatically number every block of equations once (the block is created by Ctrl_shift+M i.e. using the "aligned*" environment in LyX) the problem in creating a "split" or "aligned" environment is to do it within LyX. Even if it's possible it needs to be done every time manually through the menus. Is there a way (by proper definitions in the preamble. Or maybe options inside LyX) to automatically make every block numbered once, and every single equation environment numbered as well (without manually numbering them)? –  PineApple Jun 1 '12 at 10:43
    
@PineApple I added a description on how to add a keyboard shortcuts for numbered equations. Could avoid redefining environments altogether. –  Torbjørn T. Jun 1 '12 at 16:44
    
@PineApple Oh, and to create a keyboard shortcut that inserts a numbered equation with an aligned environment (align and aligned are not the same, by the way), use the function command-sequence math-display;math-number-toggle ;math-insert \aligned; inset-modify tabular append-column. That will give you alignment and a single number for the whole block. –  Torbjørn T. Jun 1 '12 at 20:17
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.