# “Esami” package: \randestrai and \sqrt not working together?

The \randestrai command from the "esami" package allows to define a set of elements to randomly choose within, such as a set of formulas. It works with formulas including latex commands inside, for example I can safely use

\randestrai{\frac{1}{2}x+1,2x-\frac{1}{2}}{formula}


or

\randestrai{A \to B, \overline{A} \land B}{formula}


but once I use the \sqrt command in one of the elements an error messages arises telling me that there is an extra "}" that actually doesn't exists.

Example: if I write

\randestrai{\sqrt 2, 1}{formula}


I get the error message:

! Argument of \reserved@a has an extra }. \par l.10 \randestrai{\sqrt 2, 1}{formula} I've run across a }' that doesn't seem to match anything.

Why is that? Is there a workaround?

\sqrt is a risky command to put there (it depends on how \randestrai is implemented).

Make it robust in a different way:

\documentclass{article}
\usepackage{esami}
\usepackage{etoolbox}

\robustify{\sqrt}

\date{2018/11/02}

\begin{document}

\randestrai{\frac{1}{2}x+1,2x-\frac{1}{2}}{formula}
$\formulai$

\randestrai{A \to B, \overline{A} \land B}{formula}
$\formulai$

\randestrai{\sqrt{4+3}, \sqrt{2+5}}{formula}
$\formulai$

\end{document}


The definition of \sqrt is \@ifnextchar [\@sqrt \sqrtsign (see \sqrtsign and \sqrt), which checks for an optional argument (the root number). It seems that the list processing in \randestrai breaks in some way because of this definition. As a workaround you can bypass the check and directly use \sqrtsign for a square root without the number.

MWE:

\documentclass{article}
\usepackage{esami}
\date{2018/04/21}%%% THE DATE IN THE FORMAT YYYY/MM/DD
\begin{document}
\randestrai{\frac{1}{2}x+1,2x-\frac{1}{2}}{formula}
$\formulai$

\randestrai{A \to B, \overline{A} \land B}{formula}
$\formulai$

\randestrai{\sqrtsign{4+3}, \sqrtsign{2+5}}{formula}
$\formulai$

\end{document}


Result:

Edit: in general, but especially for adding indexes, the solution of egreg is preferred. However, you can define a square root command that can be used in \randestrai without being robust:

\def\sqsciatto#1#2{{}^{\scriptscriptstyle #2}\mkern-11mu\sqrtsign{#1}}

\randestrai{\sqsciatto{4+3}{7}, \sqsciatto{2+5}{3}}{formula}
$\formulai$
`

Result:

• Good idea but it seems it wouldn't work if I want roots with indexes different from 2 – Marco Disce Nov 2 '18 at 13:31
• Indeed, for that you should use egregs answer. But it can be done with a but of trouble, see edit. – Marijn Nov 2 '18 at 14:47