summaryrefslogtreecommitdiff
path: root/macros/context/contrib/context-calendar-examples/tex/context/third/calendar-examples/Photocalendar.tex
blob: f55b954e142646fe5afb7eea9718cdca1300ab76 (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
% Context file
% Filename: Photocalendar.tex
% 
% 14-01-2023
% Created by Willi Egger, w.egger@boede.nl
% This file is in the Public Domain

% Mind you that Thomas Schmitz put on the \CONTEXT -wiki a lua-script, which 
% creates a tex-file which can be compiled with \CONTEXT\ already back in 2007 
% for the preparation of a photo-calendar.
% The nice thing about it is, that it uses a small number of formulae. Nice is,
% that it also uses the Sohael Babwani formulae. See:
% https://wiki.contextgarden.net/Calendar_script

% This example file creates a photo calendar based on the PocketDiary-module.
% 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

% The calendar is typeset on A4 portrait. The calendar is a flip-over type,
% where in the top-part is a photo and thereunder the month-table with
% indication of the month name and year.
% The pictures to be used are placed in a subdirectory. Each picture gets
% a symbolic name (number) to be used in the \dorecurse loop.
% For completing the calendar we need 13 pictures. The picture 13 is used on
% the title page.
% This file supports 6 languages, which are selected through the \mainlanguage[]


\usemodule[pocketdiary]

\setupbodyfont[ibmplex,ss,12pt]

\setuppagenumbering[location=]

\setuppapersize[A4,portrait][A4,portrait]

\setuplayout
  [topspace=20mm,
  backspace=8.6mm,
  header=0pt,
  footer=0pt,
  height=middle,
  width=middle]

% Supported languages: en, de, nl, fr, it, es
\mainlanguage[en]

% Where to find the calendar pictures
\setupexternalfigures
  [directory=./MyPhotoDirectory]

% Give pictures symbolic names for using in a loop
\useexternalfigure
  [1]
  [A.jpg]

\useexternalfigure
  [2]
  [B.jpg]

\useexternalfigure
  [3]
  [C.jpg]

\useexternalfigure
  [4]
  [D.jpg]

\useexternalfigure
  [5]
  [E.jpg]

\useexternalfigure
  [6]
  [F.jpg] %[TV-Kasten-Flurin.jpg]

\useexternalfigure
  [7]
  [G.jpg]

\useexternalfigure
  [8]
  [H.jpg]

\useexternalfigure
  [9]
  [I.jpg]

\useexternalfigure
  [10]
  [J.jpg]

\useexternalfigure
  [11]
  [K.jpg]

\useexternalfigure
  [12]
  [L.jpg]

\useexternalfigure
  [13]  
  [M.jpg]

% Setup the variables for the Pocket diary, only year is used for the title page and the variable passed to Lua. 

\setvariables
  [PocketDiary]
  [Year=2023]

% Let the header and the footer be empty:

\setupheadertexts[][]

\setupfootertexts[][]

% Add the international interfaces: 
\setuplabeltext[en][fotocal={Photo Calendar}]
\setuplabeltext[nl][fotocal=Fotokalender]
\setuplabeltext[de][fotocal=Fotokalender]
\setuplabeltext[fr][fotocal={Calendrier photo}]
\setuplabeltext[it][fotocal={Calendario fotografico}]
\setuplabeltext[es][fotocal={Calendario fotográfico}]

% Lua is performing the magic:

\startluacode
  local report = logs.reporter("Photo calendar")

  function thirddata.calendar.Photo_calendar_page(y)

    report("Working in function: calendar.Foto_calendar_page")

    local year = y
    --local path = file.dirname("./Fotokalender-fotos/")
    for i = 1,12 do

      local monthname = string.lower(os.date("%B",
        os.time{year=year,month=i,day=1}))
            
      context.startplacefigure({number="",title=""})
         context.externalfigure({i}, {width = "0.8\\textwidth"})
      context.stopplacefigure()
      context.strut()
      context("\\vfill")
      context.startalign({"middle"})
        context("\\bfa")
        context.labeltext(monthname)
        context("~")
        context(year)
      context.stopalign()
      context.blank()
      
      thirddata.diary.monthtableH(i,year)

      context.page()
    end
  end
\stopluacode

% The setup of the table with the day numbers:
 
\startsetups table:month
   \setupTABLE[c]
              [each]
              [width=\dimexpr\textwidth/7,
               frame=on,
               style=\tfa]
   \setupTABLE[r][each][height=1.8\lineheight,align={center,lohi}]
   \setupTABLE[c][7][foregroundcolor=red]
\stopsetups

% We need a simple macro with one parameter to call the lua-code:

\define[1]\Photocalendarpages
  {\ctxlua{thirddata.calendar.Photo_calendar_page(#1)}}

% Layout of the TeX part of the calendar:

\starttext

\startstandardmakeup[page=yes,doublesided=yes]
  \startplacefigure
    [location=middle,
     title=,
     number=]
    {\externalfigure[13][width=\paperwidth]}
  \stopplacefigure
  \midaligned{\bfc \labeltext{fotocal}~\getvariable{PocketDiary}{Year}}
\stopstandardmakeup

\Photocalendarpages{\getvariable{PocketDiary}{Year}}

\stoptext