2

I have this equation and I got a error about \right] but it is in my code. What is wrong?

My code:

\usepackage{amsmath}
\newcommand{\barU}{\bar{U}}
\newcommand{\barV}{\bar{V}}
\newcommand{\barW}{\bar{W}}
\newcommand{\barP}{\bar{P}}

\begin{equation}
    \begin{aligned}
     \label{eq:mx2}
     %-------------
     \frac{\partial\barU}{\partial t} + \frac{\partial u}{\partial t} &= -\left[\barU\left(\frac{\partial \barU}{\partial x} + 
     \frac{\partial u}{\partial x}\right) + u\left(\frac{\partial \barU}{\partial x} + 
     \frac{\partial u}{\partial x}\right) + \barV\left(\frac{\partial \barU}{\partial y} + 
     \frac{\partial u}{\partial y}\right) + v\left(\frac{\partial \barU}{\partial y} + 
     \frac{\partial u}{\partial y}\right) + \\
     &\barW\left(\frac{\partial \barU}{\partial z} + 
     \frac{\partial u}{\partial z}\right) + w\left(\frac{\partial \barU}{\partial z} + 
     \frac{\partial u}{\partial z}\right)\right] - \left(\frac{\partial \barP}{\partial x} + \frac{\partial p}{\partial x}\right) +
     \frac{1}{Re}(\nabla^2\barU + \nabla^2u)
    \end{aligned}
   \end{equation}

The result:

enter image description here

Why the \right] doesn't appears?

Mateus
  • 451

2 Answers2

5

Indeed the \right] was missing, and anyway the opening and closing brackets were not on the same line, so you should have added a right. at the end of the firstline and a \left. at the beginning of the second line. It's simpler to use \biggl[ ... \\ ...\biggr], all the more so as you're guaranted both brackets will have the same size. As for your previous post I propose a slightly different alignment, and recommend the use of the \diffp command, from esdiff:

\documentclass[a4paper]{article}
\usepackage[showframe]{geometry}
\usepackage{mathtools, esdiff}
\usepackage{booktabs}

\DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
\DeclareFontShape{U}{mathx}{m}{n}{
<5><6><7><8><9><10>
<10.95><12><14.4><17.28><20.74><24.88>
mathx10
}{}
\DeclareSymbolFont{mathx}{U}{mathx}{m}{n}
\DeclareFontSubstitution{U}{mathx}{m}{n}
\DeclareMathAccent{\widebar}{0}{mathx}{"73}

\newcommand{\barU}{\widebar{U}}
\newcommand{\barV}{\widebar{V}}
\newcommand{\barW}{\widebar{W}}
\newcommand{\barP}{\widebar{P}}

\begin{document}

\begin{equation}
 %-------------
 \diffp{\barU}{t} + \diffp{u}{t}=
 \label{eq:mx2}
\begin{aligned}[t] -\biggl[\barU\left(\diffp{\barU}{x} +
    \diffp{u}{x}\right) + u\left(\diffp{\barU}{x} +
    \diffp{u}{x}\right) + \barV\left(\diffp{\barU}{y} +
    \diffp{u}{y}\right) + v\left(\diffp{\barU}{y} +
    \diffp{u}{y}\right) + \\
    \barW\left(\diffp{\barU}{z} +
    \diffp{u}{z}\right) + w\left(\diffp{\barU}{z} +
    \diffp{u}{z}\right)\biggr] - \left(\diffp{\barP}{x} + \diffp{p}{x}\right) +
     \frac{1}{Re}\bigl(\nabla^2\barU + \nabla^2u\bigr)
\end{aligned}
\end{equation}

\end{document} 

enter image description here

Bernard
  • 271,350
2

I also suggest not auto-sizing the large square brackets; instead, use \biggl[ and \biggr]. To improve (i.e., reduce) the spacing around the round parentheses, consider loading the mleftright package and running \mleftright in the preamble.

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=2.5cm]{geometry} % set page margins appropriately
\usepackage{mleftright}\mleftright % for better spacing before \left and after \right
\usepackage{amsmath}
\newcommand{\barU}{\bar{U}}
\newcommand{\barV}{\bar{V}}
\newcommand{\barW}{\bar{W}}
\newcommand{\barP}{\bar{P}}
\begin{document}
\begin{equation}\label{eq:mx2}
\begin{aligned}
\frac{\partial\barU}{\partial t} + \frac{\partial u}{\partial t} = 
    -\biggl[
 \barU &\left(\frac{\partial \barU}{\partial x} + \frac{\partial u}{\partial x}\right) 
     + u\left(\frac{\partial \barU}{\partial x} + \frac{\partial u}{\partial x}\right) 
  +\barV\left(\frac{\partial \barU}{\partial y} + \frac{\partial u}{\partial y}\right) 
     + v\left(\frac{\partial \barU}{\partial y} + \frac{\partial u}{\partial y}\right) \\
{}+\barW &\left(\frac{\partial \barU}{\partial z} + \frac{\partial u}{\partial z}\right) 
     + w\left(\frac{\partial \barU}{\partial z} + \frac{\partial u}{\partial z}\right)
     \biggr] 
     -  \left(\frac{\partial \barP}{\partial x} + \frac{\partial p}{\partial x}\right) 
     +  \frac{1}{Re}(\nabla^2\barU + \nabla^2u)
\end{aligned}
\end{equation}
\end{document}
Mico
  • 506,678
  • 2
    I didn't know about the mleftright package – for my excuse, Heiko Oberdiek wrote so many packages… Thanks for making me discover it (+1). – Bernard May 27 '18 at 07:51