This is only a fun answer. I am trying out LoopSpace's great update of the tikzmark package, which has now a command in that I was always looking for: \tikzmarknode
. And it just works. (Yes, using tikz
here may be an overkill, as I said, this is just for fun and to learn something new.) EDIT: Moved the brackets away from the boxes, big thanks to @manooooh!
\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{tikzmark,fit}
\newcommand\bigzero{\makebox(0,0){\text{\huge0}}}
\begin{document}
\begin{equation}
\left(~\begin{matrix}
\tikzmarknode{1A}{0}&1\\
1&\tikzmarknode{1B}{0}&&&&\bigzero\\
&&\tikzmarknode{2A}{0}&1\\
&&1&\tikzmarknode{2B}{0}\\
&&&&\ddots\\
&\bigzero&&&&\tikzmarknode{3A}{0}&1\\
&&&&&1&\tikzmarknode{3B}{0}
\end{matrix}~\right)
\begin{tikzpicture}[overlay, remember picture]
\foreach \X in {1,2,3}
{\node[inner sep=1pt,draw,fit=(\X A)(\X B)]{};}
\end{tikzpicture}
\end{equation}
\end{document}