Debian Codegraph @

texmf-dist/tex/generic/pgf/frontendlayer/tikz/libraries/tikzlibrarycalendar.code.tex

raw
1 % Copyright 2018 by Till Tantau
2 %
3 % This file may be distributed and/or modified
4 %
5 % 1. under the LaTeX Project Public License and/or
6 % 2. under the GNU Public License.
7 %
8 % See the file doc/generic/pgf/licenses/LICENSE for more details.
9
10 \ProvidesFileRCS{tikzlibrarycalendar.code.tex}
11
12
13 \pgfutil@usemodule{pgfcalendar}
14
15
16 %
17 % General options (these options affect all calendars typeset unsind \calendar):
18 %
19 % Start, end, and code executed for each current date
20 %
21
22 \tikzoption{dates}{\tikz@lib@cal@parse#1\relax}
23 \def\tikz@lib@cal@parse#1to#2\relax{%
24 \def\tikz@lib@cal@start{#1}
25 \def\tikz@lib@cal@end{#2}%
26 }
27 \tikzoption{execute at begin day scope}{\expandafter\def\expandafter\tikz@atbegin@day\expandafter{\tikz@atbegin@day#1}}
28 \tikzoption{execute at end day scope}{%
29 \def\pgf@temp{#1}%
30 \expandafter\expandafter\expandafter\def%
31 \expandafter\expandafter\expandafter\tikz@atend@day%
32 \expandafter\expandafter\expandafter{\expandafter\pgf@temp\tikz@atend@day}}
33 \tikzoption{execute before day scope}{\expandafter\def\expandafter\tikz@before@day\expandafter{\tikz@before@day#1}}
34 \tikzoption{execute after day scope}{\expandafter\def\expandafter\tikz@after@day\expandafter{\tikz@after@day#1}}
35
36 \let\tikz@atbegin@day=\pgfutil@empty
37 \let\tikz@atend@day=\pgfutil@empty
38 \let\tikz@before@day=\pgfutil@empty
39 \let\tikz@after@day=\pgfutil@empty
40
41
42
43 %
44 % Options affecting some calendars:
45 %
46
47 %
48 % Shifts and skips
49 %
50
51 % Shift between days
52
53 \tikzoption{day xshift}{\def\tikz@lib@cal@xshift{#1}}
54 \tikzoption{day yshift}{\def\tikz@lib@cal@yshift{#1}}
55
56 \def\tikz@lib@cal@yshift{3ex}
57 \def\tikz@lib@cal@xshift{3.5ex}
58
59
60 % Shift between months
61
62 \tikzoption{month xshift}{\def\tikz@lib@cal@month@xshift{#1}}
63 \tikzoption{month yshift}{\def\tikz@lib@cal@month@yshift{#1}}
64
65 \def\tikz@lib@cal@month@yshift{9ex}
66 \def\tikz@lib@cal@month@xshift{9ex}
67
68
69
70
71 % Templates for typesetting days, month, years
72
73 \tikzoption{day code}{\def\tikzdaycode{#1}}
74 \tikzoption{day text}{\def\tikzdaytext{#1}}
75 \tikzoption{days}{\tikzset{every day/.append style={#1}}}
76 \tikzset{every day/.style={anchor=base east}}
77
78 \tikzoption{month code}{\def\tikzmonthcode{#1}}
79 \tikzoption{month text}{\def\tikzmonthtext{#1}}
80 \tikzset{every month/.style={}}
81
82 \tikzoption{year code}{\def\tikzyearcode{#1}}
83 \tikzoption{year text}{\def\tikzyeartext{#1}}
84 \tikzset{every year/.style={}}
85
86 \def\tikzdaycode{\node[name=\pgfcalendarsuggestedname,every day]{\tikzdaytext};}
87 \def\tikzmonthcode{\node[every month]{\tikzmonthtext};}
88 \def\tikzyearcode{\node[every year]{\tikzyeartext};}
89
90 \def\tikzdaytext{\%d-}
91 \def\tikzmonthtext{\%mt}
92 \def\tikzyeartext{\%y0}
93
94
95 % Internal option for storing the "width" of a calendar as a number of
96 % days
97
98 \tikzoption{tikz@lib@cal@width}{\def\tikz@lib@cal@width{#1}}
99
100 \def\tikz@lib@cal@width{1}
101
102 %
103 % Days on a line
104 %
105
106 \tikzset{day list downward/.style={%
107 execute before day scope={
108 \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}
109 {%
110 % On first of month, except when first date in calendar.
111 \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@month@yshift}%
112 \pgftransformyshift{-\pgf@y}
113 }%
114 }{}%
115 },
116 execute after day scope={\pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}\pgftransformyshift{-\pgf@y}},
117 tikz@lib@cal@width=1
118 }}
119 \tikzset{day list upward/.style={%
120 execute before day scope={
121 \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}
122 {%
123 % On first of month, except when first date in calendar.
124 \pgftransformyshift{\tikz@lib@cal@month@yshift}%
125 }%
126 }{}%
127 },
128 execute after day scope={\pgftransformyshift\tikz@lib@cal@yshift},
129 tikz@lib@cal@width=1
130 }}
131 \tikzset{day list right/.style={%
132 execute before day scope={
133 \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}
134 {%
135 % On first of month, except when first date in calendar.
136 \pgftransformxshift{\tikz@lib@cal@month@xshift}%
137 }%
138 }{}%
139 },
140 execute after day scope={\pgftransformxshift\tikz@lib@cal@xshift},
141 tikz@lib@cal@width=30% not quite right, but close enough in most cases...
142 }}
143
144 \tikzset{day list left/.style={%
145 execute before day scope={
146 \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}
147 {%
148 % On first of month, except when first date in calendar.
149 \pgfmathsetlength{\pgf@x}{\tikz@lib@cal@month@xshift}
150 \pgftransformxshift{-\pgf@x}%
151 }%
152 }{}%
153 },
154 execute after day scope={
155 \pgfmathsetlength{\pgf@x}{\tikz@lib@cal@xshift}
156 \pgftransformxshift{-\pgf@x}%
157 },
158 tikz@lib@cal@width=30% not quite right, but close enough in most cases...
159 }}
160
161
162
163 %
164 % Week list
165 %
166
167 \tikzset{week list/.style={%
168 execute before day scope={%
169 \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}
170 {%
171 % On first of month, except when first date in calendar.
172 \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@month@yshift}%
173 \pgftransformyshift{-\pgf@y}
174 }%
175 }{}%
176 },
177 execute at begin day scope={%
178 \pgfmathsetlength\pgf@x{\tikz@lib@cal@xshift}%
179 \pgf@x=\pgfcalendarcurrentweekday\pgf@x%
180 \pgftransformxshift{\pgf@x}%
181 },
182 execute after day scope={%
183 \ifdate{Sunday}{%
184 \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
185 \pgftransformyshift{-\pgf@y}
186 }{}%
187 },
188 tikz@lib@cal@width=7
189 }}
190
191
192
193 %
194 % Month list
195 %
196
197 \tikzset{month list/.style={%
198 execute before day scope={%
199 \ifdate{day of month=1}{\ifdate{equals=\pgfcalendarbeginiso}{}
200 {%
201 % On first of month, except when first date in calendar.
202 \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@month@yshift}%
203 \pgftransformyshift{-\pgf@y}
204 }%
205 }{}%
206 \ifdate{day of month=1}
207 {%
208 \edef\tikz@lib@cal@month@list@start{\pgfcalendarcurrentweekday}%
209 }{}%
210 \ifdate{equals=\pgfcalendarbeginiso}%
211 {%
212 % Computer day of week for start of month
213 {%
214 \c@pgf@counta=\pgfcalendarcurrentjulian%
215 \advance\c@pgf@counta by-\pgfcalendarcurrentday%
216 \advance\c@pgf@counta by1\relax%
217 \pgfcalendarjuliantoweekday{\c@pgf@counta}{\c@pgf@countb}%
218 \xdef\pgf@temp{\the\c@pgf@countb}%
219 }%
220 \let\tikz@lib@cal@month@list@start=\pgf@temp%
221 }{}%
222 },
223 execute at begin day scope={%
224 \pgfmathsetlength\pgf@xa{\tikz@lib@cal@xshift}%
225 \pgf@xb=\pgfcalendarcurrentday\pgf@xa%
226 \advance\pgf@xb by\tikz@lib@cal@month@list@start\pgf@xa%
227 \advance\pgf@xb by-\pgf@xa\relax%
228 \pgftransformxshift{\pgf@xb}%
229 },
230 tikz@lib@cal@width=37
231 }}
232
233
234
235
236 %
237 % Month labels
238 %
239
240 \tikzset{month label left/.style={%
241 execute before day scope={\ifdate{day of month=1}{\tikzmonthcode}{}},
242 every month/.append style={anchor=base east,xshift=-3.5ex}
243 }}
244
245 \tikzset{month label left vertical/.style={%
246 execute before day scope={\ifdate{day of month=1}{\tikzmonthcode}{}},
247 every month/.append style={anchor=base east,xshift=-4.5ex,yshift=2.25ex,rotate=90}
248 }}
249
250 \tikzset{month label right/.style={%
251 execute before day scope={\ifdate{day of month=1}{%
252 {%
253 \pgfmathsetlength{\pgf@xa}{\tikz@lib@cal@xshift}%
254 \pgftransformxshift{\tikz@lib@cal@width\pgf@xa}%
255 \pgftransformxshift{-\pgf@xa}%
256 \tikzmonthcode%
257 }}{}},
258 every month/.append style={anchor=base west,xshift=1ex}
259 }}
260
261 \tikzset{month label right vertical/.style={%
262 execute before day scope={\ifdate{day of month=1}{%
263 {%
264 \pgfmathsetlength{\pgf@xa}{\tikz@lib@cal@xshift}%
265 \pgftransformxshift{\tikz@lib@cal@width\pgf@xa}%
266 \pgftransformxshift{-\pgf@xa}%
267 \tikzmonthcode%
268 }}{}},
269 every month/.append style={anchor=base west,xshift=2ex,yshift=2.25ex,rotate=-90}
270 }}
271
272 \tikzset{month label above centered/.style={%
273 execute before day scope={%
274 \ifdate{day of month=1}{%
275 {
276 \pgfmathsetlength{\pgf@xa}{\tikz@lib@cal@xshift}%
277 \pgf@xb=\tikz@lib@cal@width\pgf@xa%
278 \advance\pgf@xb by-\pgf@xa%
279 \pgf@xb=.5\pgf@xb%
280 \pgftransformxshift{\pgf@xb}%
281 \pgftransformxshift{-1.5ex}%
282 \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
283 \pgftransformyshift{1.25\pgf@y}
284 \tikzmonthcode%
285 }
286 }{}},
287 every month/.append style={anchor=base}
288 }}
289
290 \tikzset{month label above left/.style={%
291 execute before day scope={%
292 \ifdate{day of month=1}{%
293 {
294 \pgftransformxshift{-3.25ex}%
295 \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
296 \pgftransformyshift{1.25\pgf@y}
297 \tikzmonthcode%
298 }
299 }{}},
300 every month/.append style={anchor=base west}
301 }}
302
303
304
305 \tikzset{month label above right/.style={%
306 execute before day scope={%
307 \ifdate{day of month=1}{%
308 {
309 \pgfmathsetlength{\pgf@xa}{\tikz@lib@cal@xshift}%
310 \pgf@xb=\tikz@lib@cal@width\pgf@xa%
311 \advance\pgf@xb by-\pgf@xa%
312 \pgftransformxshift{\pgf@xb}%
313 \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
314 \pgftransformyshift{1.25\pgf@y}
315 \tikzmonthcode%
316 }
317 }{}},
318 every month/.append style={anchor=base east}
319 }}
320
321 \tikzset{month label below centered/.style={%
322 execute before day scope={%
323 \ifdate{day of month=1}{%
324 {
325 \pgfmathsetlength{\pgf@xa}{\tikz@lib@cal@xshift}%
326 \pgf@xb=\tikz@lib@cal@width\pgf@xa%
327 \advance\pgf@xb by-\pgf@xa%
328 \pgf@xb=.5\pgf@xb%
329 \pgftransformxshift{\pgf@xb}%
330 \pgftransformxshift{-1.5ex}%
331 \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
332 \pgftransformyshift{-1.25\pgf@y}
333 \tikzmonthcode%
334 }
335 }{}},
336 every month/.append style={anchor=base}
337 }}
338
339 \tikzset{month label below left/.style={%
340 execute before day scope={%
341 \ifdate{day of month=1}{%
342 {
343 \pgftransformxshift{-3.25ex}%
344 \pgfmathsetlength{\pgf@y}{\tikz@lib@cal@yshift}%
345 \pgftransformyshift{-1.25\pgf@y}
346 \tikzmonthcode%
347 }
348 }{}},
349 every month/.append style={anchor=base west}
350 }}
351
352
353
354 %
355 % Code of the actual \calendar command (tikz.code.tex contains \let\calendar=\tikz@lib@cal@calendar):
356 %
357
358 \def\tikz@lib@cal@calendar{%
359 \begingroup%
360 \let\tikz@lib@cal@ifs=\pgfutil@empty%
361 \tikz@resetexpandcount
362 \tikzset{name=,at={(0,0)}}%
363 \let\%=\pgfcalendarshorthand%
364 \tikzset{every calendar/.try}%
365 \tikz@lib@cal@scanner%
366 }
367
368 \def\tikz@lib@cal@scanner{%
369 \afterassignment\tikz@lib@cal@handle\let\pgf@let@token=%
370 }
371
372 \def\tikz@lib@cal@handle{%
373 \pgfutil@switch\pgfutil@ifx\pgf@let@token{%
374 {;}{\let\pgfutil@next\tikz@lib@cal@stop}%
375 {(}{\let\pgfutil@next\tikz@lib@cal@name}%)
376 {a}{\let\pgfutil@next\tikz@lib@cal@at}%
377 {[}{\let\pgfutil@next\tikz@lib@cal@option}%]
378 {i}{\let\pgfutil@next\tikz@lib@cal@if}%
379 }{\tikz@resetexpandcount\pgfutil@next}{\tikz@lib@cal@expand}%
380 }
381 \def\tikz@lib@cal@expand{%
382 \advance\tikz@expandcount by -1
383 \ifnum\tikz@expandcount<0\relax%
384 \tikzerror{Giving up on this calendar}%
385 \let\pgfutil@next=\tikz@lib@cal@end%
386 \else%
387 \let\pgfutil@next=\tikz@lib@cal@@expand
388 \fi%
389 \pgfutil@next}
390
391 \def\tikz@lib@cal@@expand{\expandafter\tikz@lib@cal@scanner\pgf@let@token}
392
393
394 \def\tikz@lib@cal@name#1){%
395 \tikzset{name=#1}%
396 \tikz@lib@cal@scanner%
397 }
398 \def\tikz@lib@cal@at t#1(#2){%
399 \tikzset{at={(#2)}}%
400 \tikz@lib@cal@scanner%
401 }
402 \def\tikz@lib@cal@option#1]{%
403 \tikzset{#1}%
404 \tikz@lib@cal@scanner%
405 }
406 \def\tikz@lib@cal@if f#1(#2){%
407 \pgfutil@ifnextchar[{\tikz@lib@cal@if@opt{#2}}{\tikz@lib@cal@if@code{#2}}}%}
408
409 \def\tikz@lib@cal@if@opt#1[#2]{\tikz@lib@cal@if@code{#1}{\tikzset{#2}}}
410 \def\tikz@lib@cal@if@code#1#2{%
411 \pgfutil@ifnextchar e{\tikz@lib@cal@if@else{#1}{#2}}{\tikz@lib@cal@if@else{#1}{#2}else{}}}
412
413 \def\tikz@lib@cal@if@else#1#2else{%
414 \pgfutil@ifnextchar[{\tikz@lib@cal@if@else@opt{#1}{#2}}{\tikz@lib@cal@if@else@code{#1}{#2}}}%}
415 \def\tikz@lib@cal@if@else@opt#1#2[#3]{\tikz@lib@cal@if@else@code{#1}{#2}{\tikzset{#3}}}
416 \def\tikz@lib@cal@if@else@code#1#2#3{%
417 \expandafter\def\expandafter\tikz@lib@cal@ifs\expandafter{\tikz@lib@cal@ifs\ifdate{#1}{#2}{#3}}%
418 \tikz@lib@cal@scanner%
419 }
420 \def\tikz@lib@cal@stop{%
421 \pgftransformshift{\tikz@node@at}%
422 \expandafter\pgfcalendar\expandafter{\tikz@fig@name}{\tikz@lib@cal@start}{\tikz@lib@cal@end}%
423 {%
424 \tikz@before@day%
425 \scope%
426 \tikz@atbegin@day%
427 \tikz@lib@cal@ifs%
428 \tikzdaycode%
429 \tikz@atend@day%
430 \endscope%
431 \tikz@after@day%
432 }%
433 \endgroup%
434 }
435
436 \tikzoption{if}{%
437 \let\tikz@lib@cal@scanner@orig=\tikz@lib@cal@scanner%
438 \let\tikz@lib@cal@scanner=\relax%
439 \tikz@lib@cal@if f#1\relax%
440 \let\tikz@lib@cal@scanner=\tikz@lib@cal@scanner@orig}
441
442
443
444 \endinput