summaryrefslogtreecommitdiff
path: root/macros/context/contrib/context-calendar-examples/t-calendar-examples/tex/context/third/calendar-examples/A5-day_per_page.tex
blob: 6dd5c69843d0f220e97c35e3e329e9e3a55fedb4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
% Context file
% Filename: A5-day_per_page.tex
% 
% 14-01-2023
% Created by Willi Egger, w.egger@boede.nl
% This document is in the Public Domain.

% This is an example of how to use the PocketDiary-module outside the built-in
% structure of a PocketDiary.
% In order to use this example you need to have the PocketDiary-module
% installed from:
% https://modules.contextgarden.net/cgi-bin/module.cgi/action=view/id=132
% If you want collating marks placed on the outermost sheet of a section, 
% then you need to install also the Collatingmarks-module from:
% https://modules.contextgarden.net/cgi-bin/module.cgi/action=view/id=129
% The used imposition scheme is contained in the \CONTEXT\ distro.

% This is an example how to prepare a calendar, where each page contains one
% day. On the left side there is a time-schedule starting at 06:00 ending
% at 22:00. The header contains left the month and right the year. Below the
% header there is a table showing left the day and the short dayname followed by
% the week number and the day number of the year. If the day in question is a
% Christian holiday, then the name of it is stated in the center. 
% To the right astronomical data
% are shown: Lunar days/moon phase, sun rise, sun set and light hours.
% In order to have complete section at the end of the calendar a number of
% pages with lines are added.

\usemodule[pocketdiary]
\usemodule[collatingmarks][Collatingmarks=yes]

% define the different modes to enable the international interface:

\definemode[English,Dutch,German,French,Italian,Spanish][keep]

\enablemode[English]
% \enablemode[German]
% \enablemode[Dutch]
% \enablemode[Italian]
% \enablemode[French]
% \enablemode[Spanish]

% The variable sets for the PocketDiary module:

\setvariables
  [PocketDiary]
  [Year=2023,
   Week=1,
   Day=1,
   Month=1,
   Nextyear=yes,
   Yearnext=2024]

\setvariables
  [PocketDiaryFooter]
  [Lefttext={\jobname .pdf},
   Centertext=\pagenumber,
   Righttext=]

\setvariables
  [PocketDiaryColors]
  [Separatorline=blue,
   Gridline={s=.75}]

\setvariables
  [PocketDiaryGeoPosition]
  [lat=52.467860, 
   lon=16.981240,
   timezoneoffset=1,
   continent=EU] % EU, US or empty for no Daylight Saving Time (DST)

\setvariables
  [PocketDiaryAddress]
  [Familyname=YourFamilyName,
   Forename=YourName,
   Street=YourStreet and Number,
   Zipcode=YourPostalCode,
   City=YourPlace,
   Country=YourCountry,
   Phone=YourPhoneNumber,
   Mobile=YourMobilePhoneNumber,
   E-mail=YourEmail@YourProvider,
   Web=YourWWW]

\setupbodyfont[ibmplex,ss,10pt]

\definefontfeature[f:Tabular][tnum=yes]

\addfeature[f:Tabular]

\startmode[English]
  \mainlanguage[en]
\stopmode

\startmode[German]
  \mainlanguage[de]
\stopmode

\startmode[French]
  \mainlanguage[fr]
\stopmode

\startmode[Italian]
  \mainlanguage[it]
\stopmode

\startmode[Spanish]
  \mainlanguage[es]
\stopmode

% The document is double sided printed, the page number will be set in the \setupfootertexts:

\setuppagenumbering[alternative=doublesided,location=]

\setuppapersize[A5][A4,landscape]
% \setuppapersize[A5][A5]

% Adapt the page layout to the size of the page:

\setuplayout
  [topspace=.6cm,
   backspace=1.5cm,
   header=2\bodyfontsize,
   headerdistance=.5\bodyfontsize,
   footer=1.2\bodyfontsize,
   footerdistance=.5\bodyfontsize,
   margin=0pt,
   height=middle,
   width=middle,
   location=middle]

% Enable the imposition: 2 pages recto and verso using 4 sheets of A4 for forming one section

\setuparranging[2*2*4]

% Setup of the Collating marks module:

\setupMPvariables % for collatingmarks
  [pages=8,  % pages per sheet of paper doublesided
   sheets=2,  % sheets of paper used per section
   horpageshift=-0.5mm]

% \showframe

% Let Lua do the work:

\startluacode

  local report = logs.reporter("Calendar-1-day-per-page")

  function thirddata.diary.year_of_monthtables(
	  year,lat,lon,timeoffset,continent)

    report("Working in function: diary.year_of_monthtables")

    for i = 1,12 do
      local monthname = string.lower(os.date
                        ("%B",os.time{year=year,month=i,day=1}))

      thirddata.diary.header_text(monthname,year)
        
      thirddata.diary.monthblock(i,year,lat,lon,timeoffset,continent)
    end
  end

  function thirddata.diary.monthblock(month,year,lat,lon,timeoffset,continent)

    report("Working in function diary.monthblock")

    local nofdays = 1

    local monthname = thirddata.calendar.select_nameofmonth(month,year)
    local yeardays   = thirddata.calendar.isleapyear(year)

    if month == 2 and yeardays == 366 then
      nofdays = thirddata.calendar.nofdays_month(month,year) + 1
    else
      nofdays = thirddata.calendar.nofdays_month(month,year)
    end

    --report("Number of days in month: %s", nofdays)

    for i = 1,nofdays do
      local ordinalday = thirddata.calendar.ordinalday(i,month,year)
      local weeknumber = thirddata.calendar.weeknumber(i,month,year)
      local dayname    = string.lower(os.date			                                      ("%a",os.time{day=i,month=month,year=year}))
      local holiday    = thirddata.calendar.checkchristianfeast(i,month,year) 
      local moondata   = thirddata.moonphase.lunardays(year,month,i)
      local dst_start,dst_stop = thirddata.diary.DST(year,continent)
      local sunrise,sunset,lighthours =
              thirddata.srss.sundata(
                i,month,year,lat,lon,timeoffset,dst_start,dst_stop)

      if holiday ~= "" then
        report("Holiday: %s", holiday)
      	report("Day number: %s", i)
      end
                
      context.bTABLE({setups="table:dayblock"})
        context.bTR()
           context.bTD()
              context.starttabulate{"|lw(0.1\\textwidth)|p(0.06\\textwidth)|p|"}
              context.NC()
                context("\\bf")
                --report("Daynumber: %s Month %s", i,month)
                if  dayname == "sun" or holiday ~= "" and holiday ~= "ashw" then
                  local dnu = i
                  local dna = dayname
                  context.color({"red"},
                    function() context(dnu) end)          --day number
                  context("~")
                  context.color({"red"},
                    function() context.labeltext(dna) end)--dayname
                else  
                  context(i)                 --day
                  context("~")
                  context.labeltext(dayname) --dayname
                end
              context.NC()
                context.switchtobodyfont{"6pt"}
                context.labeltext("week")
                context(":")
                context.par()
                context(weeknumber)
              context.NC()
                context.switchtobodyfont{"6pt"}
                context.labeltext("day")
                context(":")
                context.par()
                context(ordinalday)
                context("/")
                context(yeardays)
              context.NC()
              context.NR()
            context.stoptabulate()
          context.eTD()
          context.bTD()
            context.starttabulate{"|lw(0.2\\textwidth)|p|p|p|p|"}
              context.NC()
                if holiday == "" then
                  context.strut()
                else
                  context.labeltext(holiday)
                end  
              context.NC()
                if tonumber(moondata) then
                  context.labeltext("moondays")
                else
                  context.labeltext("moon")
                end
                context(":~")
                context.par()
                context(moondata)
              context.NC()
                context("\\SunA[background=Sunrise]{}")
                context.par()
                context(sunrise)
              context.NC()
                context("\\SunA[background=Sunset]{}") 
                context.par()
                context(sunset)
              context.NC()
                context("\\SunB[background=Light]{}")
                context.par()
                context(lighthours)
              context.NC()            
              context.NR()
            context.stoptabulate()
          context.eTD()
        context.eTR()
      context.eTABLE()
      context.page()
    end
  end

  function thirddata.diary.header_text(monthname,year)
    context.setupheadertexts(
      {function()
         context("\\bf")
         context.labeltext(monthname)
         return true
       end
      },
      {function()
         context(year)
         return true
       end
      },
      {function()
         context("\\bf")
         context.labeltext(monthname)
         return true
       end
      },
      {function()
         context(year)
         return true
       end
      })
  end

\stopluacode   

\startsetups[table:dayblock]
  \setupTABLE[each][each][frame=off]
  \setupTABLE[r][each][offset=0pt,loffset=3pt,roffset=3pt,align=lohi] 
  \setupTABLE[c][1][width=0.35\textwidth,align=lohi] 
  \setupTABLE[c][2][style={\switchtobodyfont[6pt]},width=0.65\textwidth] \stopsetups

\define[5]\Yearofmonthtables{%
  \ctxlua{thirddata.diary.year_of_monthtables(#1,#2,#3,#4,#5)}}


\startbuffer[Yearofmonthtables]
  \Yearofmonthtables %Year,lat,lon,timeoffset,continent
     {\getvariable{PocketDiary}{Year}}
     {\getvariable{PocketDiaryGeoPosition}{lat}}
     {\getvariable{PocketDiaryGeoPosition}{lon}}
     {\getvariable{PocketDiaryGeoPosition}{timeoffset}}
     {"\getvariable{PocketDiaryGeoPosition}{continent}"}
\stopbuffer

% Create a time-table as a background to the page

\startreusableMPgraphic{Time-Lines}
  numeric w; w:= OverlaytWidth;
  numeric h; h:= (OverlayHeight-2cm)/18;
  numeric t;
  path p,q;
  p := unitsquare xscaled OverlayWidth yscaled (OverlayHeight-2cm);

  q:= llcorner p -- lrcorner p;
  draw q withpen pencircle scaled .5pt
      withcolor \MPcolor{Grid};
  for i = 1 upto 17:
    draw q  shifted (0,i*h) withpen pencircle scaled .5pt
      withcolor \MPcolor{Grid};
      t :=   24 - 1 - i ;
      label.top(textext(""& decimal t & ":00"),point 0 of q)
        shifted (15pt,((i-1)*h)+1pt);
  endfor; 
\stopreusableMPgraphic

\defineoverlay[Textbackground][\reuseMPgraphic{Time-Lines}]

% Implement international interface:
\setuplabeltext[en][title=Title]
\setuplabeltext[nl][title=Titel]
\setuplabeltext[de][title=Titel]
\setuplabeltext[fr][title=Titre]
\setuplabeltext[it][title=Titolo]
\setuplabeltext[es][title=Título]

\setuplabeltext[en][author=Author]
\setuplabeltext[nl][author=Auteur]
\setuplabeltext[de][author=Autor]
\setuplabeltext[fr][author=Auteur]
\setuplabeltext[it][author=autore]
\setuplabeltext[es][author=Autor]

\setuplabeltext[en][typography=Typography]
\setuplabeltext[nl][typography=Typografie]
\setuplabeltext[de][typography=Typographie]
\setuplabeltext[fr][typography=Typographie]
\setuplabeltext[it][typography=Tipografia]
\setuplabeltext[es][typography=Tipografía]

\setuplabeltext[en][compilation=Compilation date]
\setuplabeltext[nl][compilation=Compilatie datum]
\setuplabeltext[de][compilation=Kompilationsdatum]
\setuplabeltext[fr][compilation=Date de compilation]
\setuplabeltext[it][compilation=Dato di compilazione]
\setuplabeltext[es][compilation=Fecha de compilación]

% Setup the TeX side of the document:

\starttext

  \startstandardmakeup[page=yes,doublesided=no]
    \strut
    \startalignment [middle]
      \godown[.3\textheight]
      {\bfa \labeltext{calendar}}
      \vfil
      {\bf \getvariable{PocketDiary}{Year}}
    \stopalignment
  \stopstandardmakeup

  \startstandardmakeup[page=yes,doublesided=no]
    \starttabulate[|l|p|]
      \NC \labeltext{title}
      \EQ {\bf \labeltext{calendar}} \NC\NR
      \NC \labeltext{author}
      \EQ \getvariable{PocketDiaryAddress}{Forename}
          \getvariable{PocketDiaryAddress}{Familyname} \NC\NR
      \NC \labeltext{typography} 
      \EQ \CONTEXT\ with \LUAMETATEX \NC\NR
      \NC \labeltext{compilation}
      \EQ \currentdate \NC\NR
    \stoptabulate
  \stopstandardmakeup

  \getbuffer[Lost-Returnto]

  \setupbackgrounds[text][background=]

  \setupbackgrounds[text][background=Textbackground]

  \getbuffer[Yearofmonthtables]

  \setupbackgrounds[text][background=]

  \getbuffer[Yearcurrentplan]

  \setupheadertexts[\bfa \getvariable{PocketDiary}{Yearnext}]

  \getbuffer[Yearnextplan]

  \dorecurse
    {3}
    {\getbuffer[Todo]}
    
  \dorecurse
    {10}
    {\getbuffer[Lines]}

\stoptext