|
Ich habe 3 Funktionen (alles funktioniert soweit) Die Funktionen verwenden mehrfach die selben Hilfsgrößen
Frage: Das kann man doch sicher irgendwie zusammenfassen?
Öffne in Overleaf
\documentclass[margin=5mm, varwidth]{standalone} \usepackage{tikz} \begin{document} \pgfmathtruncatemacro{\year}{2018} \pgfmathtruncatemacro{\month}{10} \pgfmathtruncatemacro{\day}{31} \newcommand\Date{\year-\month-\day} \def\Weekdayname{{"Montag","Dienstag","Mittwoch", "Donnerstag","Freitag","Samstag","Sonntag"}} % Kalenderwoche % https://www.tondering.dk/claus/cal/week.php \pgfmathdeclarefunction{CW}{3}{% CW(year, month, day) \pgfmathtruncatemacro{\a}{#2<3 ? #1-1 : #1}% \pgfmathtruncatemacro{\b}{floor(\a/4)-floor(\a/100)+floor(\a/400)}% \pgfmathtruncatemacro{\c}{floor((\a-1)/4)-floor((\a-1)/100)+floor((\a-1)/400)}% \pgfmathtruncatemacro{\s}{\b-\c}% \pgfmathtruncatemacro{\e}{#2<3 ? 0 : \s+1}% %\f + 1 ist die Tagesnummer des Jahres \pgfmathtruncatemacro{\f}{#2<3 ? #3-1+31*(\month-1) : #3+floor((153*(#2-3)+2)/5)+58+\s}% %\pgfmathtruncatemacro{\f}{DayNo(\year,\month,\day)-1} % möglich \pgfmathtruncatemacro{\g}{mod(\a+\b,7)}% % \d ist die Tagesnamen-Nummer (0=Monday, 1=Tuesday, etc.) \pgfmathtruncatemacro{\d}{mod(\f+\g-\e,7)}% \pgfmathtruncatemacro{\n}{\f+3-\d}% \pgfmathtruncatemacro{\CW}{\n<0 ? 53-floor((\g-\s)/5) : ( \n>(364+\s) ? 1 : floor(\n/7)+1)}% \pgfmathparse{int(\CW)}% } \Date $~\Rightarrow~$ \pgfmathparse{CW(\year,\month,\day)}Kalenderwoche \pgfmathresult % Tagesnummer pgfmath % https://www.tondering.dk/claus/cal/week.php % https://texwelt.de/wissen/fragen/23485/ \pgfmathdeclarefunction{DayNo}{3}{% DayNo(year,month,day) \pgfmathtruncatemacro{\a}{#2<3 ? #1-1 : #1}% \pgfmathtruncatemacro{\b}{floor(\a/4)-floor(\a/100)+floor(\a/400)}% \pgfmathtruncatemacro{\c}{floor((\a-1)/4)-floor((\a-1)/100)+floor((\a-1)/400)}% \pgfmathtruncatemacro{\s}{\b-\c}% \pgfmathtruncatemacro{\e}{#2<3 ? 0 : \s+1}% \pgfmathtruncatemacro{\f}{#2<3 ? \day-1+31*(\month-1) : #3+floor((153*(#2-3)+2)/5)+58+\s}% \pgfmathparse{int(\f+1)} } Tagesnummer zu \Date~ ist \pgfmathparse{DayNo(\year,\month,\day)}\pgfmathresult % Tagesname \pgfmathdeclarefunction{DayName}{3}{% CW(year, month, day) \pgfmathtruncatemacro{\a}{#2<3 ? #1-1 : #1}% \pgfmathtruncatemacro{\b}{floor(\a/4)-floor(\a/100)+floor(\a/400)}% \pgfmathtruncatemacro{\c}{floor((\a-1)/4)-floor((\a-1)/100)+floor((\a-1)/400)}% \pgfmathtruncatemacro{\s}{\b-\c}% \pgfmathtruncatemacro{\e}{#2<3 ? 0 : \s+1}% %\f + 1 ist die Tagesnummer des Jahres \pgfmathtruncatemacro{\f}{#2<3 ? #3-1+31*(\month-1) : #3+floor((153*(#2-3)+2)/5)+58+\s}% %\pgfmathtruncatemacro{\f}{DayNo(\year,\month,\day)-1} % möglich \pgfmathtruncatemacro{\g}{mod(\a+\b,7)}% % \d ist die Tagesnamen-Nummer (0=Monday, 1=Tuesday, etc.) \pgfmathtruncatemacro{\d}{mod(\f+\g-\e,7)}% %\pgfmathparse{int(\d)}% Day number \pgfmathparse{\Weekdayname[\d]}% Day name } % \pgfmathparse{\Wochentagname[5]}\pgfmathresult Das Datum \Date~ ist ein \pgfmathparse{DayName(\year, \month, \day)}\pgfmathresult \end{document} |
|
Man kann dafür entgegen der Behauptung aus der Frage sehr gut
Im folgenden verwende ich den Präfix Öffne in Overleaf
\documentclass[margin=5mm, varwidth]{standalone} \usepackage{tikz} \newcommand*{\Year}{2018} \newcommand*{\Month}{10} \newcommand*{\Day}{31} \newcommand*\Weekdayname{{"Montag","Dienstag","Mittwoch", "Donnerstag","Freitag","Samstag","Sonntag"}} \newcommand*{\DCa}{}% Sicherstellen, dass dieses Makro noch frei ist. \newcommand*{\DCb}{}% Sicherstellen, dass dieses Makro noch frei ist. \newcommand*{\DCc}{}% Sicherstellen, dass dieses Makro noch frei ist. \newcommand*{\DCd}{}% Sicherstellen, dass dieses Makro noch frei ist. \newcommand*{\DCe}{}% Sicherstellen, dass dieses Makro noch frei ist. \newcommand*{\DCf}{}% Sicherstellen, dass dieses Makro noch frei ist. \newcommand*{\DCg}{}% Sicherstellen, dass dieses Makro noch frei ist. \newcommand*{\DCs}{}% Sicherstellen, dass dieses Makro noch frei ist. \newcommand*{\DCn}{}% Sicherstellen, dass dieses Makro noch frei ist. \newcommand*{\DCcommon}[3]{% \pgfmathtruncatemacro{\DCa}{#2<3 ? #1-1 : #1}% \pgfmathtruncatemacro{\DCb}{% floor(\DCa/4)-floor(\DCa/100)+floor(\DCa/400) }% \pgfmathtruncatemacro{\DCc}{% floor((\DCa-1)/4)-floor((\DCa-1)/100)+floor((\DCa-1)/400) }% \pgfmathtruncatemacro{\DCs}{\DCb-\DCc}% \pgfmathtruncatemacro{\DCe}{#2<3 ? 0 : \DCs+1}% \pgfmathtruncatemacro{\DCf}{#2<3 ? #3-1+31*(#2-1) : #3+floor((153*(#2-3)+2)/5)+58+\DCs}% } \newcommand*{\DCcommonii}[3]{% \DCcommon{#1}{#2}{#3}% \pgfmathtruncatemacro{\DCg}{mod(\DCa+\DCb,7)}% % \d ist die Tagesnamen-Nummer (0=Monday, 1=Tuesday, etc.) \pgfmathtruncatemacro{\DCd}{mod(\DCf+\DCg-\DCe,7)}% } % Kalenderwoche % https://www.tondering.dk/claus/cal/week.php \pgfmathdeclarefunction{CW}{3}{% CW(year, month, day) \DCcommonii{#1}{#2}{#3}% \pgfmathtruncatemacro{\DCn}{\DCf+3-\DCd}% \pgfmathtruncatemacro{\DCcw}{% \DCn<0 ? 53-floor((\DCg-\DCs)/5) : (\DCn>(364+\DCs) ? 1 : floor(\DCn/7)+1) }% \pgfmathparse{int(\DCcw)}% } \newcommand*{\CW}[3]{% \pgfmathparse{CW(#1,#2,#3)}\pgfmathresult } % Tagesnummer pgfmath % https://www.tondering.dk/claus/cal/week.php % https://texwelt.de/wissen/fragen/23485/ \pgfmathdeclarefunction{DayNo}{3}{% DayNo(year,month,day) \DCcommon{#1}{#2}{#3}% \pgfmathparse{int(\DCf+1)}% } \newcommand*{\DayNo}[3]{% \pgfmathparse{DayNo(#1,#2,#3)}\pgfmathresult } % Tagesname \pgfmathdeclarefunction{DayName}{3}{% CW(year, month, day) \DCcommonii{#1}{#2}{#3}% \pgfmathparse{\Weekdayname[\DCd]}% Day name } \newcommand*{\DayName}[3]{% \pgfmathparse{DayName(#1,#2,#3)}\pgfmathresult } \begin{document} \Year-\Month-\Day{} liegt in Kalenderwoche \CW\Year\Month\Day, ist der \DayNo\Year\Month\Day. Tag des Jahres und ein \DayName\Year\Month\Day. \end{document} Den Öffne in Overleaf
\newcommand*{\CW}[3]{% \begingroup\pgfmathparse{CW(#1,#2,#3)}\pgfmathresult\endgroup } \newcommand*{\DayNo}[3]{% \begingroup\pgfmathparse{DayNo(#1,#2,#3)}\pgfmathresult\endgroup } \newcommand*{\DayName}[3]{% \begingroup\pgfmathparse{DayName(#1,#2,#3)}\pgfmathresult\endgroup } Würde man das als Paket |


Was spricht gegen ein einfaches
\newcommand? Übrigens habe ich glaube ich anderswo schon erwähnt, dass man Makronamen mit nur einem Buchstaben vermeiden sollte, da diese für die ganzen Akzente reserviert sind (\b,\c,\d) und dass man\day,\monthund\yearnicht überschreiben sollte, weil sonst das Datum im Rest des Dokuments nicht mehr stimmt.