I am using \IfStrEqCase to choose between various options within an environment. In the MWE below, if the line with the actions to be performed for any non-recognised option (\ifqsbreak{}.....\fi) is commented out, everything works fine. If I include the line, I get an error message (Missing number, treated as zero). I have tried replacing \IfStrEqCase with a simple \if statement, and it works as I would expect it to.
\documentclass[a4, 11pt]{article}
\newcommand{\Docform}{TQ}
\newcounter{question}
\newcounter{subquestion}
\newif\ifqsbreak
\usepackage{xstring}
\newenvironment{SubQuestion}[1][nobreak]% The optional argument determines whether the question should be kept as a block
{%
\refstepcounter{subquestion}
\IfStrEqCase{\Docform}
{
% Question format for TQ
{TQ}
{\subsection*{Q\thequestion.\thesubquestion}}%
}
% All other options
[
\ifqsbreak{}\else\begin{minipage}[t]{\linewidth} !In a minipage \fi
]
}
%-----------------------------------------------------------
% This is the closing statement for the SubQuestion environment
%-----------------------------------------------------------
{
\IfStrEqCase{\Docform}
{
{TQ}
{}
}
% Closing statement for all other options
[
\ifqsbreak{}\else\end{minipage}\fi
]
}
%------------------------------------------------------
\begin{document}
Some opening text
\begin{SubQuestion}
Some text in the sub-question
\end{SubQuestion}
\end{document}
I guess that there is some interference between \IfStrEqCase and the \begin{minipage} because if i remove the \begin{minipage} there is no problem. But I don't see why the \begin{minipage} should even be invoked, given that the code should skip over everything within the [...].
\IfStrEqCase. This is due to the fact that the content within the optional parmeter has an also makes use of an optional paramter so it needs to be[{ \ifqsbreak...[]...}]. – Peter Grill Jun 01 '20 at 17:24