2

I am trying to create a list of dates that I can not only use to create a calendar but also use it to output in the document. So far the implementation to display the calendar has been answered by Calendar with tikz

Throughout the document I have a check if the date is a holiday or not. If it is a holiday, then go to the next working day. There are a few examples already but they don't seem to meet my need (perhaps I do not understand the code well enough). The code that most closely represented what I needed can be found here Add (n) working days to a specific date

The issue that i have is that I would like to define the holidays or vacation days only once and using just month and day (like the calendar or first example) as opposed to year, month and day (in the second example).

Note: The dates that I am interested in spans multiple years.

I tried a simple example as follows:

\newcommand{\vacay}{equals=10-31, equals=05-31}

\pgfcalendarifdate{\thisyear-\thismonth-\thisday}{
        equals=10-31,
        equals=05-31 
    }{\thisyear-\thismonth-\thisday \, this is a holiday}{\thisyear-\thismonth-\thisday \, is not holiday}
    
Passing in a holiday array:
\pgfcalendarifdate{\thisyear-\thismonth-\thisday}{
        \vacay
}{\thisyear-\thismonth-\thisday \, this is a holiday}{\thisyear-\thismonth-\thisday \, is not holiday}

I am not sure why the second example (passing a holiday array) would not work in this case; or, if there is a better way to share an array of holidays for both a calendar and for text.

1 Answer 1

2

As always, this is an expansion issue.

The error message says

Package pgfkeys Error: I do not know the key '/pgf/calender/equals=10-31, equals=05-31'

(All conditionals are actually PGFkeys in the /pgf/calendar namespace.)

With a trivial, seemingly unnecessary key

\pgfqkeys{/pgf/calendar}{style/.style={#1}}

we can remedy this and use this new style with the handler .expand once (or .expanded:

{style/.expand once=\vacay}

We could have done also something like

\newcommand*\temp{\pgfcalendarifdate{\thisyear-\thismonth-\thisday}
\expandafter\temp\expandafter{\vacay}{<true>}{<false>}

but the style style is much more user-friendly, in my opinion.

Code

\documentclass{article}
\usepackage{pgfcalendar}

\newcommand*\thisyear{2022}
\newcommand*\thismonth{10}
\newcommand*\thisday{31}

\newcommand*\vacay{equals=10-31, equals=05-31}
\pgfqkeys{/pgf/calendar}{style/.style={#1}}
\begin{document}
Passing normal: \thisyear-\thismonth-\thisday\space is%
  \pgfcalendarifdate{\thisyear-\thismonth-\thisday}
    {equals=10-31, equals=05-31}{}{n't}
    a holiday.
    
Passing in a holiday array: \thisyear-\thismonth-\thisday\space is%
  \pgfcalendarifdate{\thisyear-\thismonth-\thisday}
    {style/.expand once=\vacay}{}{n't}
    a holiday.
\end{document}

Output

enter image description here

You must log in to answer this question.

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