summaryrefslogtreecommitdiff
path: root/macros/context/contrib/context-calendar-examples/tex/context/third/calendar-examples/A6-1week_per_2pages.mkiv
blob: eaee939c4c9e3ca0fbed259788748aac49c1e1e7 (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
%D \module
%D   [     file=t-calendar-examples.tex,
%D      version=2023.04.15,
%D        title=Calendar examples based on PocketDiary,
%D     subtitle=A5/A6 format, 1 week per 2 facing pages,
%D       author=W. Egger,
%D         date=\currentdate,
%D    copyright=W. Egger,
%D      license=Public Domain]

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

%D This is an example how to prepare a calendar, where two facing pages carry
%D one week as a table. Saturday and Sunday are placed together in one row.
%D The header contains the month name to the left and the week number and the
%D year to the right.
%D The footer contains three fields. The first contains the job-name, the center
%D field shows the page number, the right field is not filled. -- However 
%D this can easily be changed in the variable set "PocketDiaryFooter".
%D Each row of the week-table shows top left the day number followed by the short
%D name of the day. Next to this the ordinal day number of the year is typeset.
%D If the day in question is a Christian holiday, then its name is placed next
%D to the general information.
%D This example supports 6 languages i.e. English, German, Dutch, French,
%D Italian and Spanish. The respective interface is activated by enabling the
%D respective mode
%D The original idea was to have an A6 calendar, where 4 pages are print on the
%D A4 paper. This is activated by enabling the mode "A6". By activating the mode
%D "A5" the calendar is prepared A5 sized on a A4 landscape paper.
%D Because there are astronomical data concerning the sun rise, sun set times it
%D is necessary to fill in the correct geo-positional data in the variable set
%D "PocketDiaryGeoPosition".

%D Load the PocketDiary module

\usemodule[pocketdiary]

%D Load the Collating marks module

\usemodule[collatingmarks][Collatingmarks=yes]
 
%D Define the modes for the different formats

\definemode[A5,A6][keep]

%D Enable the desired format of the calendar

\enablemode[A5]

%D Set the interface language which includes EN,DE,NL,FR,IT,ES

\mainlanguage[en]

%D Setup the variable sets for the PocketDiary module

\setvariables
  [PocketDiary]
  [Year=2020,
   Week=1,
   Day=1,
   Month=1,
   Nextyear=yes]

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

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

\setvariables %Koziegłowy 52.467860 16.981240
  [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]

%D Setup the desired font to be used

\setupbodyfont[ibmplex,ss,10pt]

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

\addfeature[f:Tabular]

%D Make the document doublesided, switch off the page numbering. The latter
%D is done in the PocketDiary footer setup

\setuppagenumbering[alternative=doublesided,location=]

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

%D Elaborate the definitions for the A6 format

\startmode[A6]
  \definepapersize[Agenda][width=100mm,height=140mm]

  \setuppapersize[Agenda][A4,portrait]
	% \setuppapersize[Agenda][Agenda]
  
	% The vertical page-shift enables to make a 2.5mm cut at the head of the
	% section
  \definepageshift
    [ver]
    [vertical]
    [2.5mm,2.5mm,2.5mm,2.5mm,2.5mm,2.5mm,2.5mm,2.5mm,
     2.5mm,2.5mm,2.5mm,2.5mm,2.5mm,2.5mm,2.5mm,2.5mm]

  \setuppageshift[paper][ver]

  \setuparranging[2*4*2]

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

%D Elaborate the definition for the A5 format

\startmode[A5]
  \definepapersize[Agenda][width=148mm,height=210mm]
  
  \setuppapersize[Agenda][A4,landscape]
  
	\setuparranging[2SIDE]  
  %\setuparranging[2*2*4]

  \setupMPvariables % for collatingmarks
    [pages=4,  % pages per sheet of paper doublesided
     sheets=4,  % sheets of paper used per section
     horpageshift=0mm]
\stopmode
 
%D Let Lua the main work:
   
\startluacode

  local report = logs.reporter("Calendar-1-week-per-2-pages")
  
  function thirddata.diary.year_of_weektables(year,
              lat,lon,timeoffset,continent)
    
    local year       = year
    local lat        = lat
    local lon        = lon
    local timeoffset = timeoffset
    local continent  = continent
    
    report("Working in function: diary.year_of_weektables")
      
    for calendarmonth = 1,12 do 
    --for calendarmonth = 1,12 do 
      thirddata.diary.monthblock
        (calendarmonth,year,lat,lon,timeoffset,continent)
    end
  end
  
  function thirddata.diary.monthblock(month,year,
              lat,lon,timeoffset,continent)

    report("Working in function diary.monthblock: %s", month)

    local c = thirddata.calendar.month(month,year) --returns number of weeks in a given month
    local wkf = thirddata.calendar.weeknumber(1,month,year) --weeknumber of 1st day of a given month

    report("First week in month %s of year %s is %s",month,year,wkf)

    local wkl = wkf + c - 1 -- last week of a given month based on wkf and c, is wrong for January

    report("Weeks in the selected month: %s", c)
    report("First week of month: %s", wkf)

    if month == 1 and wkf > 51 then
        
      --report("Calculating in week number %s", wkf)
      calcyear = year - 1
      thirddata.diary.setup_header_texts(wkf,month,calcyear)
      
      thirddata.diary.thisweek(wkf,month,year,lat,lon,timeoffset,continent)

      report("Week %s - Year %s",wkf,year)

      --year = year + 1
      wkf = 1
      wkl = wkf + c - 2

      for i = wkf, wkl do
        thirddata.diary.setup_header_texts(i,month,year)
        thirddata.diary.thisweek(i,month,year,lat,lon,timeoffset,continent)
      end
    else
      for i = wkf, wkl do

        report("Calculating in week number %s", i)

        thirddata.diary.setup_header_texts(i,month,year)
        thirddata.diary.thisweek(i,month,year,
                          lat,lon,timeoffset,continent) 
       end
    end
  end


  function thirddata.diary.setup_header_texts(week,month,year)

    local monthname = string.lower(os.date
                      ("%B",os.time{year=year,month=month,day=1}))
                                      
    context.setupheadertexts(
      {function()
         context("\\bf")
         context.labeltext(monthname)
         return true
       end
      },
      {function()
         context.labeltext("week")
         context(": ~")
         context(week)
         context("\\quad")
         context(year)
         return true
       end
      },
      {function()
         context("\\bf")
         context.labeltext(monthname)
         return true
       end
      },
      {function()
          context.labeltext("week")
          context(": ~")
          context(week)
          context("\\quad")
          context(year)
          return true
        end
      })
  end

\stopluacode   

%D Setup the table for the week calendar

\startsetups[table:week]
  \setupTABLE[split=yes]
  \setupTABLE[each][each][frame=on]
  \setupTABLE
    [r]
    [each]
    [offset=0pt,
     loffset=3pt,
     roffset=3pt,
     height=0.23\textheight] 
  \setupTABLE[c][1][width=0.5\textwidth] 
  \setupTABLE[c][2][width=0.5\textwidth]
\stopsetups

%D Define the macro for invoking the calculations

\define[5]\Yearofweektables{\ctxlua{thirddata.diary.year_of_weektables(#1,#2,#3,#4,#5)}}

%D Create a buffer containing all variables for the calculations

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

%D  Setup the \TEX\ side of the document

\starttext

%D Establish the content for the title pages

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

  \startstandardmakeup[page=yes,doublesided=no]
    \starttabulate[|l|p|]
       \NC \translate[en=Title,
                     nl=Titel,
                     de=Titel,
                     fr=Titre,
                     it=Titolo]
      \EQ {\bf \labeltext{calendar}} \NC\NR
      \NC \translate[en=Author,
                     nl=Auteur,
                     de=Autor,
                     fr=Auteur,
                     it=autore,
                     es=Autor]
      \EQ \getvariable{PocketDiaryAddress}{Forename}
          \getvariable{PocketDiaryAddress}{Familyname} \NC\NR
      \NC \translate[en=Typography,
                     nl=Typografie,
                     de=Typographie,
                     fr=Typographie,
                     it=Tipografia,
                     es=Tipografía]
      \EQ \CONTEXT\ with \LUAMETATEX \NC\NR
      \NC \translate[en=Compilation date,
                     nl=Compilatie datum,
                     de=Kompilationsdatum,
                     fr=Date de compilation,
                     it=Dato di compilazione,
                     es=Fecha de compilación]
      \EQ \currentdate \NC\NR
    \stoptabulate
  \stopstandardmakeup

%D Insert a page with lost-return-to information (PocketDiary 
%D template)

  \getbuffer[Lost-Returnto]

%D Add a year table with all months

  \getbuffer[Yearcurrentplan]

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

%D Add a year table of the next year with all months

  \getbuffer[Yearnextplan]

  \setupheadertexts[]

%D Insert all weektables by loading the buffer

  \getbuffer[Yearofweektables]

%D Add pages for notes
\dorecurse
  {4}
  {\getbuffer[Lines]}
	
\stoptext