16

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}
4
  • 3
    \boxed hides the & from the parser. Try the similar command \Aboxed from the mathtools package
    – daleif
    Jan 1, 2017 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 1, 2017 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 Jan 1, 2017 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 1, 2017 at 22:43

3 Answers 3

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.

1
44

\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

2
  • Good solution. Unfortunately, this code is in the real case inside a www page using Mathjax, and mathjax doesn't supports this mathtools package. Jan 1, 2017 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 2, 2017 at 4:46
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} 
1
  • Unfortunately, not supported by MathJax. Jan 1, 2017 at 18:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .