Here's one possible way to achieve this:
\def\@multiqprefix{@MultiFig}
\def\@multiq#1{\gdef\expandafter\noexpand\csname\@multiqprefix#1\endcsname{multifig}}
\def\@ifNotMultiQ#1{\expandafter\if#1\relax}
\def\@subfigpart#1#2{\@ifNotMultiQ{\csname\@multiqprefix\Roman{#1}\endcsname}\else{/\Alph{#2}}\fi}
\renewcommand{\thefigure}{\theenumi\@subfigpart{enumi}{figure}}
\AtEndEnvironment{figure}{
\ifnum\value{figure}=2\immediate\write\@auxout{\@multiq{\Roman{enumi}}}\fi
}
It works by subverting the figure environment. When a second figure is supplied for a given question (the figure counter is used per question in this context, so I'm testing for its value being 2), a control sequence gets written in the aux file of the form
\gdef @MultiFigI {multifig}
where the trailing I corresponds to the question number in roman numeral form. Arabic numerals make it harder because they aren't normally allowed in control sequences, and there would no doubt be a load of \csnames all over the place if I went that way. {multifig} is a placeholder. Its value is never used, but it might come in handy one day.
\thefigure is overridden to test whether the current question is in fact a multi-figure one, and if it is, supplies the trailing \A, \B etc for all of the figures in the question.
My biggest hang-up was getting \@multiq right. Without the \expandafter\noexpand, the file would read first but on the second pass, you'd get items in the aux file like
\gdef multifig {multifig}
because the \@MultiFig would get expanded as it was written.
This solution has the following issues:
- It adds etoolbox as a required package
- It means you need three passes
of the latex file to get the references right (but the tool I use to
build the document, Kile, sorts this out automatically)
Q1
comes from. Can you present a minimal example in the “old style”?\newif\ifsolefigure\renewcommand{\thefigure}{\theenumi\ifsolefigure\else/\Alph{figure}\fi\global\solefigurefalse}
and manually insert\solefiguretrue
in each item with only one figure. But this requires manual mark-up with this\solefiguretrue
. (I anticipate though some problems if your figures are really in floats, but I personally would not use floats in such circumstances, and I would manually caption the figures).