5

I was trying to insert matrix into a \subsection{}:

\subsection{Suppose $X= \begin{array}{cc}
1 & 2 \\
3 & 4
\end{array}$}

This gives me an error:

 ! TeX capacity exceeded, sorry [input stack size=5000].

What is wrong here? Thanks!

2 Answers2

5

If you need the matrix to show up in the table of contents, as well, here is one technique:

\documentclass{article}
\usepackage{tabstackengine}
\setstacktabbedgap{1ex}
\savestack{\mathexpr}{$X= \bracketMatrixstack{1 & 2 \\3 & 4}$}
\begin{document}
\tableofcontents
\section{Main Topic}
\subsection{Suppose \mathexpr}
\section{Next Topic}
\end{document}

enter image description here

5

I guess you want smallmatrix rather than array. But you can also use the full size version, if you really want.

The key is that \begin, \end and \\ are fragile so they need \protect in front of them when in a moving argument (section title or caption).

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\subsection{Suppose $X=\left[\protect\begin{smallmatrix}
1 & 2 \protect\\
3 & 4
\protect\end{smallmatrix}\right]$}

\subsection{Suppose $X=\protect\begin{bmatrix}
1 & 2 \protect\\
3 & 4
\protect\end{bmatrix}$}

\end{document}

enter image description here

egreg
  • 1,121,712