# Matrices with cryptocode package

I am using the package cryptocode to typeset protocols in a nice way, but I have a problem with matrices. Here is a MWE which shows the problem:

\documentclass{article}

\usepackage{cryptocode}

\begin{document}

\begin{figure}%[ht]
\begin{center}
\fbox{%
\pseudocode{%
\<\< \text{compute } P = \begin{pmatrix}
A \\ B + C
\end{pmatrix} \\
\text{compute } Q = R+S-T \<\< \\
\< \sendmessageright*{Q} \< \\
\< \sendmessageleft*{P} \< \\
}
}
\end{center}
\end{figure}

\end{document}


The result is

and, as you can see, the matrix is not typeset correctly (the alignment is wrong). How can I solve this?

Apparently the command \pseudocode mingles with the definition of \\ and other internals that are also relevant for \pmatrix. I can't offer a general solution. A quick hack is to save the matrix outside of \pseudocode in a box and to use this box inside of \pseudocode, like this: Before the pseudo code, add

\newsavebox\Pmatrix
\setbox\Pmatrix\hbox
{$\begin{pmatrix} A \\ B + C \end{pmatrix}$%
}


In the pseudo code, use \Pmatrix instead of the matrix:

\<\< \text{compute } P = \usebox\Pmatrix \\

• Works perfectly! It may not be a general solution but it does what it should. Thank you so much! Commented Sep 9, 2016 at 10:56

As gernot explained pseudocode mingles with the definition of \\. An alternative solution to using boxes defined outside of \pseudocode is to use \pclb instead of \\ within the matrix. This works as \pclb (more or less) maps to the original definition of \\.

So the following

\pseudocode{%

• \tabularnewline is better Commented Dec 1, 2016 at 13:58