Debian Codegraph @

texmf-dist/tex/latex/polyglossia/hebrewcal.sty

raw
1 \ProvidesPackage{hebrewcal}
2 [2022/07/18 v2.8 %
3 Hebrew calendar for polyglossia (adapted from hebcal.sty in Babel)]
4
5 \ifdefined\RequireBidi
6 \RequireBidi
7 \else
8 \RequirePackage{iftex}
9 \ifluatex
10 \RequirePackage{luabidi}
11 \else
12 \RequirePackage{bidi}
13 \fi
14 \fi
15
16 %% TODO rewrite this on the basis of Reingold & Dershowitz
17 %% on the model of hijrical (using calc)
18
19 \@ifundefined{@Remainder}{\input{cal-util.def}}{}
20
21 %
22 % OPTIONS
23 %
24 \DeclareKeys[hebrewcal]
25 {
26 marcheshvan.if = @xpg@hebrew@marcheshvan,
27 marcheshvan.default:n = true,
28 fullyear.if = @xpg@hebrew@fullyear,
29 fullyear.default:n = true,
30 transliteration.choice:,
31 transliteration / academy.code =
32 {%
33 \@hebrewcal@academytranstrue
34 },
35 transliteration / alt.code =
36 {%
37 \@hebrewcal@academytransfalse
38 },
39 transliteration.default:n = alt,
40 transliteration/unknown.code = \PackageWarning{hebrewcal}{Unknown transliteration option `#1'}%
41 }
42
43 \newif\@xpg@hebrew@marcheshvan
44 \newif\@xpg@hebrew@marcheshvan
45 \newif\if@hebrewcal@academytrans
46
47 \ProcessKeyOptions[hebrewcal]
48 %%
49 %% END OPTIONS
50
51 \newcount\hebrewday \newcount\hebrewmonth \newcount\hebrewyear
52 \def\hebrewdate#1#2#3{%
53 \HebrewFromGregorian{#1}{#2}{#3}%
54 {\hebrewday}{\hebrewmonth}{\hebrewyear}%
55 \if@RTL
56 \@FormatForHebrew{\hebrewday}{\hebrewmonth}{\hebrewyear}%
57 \else
58 \@FormatForEnglish{\hebrewday}{\hebrewmonth}{\hebrewyear}%
59 \fi}
60 \def\hebrewtoday{\hebrewdate{\day}{\month}{\year}}
61 % The command name is capitalised in the doc, and this is consistent
62 % with other names such as \Hijritoday and \Jalalitoday.
63 \let\Hebrewtoday=\hebrewtoday
64 \def\hebrewsetreg{%
65 \HebrewFromGregorian{\day}{\month}{\year}%
66 {\hebrewday}{\hebrewmonth}{\hebrewyear}}
67 \def\HebrewYearName#1{{%
68 \@tempcnta=#1\divide\@tempcnta by 1000\multiply\@tempcnta by 1000
69 \ifnum#1=\@tempcnta\relax % divisible by 1000: disambiguate
70 \Hebrewnumeral{#1}\ (לפ"ג)%
71 \else % not divisible by 1000
72 \ifnum#1<1000\relax % first millennium: disambiguate
73 \Hebrewnumeral{#1}\ (לפ"ג)%
74 \else
75 \ifnum#1<5000
76 \Hebrewnumeral{#1}%
77 \else
78 \ifnum#1<6000 % current millennium, print without thousands
79 \@tempcnta=#1\relax
80 \if@xpg@hebrew@fullyear\else\advance\@tempcnta by -5000\fi
81 \Hebrewnumeral{\@tempcnta}%
82 \else % #1>6000
83 \Hebrewnumeral{#1}%
84 \fi
85 \fi
86 \fi
87 \fi}}
88 \def\HebrewMonthName#1#2{%
89 \ifnum #1 = 7
90 \@CheckLeapHebrewYear{#2}%
91 \if@HebrewLeap אדר\ ב'%
92 \else אדר%
93 \fi
94 \else
95 \ifcase#1
96 % nothing for 0
97 \or תשרי%
98 \or\if@xpg@hebrew@marcheshvan מרחשון\else חשון\fi
99 \or כסלו%
100 \or טבת%
101 \or שבט%
102 \or אדר\ א'%
103 \or אדר\ ב'%
104 \or ניסן%
105 \or אייר%
106 \or סיון%
107 \or תמוז%
108 \or אב%
109 \or אלול%
110 \fi
111 \fi}
112 \def\@FormatForHebrew#1#2#3{%
113 \Hebrewnumeral{#1}~ב\HebrewMonthName{#2}{#3}~%
114 \HebrewYearName{#3}}
115 \def\HebrewMonthNameInEnglish#1#2{%
116 \ifnum #1 = 7
117 \@CheckLeapHebrewYear{#2}%
118 \if@HebrewLeap Adar II\else Adar\fi
119 \else
120 \ifcase #1
121 % nothing for 0
122 \or \if@hebrewcal@academytrans Tishri \else Tishrei \fi
123 \or
124 \if@hebrewcal@academytrans%
125 \if@xpg@hebrew@marcheshvan Marẖeshvan\else Heshvan\fi
126 \else
127 \if@xpg@hebrew@marcheshvan Marcheshvan\else Heshvan\fi
128 \fi
129 \or Kislev
130 \or \if@hebrewcal@academytrans Tevet \else Tebeth \fi
131 \or \if@hebrewcal@academytrans Shvat \else Shebat \fi
132 \or Adar I%
133 \or Adar II%
134 \or Nisan%
135 \or \if@hebrewcal@academytrans Iyyar \else Iyar \fi
136 \or Sivan%
137 \or Tammuz%
138 \or \if@hebrewcal@academytrans Av \else Ab \fi
139 \or Elul%
140 \fi
141 \fi}
142 \def\@FormatForEnglish#1#2#3{%
143 \HebrewMonthNameInEnglish{#2}{#3} \number#1,\ \number#3}
144 \newcount\@common
145 \newif\if@HebrewLeap
146 \def\@CheckLeapHebrewYear#1{%
147 {%
148 \countdef\tmpa = 0 % \tmpa==\count0
149 \countdef\tmpb = 1 % \tmpb==\count1
150 \tmpa = #1
151 \multiply \tmpa by 7
152 \advance \tmpa by 1
153 \@Remainder{\tmpa}{19}{\tmpb}%
154 \ifnum \tmpb < 7 % \tmpb = (7*year+1)%19
155 \global\@HebrewLeaptrue
156 \else
157 \global\@HebrewLeapfalse
158 \fi}}
159 \def\@HebrewElapsedMonths#1#2{%
160 {%
161 \countdef\tmpa = 0 % \tmpa==\count0
162 \countdef\tmpb = 1 % \tmpb==\count1
163 \countdef\tmpc = 2 % \tmpc==\count2
164 \tmpa = #1
165 \advance \tmpa by -1
166 #2 = \tmpa % #2 = \tmpa = year-1
167 \divide #2 by 19 % Number of complete Meton cycles
168 \multiply #2 by 235 % #2 = 235*((year-1)/19)
169 \@Remainder{\tmpa}{19}{\tmpb}% \tmpa = years%19-years this cycle
170 \tmpc = \tmpb
171 \multiply \tmpb by 12
172 \advance #2 by \tmpb % add regular months this cycle
173 \multiply \tmpc by 7
174 \advance \tmpc by 1
175 \divide \tmpc by 19 % \tmpc = (1+7*((year-1)%19))/19 -
176 \advance #2 by \tmpc % add leap months
177 \global\@common = #2}%
178 #2 = \@common}
179 \def\@HebrewElapsedDays#1#2{%
180 {%
181 \countdef\tmpa = 0 % \tmpa==\count0
182 \countdef\tmpb = 1 % \tmpb==\count1
183 \countdef\tmpc = 2 % \tmpc==\count2
184 \@HebrewElapsedMonths{#1}{#2}%
185 \tmpa = #2
186 \multiply \tmpa by 13753
187 \advance \tmpa by 5604 % \tmpa=MonthsElapsed*13758 + 5604
188 \@Remainder{\tmpa}{25920}{\tmpc}% \tmpc == ConjunctionParts
189 \divide \tmpa by 25920
190 \multiply #2 by 29
191 \advance #2 by 1
192 \advance #2 by \tmpa % #2 = 1 + MonthsElapsed*29 +
193 \@Remainder{#2}{7}{\tmpa}% % \tmpa == DayOfWeek
194 \ifnum \tmpc < 19440
195 \ifnum \tmpc < 9924
196 \else % New moon at 9 h. 204 p. or later
197 \ifnum \tmpa = 2 % on Tuesday ...
198 \@CheckLeapHebrewYear{#1}% of a common year
199 \if@HebrewLeap
200 \else
201 \advance #2 by 1
202 \fi
203 \fi
204 \fi
205 \ifnum \tmpc < 16789
206 \else % New moon at 15 h. 589 p. or later
207 \ifnum \tmpa = 1 % on Monday ...
208 \advance #1 by -1
209 \@CheckLeapHebrewYear{#1}% at the end of leap year
210 \if@HebrewLeap
211 \advance #2 by 1
212 \fi
213 \fi
214 \fi
215 \else
216 \advance #2 by 1 % new moon at or after midday
217 \fi
218 \@Remainder{#2}{7}{\tmpa}% % \tmpa == DayOfWeek
219 \ifnum \tmpa = 0 % if Sunday ...
220 \advance #2 by 1
221 \else %
222 \ifnum \tmpa = 3 % Wednesday ...
223 \advance #2 by 1
224 \else
225 \ifnum \tmpa = 5 % or Friday
226 \advance #2 by 1
227 \fi
228 \fi
229 \fi
230 \global\@common = #2}%
231 #2 = \@common}
232 \def\@DaysInHebrewYear#1#2{%
233 {%
234 \countdef\tmpe = 12 % \tmpe==\count12
235 \@HebrewElapsedDays{#1}{\tmpe}%
236 \advance #1 by 1
237 \@HebrewElapsedDays{#1}{#2}%
238 \advance #2 by -\tmpe
239 \global\@common = #2}%
240 #2 = \@common}
241 \def\@HebrewDaysInPriorMonths#1#2#3{%
242 {%
243 \countdef\tmpf= 14 % \tmpf==\count14
244 #3 = \ifcase #1 % Days in prior month of regular year
245 0 \or % no month number 0
246 0 \or % Tishri
247 30 \or % Heshvan
248 59 \or % Kislev
249 89 \or % Tevet
250 118 \or % Shvat
251 148 \or % Adar I
252 148 \or % Adar II
253 177 \or % Nisan
254 207 \or % Iyyar
255 236 \or % Sivan
256 266 \or % Tammuz
257 295 \or % Av
258 325 \or % Elul
259 400 % Dummy
260 \fi
261 \@CheckLeapHebrewYear{#2}%
262 \if@HebrewLeap % in leap year
263 \ifnum #1 > 6 % if month after Adar I
264 \advance #3 by 30 % add 30 days
265 \fi
266 \fi
267 \@DaysInHebrewYear{#2}{\tmpf}%
268 \ifnum #1 > 3
269 \ifnum \tmpf = 353
270 \advance #3 by -1
271 \fi % Short Kislev
272 \ifnum \tmpf = 383
273 \advance #3 by -1
274 \fi
275 \fi
276 \ifnum #1 > 2
277 \ifnum \tmpf = 355
278 \advance #3 by 1
279 \fi % Long Heshvan
280 \ifnum \tmpf = 385
281 \advance #3 by 1
282 \fi
283 \fi
284 \global\@common = #3}%
285 #3 = \@common}
286 \def\@FixedFromHebrew#1#2#3#4{%
287 {%
288 #4 = #1
289 \@HebrewDaysInPriorMonths{#2}{#3}{#1}%
290 \advance #4 by #1 % Add days in prior months this year
291 \@HebrewElapsedDays{#3}{#1}%
292 \advance #4 by #1 % Add days in prior years
293 \advance #4 by -1373429 % Subtract days before Gregorian
294 \global\@common = #4}% % 01.01.0001
295 #4 = \@common}
296 \def\@GregorianDaysInPriorMonths#1#2#3{%
297 {%
298 #3 = \ifcase #1
299 0 \or % no month number 0
300 0 \or
301 31 \or
302 59 \or
303 90 \or
304 120 \or
305 151 \or
306 181 \or
307 212 \or
308 243 \or
309 273 \or
310 304 \or
311 334
312 \fi
313 \@CheckIfGregorianLeap{#2}%
314 \if@GregorianLeap
315 \ifnum #1 > 2 % if month after February
316 \advance #3 by 1 % add leap day
317 \fi
318 \fi
319 \global\@common = #3}%
320 #3 = \@common}
321 \def\@GregorianDaysInPriorYears#1#2{%
322 {%
323 \countdef\tmpc = 4 % \tmpc==\count4
324 \countdef\tmpb = 2 % \tmpb==\count2
325 \tmpb = #1
326 \advance \tmpb by -1
327 \tmpc = \tmpb % \tmpc = \tmpb = year-1
328 \multiply \tmpc by 365 % Days in prior years =
329 #2 = \tmpc % = 365*(year-1) ...
330 \tmpc = \tmpb
331 \divide \tmpc by 4 % \tmpc = (year-1)/4
332 \advance #2 by \tmpc % ... plus Julian leap days ...
333 \tmpc = \tmpb
334 \divide \tmpc by 100 % \tmpc = (year-1)/100
335 \advance #2 by -\tmpc % ... minus century years ...
336 \tmpc = \tmpb
337 \divide \tmpc by 400 % \tmpc = (year-1)/400
338 \advance #2 by \tmpc % ... plus 4-century years.
339 \global\@common = #2}%
340 #2 = \@common}
341 \def\@AbsoluteFromGregorian#1#2#3#4{%
342 {%
343 \countdef\tmpd = 0 % \tmpd==\count0
344 #4 = #1 % days so far this month
345 \@GregorianDaysInPriorMonths{#2}{#3}{\tmpd}%
346 \advance #4 by \tmpd % add days in prior months
347 \@GregorianDaysInPriorYears{#3}{\tmpd}%
348 \advance #4 by \tmpd % add days in prior years
349 \global\@common = #4}%
350 #4 = \@common}
351 \def\HebrewFromGregorian#1#2#3#4#5#6{%
352 {%
353 \countdef\tmpx= 17 % \tmpx==\count17
354 \countdef\tmpy= 18 % \tmpy==\count18
355 \countdef\tmpz= 19 % \tmpz==\count19
356 #6 = #3
357 \global\advance #6 by 3761 % approximation from above
358 \@AbsoluteFromGregorian{#1}{#2}{#3}{#4}%
359 \tmpz = 1 \tmpy = 1
360 \@FixedFromHebrew{\tmpz}{\tmpy}{#6}{\tmpx}%
361 \ifnum \tmpx > #4
362 \global\advance #6 by -1 % Hyear = Gyear + 3760
363 \@FixedFromHebrew{\tmpz}{\tmpy}{#6}{\tmpx}%
364 \fi
365 \advance #4 by -\tmpx % Days in this year
366 \advance #4 by 1
367 #5 = #4
368 \divide #5 by 30 % Approximation for month from below
369 \loop % Search for month
370 \@HebrewDaysInPriorMonths{#5}{#6}{\tmpx}%
371 \ifnum \tmpx < #4
372 \advance #5 by 1
373 \tmpy = \tmpx
374 \repeat
375 \global\advance #5 by -1
376 \global\advance #4 by -\tmpy
377 }%
378 }
379
380 \endinput