1

I would like to define a really special subfigure label for a whole document. Below is a simplified example of what I am trying to do.

I would like to assign a different label to the subfigure if the counter value is a multiple of 3 or 5. I saw some answers that are kind of related to what I am trying but are a bit different for instance Unusual numbering: combine alph, Alph, arabic

To do that I am redefining the thesubfigure command and trying to define a newcommand myletterLabel

\renewcommand{\thesubfigure}{\myletterLabel{subfigure}}

The thing is every time I try to define a variable in \@myletterLabel, Latex complains about it whether I use \def, \pgfmathsetmacro or so. I am only able to use the if else\ifnum syntax but
I would need to compute the modulo 3 and 5 of the counter (I have much more subfigure than 26 so I do not want to write the if else case by hand).

Would there be a solution? Thanks a lot in advance

\newcommand{\myletterLabel}[1]{%
  \expandafter\@myletterLabel\csname c@#1\endcsname
}
\newcommand{\@myletterLabel}[1]{%
  \ifnum#1=0*%
  \else\ifnum#1<27
    \@alph{#1}%
  \fi%
  \fi%
}
\makeatother
2
  • What precisely do you want to get when the counter exceeds 26? And what would you do when you have a multiple of 3 or 5? And if the number is a multiple of both?
    – egreg
    Jun 25, 2022 at 21:37
  • Hi @egreg, So in terms of label (it's just an example) if the counter is not a multiple of 3 or 5 { label using \arabic{subfigure} } If the counter is a multiple of 3 but not 5 { label using lowercase roman number \roman{subfigure} } if the counter is a multiple of 5 { label using capital roman number \Roman{subfigure} } Jun 25, 2022 at 21:56

1 Answer 1

2

Like this?

\documentclass{article}
\usepackage{subcaption}

\ExplSyntaxOn

\NewExpandableDocumentCommand{\weird}{m}
 {
  \romainbqt_weird:n { #1 }
 }

\cs_new:Nn \romainbqt_weird:n
 {
  \bool_lazy_and:nnTF
   {
    !\int_compare_p:n { \int_mod:nn { \value{#1} } { 3 } == 0 }
   }
   {
    !\int_compare_p:n { \int_mod:nn { \value{#1} } { 5 } == 0 }
   }
   {% neither a multiple of 3 nor 5
    \int_to_arabic:n { \value{#1} }
   }
   {% check for a multiple of 5
    \int_compare:nTF { \int_mod:nn { \value{#1} } { 5 } == 0 }
     {
      \int_to_Roman:n { \value{#1} }
     }
     {
      \int_to_roman:n { \value{#1} }
     }
   }
 }

\ExplSyntaxOff

\renewcommand{\thesubfigure}{\weird{subfigure}}

\begin{document}

\begin{figure}

\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}\hfil
\begin{subfigure}{10em}\caption{test}\end{subfigure}

\end{figure}

\end{document}

enter image description here

With \bool_lazy_and:nnTF we check for two predicates, in this case “not a multiple of 3” and “not a multiple of 5”. When this returns true, we issue the standard arabic representation; otherwise, the number might be a multiple of 5 and we use uppercase Roman numerals; last resort, lowercase Roman numeral.

1
  • Hi @egreg, thanks a lot that's exactly what I needed and it is simple to modify/adapt Jun 26, 2022 at 9:22

You must log in to answer this question.

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