# Increment counter by 2 in tasks package

I am using the tasks package to layout answers to exercises. However the exercises are numbered 1, 3, 5, 7, etc. Of course tasks wants to increment by 1 to get 1, 2, 3, 4, etc. Is there anyway to set a increment value for tasks?

\documentclass{article}

\begin{document}

\task $x^2$
\task $y^5$
\task $a^5$
\task $b^5$
\task $c^5$
\task $d^5$

\end{document}

• You could add \stepcounter{task} to the second and following task items. Commented May 28, 2023 at 5:44
• please always provide an example. You say "Of course tasks wants to increment by 1 to get 1,2,3,4, etc" but I did not get 1,2,3 from \documentclass{article} \usepackage{tasks} \begin{document} \begin{tasks}(3) \task $x^2$ \task $y^5$ \task $a^5$ \task $b^5$ \task $c^5$ \task $d^5$ \end{tasks} \end{document} Commented May 28, 2023 at 12:33
• You're absolutely right, by default it goes, a), b), c) etc. I updated the code to give a compete example that uses arabic instead. Commented May 28, 2023 at 22:07

When the value for label has the form \foo*, tasks will apply \foo to the default counter. Define a command that does simple arithmetic with the counter's value.

\documentclass{article}

\NewExpandableDocumentCommand{\makeodd}{m}{%
\inteval{2*\value{#1}-1}%
}

\begin{document}

\task $x^2$
\task $y^5$
\task $a^5$
\task $b^5$
\task $c^5$
\task $d^5$

\end{document}


Using the stepcounter idea by Circada in their comment we get what we're looking for. Better than adding the numbers manually using \task[number]. It's easier to add new entries without manually renumbering everything.

\documentclass{article}

\begin{document}

\task $x^2$
\task $y^5$ \stepcounter{task}
\task $a^5$ \stepcounter{task}
\task $b^5$ \stepcounter{task}
\task $c^5$ \stepcounter{task}
\task $d^5$ \stepcounter{task}

\end{document}


• Use \refstepcounter{task} if you need to make a cross-reference to an item with label/ref. Commented May 29, 2023 at 1:53

Musing arithmetically,

MWE

\documentclass{article}

\ExplSyntaxOn
\NewDocumentCommand { \makeodd } { m } {
\int_set:Nn \l_tmpa_int { \value{#1} }
\int_eval:n {
\l_tmpa_int + \l_tmpa_int -1
}
}
\ExplSyntaxOff

\begin{document}
Since the set of natual numbers is infinite, and the set of odd numbers is also infinite, one can be mapped to the other (in this case, via $n*2-1$) to display odd-numbered labels in the enumerate-style task list without needing to change the actual task number.

For the case where the start value for the list numbering is 1, the calculation \texttt{\textbackslash makeodd}, in expl3 syntax

\begin{quotation}\noindent
\begin{verbatim}
\NewDocumentCommand { \makeodd } { m } {
\int_set:Nn \l_tmpa_int { \value{#1} }
\int_eval:n {
\l_tmpa_int + \l_tmpa_int -1
}
}
\end{verbatim}
\end{quotation}

and called via the \verb|tasks| environment's \verb|label=| option,

\begin{quotation}\noindent
\verb|label={(\makeodd*)},|
\end{quotation}

gives:

style=enumerate,
label={(\makeodd*)},
label-width=4ex,
%       start = {20},
](3)
\task $xx^2$
\task $xy^5$
\task $xa^5$
\task $xb^5$
\task $xc^5$
\task $xd^5$