summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/yplan/yplan
blob: 1bd69f867da66eed569d97492eb85d640d5dd495 (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
#!/usr/bin/perl
# ===========
# Filename : yplan[.pl]
# Revision : 0.3, 2000-03-14
# Purpose  : Writes LaTeX2e code for an A4 year-planner,
#          : in the style designed by Dick Nickalls
# Author   : John Palmer,
#          : using matter from Dick Nickalls and Harald Harders
# ===========
# Revision History
# 0.3, 2000-03-14 avoids long lines in the program where possible
# 0.2, 2000-03-08 YEAR arg mandatory; PAGE arg added;
#                 error-messages changed
# 0.1, 2000-02-18 alternative languages added (after Harald Harders)
# 2000-02-11 adding the bulk of the boilerplate
#            (copied from Dick Nickalls)
# 1999-08-28 dividing into two pages and adding more TeX boilerplate
# 1999-08-18 program begun: first attempt to align days of week
# ===========
# Usage: yplan LANGUAGE LETTERCASE PAGE YEAR >FILE.tex
#   where:
#   LANGUAGE is one of: english, german, french, italian, spanish,
#   portuguese, swedish, latin; if omitted, english is assumed;
#   LETTERCASE is one of: uppercase, lowercase; controls the setting
#   of month-names; if omitted, uppercase is assumed;
#   PAGE is one of: p1, p2; selects the first or second six months
#   of the chosen YEAR; if omitted, both pages are printed;
#   YEAR must be written with four digits;
#   FILE.tex is where to put the generated LaTeX code.
# Acceptable variants:
#   Arguments wholly or partly in uppercase are translated to
#   lowercase.
#   Arguments are recognised even if given in the wrong order.
#   You may write any argument with - or / at the start, and, in
#   general, obvious extra characters at start and end of arguments
#   are ignored.
# Fatal errors:
#   The program will stop with an error-message in these cases:
#   if YEAR missing; if YEAR <1999; if LANGUAGE not in the set above.
# Location: in CTAN at macros/latex/contrib/other/yplan/yplan.pl
#============
# Things to do:
#============
sub Leapyear
{ 
  my $year = shift; # one argument
  if (($year%4) != 0) {return 0}
  elsif (($year%400) == 0) {return 1}
  elsif (($year%100) == 0) {return 0}
  else {return 1};
}
#============
# Multilingual facilities Copyright 1999 Harald Harders
# <harald.harders@dlr.de>
# Adapted to Perl, with Swedish, Latin extensions,
# by John Palmer, 2000

@{$MonthsOfYear{english}} =
('','January','February','March','April','May','June',
'July','August','September','October','November','December');
@{$DaysOfWeek{english}} = ('Su','Mo','Tu','We','Th','Fr','Sa');
$LY{english} = 'leap year';

@{$MonthsOfYear{german}} =
( '','Januar','Februar','M\"arz','April','Mai','Juni',
'Juli','August','September','Oktober','November','Dezember');
@{$DaysOfWeek{german}} = ('So','Mo','Di','Mi','Do','Fr','Sa','So');
$LY{german}= 'Schaltjahr';

@{$MonthsOfYear{french}} =
('','Janvier',"F\\'evrier",'Mars','Avril','Mai','Juin',
'Juillet','Ao\^ut','Septembre','Octobre','Novembre',"D\\'ecembre");
@{$DaysOfWeek{french}} = ('Di','Lu','Ma','Me','Je','Ve','Sa');
$LY{french}= "ann\\'ee bissextile";

@{$MonthsOfYear{italian}} =
('','Gennaio','Febbraio','Marzo','Avrile','Maggio','Giugno',
'Luglio','Agosto','Septembre','Ottobre','Novembre','Dicembre');
@{$DaysOfWeek{italian}} = ('Do','Lu','Ma','Me','Gi','Ve','Sa');
$LY{italian}= 'anno di salto';

@{$MonthsOfYear{spanish}} =
('','Enero','Febrero','Marcha','Abril','Mayo','Junio',
'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
@{$DaysOfWeek{spanish}} = ('Do','Lu','Ma','Mi','Ju','Vi',"S\\'a");
$LY{spanish}= 'A\~no bisiesto';

@{$MonthsOfYear{portuguese}} =
('','Janeiro','Fevereiro','Mar\c{c}o','Abril','Maio','Junho',
'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro');
# \c needs special treatment when converting to uppercase
@{$DaysOfWeek{portuguese}} =
('Dom','Seg','Ter','Qua','Qui','Sex',"S\\'ab");
$LY{portuguese}= 'Ano de pulo';

@{$MonthsOfYear{swedish}} =
('','Januari','Februari','Mars','April','Mai','Juni',
'Juli','Augusti','September','October','November','December');
@{$DaysOfWeek{swedish}} =
('S\"o','M\aa{}','Ti','On','To','Fr','L\"o');
$LY{swedish} = 'skott\aa{}r';

@{$MonthsOfYear{latin}} =
('','Ianuarius','Februarius','Martius','Aprilis','Maius','Iunius',
'Iulius','Augustus','Septembris','Octobris','Nouembris','Decembris');
@{$DaysOfWeek{latin}} = ('So','Lu','Ma','Me','Io','Ve','Sa');
$LY{latin} = 'annvs bissextilis';
# use v not u as it will be set as \textsc
# Antiquarian note:
# There is evidence for a seven-day cycle in Latin-speaking
# communities in the 1st cent. AD.  The days are: (dies) Solis,
# Lunae, Martis, Mercurii, Iouis, Veneris, Saturni.  Iulius, Augustus
# were originally Quintilis, Sextilis but were renamed after two
# personages of the 1st cent. BC.  In Latin of this period there is
# no distinction between I and J (I used for both) or between
# U and V (lowercase u, uppercase V). ---JP
#============
# Set default values for the arguments:
$Year = '';
$Language = 'english';
$Monthcase = 'uppercase';
$Page = '';

# Override them by actual arguments:
foreach (@ARGV)
{
  if ($_ =~ m/(p1|p2)/i) { $Page = lc $1 }
  elsif ($_ =~ m/([0-9]+)/) { $Year = $1 }
  elsif ($_ =~ m/(uppercase|lowercase)/i) { $Monthcase = lc $1 }
  elsif ($_ =~ m/([a-z]+)/i) { $Language = lc $1 };
};
if ($Year !~ /^\d+$/)
{ die "Usage: yplan [language] [lowercase] [page] year >file.tex\n" };
if ($Year < 1999)
{ die "Years < 1999 not available\n" };
if (! exists $MonthsOfYear{$Language})
{ die "Language $Language not available\n" };
if ($Monthcase =~ m/uppercase/)
{ foreach (@{$MonthsOfYear{$Language}})
  { $_ = uc $_; $_ =~ s/\\C/\\c/g;
    if ($Language eq 'latin') {$_ =~ s/U/V/g}
  }
};
$shortYear = $Year ; $shortYear =~ s/..(..)/$1/ ;
#============
# count days from 1999 January 1 to $Year January 1:
$thisYear = 1999 ;
$startDayofWeek[1] = 5 ;
# 1999 January 1 is a Friday. 0=Sunday,1=Monday,etc.
# count days from 1999 January 1 to $Year January 1:
while ($thisYear < $Year)
{
  $daysinYear = Leapyear($thisYear) ? 366 : 365 ;
  $startDayofWeek[1] = $startDayofWeek[1] + $daysinYear ;
  $thisYear++;
};
$startDayofWeek[1] = $startDayofWeek[1] % 7 ;
#============
# make a list of the lengths of months:
@monthLengths =
( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ) ;
$Ly = '';
if (Leapyear($thisYear))
{ $monthLengths[2] = 29 ; $Ly = $LY{$Language} };
#============
# for each month, determine the day of week of day 1 of the month
for ($i=1; $i<12; $i++) 
{
  $startDayofWeek[1+$i] =
  ( $startDayofWeek[$i] + $monthLengths[$i] ) % 7;
};
#============
# for each month, write an appropriately shifted array of daysofMonth;
# meantime determine the greatest index (plus one) to any such array:
$stopRow = 0;
for ($i=1; $i<=12; $i++)
{
  $monthVec[$i] = (); # create the array
  $j = $startDayofWeek[$i];
  $k = 1;
  while ($k <= @monthLengths[$i])
  {
    ${$monthVec[$i]}[$j] = $k;
    $k++; $j++;
  };
  if ($stopRow < $j) { $stopRow = $j };
};
#============
# fill in $monthVec[0] with the days of week:
$j = 0;
for ($i=0; $i<$stopRow; $i++)
{
  ${$monthVec[0]}[$i] = $j; $j++; $j %= 7;
};
#============
# determine the least of @startDayofWeek:
$topDayofWeek = 6;
for ($i=1; $i<=12; $i++)
{
  if ($startDayofWeek[$i]<$topDayofWeek)
  {$topDayofWeek=$startDayofWeek[$i]} 
};
#============
# emit the opening boilerplate:
print <<ENDFRONT;
%% Yplan
%% Vertical year-planner calendar
%%
%% ---------------------------
%% Copyright 1999 RWD Nickalls, 2000 John Palmer
%% Multlingual support based on yplan.sty,
%% copyright 1999 Harald Harders
%% This program Yplan[.pl] can be redistributed and/or modified
%% under the terms of the LaTeX Project Public License distributed
%% from CTAN archives in directory macros/latex/base/lppl.txt;
%% either version 1 of the License, or any later version.
%% --------------------------
%% Author of the original LaTeX source:
%% Dr RWD Nickalls,
%% Department of Anaesthesia,
%% City Hospital,
%% Nottingham, UK.
%%
%% dicknickalls\@compuserve.com
%% TEL: +44-(0)-115-9691169 Ext:45637
%% FAX: +44-(0)-115-9627713
%% 
%% Author of the original multilingual package:
%% Harald Harders,
%% harald.harders\@dlr.de
%%
%% Author of the Perl program:
%% John W Palmer,
%% johnp\@bcs.org.uk
%%
%% Designed for LaTeX 2e, although it can be easily adapted for
%% use with LaTeX 2.09, since it is only a big table.
%%
%% I designed this year planner as one year my
%% A4 diary had no good year planner at the end
%% The vertical size can be adjusted by changing \datestrut.
%% ---enjoy!  RWDN
%%
%%------------------------------------
\\documentclass[a4paper]{article}
%%------------------------------------
\\setlength{\\topmargin}{-1cm}
\\setlength{\\oddsidemargin}{-13.5mm}
\\setlength{\\textwidth}{18.5cm}
%%
\\newcommand{\\monthstrut}{\\rule{0pt}{12pt}}
%% \\monthstrut controls the white space above the month.
%%
\\newcommand{\\datestrut}{\\rule{0pt}{12pt}}
%% \\datestrut controls the white space above the date.
%%
\\newcommand{\\bs}{\$\\backslash\$}
%% Used in the footnotes.
%%--------------------------------------
\\begin{document}
%---------------
%% no pagenumbering
\\pagestyle{empty}
%--------------------
ENDFRONT
#============
# start emitting rows.  In each row, col 0 is a dayofWeek,
# the remainder are daysofMonth for different months.

$ema=6; $emb=12;
if ($Page eq 'p1') { $emb = 6 } elsif ($Page eq 'p2') { $ema = 12 };
for($endmonth=$ema; $endmonth<=$emb; $endmonth+=6)
{
print <<ENDHEAD;
\\begin{table}
\\hspace{1cm} {\\LARGE $Year}\\qquad\\textsc{$Ly}\\\\
{\\ } \\\\
\\begin{tabular}{|c||p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|p{2.5cm}|}
ENDHEAD
  print '%%',"\n";
  print '\hline',"\n";
  print ' \multicolumn{1}{|c||}{\monthstrut\ }',"\n" ;
  for ($j=$endmonth-5; $j<=$endmonth; $j++)
  { 
    print ' & \multicolumn{1}{|c|}{',
         ${$MonthsOfYear{$Language}}[$j],'}',"\n";
  };
  print "\\\\\n\\hline\n\\hline\n";
  for ($i=$topDayofWeek; $i<$stopRow; $i++)
  {
    print '\datestrut ',
         ${$DaysOfWeek{$Language}}[${$monthVec[0]}[$i]];
    for ($j=$endmonth-5; $j<=$endmonth; $j++)
    { 
      if ($j>0) { print ' & ' };
      print ${$monthVec[$j]}[$i];
    };
    print " \\\\\n"; # that's space, two backslashes and a newline
    if (${$monthVec[0]}[$i]==0) # Sunday
    { print '\hline\hline',"\n" } # full double rule at `end' of week
    else
    { print '\cline{1-1}'; # always put rule in day-of-week column
      for ($j=$endmonth-5; $j<=$endmonth; $j++)
      { if (${$monthVec[$j]}[$i] || ${$monthVec[$j]}[$i+1])
        { print '\cline{',($j-$endmonth+7),'-',($j-$endmonth+7),'}' }
        # in month columns put rule only above or below a day-number
      };
      print "\n";
      if ($i==$stopRow-1) { print '\hline',"\n" };
      # end of tabular matter
    };
  };
print <<ENDFOOT;
\\end{tabular}
{\\ } \\\\
%%\\newcommand{\\bs}{\$\\backslash\$}
\\textsc{ctan}/macros/latex/contrib/other/yplan/yplan.pl%
\\hfill\\hbox{\\copyright{} 1999 RWD Nickalls, H Harders, 2000 J Palmer}
\\end{table}
%-----------------
ENDFOOT
};
print '\end{document}',"\n";
#============
# End of program
#============