For a recent project I tried to become acquainted with LaTeX3 but unfortunately, I have some difficulties and cannot find the issue, which is why I'm asking for a helpful hint.
In the project, I want to check whether a given year of a date is a leap year. That's why I defined an \isLeapYear
macro calling a LaTeX3 function under the hood.
The common algorithm to check whether a given year is a leap year is the following (from Wikipedia):
Taking this, I wrote the following code. Remember, that I'm just starting to learn LaTeX3, and to be honest, it's quite challenging even though I am more or less proficient in several programming languages.
\prg_new_conditional:Npnn \is_leapyear:n #1 { p, T, F, TF }
{
\int_set:Nn \l_tmpa_int { \curriculum_modulo:nn {#1} {4} }
\tl_if_eq:nnTF {\l_tmpa_int} {0} {
\int_set:Nn \l_tmpa_int { \curriculum_modulo:nn {#1} {100} }
\tl_if_eq:nnTF {\l_tmpa_int} {0} {
\int_set:Nn \l_tmpa_int { \curriculum_modulo:nn {#1} {400} }
\tl_if_eq:nnTF {\l_tmpa_int} {0} {\prg_return_true}{\prg_return_false}
}{\prg_return_true}
} {\prg_return_false}
}
\newcommand{\isLeapYear}[1]
{
\bool_if:nTF { \is_leapyear_p:n {#1} } {leap~year} {normal~year}
}
When running this code \isLeapYear{2024}
a Missing number, treated as zero. error occurs.
Here is the exact error message.
! Missing number, treated as zero.
<to be read again>
\__bool_=_0:
l.25 \isLeapYear{2024}
A number should have been here; I inserted `0'.
(If you can't figure out why I needed to see a number,
look up `weird error' in the index to The TeXbook.)
Is there a major issue in my approach or am I missing something? I look forward to any helpful hints that increase my knowledge of LaTeX3 and take me further.
MWE
\documentclass{article}
\ExplSyntaxOn
% https://www.alanshawn.com/latex3-tutorial/#implementing-modulo-operation
\cs_set:Npn \curriculum_modulo:nn #1#2 {
\int_set:Nn \l_tmpa_int { \int_div_truncate:nn {#1}{#2} }
\int_eval:n { (#1) - \l_tmpa_int * (#2) }
}
\prg_new_conditional:Npnn \is_leapyear:n #1 { p, T, F, TF }
{
\int_set:Nn \l_tmpa_int { \curriculum_modulo:nn {#1} {4} }
\tl_if_eq:nnTF {\l_tmpa_int} {0} {
\int_set:Nn \l_tmpa_int { \curriculum_modulo:nn {#1} {100} }
\tl_if_eq:nnTF {\l_tmpa_int} {0} {
\int_set:Nn \l_tmpa_int { \curriculum_modulo:nn {#1} {400} }
\tl_if_eq:nnTF {\l_tmpa_int} {0} {\prg_return_true}{\prg_return_false}
}{\prg_return_true}
} {\prg_return_false}
}
\newcommand{\isLeapYear}[1]
{
\bool_if:nTF { \is_leapyear_p:n {#1} } {leap~year} {normal~year}
}
\ExplSyntaxOff
\begin{document}
\isLeapYear{2024}
\end{document}