TransWikia.com

How to iterate over days and weeks of the year

TeX - LaTeX Asked by user1685095 on July 7, 2021

Thanks to the help of this community I’ve managed to create a digital planner template page.

documentclass{article}
usepackage[landscape, margin=0.5cm]{geometry}
usepackage{tabularx}
usepackage[table, svgnames]{xcolor}
usepackage{advdate}
usepackage[dayofweek]{datetime}
usepackage{pgffor}
newcommand{grayline}{arrayrulecolor{lightgray}cline{1-5}arrayrulecolor{white}}
newcommand{Hsquare}{%
  text{fboxsep=0ptfbox{rule{0pt}{2ex}rule{2ex}{0pt}}}%
}
newcountdayscnt
dayscnt=1

pagecolor{black}
color{white}
setlength{extrarowheight}{10pt}
ThisYear{2021}
ThisMonth{1} % Start in January
ThisDay{1} % Set the day number to zero
newcounter{mycntr}
mycntr=1
newcounter{rownumber}
begin{document}
loop
    begin{minipage}[b]{0.475linewidth}
    setcounter{rownumber}{0}
    deffillfirsttable{}%
    {
        loopifnumtherownumber<12
        addtocounter{rownumber}{1}
        expandafterdefexpandafterfillfirsttableexpandafter{%
            fillfirsttable
            & & & & 
            hline
            & & & & 
            grayline
        }%
        repeat
    }
    noindent
    begin{tabularx}{linewidth}{wc{0.5cm}|X|X|X|X|}
        cline{1-5}
        multicolumn{5} {r|} {Date: AdvanceDate[value{mycntr}]todaystepcounter{mycntr}}
        hline
        fillfirsttable
    end{tabularx}
    end{minipage}
    hfill
    begin{minipage}[b]{0.475linewidth}
    parnoindentrule{textwidth}{0.4pt}
    parnoindentrule{textwidth}{0.4pt}
    parnoindentrule{textwidth}{0.4pt}
    parnoindentrule{textwidth}{0.4pt}
    parnoindentrule{textwidth}{0.4pt}
    parnoindentrule{textwidth}{0.4pt}
    Shutdown complete: 

    setcounter{rownumber}{0}
    deffillsecondtable{}%
    {
        loopifnumtherownumber<10
        addtocounter{rownumber}{1}
        expandafterdefexpandafterfillsecondtableexpandafter{%
            fillsecondtable
            &  hline
        }%
        repeat
    }
    noindent
    begin{tabularx}{linewidth}{X|X}
    TASKS: & IDEAS:   hline
    fillsecondtable
    end{tabularx}
    end{minipage}

advance dayscnt 1
ifnum dayscnt<10
repeat

end{document}

Now I would like to create a document where each such page would represent particular day with date and week number already filled.

I’m not sure whether latex has capabilities to calculate dates and weeks. Maybe I could pass them as argument somehow when building?

EDIT1: I think the only problem is nested loops…

One Answer

I used pgffor for the loop and defined a new command that typesets your whole calendar page (mainly for readability) and then used the foreach and your hint with AdvanceDate to produce this.

documentclass{article}
usepackage[landscape, margin=0.5cm]{geometry}
usepackage{tabularx}
usepackage[table, svgnames]{xcolor}
usepackage{amsmath}
newcommand{grayline}{arrayrulecolor{lightgray}cline{1-5}arrayrulecolor{white}}
newcommand{Hsquare}{%
    text{fboxsep=0ptfbox{rule{0pt}{2ex}rule{2ex}{0pt}}}%
}
deftabularxcolumn#1{m{#1}}

%% use pgffor package for the loop
usepackage{pgffor}
usepackage{advdate}

%% typeset a whole calendar page
newcounter{rownumber}
defcalendarpage#1{
    begin{minipage}[b]{0.475linewidth}
        setcounter{rownumber}{0}
        deffillfirsttable{}%
        loopifnumtherownumber<12
        addtocounter{rownumber}{1}
        expandafterdefexpandafterfillfirsttableexpandafter{%
            fillfirsttable
            & & & & 
            hline
            & & & & 
            grayline
        }%
        repeat
        noindent
        begin{tabularx}{linewidth}{wc{0.5cm}|X|X|X|X|}
            cline{1-5}
            multicolumn{5} {r|} {Date: AdvanceDate[#1]today}
            hline
            fillfirsttable
        end{tabularx}
    end{minipage}
    hfill
    begin{minipage}[b]{0.475linewidth}
        Reflections:
        parnoindentrule{textwidth}{0.4pt}
        parnoindentrule{textwidth}{0.4pt}
        parnoindentrule{textwidth}{0.4pt}
        parnoindentrule{textwidth}{0.4pt}
        parnoindentrule{textwidth}{0.4pt}
        parnoindentrule{textwidth}{0.4pt}
        Shutdown complete: Hsquare 
        
        setcounter{rownumber}{0}
        deffillsecondtable{}%
        loopifnumtherownumber<10
        addtocounter{rownumber}{1}
        expandafterdefexpandafterfillsecondtableexpandafter{%
            fillsecondtable
            Hsquare &  hline
        }%
        repeat
        noindent
        begin{tabularx}{linewidth}{X|X}
            TASKS: & IDEAS:   hline
            fillsecondtable
        end{tabularx}
    end{minipage}
}

begin{document}
    
    pagecolor{black}
    color{white}
    setlength{extrarowheight}{10pt}

    foreach i in {1,...,31}{
        calendarpage{i}
    }
end{document}

Correct answer by DrecksHippy on July 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP