1

Is there a way to create a week count in this calendar? I am interested in including text to consider the number of the week, would this be possible using the used for loop?. I tried creating a new counter for the week and then update it as soon Monday is reached so that the week counter adds 1 but I could not make it work with this approach.

Any suggestions?

\documentclass{article}
\usepackage[paperheight=4in,paperwidth=4in]{geometry}
\usepackage{ifthen}
\usepackage{forloop}
\usepackage{nth}    % for 1st, 2nd, 3rd automagically!

% set counters for day and month
\newcounter{daycount}
\newcounter{monthcount}
\setcounter{daycount}{0}
\setcounter{monthcount}{1}
\newcounter{yearcount}
\setcounter{yearcount}{2012}
\newcounter{dispdaycount}    % for Mon, Tue, etc
\setcounter{dispdaycount}{6} % 2012 started on Sunday, the loop increments this by 1
\newcounter{masterDayCount}  % used in the main loop from 1 to 365 (or 366 in a leap year!)

% setup words for the days of the week
\newcommand{\displayday}[1]{%
    \ifthenelse{\equal{#1}{1}}{Mon}{}%
    \ifthenelse{\equal{#1}{2}}{Tue}{}%
    \ifthenelse{\equal{#1}{3}}{Wed}{}%
    \ifthenelse{\equal{#1}{4}}{Thu}{}%
    \ifthenelse{\equal{#1}{5}}{Fri}{}%
    \ifthenelse{\equal{#1}{6}}{Sat}{}%
    \ifthenelse{\equal{#1}{7}}{Sun}{}%
}

% setup words for the months of the year
\newcommand{\displaymonth}[1]{%
    \ifthenelse{\equal{#1}{1}}{Jan}{}%
    \ifthenelse{\equal{#1}{2}}{Feb}{}% 
    \ifthenelse{\equal{#1}{3}}{Mar}{}%
    \ifthenelse{\equal{#1}{4}}{Apr}{}%
    \ifthenelse{\equal{#1}{5}}{May}{}%
    \ifthenelse{\equal{#1}{6}}{Jun}{}%
    \ifthenelse{\equal{#1}{7}}{Jul}{}%
    \ifthenelse{\equal{#1}{8}}{Aug}{}%
    \ifthenelse{\equal{#1}{9}}{Sep}{}%
    \ifthenelse{\equal{#1}{10}}{Oct}{}% 
    \ifthenelse{\equal{#1}{11}}{Nov}{}%
    \ifthenelse{\equal{#1}{12}}{Dec}{}%
}

% check the date to make sure the day is not above the allowed range e.g, there are only 31 days in Jan, not more
% to be used as \checkdate{daycount}{monthcount}
\newcommand{\checkdate}[2]{% 
\ifthenelse{#2=2}
    {%
        % February only has 28 days (or 29 in a leap year like 2012)
        \ifthenelse{#1>29}
            {%
                \addtocounter{daycount}{-29}% 
                \addtocounter{monthcount}{1}%
            }%
            {}%
    }%
    {}%
\ifthenelse{#2=4 \or #2=6 \or #2=9 \or #2=11}
    {%
        % 30 day months, April, May, September, November
        \ifthenelse{#1>30}
            {%
                \addtocounter{daycount}{-30}% 
                \addtocounter{monthcount}{1}%
            }%
            {}%
    }%
    {}%
\ifthenelse{#2=1 \or #2=3 \or #2=5 \or #2=7 \or #2=8 \or #2=10 \or #2=12}
    {%
        % 31 day months
        \ifthenelse{#1>31}
            {%
                \ifthenelse{#2=12}
                {%
                    % if we're in December and the count is above 31, we need to set the month back to Jan
                    \addtocounter{monthcount}{-12}
                }%
                {}%
                \addtocounter{daycount}{-31}%
                \addtocounter{monthcount}{1}%
            }
            {}
    }%
    {}%
}

% worthy quotes
\newcommand{\worthyQuote}[1]{%
\ifthenelse{\equal{#1}{1}}{All we are\ldots}{}% 
\ifthenelse{\equal{#1}{2}}{\dots is dust in the wind dude \ldots}{}% 
\ifthenelse{\equal{#1}{3}}{dust}{}%
\ifthenelse{\equal{#1}{4}}{wind}{}%
\ifthenelse{\equal{#1}{5}}{dude!}{}%
\ifthenelse{\equal{#1}{6}}{Quote 6}{}%
\ifthenelse{\equal{#1}{7}}{Quote 7}{}%
\ifthenelse{\equal{#1}{8}}{Quote 8}{}%
\ifthenelse{\equal{#1}{9}}{Quote 9}{}%
\ifthenelse{\equal{#1}{10}}{Quote 10}{}%
\ifthenelse{\equal{#1}{11}}{Quote 11}{}%     
\ifthenelse{\equal{#1}{12}}{Quote 12}{}%
\ifthenelse{\equal{#1}{13}}{Quote 13}{}%
\ifthenelse{\equal{#1}{14}}{Quote 14}{}%
\ifthenelse{\equal{#1}{15}}{Quote 15}{}%
\ifthenelse{\equal{#1}{16}}{Quote 16}{}%
\ifthenelse{\equal{#1}{17}}{Quote 17}{}%
\ifthenelse{\equal{#1}{18}}{Quote 18}{}%
\ifthenelse{\equal{#1}{19}}{Quote 19}{}%
\ifthenelse{\equal{#1}{20}}{Quote 20}{}%
\ifthenelse{\equal{#1}{21}}{Quote 21}{}%
\ifthenelse{\equal{#1}{22}}{Quote 22}{}% finish these yourself!
}

\begin{document}

\pagestyle{empty}

\forloop{masterDayCount}{1}{\value{masterDayCount} < 367}
    {%
        % new page for a new day
        \clearpage%
        % up the day counters
        \addtocounter{daycount}{1}%
        \addtocounter{dispdaycount}{1}%
        % check that the displayed day counter doesn't go above 7
        \ifthenelse{\thedispdaycount>7}{\setcounter{dispdaycount}{1}}{}%
        % check the daycount for the relevant month
        \checkdate{\thedaycount}{\themonthcount}%
        % change this to suit your own style
        \begin{flushright}
        {\huge\displayday{\thedispdaycount} \nth{\thedaycount}  \displaymonth{\themonthcount} \theyearcount}\\
        {\textit{\worthyQuote{\themasterDayCount}}}
        \end{flushright}
    }

\end{document}

Attempt to include week counter

\newcounter{weekcount}
\setcounter{weekcount}{1}

\forloop{masterDayCount}{1}{\value{masterDayCount} < 367}
    {%
        % new page for a new day
        \clearpage%
        % up the day counters
        \addtocounter{daycount}{1}%
        \addtocounter{dispdaycount}{1}%

        % Here is where I tried to update the week counter
        \ifthenelse{\equal{\displayday{\thedispdaycount}}}{\string Mon}    {% if True
        \addtocounter{weekcount}{1}}

        % check that the displayed day counter doesn't go above 7
        \ifthenelse{\thedispdaycount>7}{\setcounter{dispdaycount}{1}}{}%
        % check the daycount for the relevant month
        \checkdate{\thedaycount}{\themonthcount}%
        % change this to suit your own style
        \begin{flushright}
        {\LARGE \displayday{\thedispdaycount} {\thedaycount}  \displaymonth{\themonthcount} \theyearcount}\\
        {\textit{Semana {\theweekcount}}}\\
        {\textit{\worthyQuote{\themasterDayCount}}}
        \end{flushright}
    }

Original post: How to create Page-a-Day Calendar Template

5
  • 1
    Welcome! TikZ has a beautiful library for that, calendar. Are you aware of that?
    – user194703
    Nov 20, 2019 at 21:06
  • Yes, I already checked Tikz and came across some useful approaches like this one: tex.stackexchange.com/questions/387240/…, though I was wondering about the possibility of adding the week number every day belongs to bt could not find a built-in function for this in Tikz, do you have any suggestion?
    – Fence
    Nov 21, 2019 at 19:25
  • I do not really understand what you mean by "adding the week number every day belongs to bt" (what does that mean? Is "bt" a "but"? Please explain) but /usr/local/texlive/2019/texmf-dist/tex/generic/pgf/utilities/pgfcalendar.code.tex is full of useful routines, and has w = week day of current date in it.
    – user194703
    Nov 21, 2019 at 19:39
  • Yes, "bt" was a "but" typo, what I meant with week number is that every day of the year belongs to a week number. E.g, days from 1 to 7 of January (assuming that January 1st is Monday) belong to the week number one, days from 8 to 15 to week number two and so on, but this functionality seems to not be included in tikz.
    – Fence
    Nov 21, 2019 at 19:43
  • You seem to be looking for \pgfcalendarjuliantodate, see p. 992 of pgfmanual v3.1.4. It allows you to find out the calendar week of a date.
    – user194703
    Nov 21, 2019 at 19:53

1 Answer 1

1

There is no built-in function for the weekdate number in the calendar module.

But we can add one!

This solution uses the ISO 8601. This means:

  1. A new week starts on Monday.
  2. The first week of the year has Jan 4th (= the year starts on Mon, Tue, Wed or Thu).
  3. Week 53 exists in Common Years when they start/end on a Thu, leap years have week 53 when they either end or start on a Thu.
  4. There's no week 0.

My solution stores away the calculation in a macro called \pgfcalendar@weeknumber@<year> so that it doesn't need to calculated at worst 366 times in a year. (Though, \pgfcalendar also doesn't just increment days/months/year/weekday and does a lot of calculations everytime.)

Some conditions are involved around the last and first days of the year since we either need to find out the weeknumber of the previous year or check for 3.

The code is part of my tikz-ext package. It provides the LaTeX package pgfcalendar-ext and the TikZ library ext.calendar-plus.

If you really want to count up, I suggest to use my solution at the first day of the year and when your counting reaches 53 (because sometimes 1 follows after 52).


Macro:

\pgfcalendarjulianyeartoweek{<julian count>}{<year>}{<week number count>}

The parameters are

  1. a count with the Julian date (inside pgfcalendar this is \pgfcalendarcurrentjulian)
  2. the year (yes, we could calculate that from 1. again but that's work, inside of pgfcalendar we can use \pgfcalendarcurrentyear)
  3. a count that will the week number

Here's an example of how you could access this inside a simple \pgfcalendar.

Further down, I show the full usage of my libraries with the week numbers (including the appropriate styles and new shorthands).

Code

\documentclass{article}
\usepackage{pgfcalendar-ext}
\newcount\myCount
\begin{document}
\pgfcalendar{}{2022-01-01}{2022-12-31}{
  Julian day \the\pgfcalendarcurrentjulian\space is
  \pgfcalendarcurrentday.\,\pgfcalendarcurrentmonth.\,\pgfcalendarcurrentyear\space has week number
  \pgfcalendarjulianyeartoweek{\pgfcalendarcurrentjulian}{\pgfcalendarcurrentyear}{\myCount}%
  \the\myCount\par}
\end{document}

Output

enter image description here

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{ext.calendar-plus}
\begin{document}
\small\sffamily
\colorlet{darkgreen}{green!50!black}%
\colorlet{darkblue}{blue!50!black}%
\foreach \y in {2019,...,2025}{%
\begin{tikzpicture}
  \calendar[
     dates/.expanded=\y-01-01 to \the\numexpr\y+1\relax-12-31, week list,
     month label left, month yshift=0pt, every month/.append style={xshift=+-4ex},
     month text=\textcolor{darkgreen}{\%mt},
     every week/.style={xshift=+-4ex,anchor=base east},
     week text={\textcolor{darkblue}{\%n-}},
     execute before day scope={
       \ifdate{equals=\pgfcalendarbeginiso}{
         \node[anchor=south, xshift={\pgfkeysvalueof{/tikz/day xshift}*2},
           yshift={1.1*\pgfkeysvalueof{/tikz/day yshift}}]{\bfseries\Large\y};}{}%
       \ifdate{Monday, equals=\pgfcalendarbeginiso}{%
         \pgfkeysvalueof{/tikz/weeknumber code}%
       }{}%enter image description here
     },
%     days={label={[inner sep=+0pt,font=\tiny,gray]above:\%n-}}% shows weeknumber
   ]
   if (Sunday) [black!50] if (Saturday) [black!75]
   if (
     and={
       day of month=1,
       not={equals=\pgfcalendarbeginiso},
       not=Monday
     }) [days={append after command={edge[fill, darkgreen, to path={
       (\tikztostart.north) -| (\tikztostart.west) .. controls
       ([shift=(-45:.5mm)]\tikztostart.north west) .. cycle}] ()}}];
\end{tikzpicture}}
\end{document}

Output

enter image description here

And another one (this pictures are big)!

You must log in to answer this question.

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