Überarbeitungsverlauf[Zurück]
Klicke auf Einblenden/Ausblenden von Überarbeitungen 3
Markdown + Themen

19 Feb '19, 08:04

saputello's gravatar image

saputello
11.1k174365

pgfmath: Mehrere 'pgfmathdeclarefunction's, mit gleichen Hilfsgrößen, zusammenfassen

Ich habe 3 Funktionen (alles funktioniert soweit) [![alt text][1]][1] Die Funktionen verwenden mehrfach die selben Hilfsgrößen `DayNo (Tagesnummer) verwendet: a, b, c, s, e, f DayName verwendet: a, b, c, s, e, f, g, d CW (Kalenderwoche) verwendet: a, b, c, s, e, f, g, d, n (alle Größen)` **Frage: Das kann man doch sicher irgendwie zusammenfassen?** def `\def` / newcommand `\newcommand` / pgfmathsetmacro `\pgfmathsetmacro` hat natürlich nicht funktioniert. \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} [1]: https://texwelt.de/wissen/upfiles/55555555_265.png
Klicke auf Einblenden/Ausblenden von Überarbeitungen 2

02 Nov '18, 01:47

cis's gravatar image

cis
9.5k96460491

pgfmath: Mehrere 'pgfmathdeclarefunction's, mit gleichen Hilfsgrößen, zusammenfassen

Ich habe 3 Funktionen (alles funktioniert soweit) [![alt text][1]][1] Die Funktionen verwenden mehrfach die selben Hilfsgrößen `DayNo (Tagesnummer) verwendet: a, b, c, s, e, f DayName verwendet: a, b, c, s, e, f, g, d CW (Kalenderwoche) verwendet: a, b, c, s, e, f, g, d, n (alle Größen)` **Frage: Das kann man doch sicher irgendwie zusammenfassen?** def / newcommand / pgfmathsetmacro hat natürlich nbicht nicht funktioniert. \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} [1]: https://texwelt.de/wissen/upfiles/55555555_265.png
Klicke auf Einblenden/Ausblenden von Überarbeitungen 1

02 Nov '18, 01:47

cis's gravatar image

cis
9.5k96460491

Willkommen, erstes Mal hier? Schau mal unter FAQ!

×