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

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

\definemode[English,Dutch,German,French,Italian][keep]
\definemode[A5,A6][keep]

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

\enablemode[A6]
% \enablemode[A5]

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

\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

\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]

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

  \setuppapersize[Agenda][A4,portrait]

  % 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 collating marks
    [pages=8,  % pages per sheet of paper doublesided
     sheets=2,  % sheets of paper used per section
     horpageshift=-0.5mm]
\stopmode

\startmode[A5]
  \definepapersize[Agenda][width=148mm,height=210mm]
  
  \setuppapersize[Agenda][A4,landscape]
    
  \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

% 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 i = 1,12 do  --i is month
      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: %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

    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)

      thirddata.diary.setup_header_texts(wkf,month,year)
      year = year - 1
      thirddata.diary.thisweek(wkf,year,lat,lon,timeoffset,continent) 
      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,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,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

\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

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


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

\starttext

  \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

  \getbuffer[Lost-Returnto]

  \getbuffer[Yearcurrentplan]

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

  \getbuffer[Yearnextplan]

  \setupheadertexts[]
  
  \getbuffer[Yearofweektables]

  \dorecurse
    {13}
    {\getbuffer[Lines]}
\stoptext