16

I wrote a matrix equation

\[
  \left[ \begin{array}{c}
    v^{0}_{n} \\
    v^{K-1}_{n}
  \end{array} \right] = 
    -\frac{1}{C_{ref}} 
      \left[ \begin{array}{ccc} V^{0}_{0,n} & \cdots & V^{0}_{M-1,m} \\
        \vdots & \ddots & \vdots \\
        V^{K-1}_{0,n} & \cdots &  V^{K-1}_{M-1,n}
      \end{array}  \right]
      \left[ \begin{array}{c}
        C_{0,n} \\
        C_{M-1,n}
      \end{array}
  \right]
\]

I want to put an equation number at the end of this equation. But only way I know how to do that is to put this whole equation in \begin{equation} and \end{equation} which gives an error. The error is

Bad math environment delimiter

When I delete \[ and \] from the start and end of my equation, I no longer get an error. My question is that why am I getting this error just by moving an equation in \begin and \end.

Troy
  • 13,741
azmuhak
  • 263
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Please add some line breaks in your code. In its present form, it's not very readable, and horizontal scrolling is painful. – jub0bs Dec 05 '13 at 06:18
  • 1
    @Mico: I think your comment actually answers the OP's question. I was too quick to answer before the OP finished editing the question :) I'm deleting mine now. As for your question: No, \tag{...} doesn't cause duplicate numbering in equation-like environments. But it simply replaces the numbers that would've been given by those environments. – Herr K. Dec 05 '13 at 06:30
  • @KevinC - Thanks! I've (re)posted my comment as an answer. – Mico Dec 05 '13 at 09:06

3 Answers3

21

The LaTeX macros \begin{equation} and \[ both initiate a display-math group, and the macros \end{equation} and \] both terminate a display-math group. (In addition, the equation environment provides a method for numbering the equations, whereas \[ ... \] does not.) The LaTeX macros \begin{equation} and \[ are designed purposefully so as not to let users open a display-math group twice; this is why you're getting the error message "Bad math environment delimiter" when LaTeX encounters \[ after having processed \begin{equation}.

The upshot: Use one or the other method for setting up a display-math group, but don't use both simultaneously.

For a more-detailed discussion of how various LaTeX displaymath environments are set up, see this answer to the question "What are the differences between $$, \[, align, equation and displaymath?" Shameless self-citation alert!

Mico
  • 506,678
3

I can't improve @Mico 's correct accepted answer to the question you asked, but can suggest that you use a bmatrix environment instead of hard coding the brackets and the arrays. You save typing, improve readability, and minimize fiddling:

\[
\begin{bmatrix}
    v^{0}_{n} \\
    v^{K-1}_{n}
\end{bmatrix} =
    -\frac{1}{C_{ref}} 
\begin{bmatrix}
     V^{0}_{0,n} & \cdots & V^{0}_{M-1,m} \\
        \vdots & \ddots & \vdots \\
        V^{K-1}_{0,n} & \cdots &  V^{K-1}_{M-1,n}
\end{bmatrix}
\begin{bmatrix}
        C_{0,n} \\
        C_{M-1,n}
\end{bmatrix}
\]
Troy
  • 13,741
Ethan Bolker
  • 9,333
  • 3
  • 42
  • 69
1

Since this is the suggested thread when looking up the Bad math environment delimiter error on Google, let me add an additional fix. The gist is this: the reverse order of Mico's answer is also true, namely that if you are inside a math environment, \begin{equation}, \begin{align} etc ... don't work.

There are three related errors you might encounter: Bad math environment delimiter, Missing \endgroup inserted and \begin{align} allowed only in paragraph mode, varying depending on whether you have mathtools loaded or not and which math environment you're opening.

In my case, I had loaded mathtools and had accidentally forgotten a closing $ in a paragraph some lines above a begin{equation}, causing LaTeX to stay in math mode. MWE of my situation:

\documentclass[a4paper]{article}
\usepackage{mathtools}  % Without this loaded, you get "Missing \endgroup" i.o. "Bad math".

\begin{document}

$\zeta(s) is the Riemann zeta function. Oops, forgot a dollar sign there. Some more sample text. I, the unsuspecting author, will now attempt to enter a math environment. \begin{equation} % If this is align, you get "allowed only in paragraph mode". \zeta(s) = \sum_{n=1}^\infty \frac{1}{n^s} \end{equation} The compiler did not like that.

\end{document}

Mew
  • 843