m-bibles.mkxl /size: 14 Kb    last modification: 2025-02-21 11:03
1%D \module
2%D   [       file=m-bibles,
3%D        version=2024.11.01,
4%D          title=\CONTEXT\ Extra Modules,
5%D       subtitle=Parallel Bibles,
6%D         author=Hans Hagen & Mikael Sundqvist,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14%D This is one of the test files that we use while upgrading columnsets to use new
15%D \LUAMETATEX\ features.
16%D
17%D The \XML\ bible files are fetched from:
18%D
19%D \starttyping
20%D https://github.com/Beblia/Holy-Bible-XML-Format
21%D \stoptyping
22
23% todo: use labeltext
24
25% \enablemode[balance-verses] % too late
26
27\startmodule [bibles]
28
29% \enabletrackers[vspacing.collect]
30% \enabletrackers[vspacing.snapping]
31
32% \showmakeup[line]
33% \enabletrackers[system.usage=summary]
34% \showframe
35% \showgrid
36
37\registerctxluafile{m-bibles}{}
38
39\enableexperiments[fonts.compact]
40
41\dontcomplain
42
43\setuplayout
44  [topspace=.05ph,
45   bottomspace=.05ph,
46   backspace=.05ph,
47   header=.05ph,
48   grid=yes,
49   footer=0pt,
50   width=middle,
51   height=middle]
52
53% \setupinteraction
54%   [state=start,
55%    color=,
56%    contrastcolor=]
57%
58% \setuplist
59%   [interaction=all]
60
61% hlig rlig dlig ccmp
62
63\starttypescript [serif] [unifraktur] [name]
64    \setups[font:fallback:serif]
65    \definefontsynonym [Serif]     [file:unifrakturcook-light] [features=default]
66    \definefontsynonym [SerifBold] [file:unifrakturcook]       [features=default]
67\stoptypescript
68
69\starttypescript[unifraktur]
70    \definetypeface [\typescriptone] [rm] [serif] [unifraktur] [default]
71    \definetypeface [\typescriptone] [ss] [serif] [unifraktur] [default]
72    \definetypeface [\typescriptone] [mm] [math]  [modern]
73    \definetypeface [\typescriptone] [tt] [mono]  [modern]
74\stoptypescript
75
76\definefontfeature
77  [default]
78  [default]
79  [hz=quality,
80   protrusion=quality]
81
82\setupinterlinespace
83  [top=.72]
84
85% \setupbodyfont[unifraktur,10pt] \setupinterlinespace[line=2.25ex]
86
87% \setupbodyfont[lucida,9pt]
88\setupbodyfont[pagella,9pt]
89% \setupbodyfont[pagella,7pt]
90
91% \showmakeup[expansion]
92% \enabletrackers[paragraphs.passes=summary]
93
94\startsetups balance:example
95  \balancetopskip          \strutht
96  \balancebottomskip       \strutdp
97  \balanceemergencystretch 0pt
98  \balanceadjdemerits      0
99  \balancetolerance        10
100\stopsetups
101
102\setupwhitespace
103  [none]
104
105% \setuplayout
106%   [limitstretch=yes]
107
108% \setuplayout
109%  %[vz=4]
110%   [vz=8]
111
112%  2-1  1 2     | 1 2
113%  3-1  1 2 3   | 1 2 3
114%  4-1  1 2 3 4 | 1 2 3 4
115
116%  4-2  1 2     | 3 4
117%  6-2  1 2 3   | 4 5 6
118%  8-2  1 2 3 4 | 5 6 7 8
119
120% \enablemode[balance-four-two]
121
122% \startmode[balance-two-one]
123%     \definecolumnset[bible][n=2]
124%     \definesubcolumnset[bible][1][1,3]
125%     \definesubcolumnset[bible][2][2,4]
126% \stopmode
127
128% \startmode[balance-three-one]
129%     \definecolumnset[bible][n=3]
130%     \definesubcolumnset[bible][1][1,4]
131%     \definesubcolumnset[bible][2][2,5]
132%     \definesubcolumnset[bible][3][3,6]
133% \stopmode
134
135% \startmode[balance-four-one]
136%     \definecolumnset[bible][n=4]
137%     \definesubcolumnset[bible][1][1,5]
138%     \definesubcolumnset[bible][2][2,6]
139%     \definesubcolumnset[bible][3][3,7]
140%     \definesubcolumnset[bible][4][4,8]
141% \stopmode
142
143% \startmode[balance-four-two]
144%     \definecolumnset[bible][n=2]
145%     \definesubcolumnset[bible][1][1]
146%     \definesubcolumnset[bible][2][2]
147%     \definesubcolumnset[bible][3][3]
148%     \definesubcolumnset[bible][4][4]
149% \stopmode
150
151% \startmode[balance-six-two]
152%     \definecolumnset[bible][n=3]
153%     \definesubcolumnset[bible][1][1]
154%     \definesubcolumnset[bible][2][2]
155%     \definesubcolumnset[bible][3][3]
156%     \definesubcolumnset[bible][4][4]
157%     \definesubcolumnset[bible][5][5]
158%     \definesubcolumnset[bible][6][6]
159% \stopmode
160
161% \startmode[balance-eight-two]
162%     \definecolumnset[bible][n=4]
163%     \definesubcolumnset[bible][1][1]
164%     \definesubcolumnset[bible][2][2]
165%     \definesubcolumnset[bible][3][3]
166%     \definesubcolumnset[bible][4][4]
167%     \definesubcolumnset[bible][5][5]
168%     \definesubcolumnset[bible][6][6]
169%     \definesubcolumnset[bible][7][7]
170%     \definesubcolumnset[bible][8][8]
171% \stopmode
172
173\definecolumnset
174  [bible]
175  [n=2,
176   align={lesswidows,lessclubs,lessbroken,lessorphans}]
177
178\definesubcolumnset[bible][1][1]
179\definesubcolumnset[bible][2][2]
180\definesubcolumnset[bible][3][3]
181\definesubcolumnset[bible][4][4]
182
183\setuppagenumbering
184  [alternative=doublesided]
185
186\setupalign
187%   [tolerant,depth,granular]
188  [tolerant,granular]
189
190% \enabletrackers[paragraphs.passes=summary]
191
192\newinteger\parpassdefaultone
193\parpassdefaultone\parpassidentifier{quality}
194
195\startsetups align:pass:quality
196    \parpasses  5
197        identifier           \parpassdefaultone
198        tolerance            100
199        adjustspacing          0
200        emergencyfactor        0
201        hyphenation            0
202        mathpenaltyfactor  20000
203        orphanlinefactors   4 100 250 500 1000
204        toddlerpenalties    1 options 2 200 50
205    next
206        tolerance            200
207        adjustspacing          3
208        adjustspacingstep      1
209        adjustspacingshrink    5
210        adjustspacingstretch  10
211    next
212        tolerance            300
213        adjustspacing          0
214    next
215        tolerance            200
216        adjustspacing          3
217        adjustspacingshrink   20
218        adjustspacingstretch  40
219    next
220        tolerance            400
221        hyphenation            1
222        extrahyphenpenalty   200
223        adjustspacing          3
224        adjustspacingshrink   30
225        adjustspacingstretch  60
226        emergencystretch       1\bodyfontsize
227        emergencyfactor     1000
228        mathpenaltyfactor   1000
229     \relax
230\stopsetups
231
232\setupalignpass
233  [quality]
234
235% \setupalign[notwins]
236
237% \enabletrackers[pages.loners] % none as we have high penalties
238
239\setuphead
240  [chapter,section,subsection]
241  [number=no,
242   page=,
243   continue=no,
244   expansion=yes]
245
246\setuphead
247  [chapter]
248  [before=,
249%    after=\blank[2*line,force]]
250   after=\blank[2*line]]
251
252\setuphead
253  [section]
254  [before=,
255%    beforesection=\blank[line,force]]
256   beforesection=\blank[2*line]]
257
258\setuphead
259  [subsection]
260  [before=\blank[line]\testcolumn[5],
261   after=\blank[line,samepage],
262%    beforesection=\blank[line,force]]
263   beforesection=\blank[2*line]]
264
265\setuphead [chapter]    [style=\bfd]
266\setuphead [section]    [style=\bfc]
267\setuphead [subsection] [style=\bfa]
268
269% \localcontrolledloop 1 4 1 {
270%     \definehead [chapter:#I]    [chapter]    [marking=new]
271%     \definehead [title:#I]      [title]      [marking=new]
272%     \definehead [section:#I]    [section]    [marking=new]
273%     \definehead [subsection:#I] [subsection] [marking=new]
274% }
275
276\definehead [chapter:1]    [chapter]    [marking=new]
277\definehead [chapter:2]    [chapter]    [marking=new]
278\definehead [chapter:3]    [chapter]    [marking=new]
279\definehead [chapter:4]    [chapter]    [marking=new]
280
281\definehead [title:1]      [title]      [marking=new]
282\definehead [title:2]      [title]      [marking=new]
283\definehead [title:3]      [title]      [marking=new]
284\definehead [title:4]      [title]      [marking=new]
285
286\definehead [section:1]    [section]    [marking=new]
287\definehead [section:2]    [section]    [marking=new]
288\definehead [section:3]    [section]    [marking=new]
289\definehead [section:4]    [section]    [marking=new]
290
291\definehead [subsection:1] [subsection] [marking=new]
292\definehead [subsection:2] [subsection] [marking=new]
293\definehead [subsection:3] [subsection] [marking=new]
294\definehead [subsection:4] [subsection] [marking=new]
295
296\setupheader
297  [style=bold]
298
299\setupheadertexts
300  [pagenumber]
301
302\startsetups header:right
303    \doifelsemarking {subsection:3} {
304        \getmarking[section:3]
305        \quad
306        \getmarking[subsection:3]
307    } {
308        % nothing
309    }
310    \hfill
311    \doifelsemarking {subsection:4} {
312        \getmarking[subsection:4]
313    \quad
314        \getmarking[section:4]
315    } {
316        % nothing
317    }
318%     \qquad
319%     \pagenumber
320\stopsetups
321
322\startsetups header:left
323%     \pagenumber
324%     \qquad
325    \doifelsemarking {subsection:1} {
326        \getmarking[section:1]
327        \quad
328        \getmarking[subsection:1]
329    } {
330        % nothing
331    }
332    \hfill
333    \doifelsemarking {subsection:2} {
334        \getmarking[subsection:2]
335        \quad
336        \getmarking[section:2]
337    } {
338        % nothing
339    }
340\stopsetups
341
342\setupheadertexts
343  [] [\directsetup{header:right}]
344  [\directsetup{header:left}] []
345
346\newgluespec \VerseSkip \VerseSkip .5em plus .25em minus .125em \relax
347
348\def\BibleBook     {1}
349\def\BibleChapter  {1}
350\def\BibleTestament{Old}
351\def\BibleVerse    {1}
352
353%D We define these at the lua end but it's not faster ... non critical.
354
355% \protected\def\BibleSetFile#1#2{\setvalue{BibleFile:#1}{#2}}
356% \def\BibleFile#1{\getvalue{BibleFile:#1}}
357%
358% \def\BibleTitleName      #1{\cldcontext{moduledata.bibles.biblefiles["\BibleFile{#1}"].title}}
359% \def\BibleTestamentName#1#2{\cldcontext{moduledata.bibles.biblefiles["\BibleFile{#1}"].testaments["#2"]}}
360% \def\BibleBookName     #1#2{\cldcontext{moduledata.bibles.biblefiles["\BibleFile{#1}"].books[tonumber("#2")]}}
361% \def\BibleChapterName    #1{\cldcontext{moduledata.bibles.biblefiles["\BibleFile{#1}"].chapter}}
362
363\startxmlsetups xml:bible
364    \page[left]
365    \startcolumnset [bible]
366%         \localcontrolledloop 1 4 1 {
367        \localcontrolledrepeat 4 {
368            \startsubcolumnset[#I]\relax
369                \startnamedsection[title:#I][title={\BibleTitleName{\number#I}}]
370                    \placelist[chapter:#I][criterium=text]
371                \stopnamedsection
372            \stopsubcolumnset
373        }
374        \flushsubcolumnsets[spread]
375    \stopcolumnset
376    \page[left]
377    \xmlflush{#1}
378\stopxmlsetups
379
380\startxmlsetups xml:testament
381    \page[left]
382    \startcolumnset [bible]
383        \xdef\BibleName{\xmlatt{#1}{name}}
384        \localcontrolledloop 1 4 1 {
385            \startsubcolumnset[#I]\relax
386                \startnamedsection[chapter:#I][title={\BibleTestamentName{\number#I}{\BibleName}}]
387                    \placelist[section:#I][criterium=text]
388                \stopnamedsection
389            \stopsubcolumnset
390        }
391        \flushsubcolumnsets[spread]
392    \stopcolumnset
393    \page[left]
394    \xmlflush{#1}
395\stopxmlsetups
396
397\startxmlsetups xml:book
398    \xdef\BibleBook   {\xmlatt{#1}{number}}
399    \xdef\BibleChapter{1}
400% \ifnum\BibleBook<\plustwo
401    \startcolumnset [bible]
402        \startsubcolumnset\relax
403            \namedsection[section:1][title={\BibleBookName{1}\BibleBook}]
404        \stopsubcolumnset
405        \localcontrolledloop 2 4 1 {
406            \startsubcolumnset[#I]\relax
407                \namedsection[section:#I][title={\BibleBookName{\number#I}\BibleBook},incrementnumber=no]
408            \stopsubcolumnset
409        }
410        \flushsubcolumnsets[spread]
411        \xmlflush{#1}
412    \stopcolumnset
413% \fi
414\stopxmlsetups
415
416\startnotmode[balance-verses]
417
418    \startxmlsetups xml:chapter
419        \xdef\BibleChapter{\xmlatt{#1}{number}}
420        \localcontrolledloop 1 4 1 {
421            \startsubcolumnset[#I]\relax
422               %\startnamedsection[subsection:\the\currentloopiterator][title={\BibleChapterName{\the\currentloopiterator}}]
423                \startnamedsection[subsection:#I][title={\BibleChapterName{\number#I} \BibleChapter}]
424                    \xmlfilter{bible:#I}{/bible/testament/book[@number="\BibleBook"]/chapter[@number="\BibleChapter"]/text()}
425                   %\xmltext  {bible:\number\currentloopiterator}{/bible/testament/book[position()=\BibleBook]/chapter[position()=\BibleChapter]}
426                \stopnamedsection
427            \stopsubcolumnset
428        }
429        \flushsubcolumnsets[spread]
430    \stopxmlsetups
431
432%     \startxmlsetups xml:verse
433%         {\glyphweight140\relax \xmlatt{#1}{number}}
434%         \hskip\VerseSkip
435%         \xmlflush{#1}
436%         \par
437%     \stopxmlsetups
438
439    \startxmlsetups xml:verse
440        {\lefttoright\glyphweight140\relax \xmlatt{#1}{number}}
441        \hskip\VerseSkip
442        \xmlflush{#1}
443        \par
444    \stopxmlsetups
445
446\stopnotmode
447
448\startmode[balance-verses]
449
450    \startxmlsetups xml:chapter
451        \xdef\BibleChapter{\xmlatt{#1}{number}}
452        \localcontrolledloop 1 4 1 {
453            \startsubcolumnset[#I]\relax
454                \namedsection
455                  [subsection:#I]
456                  [title={\BibleChapterName{\number#I} \BibleChapter}]
457            \stopsubcolumnset
458        }
459        \flushsubcolumnsets[spread]
460        \xmlflush{#1}
461    \stopxmlsetups
462
463    \startxmlsetups xml:verse
464        \xdef\BibleVerse{\xmlatt{#1}{number}}%
465        \localcontrolledloop 1 4 1 {
466            \startsubcolumnset[#I]\relax
467                {\lefttoright\glyphweight140\relax \BibleVerse}
468                \hskip\VerseSkip
469                \xmlfilter{bible:#I}{/bible/testament/book[@number="\BibleBook"]/chapter[@number="\BibleChapter"]/verse[@number="\BibleVerse"]/text()}
470                \par
471            \stopsubcolumnset
472        }
473        \flushsubcolumnsets[spread]
474    \stopxmlsetups
475
476\stopmode
477
478\startxmlsetups xml:mysetups
479    \xmlsetsetup{#1}{bible|testament|book|chapter|verse}{xml:*}
480\stopxmlsetups
481
482\xmlregistersetup{xml:mysetups}
483
484\startsetups bibles:parallel
485    \localcontrolledloop 1 4 1 {
486        \xmlloadonly{bible:#I}{\BibleFile{\number#I}}{}
487    }
488    \xmlflush{bible:1}
489\stopsetups
490
491% \startxmlsetups xml:verse
492%     \startelement[verse]
493%         \startelement[versetag]
494%             {\glyphweight140\relax \xmlatt{#1}{number}}
495%         \stopelement
496%         \hskip\VerseSkip
497%         \startelement[versecontent]
498%             \xmlflush{#1}
499%         \stopelement
500%     \stopelement
501%     \par
502% \stopxmlsetups
503
504\stopmodule
505
506\continueifinputfile{m-bibles.mkxl}
507
508\usemodule[bibles]
509
510% \enablemode[balance-verses] % too late
511
512\mainlanguage[gb]
513
514% todo: locate the oldest ones (those often standardized the language)
515% todo: locate the most recent official ones (to which the patterns apply)
516% todo: make a nice title page
517
518\BibleSetFile{1}{EnglishKJBible.xml}
519\BibleSetFile{2}{PolishBible.xml}
520\BibleSetFile{3}{DutchBible.xml}
521\BibleSetFile{4}{SwedishBible.xml}
522
523\setupsubcolumnset[bible:1][language=english]
524\setupsubcolumnset[bible:2][language=polish]
525\setupsubcolumnset[bible:3][language=dutch]
526\setupsubcolumnset[bible:4][language=swedish]
527
528\starttext
529    \setups[bibles:parallel]
530\stoptext
531
532% There is room for some speedup (like in the xml part but this is non critical code
533% used in some production environment. On my 2017/8 laptop I get:
534%
535% 2024-12-29 : 137.4 136.4 137.4 138.4 136.9 138.2
536% 2025-10-03 : 136.7 (kind of erratic)
537%     verses : 144.4 144.6 144.8
538
539
540