2

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{%
    \textbf{Sender} \<\< \textbf{Receiver} \\[][\hline]
    \<\< \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

enter image description here

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

2 Answers 2

2

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 \\
1
  • Works perfectly! It may not be a general solution but it does what it should. Thank you so much!
    – minomic
    Commented Sep 9, 2016 at 10:56
3

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{%
\textbf{Sender} \<\< \textbf{Receiver} \\[][\hline]
\<\< \text{compute } P = \begin{pmatrix}
    A \pclb B + C
\end{pmatrix} \\
\text{compute } Q = R+S-T \<\< \\
\< \sendmessageright*{Q} \< \\
\< \sendmessageleft*{P} \< \\
}

yields

enter image description here

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .