# Compiling errors in a matrix that correctly show up?

I have a little problem with nested arrays.

The following examples give the correct matrix after a Latex=>PDF run but generate LaTeX errors ! missing \$ inserted. <inserted text>, that I would like to get rid of.

First Example:

$$g_{22}=\left[\begin{array}{ccc}\fbox{\begin{array}{ccc}\frac{1}{E-E_1^1} & & \\ & \ddots & \\ & & \frac{1}{E-E_1^N}\end{array}} & & \\ & \ddots & \\ & & \fbox{\begin{array}{ccc} \frac{1}{E-E_n^1} & & \\ & \ddots & \\ & & \frac{1}{E-E_n^N}\end{array}}\end{array}\right]$$


Second example:

$$H=\left[\begin{array}{cc}H_{N-n}&\begin{array}{cl}B\qquad & 0 \end{array}\\ \begin{array}{c}B^{\dag}\\ 0 \end{array} & \fbox{\begin{array}{cc}H_{n}&\quad S\\S^{\dag}&\quad\hsub\end{array}}\end{array}\right]$$

-
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces or enclose words in backticks , they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). –  doncherry Jun 30 '12 at 10:23

The problem goes away if the contents of the \fbox is typeset in the mathmode.
\documentclass{article}
$$g_{22}=\left[ \begin{array}{ccc} \fbox{ \begin{array}{ccc} \frac{1}{E-E_1^1} & & \\ & \ddots & \\ & & \frac{1}{E-E_1^N} \end{array}} & & \\ & \ddots & \\ & & \fbox{ \begin{array}{ccc} \frac{1}{E-E_n^1} & & \\ & \ddots & \\ & & \frac{1}{E-E_n^N} \end{array}} \end{array}\right]$$
`