18

Remark: The examples in this post are not the real cases, the real one is a web page using MathJax. It seems MathJax has some restrictions about the packages that can be used. In particular, mathtools seems to not be supported.

The following document fails with errors "Missing }"

\documentclass{article}
\usepackage[x11names, rgb]{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\begin{document}

\begin{align}
  \boxed{ 2x+y & = 11 } \\
  3x & = 19 - 2y
\end{align}

\end{document}

The problem seems to be the usage of \boxed (if it is removed, the error disappears) inside an align block.

Any solution of this issue or other way to enclose an equation or some terms of an equation when using align blocks?

Note the following doesn't causes any error:

\begin{align}
 \boxed{ 2x+y } & = 11 \\
  3x & = 19 - 2y
\end{align}
Chrisuu
  • 400
  • 3
    \boxed hides the & from the parser. Try the similar command \Aboxed from the mathtools package – daleif Jan 01 '17 at 17:27
  • 2
    You have discovered that MathJax is not LaTeX: it doesn't understand LaTeX commands the same as LaTeX does. If a feature is not supported in MathJax, there's little one can do on the language side. – egreg Jan 01 '17 at 20:37
  • 1
    @egreg: A comment absolutely improductive. In fact, the main problem is enclose anything with brackets inside an align. Secondary is that usual alternatives are not applicable when using MathJax – pasaba por aqui Jan 01 '17 at 22:40
  • @pasabaporaqui Why? You don't seem to know that the two systems are very different from each other. For instance, it's not that MathJax supports amsmath: the developers of MathJax have implemented some of the features of amsmath, but not all of them. – egreg Jan 01 '17 at 22:43

3 Answers3

45

\boxed cannot contain alignment points. Load mathtools (needless to load amsmath in this case) and use \Aboxed:

\documentclass{article}
\usepackage[x11names, rgb]{xcolor}
\usepackage[utf8]{inputenc}
\usepackage{mathtools}

\begin{document}

\begin{align}
  \Aboxed{ 2x+y & = 11 } \\
  3x & = 19 - 2y
\end{align}

\end{document} 

enter image description here

Bernard
  • 271,350
  • Good solution. Unfortunately, this code is in the real case inside a www page using Mathjax, and mathjax doesn't supports this mathtools package. – pasaba por aqui Jan 01 '17 at 17:39
  • \Aboxed is the "correct" way to box an equation in the align environment. If it's not supported by mathjax, you may be out of luck. – SteelAngel Jan 02 '17 at 04:46
5

Here's a workaround that works with MathJax, but it's not pretty and might need additional tweaking depending on the MathJax implementation you're working with:

$$ 
\begin{align*}
2x+y &= 11 \\ 
3x &= 19 - 2y 
\; \llap{\mathrel{\boxed{\phantom{3x = 19 - 2y}}}}
\end{align*} 
$$

Here's what this would look like on math.stackexchange.com:

enter image description here

Edit: I boxed the wrong line by mistake, but one can accomplish the same thing for any line within an align block.

Chrisuu
  • 400
  • 1
    It preferible to use \[...\] instead of $$...$$ https://tex.stackexchange.com/questions/503/why-is-preferable-to. Good LaTeX – Sebastiano Jul 20 '19 at 19:30
3

You can use tikz to create frame

\documentclass{article}
\usepackage[x11names, rgb]{xcolor}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\def\tikzmark#1{\tikz[remember picture,overlay]\node[inner ysep=0pt,anchor=base](#1){\strut};}

\begin{document}

\begin{align}
  \tikzmark{A}2x+y & = 11 \tikzmark{B} \\
                3x & = 19 - 2y
\end{align}

\tikz[remember picture,overlay]\draw(A.south west)rectangle(B.north east);

\end{document} 
Salim Bou
  • 17,021
  • 2
  • 31
  • 76