pgf icon indicating copy to clipboard operation
pgf copied to clipboard

weeknumbers in the calendar library

Open dsp1986 opened this issue 2 years ago • 1 comments

Brief outline of the proposed feature

Hello, the calendar library would be more useful to me, if it could give me an easy way to get the weeknumber as a variable available in \daycode, \monthcode, etc. environments.

Currently I found no easier way to write the weeknumber next to Mondays than this whole lot:

   \ifdate{Monday}{
        \pgfcalendardatetojulian{\YEAR-01-01}{\newyear}
        \pgfcalendarjuliantoweekday{\newyear}{\newyearweekday}
        \node[anchor=base east] {
            \nowjulday \pgfcalendarcurrentjulian\relax
            \advance\nowjulday -\newyear\relax
            \tikzmath{
                \weeknumber = \nowjulday / 7;
                \weeknumber = \weeknumber + 1;
            }
            \ifnum\newyearweekday > 0
                \ifnum\newyearweekday < 4
                    \advance\weeknumber 1\relax
                \fi
            \fi
            \ifnum\weeknumber < 10
                ~
            \fi
            \the\weeknumber 
        };
    }{}

all this calculation is obviously very clumsy to have in the documents that should simply describe the structure of my calendars.

I would like to have this code available as a variable in relevant environments by default when I load the calendar library in tikz. How do I do this?

Which files in the pgf source would need to be edited for this? is there a better way to code this?

kind regards Dom

Usage example

the above snippet could be better written as

\ifdate{Monday}{\weeknumber}{}

or

\ifdate{Monday}{\W}{}

dsp1986 avatar Aug 15 '23 22:08 dsp1986

Please make your example complete.

@Qrrbrbirlbel's tikz-ext package contains a (sub)package pgfcalendar-ext, which then provides

\pgfcalendarjulianyeartoweek{⟨Julian day⟩}{⟨year⟩}{⟨week count⟩}
% and
\pgfcalendarcurrentweek

both available in \ifdate. See the package manual for tikz-ext (v0.5.1), sec. 24.2 "Week numbering (ISO 8601)" for more info and this answer for a fancier use example.

A naive \pgfcalendarcurrentweek use example:

\documentclass{article}
%\usepackage{tikz}
\usepackage{xcolor}
\usepackage{pgfcalendar-ext}

\begin{document}
\pgfcalendar{cal}{2023-08-01}{2023-08-31}{%
  \ifdate{Monday}{
    \leavevmode\llap{\makebox[1cm][l]{\color{gray}\pgfcalendarcurrentweek}}%
  }{}%
  % copied from the 3rd example in https://tikz.dev/pgfcalendar#sec-89.2
  \leavevmode
  \hbox to0pt{\hskip\pgfcalendarcurrentweekday cm\pgfcalendarcurrentday\hss}%
  \ifdate{Sunday}{\par}{}%
}
\end{document}

image

muzimuzhi avatar Aug 16 '23 18:08 muzimuzhi