# Using cases in a node in a matrix

I am trying to put piece-wise functions into nodes in a Tikz diagram. Using cases works fine in a Tikz node that is separate within a tikzpicture environment. Putting the same node in a matrix breaks the use of & to divide a single line within the cases block.

Is there any way to get the output of the node inside the matrix to match that of the separate node?

\documentclass{article}

\usepackage{tikz, amsmath}

\usetikzlibrary{shapes, positioning}

\begin{document}
\tikzstyle{block} = [draw, rectangle, align=center]

\begin{tikzpicture}

\node[block] (b1) {Separate node:\\
$$u_{out}= \begin{cases} 255 & \mbox{if } u_{in} > 255 \end{cases}$$};

\matrix[below=of b1] (m)
{
\node[block] (b2) {Node in matrix:\\
$$u_{out}= \begin{cases} 255 & \mbox{if } u_{in} > 255 \end{cases}$$};\\
};

\end{tikzpicture}

\end{document}


Option ampersand replacement allows you to define which symbol to use instead of & in matrix environments. More detailed information in 20.5 Considerations Concerning Active Characters

\documentclass{article}

\usepackage{tikz, amsmath}

\usetikzlibrary{shapes, positioning}

\begin{document}
\tikzstyle{block} = [draw, rectangle, align=center]

\begin{tikzpicture}

\node[block] (b1) {Separate node:\\
$$u_{out}= \begin{cases} 255 & \mbox{if } u_{in} > 255 \end{cases}$$};

\matrix[below=of b1, ampersand replacement=\&] (m)
{
\node[block] (b2) {Node in matrix:\\
$$u_{out}= \begin{cases} 255 & \mbox{if } u_{in} > 255 \end{cases}$$};\\
};

\end{tikzpicture}

\end{document}