summaryrefslogtreecommitdiff
path: root/macros/context/contrib/context-calendar-examples/t-calendar-examples/tex/context/third/calendar-examples/Menu-calendar.tex
blob: 3101cbc2d8fcfc8ad8e8823345fac67b22a82ab0 (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
% Context file
% Filename: Menu-calender.tex
% 
% 14-01-2023
% Created by Willi Egger w.egger@boede.nl
% This file 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.

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

% Choose your font
 
\setupbodyfont[ibmplex,ss,10pt]

% Add a path to the picture placed on page 3:

\setupexternalfigures
  [directory=/YourFolder]

% Choose the main language it determines the interface:

\mainlanguage[en]

% This document will be doublesided, the pagenumber will be placed in the footer by means of \setupfootertexts:
\setuppagenumbering[alternative=doublesided,location=]

% The calendar has a pagesize of A6 and with the imposition 4 pages recto and verso are placed on a A4. Two sheets of A4 form one section:

\setuppapersize[A6][A4]

\setuparranging[2*4*2]

% The module Collating marks needs appropriate information:

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

% Adapt the layout of the page to the size of the page:
\setuplayout
  [topspace=.6cm,
  backspace=.6cm,
  header=2\bodyfontsize,
  headerdistance=.5\bodyfontsize,
  footer=1.2\bodyfontsize,
  footerdistance=.5\bodyfontsize,
  margin=0pt,
  height=middle,
  width=middle,
  location=middle]

% Variable sets from the PocketDiary module to be set:

\setvariables
  [PocketDiary]
  [Year=2023]

\setvariables
  [PocketDiaryFooter]
  [Lefttext=\labeltext{menu}-\labeltext{calendar},
   Centertext=\pagenumber,
   Righttext=\getvariable{PocketDiary}{Year}]

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

% The data are presented in table form. The setup of the table:
 
\startsetups table:week
   \setupTABLE[split=yes]
   \setupTABLE[c][1][width=.35\textwidth,frame=off]
   \setupTABLE[c][2][width=.65\textwidth,frame=off]
   \setupTABLE[r][height=2\lineheight,align=lohi]
   \setupTABLE[r][2,3,5,6,8,9,11,12,14,15,17,18,20,21][bottomframe=on]
\stopsetups

% There are currently 6 interfaces supported:

% English interface
\setuplabeltext[en][menu=Menu]
\setuplabeltext[en][comment=Comment]

% German interface
\setuplabeltext[de][menu=Menü]
\setuplabeltext[de][comment=Kommentar]

% French interface
\setuplabeltext[fr][menu=Menu]
\setuplabeltext[fr][comment=Commentaire]

% Dutch interfac
\setuplabeltext[nl][menu=Menu]
\setuplabeltext[nl][comment=Commentaar]

% Italian interface
\setuplabeltext[it][menu=Menu]
\setuplabeltext[it][comment=Commento]

% Spanish interface
\setuplabeltext[es][menu=Menú]
\setuplabeltext[es][comment=Comentario]

% The lua code performing all the magic:

\startluacode

  local report = logs.reporter("Menu calendar")

  function thirddata.calendar.menuweektable(mondaytimestamp,year,w)
    local stamp = mondaytimestamp
    local year = year
    local week = w
    local daynumber,dayname,monthname,holiday

    local day = stamp + 1 * 24 * 60 * 60

    report("Working in function: thirddata.calendar.menuweektable")

    local monthname = string.lower(os.date("%B",day))

    --report("Month: %s Week: %s", monthname,week)

    thirddata.calendar.myheadertext(monthname,week)

    context.bTABLE({setups="table:week"})

    for i = 1,7 do
      local day = stamp + i * 24 * 60 * 60

     --report("Day-inloop: %s", day)

      daynumber   = tonumber(os.date("%d",day)) --day number
      dayname     = string.lower(os.date("%a",day)) -- day name short
      monthnumber = tonumber(os.date("%m",day)) -- month name
      holiday     = thirddata.calendar.checkchristianfeast(daynumber,monthnumber,year) --
           -- Christian holida

      if holiday ~= "" then
        report("Holiday (before table row): %s", holiday)
        report("Day number (before table row): %s", daynumber)
        report("Day name (before table row): %s",dayname)
      end

      context.bTR()
        context.bTD({style="bfa"})

          if dayname == "sun"  or holiday ~= "" and f ~= "ashw" then
            local dnu = daynumber
            local dna = dayname
            context.color({"red"},function() context(dnu) end)
            context("~")
            context.color({"red"},function() context.labeltext(dna) end)
          else
            context(daynumber)
            context("~")
            context.labeltext(dayname)
          end
        context.eTD()
        context.bTD()
          context.labeltext(holiday)
        context.eTD()
      context.eTR()
      context.bTR()
        context.bTD({nx="2"})
          context.labeltext("menu")
        context.eTD()
      context.eTR()
      context.bTR()
        context.bTD({nx="2"})
          context.labeltext("comment")
        context.eTD()
      context.eTR()
    end
    context.eTABLE()
    context.page({"yes"})
  end

  function thirddata.calendar.myheadertext(monthname,week)

    report("Working in function myheadertext")

    context.setupheadertexts{
      function()
        context("\\bgroup\\bfa")
        context.labeltext(monthname)
        context("\\egroup")
        context("\\hfill")
        context.labeltext("week")
        context(": ")
        context(week)
        return true
      end}
  end

  function thirddata.calendar.week(weeknumber,year)
     local w = weeknumber
     local mondaytimestamp = thirddata.calendar.weekcalendar(w,year)

     report("Working in function: thirddata.calendar.week")
     --report("Mondaytimestamp %s", mondaytimestamp)

     thirddata.calendar.menuweektable(mondaytimestamp,year,w)
  end

\stopluacode

% We need a macro to call the lua-code: this macro has two parameters week number and year

\define[2]\MenuWeektable{\ctxlua{thirddata.calendar.week(#1,#2)}}

% \showframe

% The setup of the document at the TeX-side:

\starttext
  \startstandardmakeup[page=yes,doublsided=yes]
    \strut
    \godown[.3\textheight]
    \startalignment [middle]
      {\bfc \labeltext{menu}-\labeltext{calendar}}
      \vfill
      {\tfa \getvariable{PocketDiary}{Year}}
    \stopalignment
    \vfil
  \stopstandardmakeup

  \setupheadertexts[][]

  \strut\vfil

  \startplacefigure
    [number=,
     title=,
     location=middle]
     {\externalfigure[YourPicture.jpg][width=0.75\textwidth]}
  \stopplacefigure

  \vfill

  \page

  \setups{Footertext}

  \dorecurse{52}
     {\setvariables
        [PocketDiary]
        [Week=\recurselevel]
     \MenuWeektable{\recurselevel}{\getvariable{PocketDiary}{Year}}\page}

  \page

  \setupheadertexts[\bf \labeltext{notes}]

  \dorecurse
    {3}
    {\strut\page}
\stoptext