Debian Codegraph @

texmf-dist/tex/luatex/gregoriotex/gregoriotex-main.tex

raw
1 %GregorioTeX main file.
2 %
3 % Copyright (C) 2007-2025 The Gregorio Project (see CONTRIBUTORS.md)
4 %
5 % This file is part of Gregorio.
6 %
7 % Gregorio is free software: you can redistribute it and/or modify
8 % it under the terms of the GNU General Public License as published by
9 % the Free Software Foundation, either version 3 of the License, or
10 % (at your option) any later version.
11 %
12 % Gregorio is distributed in the hope that it will be useful,
13 % but WITHOUT ANY WARRANTY; without even the implied warranty of
14 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 % GNU General Public License for more details.
16 %
17 % You should have received a copy of the GNU General Public License
18 % along with Gregorio. If not, see <http://www.gnu.org/licenses/>.
19
20 % this file contains definitions for lines, initial, fonts, etc.
21
22 % The version of gregorio. All gregoriotex*.tex files must have the same.
23 % All gtex files must also have the same version.
24 \xdef\gre@gregoriotexversion{6.1.0}% GREGORIO_VERSION - VersionManager.py
25
26 % first some macros to allow checks for version:
27 % Tests that all gregoriotex files are of the same version.
28 % #1 is the name of the file
29 % #2 is the version
30
31 \def\gre@declarefileversion#1#2{%
32 \IfStrEq*{#2}{\gre@gregoriotexversion}{}{%else
33 \gre@error{Version Inconsistency!\MessageBreak gregoriotex-main.tex is in version \number\gre@gregoriotexversion \space\space while #1 is in version \number#2}}%
34 }%
35
36
37 \input gregoriotex-common.tex
38
39
40 \def\gre@nothing{}%
41
42 %%%%%%%%%%%%%%%
43 %% Backwards Compatibility
44 %%%%%%%%%%%%%%%
45
46 % Depending on version of LuaTeX / LaTeX, some primitives have different names
47 % We define local aliases for this eventuality, using \ifdefined to determine which
48 % version of the primative is available. In all cases the 'true' branch should be the
49 % more recent version.
50 \ifdefined\localleftbox%
51 \let\gre@localleftbox\localleftbox%
52 \else%
53 \let\gre@localleftbox\luatexlocalleftbox%
54 \fi%
55 \ifdefined\localrightbox%
56 \let\gre@localrightbox\localrightbox%
57 \else%
58 \let\gre@localrightbox\luatexlocalrightbox%
59 \fi%
60 \ifdefined\pdfextension%
61 \def\gre@startlink{\pdfextension startlink }%
62 \def\gre@endlink{\pdfextension endlink\relax}%
63 \else%
64 \let\gre@startlink\pdfstartlink%
65 \let\gre@endlink\pdfendlink%
66 \fi%
67 \ifdefined\savepos%
68 \let\gre@savepos\savepos%
69 \else%
70 \let\gre@savepos\pdfsavepos%
71 \fi%
72 \ifdefined\lastxpos%
73 \let\gre@lastxpos\lastxpos%
74 \else%
75 \let\gre@lastxpos\pdflastxpos%
76 \fi%
77 \ifdefined\lastypos%
78 \let\gre@lastypos\lastypos%
79 \else%
80 \let\gre@lastypos\pdflastypos%
81 \fi%
82
83 %%%%%%%%%%%%%%%
84
85 % an attribute to mark various parts of the score
86 % 1 = commentary, 2 = stafflines, 3 = initial
87 \newluatexattribute\gre@attr@part%
88 \edef\gre@attrid@part{\the\allocationnumber}
89
90 % an attribute we put on the text nodes.
91 % if it is 1, it means that there may be a dash here if this syllable is at the end of a line
92 % if it is 2, it means that it's never useful to typeset a dash
93 % if it is 0, it just means that we are in a score...
94 \newluatexattribute\gre@attr@dash%
95
96 % an attribute used for translation centering
97 \newluatexattribute\gre@attr@center%
98
99 \newluatexattribute\GreScoreId %
100
101 % attributes for tracking glyph heights
102 \newluatexattribute\gre@attr@glyph@id %
103 \newluatexattribute\gre@attr@glyph@top %
104 \newluatexattribute\gre@attr@glyph@bottom %
105
106 % attribute for syllable tracking
107 \newluatexattribute\gre@attr@syllable@id %
108
109 % attributes for soft alterations
110
111 % Alterations are numbered consecutively starting from 1. If an
112 % alteration is set twice, once for measurement and once for printing,
113 % they have the same id (unlike glyph ids).
114 \newluatexattribute\gre@attr@alteration@id %
115
116 % The pitch and type of an alteration. If an alteration has a glyph
117 % id, then \gre@attr@alteration@pitch = \gre@attr@glyph@top
118 % = \gre@attr@glyph@bottom, but we can't use the latter because we
119 % also keep track of custos alterations, which don't have glyph ids.
120 \newluatexattribute\gre@attr@alteration@pitch
121 \edef\gre@attrid@alteration@pitch{\the\allocationnumber}%
122 \newluatexattribute\gre@attr@alteration@type % see \gre@alteration for codes
123 \edef\gre@attrid@alteration@type{\the\allocationnumber}%
124
125 \newluatexcatcodetable\gre@atletter %
126 \setluatexcatcodetable\gre@atletter{%
127 \catcode`\@=11 %
128 }%
129
130 % Macro called by scores.
131 % Tests the major version of gregorio (X.0.0) against the score. Fails
132 % if the major version (X) does not match.
133 % #1 is the version of GregorioTeX the score is made for.
134
135 \def\GregorioTeXAPIVersion#1{%
136 \StrBefore{\gre@gregoriotexversion}{.}[\gre@gregoriomajorversion]%
137 \IfBeginWith{#1}{\gre@gregoriomajorversion}{\relax}{%else
138 \gre@error{Version Inconsistency!\MessageBreak GregorioTeX is in version \gre@gregoriotexversion \space\space while a score you included requires version #1. Please recompile your scores}}%
139 }%
140
141 \RequireLuaModule{gregoriotex}%
142 \ifcsname greskipheightcomputation\endcsname %
143 \directlua{gregoriotex.init(arg, false)}%
144 \else %
145 \directlua{gregoriotex.init(arg, true)}%
146 \fi %
147 \directlua{gregoriotex.set_debug_string([[\gre@debug]])}%
148
149 \xdef\gre@gregoriotexluaversion{\directlua{tex.write(gregoriotex.get_gregoriotexluaversion())}}%
150
151 % Test to make sure that gregoriotex.lua is of the same version.
152 \IfStrEq*{\gre@gregoriotexluaversion}{\gre@gregoriotexversion}{}{%else
153 \gre@error{Version Inconsistency!\MessageBreak gregoriotex-main.tex is in version \number\gre@gregoriotexversion \space\space while gregoriotex.lua is in version \gre@gregoriotexluaversion}}%
154
155
156 %%%%%%%%%%%%%%%%%%%%%%%%
157 %% aux file definitions
158 %%%%%%%%%%%%%%%%%%%%%%%%
159
160 % for now, we only use an aux file with LuaTeX
161
162 \ifluatex%
163 \newwrite\gre@gaux%
164 \fi%
165
166 \def\gre@write@gaux#1{%
167 \write\gre@gaux{#1}%
168 \relax %
169 }%
170
171 \def\gre@open@gaux{%
172 \openout\gre@gaux \jobname .gaux\relax%
173 }%
174
175 \def\gre@close@gaux{%
176 \closeout\gre@gaux %
177 }%
178
179 %%%%%%%%%%%%%%%%%%%
180 %% output directory selection
181 %%%%%%%%%%%%%%%%%%%
182
183 \def\gresetoutputdir#1{%
184 \directlua{gregoriotex.set_base_output_dir([[#1]])}%
185 }%
186
187 %%%%%%%%%%%%%%%
188 %% basic start
189 %%%%%%%%%%%%%%%
190
191 % Used for marking a gabc file read as a dependency
192 \newread\gre@read@temp
193
194 \def\gre@pitch@a{3}%
195 \def\gre@pitch@b{4}%
196 \def\gre@pitch@c{5}%
197 \def\gre@pitch@d{6}%
198 \def\gre@pitch@e{7}%
199 \def\gre@pitch@f{8}%
200 \def\gre@pitch@g{9}%
201 \def\gre@pitch@h{10}%
202 \def\gre@pitch@i{11}%
203 \def\gre@pitch@j{12}%
204 \def\gre@pitch@k{13}%
205 \def\gre@pitch@l{14}%
206 \def\gre@pitch@m{15}%
207 \def\gre@pitch@n{16}%
208 \def\gre@pitch@p{17}%
209
210 \def\gre@pitch@adjust@bottom{\the\numexpr(\gre@space@count@noteadditionalspacelinestextthreshold + \gre@pitch@a)\relax} %
211 \let\gre@pitch@belowstaff\gre@pitch@c %
212 \let\gre@pitch@ledger@below\gre@pitch@b %
213 \let\gre@pitch@barvepisema\gre@pitch@c %
214 \let\gre@pitch@underbrace\gre@pitch@b %
215 \let\gre@pitch@overbraceglyph\gre@pitch@g %
216 \let\gre@pitch@bar\gre@pitch@g %
217 \let\gre@pitch@dummy\gre@pitch@e % not above or below staff, even if 2 lines
218
219 % factor is the factor with which you open you font (the number after the at). It will decide almost everything (spaces, etc.), so it is particularly important.
220 % it is set to the default value : 17 (the value that makes it look like a standard graduale)
221 \newcount\gre@factor%
222 \gre@factor=17%
223
224 %%%%%%%%%%%%%%%%%%%
225 %% vertical spaces
226 %%%%%%%%%%%%%%%%%%%
227
228 \input gregoriotex-spaces.tex%
229
230 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231 %% macros for additionnal vertical spaces
232 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233
234 % macro called to go to the next line
235 \def\GreNewLine{%
236 \gre@debugmsg{lineheight}{GreNewLine}%
237 \gre@newlinecommon{0}{0}%
238 \relax%
239 }%
240
241 % basically same as above, but this one does a \hfill, so the lines are not justified
242 \def\GreNewParLine{%
243 \gre@debugmsg{lineheight}{GreNewParLine}%
244 \gre@newlinecommon{1}{0}%
245 \relax%
246 }%
247
248 \def\GreFinalNewLine{%
249 }%
250
251 % the macro we call each time we force a changing of line
252 % #1 is 0 in case of gabc z, 1 for Z
253 % #2 is 0 in the normal case, 1 after a bar in the new spacing algorithm
254 \def\gre@newlinecommon#1#2{%
255 \gre@trace{gre@newlinecommon{#1}{#2}}%
256 \ifgre@blockeolcustos\ifnum\gre@insidediscretionary=0\relax %
257 \gre@localrightbox{}%
258 \fi\fi %
259 \ifgre@boxing\else%
260 \global\gre@lastoflinecount=2\relax %
261 \ifnum#2=0\relax %
262 % we have to repeat the end of syllable shifts here because the manual line breaks will occur before we get to the regular shifting code in \GreSyllable
263 \ifdim\gre@dimen@enddifference <0pt\relax%
264 %% important, else we are not really at the end of the syllable
265 \kern -\gre@dimen@enddifference\relax%
266 \fi%
267 \ifgre@eolshiftsenabled%
268 \GreNoBreak% we want to make sure this shift doesn't get separated from the previous one if both occur
269 \gre@calculate@eolshift{\gre@dimen@enddifference}%
270 \gre@debugmsg{eolshift}{Manual end of line shift: \the\gre@dimen@eolshift}%
271 \kern -\gre@dimen@eolshift\relax%
272 \fi%
273 \fi %
274 \ifnum\gre@insidediscretionary=0\relax %
275 \gre@updateleftbox %
276 \fi %
277 \ifnum#1=1\relax %
278 \GreNoBreak %
279 \hfill %
280 \fi %
281 \gre@penalty{-10001}%
282 \fi %
283 %%
284 \GreResetEolCustos\relax %
285 \gre@trace@end%
286 }%
287
288 \def\gre@mark@translation{%
289 \gre@trace{gre@mark@translation}%
290 \directlua{gregoriotex.mark_translation()}%
291 \gre@trace@end%
292 }%
293 \def\gre@mark@abovelinestext{%
294 \gre@trace{gre@mark@abovelinestext}%
295 \directlua{gregoriotex.mark_abovelinestext()}%
296 \gre@trace@end%
297 }%
298
299 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
300 %% macros for the typesetting of text
301 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302
303 %% macro that sets \gre@dimen@temp@three to the width of its argument
304
305 \newbox\gre@box@temp@width%
306
307 \def\gre@widthof#1{%
308 \gre@trace{gre@widthof{#1}}%
309 \setbox\gre@box@temp@width=\hbox{#1}%
310 \global\gre@dimen@temp@three=\wd\gre@box@temp@width%
311 \relax%
312 \gre@trace@end%
313 }%
314
315 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316 %% macros for the typesetting of the initial
317 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
318
319 %% box containing the initial, and dimen containing its width (and the width of the space after)
320 \newbox\gre@box@initial%
321
322 % Where the initial appears
323 \newcount\gre@count@initialposition
324 % firsttop (0) = top of first line (that is, the top staff-line)
325 % firstbaseline (1) = baseline of first line
326 % lastbaseline (2) = baseline of last indented line
327 % lastbottom (3) = bottom of last indented line
328 \def\gresetinitialposition#1{%
329 \IfStrEqCase{#1}{%
330 {firsttop}{\gre@count@initialposition=0}%
331 {firstbaseline}{\gre@count@initialposition=1}%
332 {lastbaseline}{\gre@count@initialposition=2}%
333 {lastbottom}{\gre@count@initialposition=3}%
334 }[%
335 \gre@error{Unrecognized option "#1" for \protect\gresetinitialposition\MessageBreak Possible options are: 'firsttop', 'lastbaseline', and 'lastbottom'}%
336 ]%
337 }%
338 \gresetinitialposition{lastbaseline}%
339
340 % What part of the initial is aligned to \gre@count@initialposition:
341 % top (0) = top of initial
342 % baseline (1) = baseline of initial
343 % bottom (2) = bottom of initial
344 \newcount\gre@count@initialanchor
345 \def\gresetinitialanchor#1{%
346 \IfStrEqCase{#1}{%
347 {top}{\gre@count@initialanchor=0}%
348 {baseline}{\gre@count@initialanchor=1}%
349 {bottom}{\gre@count@initialanchor=2}%
350 }[%
351 \gre@error{Unrecognized option "#1" for \protect\gresetinitialanchor\MessageBreak Possible options are: 'top', 'baseline', and 'bottom'}%
352 ]%
353 }%
354 \gresetinitialanchor{baseline}%
355
356 \def\gre@updateleftbox{%
357 \gre@trace{gre@updateleftbox}%
358 \gre@updatelinesclef %
359 \gre@trace@end%
360 }%
361
362 \def\greillumination#1{%
363 \setbox\gre@box@initial=\hbox{#1}%
364 }%
365
366 % Set paragraph shape.
367 % #1: How many lines are indented
368 % #2: The amount of the indentation
369 \def\gre@makeparshape#1#2{%
370 \edef\gre@parshape@dims{\numexpr#1+1\relax}%
371 \gre@count@temp@one=0\relax
372 \loop
373 \edef\gre@parshape@dims{\gre@parshape@dims#2\dimexpr\gre@dimen@linewidth-#2\relax}%
374 \advance\gre@count@temp@one by 1\relax
375 \ifnum\gre@count@temp@one<#1\repeat
376 \parshape\gre@parshape@dims0pt\gre@dimen@linewidth
377 }
378
379 \def\gre@setinitial#1{%
380 \gre@trace{gre@setinitial{#1}}%
381 \gre@debugmsg{annotation}{Time to calculate the true raise.}%
382 \gre@calculate@annotationtrueraise %
383 % we print the initial always at the same place, and then we print the gre@box@annotation, centered
384 % first we print the initial
385 \ifvoid\gre@box@initial%
386 \gre@debugmsg{initial}{Fill initial box a}%
387 \setbox\gre@box@initial=\hbox{\gre@style@initial\gre@fixedtextformat{#1}\endgre@style@initial}%
388 \fi%
389 \gre@debugmsg{ifdim}{ manualinitialwidth = 0pt}%
390 \ifdim\gre@space@dimen@manualinitialwidth=0 pt\relax%
391 \global\gre@dimen@initialwidth=\wd\gre@box@initial %
392 \gre@style@initial%
393 \ifdim\gre@dimen@initialwidth<\gre@space@dimen@minimalinitialwidth\relax%
394 \global\gre@dimen@initialwidth=\gre@space@dimen@minimalinitialwidth\relax%
395 \fi%
396 \endgre@style@initial%
397 \else
398 \gre@style@initial%
399 \global\gre@dimen@initialwidth=\gre@space@dimen@manualinitialwidth\relax%
400 \endgre@style@initial%
401 \fi
402 \gre@debugmsg{ifdim}{ wd(gre@box@annotation) > initialwidth}%
403 \ifdim\wd\gre@box@annotation>\gre@dimen@initialwidth\relax%
404 \global\gre@dimen@initialwidth=\wd\gre@box@annotation%
405 \fi%
406 \gre@debugmsg{annotation}{Width check completed.}%
407 % Now compute the raise
408 \gre@dimen@temp@five = \dimexpr(\gre@dimen@textlower+\gre@space@dimen@initialraise)\relax%
409 \ifnum\gre@count@initialposition=0\relax
410 \advance\gre@dimen@temp@five by
411 \dimexpr(\gre@dimen@staffheight
412 + \gre@space@dimen@spacebeneathtext
413 + \gre@dimen@currenttranslationheight
414 + \gre@space@dimen@spacelinestext
415 + \gre@dimen@additionalbottomspace)\relax%
416 \fi % post_linebreak takes care of the other cases
417 \ifcase\gre@count@initialanchor\relax
418 % top
419 \advance\gre@dimen@temp@five by -\ht\gre@box@initial\relax
420 \or
421 % baseline: do nothing
422 \or
423 % bottom
424 \advance\gre@dimen@temp@five by \dp\gre@box@initial\relax
425 \fi
426 \setbox\gre@box@initial=\hbox to \gre@dimen@initialwidth {\hss\raise \gre@dimen@temp@five\box\gre@box@initial\hss}%
427 \gre@debugmsg{annotation}{Initial set.}%
428 \gre@style@initial%
429 \global\gre@dimen@temp@four = \gre@space@dimen@beforeinitialshift\relax%
430 \endgre@style@initial%
431 \setbox\gre@box@temp@width=\hbox attr \gre@attrid@part=3 {%
432 \gre@hskip\gre@dimen@temp@four %
433 \global\advance\gre@dimen@initialwidth by \gre@dimen@temp@four %
434 \gre@debugmsg{annotation}{Ready to place initial.}%
435 \ifgre@showlyrics%
436 \box\gre@box@initial%
437 \else%
438 \kern\wd\gre@box@initial%
439 \fi%
440 \gre@style@initial%
441 \global\gre@dimen@temp@four = \gre@space@dimen@afterinitialshift\relax%
442 \endgre@style@initial%
443 \gre@hskip\gre@dimen@temp@four %
444 \global\advance\gre@dimen@initialwidth by \gre@dimen@temp@four%
445 }%
446 % Set the paragraph shape. This should happen before anything is printed.
447 \gre@makeparshape{\gre@count@initiallines}{\wd\gre@box@temp@width}%
448 % Set the initial. If it has more than one line, we smash it so it
449 % doesn't disrupt anything, in particular the glue between lines.
450 % The Lua function lower_initial will insert vertical space
451 % appropriately.
452 \ifnum\gre@count@initiallines>1\relax
453 \llap{\smash{\box\gre@box@temp@width}}%
454 \else
455 \llap{\box\gre@box@temp@width}%
456 \fi
457 % then we center the annotation box above the initial, if there is one
458 \gre@debugmsg{annotation}{Time to set the annotation.}%
459 \ifvoid\gre@box@annotation\relax%
460 \gre@debugmsg{annotation}{There is no annotation.}%
461 \else %
462 \gre@debugmsg{annotation}{Calculate horizontal position.}%
463 \gre@dimen@temp@five=\dimexpr((\gre@dimen@initialwidth - \wd\gre@box@annotation) / 2)\relax %
464 \gre@skip@temp@four = -\gre@dimen@initialwidth\relax%
465 \gre@hskip\gre@skip@temp@four %
466 \kern\gre@dimen@temp@five %
467 \gre@debugmsg{annotation}{And place the annotation.}%
468 \raise\gre@dimen@annotationtrueraise\box\gre@box@annotation%
469 \gre@debugmsg{annotation}{Move to beginning of staff.}%
470 \kern\gre@dimen@temp@five %
471 \fi %
472 \relax %
473 \gre@trace@end%
474 }%
475
476 \def\gre@noinitial{%
477 \gre@trace{gre@noinitial}%
478 \setbox\gre@box@initial=\box\voidb@x%
479 \global\gre@dimen@initialwidth=0pt\relax%
480 \relax %
481 \gre@trace@end%
482 }%
483
484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
485 %% macros for the typesetting the things above the initial
486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
487
488 \newbox\gre@box@annotation%
489 \newbox\gre@box@add%
490 \newbox\gre@box@old%
491
492 \def\greannotation{\@ifnextchar[{\gre@annotation}{\gre@annotation[c]}}%
493
494 %This flag controls whether the annotation control line is the top line (false) or the bottom line (true)
495 \newif\ifgre@annotationbottomline%
496 \gre@annotationbottomlinefalse%
497
498 \def\gresetannotationby#1{%
499 \IfStrEqCase{#1}{%
500 {topline}%
501 {\gre@annotationbottomlinefalse}%
502 {bottomline}%
503 {\gre@annotationbottomlinetrue}%
504 }[% all other cases
505 \gre@error{Unrecognized option "#1" for \protect\gresetannotationby\MessageBreak Possible options are: 'topline' and 'bottomline'}%
506 ]%
507 }%
508
509 % This flag controls whether the top (0), baseline (1), or bottom (2) of the control line is aligned with the top line of the staff before applying annotationraise.
510 \newcount\gre@count@annotationvalign%
511 \gre@count@annotationvalign=1%
512
513 \def\gresetannotationvalign#1{%
514 \IfStrEqCase{#1}{%
515 {top}%
516 {\gre@count@annotationvalign=0}%
517 {baseline}%
518 {\gre@count@annotationvalign=1}%
519 {bottom}%
520 {\gre@count@annotationvalign=2}%
521 }[% all other cases
522 \gre@error{Unrecognized option "#1" for \protect\gresetannotationvalign\MessageBreak Possible options are: 'top', 'baseline' and 'bottom'}%
523 ]%
524 }%
525
526 \def\gre@annotation[#1]#2{%
527 \gre@trace{gre@annotation[#1]{#2}}%
528 \ifx l#1\relax%
529 \let\gre@rightfill\hfil%
530 \let\gre@leftfill\relax%
531 \else\ifx r#1\relax%
532 \let\gre@rightfill\relax%
533 \let\gre@leftfill\hfil%
534 \else\ifx c#1\relax%
535 \let\gre@rightfill\hfil%
536 \let\gre@leftfill\hfil%
537 \else%
538 \gre@error{Unrecognzied alignment option for \protect\greannotation}%
539 \fi\fi\fi%
540 % first we determine the widest box
541 \gre@widthof{\gre@style@annotation#2\endgre@style@annotation}%
542 \ifdim\gre@dimen@temp@three < \wd\gre@box@annotation\relax%
543 \gre@dimen@temp@three = \wd\gre@box@annotation\relax%
544 \fi%
545 \ifvoid\gre@box@annotation%
546 \gre@debugmsg{annotation}{We're on the first line of the annotation.}%
547 \setbox\gre@box@annotation = \hbox to \gre@dimen@temp@three{\gre@leftfill\gre@style@annotation#2\endgre@style@annotation\gre@rightfill}%
548 % We set the initial value for annotationtrueraise based on the annotationvalign setting. We always do this because if there is only one line in the annotation, then the topline is the bottomline.
549 \gre@debugmsg{annotation}{Initial set point.}%
550 \ifcase\gre@count@annotationvalign\relax%
551 %case 0 = top of first line
552 \global\gre@dimen@annotationtrueraise=-\ht\gre@box@annotation\relax%
553 \gre@debugmsg{annotation}{Aligning to top of first line: \the\gre@dimen@annotationtrueraise}%
554 \or %case 1 = baseline of first line
555 \global\gre@dimen@annotationtrueraise= 0pt\relax%
556 \gre@debugmsg{annotation}{Aligning to baseline of first line: \the\gre@dimen@annotationtrueraise}%
557 \or %case 2 = bottom of first line
558 \global\gre@dimen@annotationtrueraise=\dp\gre@box@annotation\relax%
559 \gre@debugmsg{annotation}{Aligning to bottom of first line: \the\gre@dimen@annotationtrueraise}%
560 \else% Bug
561 \gre@bug{Invalid value for \protect\gre@count@annotationvalign}%
562 \fi%
563 \else%
564 \gre@debugmsg{annotation}{We're not on the first line of the annotation.}%
565 \setbox\gre@box@old = \hbox to \gre@dimen@temp@three{\gre@leftfill\box\gre@box@annotation\gre@rightfill}%
566 \setbox\gre@box@add = \hbox to \gre@dimen@temp@three{\gre@leftfill\gre@style@annotation#2\endgre@style@annotation\gre@rightfill}%
567 % if the user has asked for the bottom line to be the controlling line, then we need to change the value of the annotationtrueraise appropriately
568 \gre@style@annotation% to make sure that an annotationseparation in font relative units translates correctly
569 \ifgre@annotationbottomline%
570 \ifcase\gre@count@annotationvalign\relax%
571 %case 0 = top of first line
572 \global\gre@dimen@annotationtrueraise=\dimexpr\ht\gre@box@old+\dp\gre@box@old+\gre@space@dimen@annotationseparation-\ht\gre@box@add\relax%
573 \gre@debugmsg{annotation}{Aligning to top of last line: \the\gre@dimen@annotationtrueraise}%
574 \or %case 1 = baseline of first line
575 \global\gre@dimen@annotationtrueraise=\dimexpr\ht\gre@box@old+\dp\gre@box@old+\gre@space@dimen@annotationseparation\relax%
576 \gre@debugmsg{annotation}{Aligning to baseline of last line: \the\gre@dimen@annotationtrueraise}%
577 \or %case 2 = bottom of first line
578 \global\gre@dimen@annotationtrueraise=\dimexpr\ht\gre@box@old+\dp\gre@box@old+\gre@space@dimen@annotationseparation+\dp\gre@box@add\relax%
579 \gre@debugmsg{annotation}{Aligning to bottom of last line: \the\gre@dimen@annotationtrueraise}%
580 \else% Bug
581 \gre@bug{Invalid value for \protect\gre@count@annotationvalign}%
582 \fi%
583 \fi%
584 \endgre@style@annotation%
585 \setbox\gre@box@annotation = \vtop spread \gre@space@dimen@annotationseparation\relax {\offinterlineskip\box\gre@box@old\vss\box\gre@box@add}%
586 \fi%
587 \gre@trace@end%
588 }%
589
590 \def\gre@writemode#1#2#3{%
591 \gre@trace{gre@writemode{#1}{#2}{#3}}%
592 \greannotation{%
593 \gre@style@modeline #1\endgre@style@modeline %
594 \gre@style@modemodifier \directlua{gregoriotex.mode_part("\luatexluaescapestring{#2}")}\endgre@style@modemodifier %
595 \gre@style@modedifferentia \directlua{gregoriotex.mode_part("\luatexluaescapestring{#3}")}\endgre@style@modedifferentia %
596 \relax %
597 }%
598 \relax %
599 \gre@trace@end%
600 }%
601
602 \def\GreMode#1#2#3{%
603 \ifvoid\gre@box@annotation%
604 \gre@writemode{#1}{#2}{#3}%
605 \fi%
606 \relax%
607 }%
608
609 \def\gre@romannumeral@majuscule#1{\uppercase\expandafter{\romannumeral#1\relax}}%
610 \def\gre@romannumeral@minuscule#1{\romannumeral#1\relax}%
611 \def\gresetmodenumbersystem#1{%
612 \IfStrEqCase{#1}{%
613 {roman-majuscule}%
614 {\let\GreModeNumber\gre@romannumeral@majuscule}%
615 {roman-minuscule}%
616 {\let\GreModeNumber\gre@romannumeral@minuscule}%
617 {arabic}%
618 {\let\GreModeNumber\relax}%
619 }[% all other cases
620 \gre@error{Unrecognized option "#1" in \protect\gresetmodenumbersystem\MessageBreak Possible options are: 'roman-majuscule', 'roman-minuscule', and 'arabic'}%
621 ]%
622 }%
623 % defaults set differently for LaTeX and PlainTeX, so see gregoriotex.sty and gregoriotex.tex
624
625 \def\GreAnnotationLines#1#2{%
626 \ifvoid\gre@box@annotation%
627 \greannotation{#1}%
628 \greannotation{#2}%
629 \fi%
630 \relax%
631 }%
632
633 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634 %% macros for the typesetting of the commentary
635 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
636
637 \def\gre@printcommentary{%
638 \gre@trace{gre@printcommentary}%
639 % see comments on this function to see what it does
640 \gre@debugmsg{commentary}{Time to calculate the true raise.}%
641 \gre@calculate@commentarytrueraise%
642 % we start by printing the commentary
643 % when doing this we place it inside a box as which is linewidth wide with an \hfill before to get it to align to the right of the page
644 % we then place that box inside one of 0 width so that our cursor doesn't move when we place the commentary
645 \ifvoid\gre@box@commentary\else%
646 \gre@debugmsg{commentary}{I am printing a commentary box}%
647 \raise\gre@dimen@commentarytrueraise\hbox to 0pt{\hbox attr \gre@attrid@part=1 to \gre@dimen@linewidth{\hfill\box\gre@box@commentary}\hss}%
648 \fi%
649 \gre@trace@end%
650 }
651
652 \newbox\gre@box@commentary
653
654 \def\grecommentary{\@ifnextchar[{\gre@commentary}{\gre@commentary[0pt]}}%
655
656 \def\gre@commentary[#1]#2{%
657 \gre@trace{gre@commentary[#1]{#2}}%
658 % we initialize commentarytrueraise here, but will only calculate it's final value just before placing the commentary so that we make sure we have the correct values for the distances which go into it
659 \gre@style@commentary% to make sure font relative units on the argument translate correctly
660 \global\gre@dimen@commentarytrueraise=#1\relax%
661 \endgre@style@commentary%
662 \ifvoid\gre@box@commentary%
663 \setbox\gre@box@commentary = \hbox{\gre@style@commentary#2\endgre@style@commentary}%
664 \else%
665 \gre@widthof{\gre@style@commentary#2\endgre@style@commentary}%
666 \ifdim\gre@dimen@temp@three < \wd\gre@box@commentary\relax%
667 \gre@dimen@temp@three = \wd\gre@box@commentary%
668 \fi%
669 \setbox\gre@box@old = \hbox to \gre@dimen@temp@three{\hfill\box\gre@box@commentary}%
670 \setbox\gre@box@add = \hbox to \gre@dimen@temp@three{\hfill\gre@style@commentary#2\endgre@style@commentary}%
671 \setbox\gre@box@commentary = \vbox spread \gre@space@dimen@commentaryseparation{\offinterlineskip\box\gre@box@old\vss\box\gre@box@add}%
672 \fi%
673 \gre@trace@end%
674 }
675
676 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
677 %% macro for putting text above lines for annotations and the like
678 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
679
680 % set space above the text lines - almost the same as for the translation
681 \def\gre@addspaceabove{%
682 \gre@trace{gre@addspaceabove}%
683 \gre@style@abovelinestext%
684 \global\gre@dimen@currentabovelinestextheight=\gre@space@dimen@abovelinestextheight\relax%
685 \endgre@style@abovelinestext%
686 \relax %
687 \gre@trace@end%
688 }%
689
690 % we don't need space above any more
691 \def\gre@removespaceabove{%
692 \gre@trace{gre@removespaceabove}%
693 \global\gre@dimen@currentabovelinestextheight=0 sp%
694 \relax %
695 \gre@trace@end%
696 }%
697
698 % the code is a bit strange here: we always execute \gre@space@skip@spaceabovelines at the beginning of a glyph. This will:
699 % - typeset the text above the lines if relevant, and making sure we execute it only once
700 % - not do anything else
701
702 \newif\ifgre@showabovelinestext%
703 \gre@showabovelinestexttrue%
704
705 \def\gresetabovelinestext#1{%
706 \IfStrEqCase{#1}{%
707 {visible}{\gre@showabovelinestexttrue}%
708 {invisible}{\gre@showabovelinestextfalse}%
709 }[% all other cases
710 \gre@error{Unknown option, "#1" for \protect\gresetabovelinestext\MessageBreak Possible options are: 'visible' and 'invisible'}%
711 ]%
712 }%
713
714 \xdef\gre@currenttextabovelines{}%
715
716 \def\GreSetTextAboveLines#1{%
717 \ifgre@showabovelinestext%
718 \gdef\gre@currenttextabovelines{%
719 \gre@typesettextabovelines{#1}{0}%
720 \gdef\gre@currenttextabovelines{}%
721 \relax %
722 }%
723 \fi%
724 }%
725
726 % typesets the text or nabc neumes above the line
727 \def\gre@typesettextabovelines#1#2{%
728 \gre@trace{gre@typesettextabovelines{#1}{#2}}%
729 \gre@style@abovelinestext%
730 \gre@debugmsg{spacing}{Raise alt text: \gre@space@dimen@abovelinestextraise}%
731 \endgre@style@abovelinestext%
732 \ifnum#2=0\relax%
733 \gre@dimen@temp@five=\gre@dimen@additionaltopspacealt\relax%
734 \else%
735 \gre@dimen@temp@five=\gre@dimen@additionaltopspacenabc\relax%
736 \fi%
737 \gre@dimen@temp@five=\dimexpr(\gre@dimen@staffheight %
738 + \gre@dimen@interstafflinespace %
739 + \gre@space@dimen@spacebeneathtext %
740 + \gre@dimen@currenttranslationheight %
741 + \gre@space@dimen@spacelinestext %
742 + \gre@dimen@additionalbottomspace %
743 + \gre@dimen@temp@five %
744 + \gre@space@dimen@abovelinestextraise)\relax%
745 \gre@mark@abovelinestext %
746 \gre@debugmsg{spacing}{Raise alt text: \the\gre@dimen@temp@five}%
747 \leavevmode\raise\gre@dimen@temp@five\hbox to 0pt{\gre@style@abovelinestext#1\endgre@style@abovelinestext\hss}%
748 \relax %
749 \gre@trace@end%
750 }%
751
752 % similarly, but for typesetting Nabc neumes above lines
753
754 \def\GreSetNabcAboveLines#1{%
755 \gdef\gre@currenttextabovelines{%
756 \gre@typesettextabovelines{#1}{1}%
757 \gdef\gre@currenttextabovelines{}%
758 \relax %
759 }%
760 }%
761
762 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
763 %% macros for the typesetting of the lines
764 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
765
766 %% first a macro to prevent the typesetting of the lines (useful for some people)
767 \newif\ifgre@showlines%
768 \gre@showlinestrue
769
770 \def\gresetlines#1{%
771 \IfStrEqCase{#1}{%
772 {visible}%
773 {\gre@showlinestrue}%
774 {invisible}%
775 {\gre@showlinesfalse}%
776 }[% all other cases
777 \gre@error{Unrecognized option "#1" for \protect\gresetlines\MessageBreak Possible options are: 'visible' and 'invisible'}%
778 ]%
779 }
780
781 %% box containing the stafflines for other lines than the first
782 \newbox\gre@box@lines%
783
784 % macro that must be called at each change of linewidth and gre@factor
785 \def\gre@generatelines{%
786 \gre@trace{gre@generatelines}%
787 \setbox\gre@box@lines=\hbox to 0pt{%
788 \vbox attr \gre@attrid@part=2 {%
789 \gre@style@normalstafflines%
790 \vskip\glueexpr(\gre@dimen@additionaltopspace+\gre@space@skip@spaceabovelines+\gre@dimen@currentabovelinestextheight)\relax%
791 \gre@count@temp@one=0\relax
792 \loop
793 \ifgre@showlines %
794 \hrule height \gre@dimen@stafflineheight width \gre@dimen@stafflinewidth\relax%
795 \else %
796 \vskip\gre@dimen@stafflineheight\relax%
797 \fi %
798 \advance\gre@count@temp@one by 1\relax
799 \ifnum\gre@count@temp@one<\gre@count@stafflines
800 \kern\gre@dimen@interstafflinespace\relax
801 \repeat
802 \kern\dimexpr(\gre@space@dimen@spacelinestext+\gre@dimen@additionalbottomspace+\gre@space@dimen@spacebeneathtext+\gre@dimen@currenttranslationheight)\relax%
803 \endgre@style@normalstafflines %
804 }%
805 \hss%
806 }%
807 \relax %
808 \gre@trace@end%
809 }%
810
811 % Macro for fusion of larger neumes
812 \def\GreFuseTwo#1#2{%
813 #1\GreNoBreak #2\relax %
814 }%
815
816 \def\GreFuse{\GreNoBreak}%
817
818 % Macros for using variant glyphs
819
820 % Changes a gregorio code point to a variant glyph
821 % #1 = the name of the gregorio code point
822 % #2 = font name
823 % #3 = glyph name, glyph variant name (preceded by .), or code point
824 \def\grechangeglyph#1#2#3{%
825 \directlua{gregoriotex.init_variant_font([[#2]], true, [[\the\gre@factor]])}%
826 \directlua{gregoriotex.change_score_glyph([[#1]],[[#2]],[[#3]])}%
827 }%
828
829 % Changes a gregorio cavum code point to a variant glyph
830 % #1 = the name of the gregorio code point
831 % #2 = font name for the hollow shape
832 % #3 = glyph name, glyph variant name (preceded by .), or code point for the hollow shape
833 % optional #4 = font name for the hollow shape
834 % optional #5 = glyph name, glyph variant name (preceded by .), or code point for the hollow shape
835 \def\grechangecavumglyph#1#2#3{%
836 \directlua{gregoriotex.init_variant_font([[#2]], true, [[\the\gre@factor]])}%
837 \directlua{gregoriotex.change_score_glyph([[#1]],[[#2]],[[#3]], [[Hollow]])}%
838 \@ifnextchar[{\gre@changecavumhole{#1}}{}%
839 }%
840 \def\gre@changecavumhole#1[#2][#3]{%
841 \gre@trace{gre@changecavumhole{#1}[#2][#3]}%
842 \directlua{gregoriotex.init_variant_font([[#2]], true, [[\the\gre@factor]])}%
843 \directlua{gregoriotex.change_score_glyph([[#1]],[[#2]],[[#3]], [[Hole]])}%
844 \gre@trace@end%
845 }%
846
847 % Resets a gregorio code point to its default setting
848 % #1 = the name of the gregorio code point
849 \def\greresetglyph#1{%
850 \directlua{gregoriotex.reset_score_glyph([[#1]])}%
851 }%
852
853 \def\greresetcavumglyph#1{%
854 \directlua{
855 gregoriotex.reset_score_glyph([[#1]], [[Hollow]])
856 gregoriotex.reset_score_glyph([[#1]], [[Hole]])
857 }%
858 }%
859
860 {%
861 \directlua{
862 gregoriotex.init_variant_font('greciliae', true, [[\the\gre@factor]])
863 gregoriotex.init_variant_font('greciliae-hollow', true, [[\the\gre@factor]])
864 gregoriotex.init_variant_font('greciliae-hole', true, [[\the\gre@factor]])
865 }%
866 \directlua{
867 gregoriotex.map_font('greciliae', 'CP')
868 gregoriotex.map_font('greciliae-hollow', 'HollowCP')
869 gregoriotex.map_font('greciliae-hole', 'HoleCP')
870 }%
871 }%
872
873 \input gregoriotex-chars.tex%
874
875 \input gregoriotex-signs.tex%
876
877 \input gregoriotex-syllable.tex%
878
879 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
880 %% macros for the translations
881 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
882
883 \newif\ifgre@translationcentering
884 \gre@translationcenteringfalse
885
886 \def\gresettranslationcentering#1{%
887 \IfStrEqCase{#1}{%
888 {left}%
889 {\gre@translationcenteringfalse}%
890 {center}%
891 {\gre@translationcenteringtrue}%
892 }[% all other cases
893 \gre@error{Unrecognized option "#1" for \protect\gresettranslationcentering\MessageBreak Possible options are: 'left' and 'center'}%
894 ]%
895 }%
896
897
898 \newif\ifgre@breakintranslation%
899 \gre@breakintranslationfalse%
900
901 \def\gresetbreakintranslation#1{%
902 \IfStrEqCase{#1}{%
903 {allow}%
904 {\gre@breakintranslationtrue}%
905 {prohibit}%
906 {\gre@breakintranslationfalse}%
907 }[% all other cases
908 \gre@error{Unrecognized option "#1" in \protect\gresetbreakintranslation\MessageBreak Possible options are: 'allow' and 'prohibit'}%
909 ]%
910 }%
911
912 \newif\ifgre@showtranslation%
913 \gre@showtranslationtrue%
914
915 \def\gresettranslation#1{%
916 \IfStrEqCase{#1}{%
917 {visible}{\gre@showtranslationtrue}%
918 {invisible}{\gre@showtranslationfalse}%
919 }[% all other cases
920 \gre@error{Unknown option, "#1" for \protect\gresettranslation\MessageBreak Possible options are: 'visible' and 'invisible'}%
921 ]%
922 }%
923
924 \def\GreWriteTranslation#1{%
925 \ifgre@showtranslation%
926 \ifgre@translationcentering %
927 \setbox\gre@box@temp@width=\hbox{#1}%
928 \gre@dimen@temp@five=\dimexpr((\wd\gre@box@syllabletext - \wd\gre@box@temp@width) / 2)\relax%
929 \gre@mark@translation %
930 \kern\gre@dimen@temp@five %
931 \raise\gre@space@dimen@spacebeneathtext\hbox to 0pt{\vbox to 0pt{\vss\hbox to 0pt{\gre@style@translation#1\endgre@style@translation\hss}}}%
932 \kern-\gre@dimen@temp@five %
933 \else %
934 \gre@mark@translation %
935 \raise\gre@space@dimen@spacebeneathtext\hbox to 0pt{\vbox to 0pt{\vss\hbox to 0pt{\gre@style@translation#1\endgre@style@translation\hss}}}%
936 \fi %
937 \fi%
938 }%
939
940 \def\GreWriteTranslationWithCenterBeginning#1{%
941 \ifgre@showtranslation%
942 \ifgre@breakintranslation\else%
943 \GreBeginNLBArea{0}{1}%
944 \fi %
945 \gre@attr@center=1\relax %
946 \gre@mark@translation %
947 \raise\gre@space@dimen@spacebeneathtext\hbox to 0pt{\kern 0pt\vbox to 0pt{\vss\hbox to 0pt{\gre@style@translation#1\endgre@style@translation\hss}}\kern 0pt}%
948 \unsetluatexattribute{\gre@attr@center}%
949 \relax %
950 \fi%
951 }%
952
953 \newif\ifgre@mustdotranslationcenterend%
954 \gre@mustdotranslationcenterendfalse%
955
956 \def\GreTranslationCenterEnd{%
957 \ifgre@showtranslation%
958 \gre@mustdotranslationcenterendtrue%
959 \relax %
960 \fi%
961 }%
962
963 \def\gre@dotranslationcenterend{%
964 \gre@trace{gre@dotranslationcenterend}%
965 \ifgre@breakintranslation\else%
966 \GreEndNLBArea{0}{1}%
967 \fi %
968 \gre@attr@center=2\relax %
969 \raise\gre@space@dimen@spacebeneathtext\hbox to 0pt{}%
970 \unsetluatexattribute{\gre@attr@center}%
971 \relax %
972 \gre@trace@end%
973 }%
974
975
976 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
977 %% other macros
978 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
979
980 \newif\ifgre@justifylastline%
981 \gre@justifylastlinefalse%
982
983 \def\gresetlastline#1{%
984 \IfStrEqCase{#1}{%
985 {justified}%
986 {\gre@justifylastlinetrue}%
987 {ragged}%
988 {\gre@justifylastlinefalse}%
989 }[% all other cases
990 \gre@error{Unrecognized option "#1" for \protect\gresetlastline\MessageBreak Possible options are: 'justified' and 'ragged'}%
991 ]%
992 }%
993
994 % make this a count so that it can be read more easily in Lua
995 \newcount\gre@variableheightexpansion\gre@variableheightexpansion=1\relax %
996 \def\gresetlineheightexpansion#1{%
997 \IfStrEqCase{#1}{%
998 {uniform}%
999 {\gre@variableheightexpansion=0\relax }%
1000 {variable}%
1001 {\gre@variableheightexpansion=1\relax }%
1002 }[% all other cases
1003 \gre@error{Unrecognized option "#1" for \protect\gresetlineheightexpansion\MessageBreak Possible options are: 'uniform' and 'variable'}%
1004 ]%
1005 }%
1006
1007 \newif\ifgre@noteadditionalspacelinestext%
1008 \def\gresetnoteadditionalspacelinestext#1{%
1009 \IfStrEqCase{#1}{%
1010 {automatic}%
1011 {\gre@noteadditionalspacelinestextfalse}%
1012 {manual}%
1013 {\gre@noteadditionalspacelinestexttrue}%
1014 }[% all other cases
1015 \gre@error{Unrecognized option "#1" for \protect\gresetnoteadditionalspacelinestext\MessageBreak Possible options are: 'automatic' and 'manual'}%
1016 ]%
1017 }%
1018 \gresetnoteadditionalspacelinestext{automatic}%default setting
1019
1020 % gre@attr@dash (see its definition in gregorio-syllable) is 0 when we are in a score, and unset when we are not
1021
1022 \newif\ifgre@beginningofscore%
1023
1024 \newcount\gre@count@stafflines
1025 \def\gre@setstafflines#1{%
1026 \gre@trace{gre@setstafflines{#1}}%
1027 \gre@count@stafflines=#1\relax
1028 \ifcase#1% 0
1029 \gre@error{Invalid number of staff lines}%
1030 \or % 1
1031 \gre@error{Invalid number of staff lines}%
1032 \or % 2
1033 \let\gre@pitch@adjust@top\gre@pitch@f %
1034 \let\gre@pitch@abovestaff\gre@pitch@g %
1035 \let\gre@pitch@ledger@above\gre@pitch@h %
1036 \let\gre@pitch@raresign\gre@pitch@g %
1037 \let\gre@pitch@overbrace\gre@pitch@i %
1038 \let\gre@char@bar@virgula\GreCPVirgulaTwo %
1039 \let\gre@char@bar@virgulahigh\GreCPVirgulaThree %
1040 \let\gre@char@bar@virgulaparen\GreCPVirgulaParenTwo %
1041 \let\gre@char@bar@virgulaparenhigh\GreCPVirgulaParenThree %
1042 \let\gre@char@bar@divisiominimis\GreCPDivisioMinimisTwo %
1043 \let\gre@char@bar@divisiominimishigh\GreCPDivisioMinimisThree %
1044 \let\gre@char@bar@divisiominima\GreCPDivisioMinimaTwo %
1045 \let\gre@char@bar@divisiominimahigh\GreCPDivisioMinimaThree %
1046 \let\gre@char@bar@divisiominimaparen\GreCPDivisioMinimaParenTwo %
1047 \let\gre@char@bar@divisiominimaparenhigh\GreCPDivisioMinimaParenThree %
1048 \let\gre@char@bar@divisiominor\GreCPDivisioMinorTwo %
1049 \let\gre@char@bar@divisiomaior\GreCPDivisioMaiorTwo %
1050 \let\gre@char@bar@divisiomaiordotted\GreCPDivisioMaiorDottedTwo %
1051 \let\gre@char@bar@divisiomaiordottedbacking\GreCPDivisioMaiorDottedBackingTwo %
1052 \or % 3
1053 \let\gre@pitch@adjust@top\gre@pitch@h %
1054 \let\gre@pitch@abovestaff\gre@pitch@i %
1055 \let\gre@pitch@ledger@above\gre@pitch@j %
1056 \let\gre@pitch@raresign\gre@pitch@i %
1057 \let\gre@pitch@overbrace\gre@pitch@k %
1058 \let\gre@char@bar@virgula\GreCPVirgulaThree %
1059 \let\gre@char@bar@virgulahigh\GreCPVirgulaFour %
1060 \let\gre@char@bar@virgulaparen\GreCPVirgulaParenThree %
1061 \let\gre@char@bar@virgulaparenhigh\GreCPVirgulaParenFour %
1062 \let\gre@char@bar@divisiominimis\GreCPDivisioMinimisThree %
1063 \let\gre@char@bar@divisiominimishigh\GreCPDivisioMinimisFour %
1064 \let\gre@char@bar@divisiominima\GreCPDivisioMinimaThree %
1065 \let\gre@char@bar@divisiominimahigh\GreCPDivisioMinimaFour %
1066 \let\gre@char@bar@divisiominimaparen\GreCPDivisioMinimaParenThree %
1067 \let\gre@char@bar@divisiominimaparenhigh\GreCPDivisioMinimaParenFour %
1068 \let\gre@char@bar@divisiominor\GreCPDivisioMinorThree %
1069 \let\gre@char@bar@divisiomaior\GreCPDivisioMaiorThree %
1070 \let\gre@char@bar@divisiomaiordotted\GreCPDivisioMaiorDottedThree %
1071 \let\gre@char@bar@divisiomaiordottedbacking\GreCPDivisioMaiorDottedBackingThree %
1072 \or % 4
1073 \let\gre@pitch@adjust@top\gre@pitch@j %
1074 \let\gre@pitch@abovestaff\gre@pitch@k %
1075 \let\gre@pitch@ledger@above\gre@pitch@l %
1076 \let\gre@pitch@raresign\gre@pitch@k %
1077 \let\gre@pitch@overbrace\gre@pitch@m %
1078 \let\gre@char@bar@virgula\GreCPVirgulaFour %
1079 \let\gre@char@bar@virgulahigh\GreCPVirgulaFive %
1080 \let\gre@char@bar@virgulaparen\GreCPVirgulaParenFour %
1081 \let\gre@char@bar@virgulaparenhigh\GreCPVirgulaParenFive %
1082 \let\gre@char@bar@divisiominimis\GreCPDivisioMinimisFour %
1083 \let\gre@char@bar@divisiominimishigh\GreCPDivisioMinimisFive %
1084 \let\gre@char@bar@divisiominima\GreCPDivisioMinimaFour %
1085 \let\gre@char@bar@divisiominimahigh\GreCPDivisioMinimaFive %
1086 \let\gre@char@bar@divisiominimaparen\GreCPDivisioMinimaParenFour %
1087 \let\gre@char@bar@divisiominimaparenhigh\GreCPDivisioMinimaParenFive %
1088 \let\gre@char@bar@divisiominor\GreCPDivisioMinorFour %
1089 \let\gre@char@bar@divisiomaior\GreCPDivisioMaiorFour %
1090 \let\gre@char@bar@divisiomaiordotted\GreCPDivisioMaiorDottedFour %
1091 \let\gre@char@bar@divisiomaiordottedbacking\GreCPDivisioMaiorDottedBackingFour %
1092 \or % 5
1093 \let\gre@pitch@adjust@top\gre@pitch@l %
1094 \let\gre@pitch@abovestaff\gre@pitch@m %
1095 \let\gre@pitch@ledger@above\gre@pitch@n %
1096 \let\gre@pitch@raresign\gre@pitch@m %
1097 \let\gre@pitch@overbrace\gre@pitch@p %
1098 \let\gre@char@bar@virgula\GreCPVirgulaFive %
1099 \let\gre@char@bar@virgulahigh\GreCPVirgulaSix %
1100 \let\gre@char@bar@virgulaparen\GreCPVirgulaParenFive %
1101 \let\gre@char@bar@virgulaparenhigh\GreCPVirgulaParenSix %
1102 \let\gre@char@bar@divisiominimis\GreCPDivisioMinimisFive %
1103 \let\gre@char@bar@divisiominimishigh\GreCPDivisioMinimisSix %
1104 \let\gre@char@bar@divisiominima\GreCPDivisioMinimaFive %
1105 \let\gre@char@bar@divisiominimahigh\GreCPDivisioMinimaSix %
1106 \let\gre@char@bar@divisiominimaparen\GreCPDivisioMinimaParenFive %
1107 \let\gre@char@bar@divisiominimaparenhigh\GreCPDivisioMinimaParenSix %
1108 \let\gre@char@bar@divisiominor\GreCPDivisioMinorFive %
1109 \let\gre@char@bar@divisiomaior\GreCPDivisioMaiorFive %
1110 \let\gre@char@bar@divisiomaiordotted\GreCPDivisioMaiorDottedFive %
1111 \let\gre@char@bar@divisiomaiordottedbacking\GreCPDivisioMaiorDottedBackingFive %
1112 \else %
1113 \gre@error{Invalid number of staff lines}%
1114 \fi %
1115 \gre@trace@end%
1116 }%
1117
1118 %macro called at the beginning of a score
1119 % #1 is the gabc score id
1120 % #2 is the high height
1121 % #3 is the low height
1122 % #4 is 1 if there is a translation somewhere
1123 % #5 is if 1 if we have space above the staff
1124 % #6 is the point-and-click filename
1125 % #7 is the number of staff lines
1126 % #8 is to set the initial clef position
1127 \def\GreBeginScore#1#2#3#4#5#6#7#8{%
1128 % scores must be new paragraphs!
1129 \ifhmode\par\fi %
1130 \gre@beginningofscoretrue%
1131 \global\gre@dimen@morawidth=0pt\relax %
1132 \GreResetEolCustos%
1133 \gre@resetledgerlineheuristics%
1134 \global\setluatexattribute\gre@attr@glyph@id{0}%
1135 \global\setluatexattribute\gre@attr@syllable@id{0}%
1136 \global\setluatexattribute\gre@attr@alteration@id{0}%
1137 \let\gre@pitch@cleftop\gre@pitch@dummy %
1138 \let\gre@pitch@clefbottom\gre@pitch@dummy %
1139 \xdef\gre@gabcname{#6}%
1140 \gre@setstafflines{#7}%
1141 \ifgre@justifylastline%
1142 \xdef\gre@saved@parfillskip{\the\parfillskip}%
1143 \parfillskip=0pt plus 0pt minus 0pt\relax%
1144 \fi %
1145 \ifgre@usestylefont%
1146 \gre@setstylefont %
1147 \fi %
1148 \gre@computespaces%
1149 \gre@cancelpenalties %
1150 \gre@attr@dash=0\relax %
1151 \gre@generatelines %
1152 \noindent%
1153 \gre@calculate@additionalspaces{#2}{#3}{#4}{#5}%
1154 #8%
1155 \directlua{
1156 gregoriotex.at_score_beginning([[#1]], #2, #3, #4, #5,
1157 \gre@pitch@adjust@top, \gre@pitch@adjust@bottom,
1158 "\luatexluaescapestring{\gre@gregoriofontname}")
1159 gregoriotex.adjust_line_height(1)
1160 }%
1161 %TODO do something like LaTeX's AtBeginDocument
1162 \ifdefined\optgabcAtScoreBeginning %
1163 \optgabcAtScoreBeginning %
1164 \fi %
1165 \global\gre@lastoflinecount=2\relax %
1166 \global\gre@endofscorefalse %
1167 \relax%
1168 }%
1169
1170 %macro called at the end of a score
1171 \def\GreEndScore{%
1172 \global\gre@lastoflinecount=0\relax %
1173 \gre@useautoeolcustos%
1174 \GreEndEUOUAE{}%
1175 \ifnum\gre@nlbstate=0\else %
1176 \GreEndNLBArea{2}{0}%
1177 \fi %
1178 \gre@localleftbox{}%
1179 \ifgre@keeprightbox\else %
1180 \gre@localrightbox{}%
1181 \fi %
1182 \hfil %
1183 \par %
1184 \ifgre@keeprightbox%
1185 \global\gre@keeprightboxfalse%
1186 \fi%
1187 % with some versions of LuaTeX, the \localrightbox and \localleftbox must be set empty in an environment with the good attributes set
1188 \gre@localleftbox{}%
1189 \gre@localrightbox{}%
1190 \gre@calculate@additionalspaces{\gre@pitch@dummy}{\gre@pitch@dummy}{0}{0}%
1191 \global\gre@dimen@currentabovelinestextheight=0 sp%
1192 \gre@removetranslationspace %
1193 \gre@restorepenalties %
1194 \gre@dimen@temp@one=0pt\relax%
1195 \gre@dimen@temp@two=0pt\relax%
1196 \gre@dimen@temp@three=0pt\relax%
1197 \gre@dimen@temp@four=0pt\relax%
1198 \gre@dimen@temp@five=0pt\relax%
1199 \gre@skip@temp@one=0pt\relax%
1200 \gre@skip@temp@two=0pt\relax%
1201 \gre@skip@temp@three=0pt\relax%
1202 \gre@skip@temp@four=0pt\relax%
1203 \setbox\gre@box@annotation=\box\voidb@x%
1204 \setbox\gre@box@commentary=\box\voidb@x%
1205 \directlua{gregoriotex.at_score_end()}%
1206 \unsetluatexattribute{\gre@attr@glyph@id}%
1207 \unsetluatexattribute{\gre@attr@glyph@top}%
1208 \unsetluatexattribute{\gre@attr@glyph@bottom}%
1209 \unsetluatexattribute{\gre@attr@dash}%
1210 \xdef\gre@bolshiftcleftypelocal{\gre@bolshiftcleftypeglobal}%
1211 \ifgre@justifylastline%
1212 \parfillskip=\gre@saved@parfillskip\relax%
1213 \fi %
1214 \global\setluatexattribute\gre@attr@glyph@id{0}%
1215 \relax%
1216 }%
1217
1218 % macro called at the end of a bar (old bar spacing algorithm only).
1219 \def\gre@endafterbar#1{%
1220 \gre@trace{gre@endafterbar{#1}}%
1221 \gre@penalty{\the\gre@space@count@endafterbarpenalty }\relax %
1222 \ifnum#1=1\relax %
1223 \gre@debugmsg{ifdim}{ enddifference > 0pt}%
1224 \ifdim\gre@dimen@enddifference > 0 pt\relax%
1225 \gre@debugmsg{ifdim}{ nextbegindifference > 0pt}%
1226 \ifdim\gre@skip@nextbegindifference > 0 pt\relax%
1227 \gre@skip@temp@four = \gre@space@skip@notebarspace\relax%
1228 \gre@hskip\gre@skip@temp@four %
1229 \else % (next begin difference >0pt)
1230 \gre@skip@temp@four = \gre@space@skip@textbartextspace\relax%
1231 \gre@hskip\gre@skip@temp@four %
1232 \fi %
1233 \else%(enddifference < 0pt)
1234 \gre@debugmsg{ifdim}{ nextbegindifference < 0pt}%
1235 \ifdim\gre@skip@nextbegindifference < 0 pt\relax%
1236 \gre@skip@temp@four = \gre@space@skip@textbartextspace\relax%
1237 \gre@hskip\gre@skip@temp@four %
1238 \else %(next begin difference < 0 pt)
1239 \gre@skip@temp@four = \gre@space@skip@interwordspacetext\relax%
1240 \gre@hskip\gre@skip@temp@four %
1241 \fi %
1242 \fi %
1243 \fi %
1244 %\gre@penalty{\the\gre@space@count@endafterbarpenalty }\relax
1245 %\global\gre@dimen@enddifference=0pt
1246 \relax %
1247 \gre@trace@end%
1248 }%
1249
1250 \newcount\gre@lastoflinecount%
1251
1252 % called at syllable level. Indicates that the syllable is the last of the line (or score)
1253 % 0 if nothing
1254 % 1 if the syllable is the last of the line
1255 % 2 after it has finished the syllable, so when it is two it means that the syllable is the first of a line
1256 \def\GreLastOfLine{%
1257 \global\gre@lastoflinecount=1\relax%
1258 \gre@debugmsg{eolshift}{set lastoflinecount to 1}%
1259 \relax%
1260 }%
1261
1262 % Flag to mark the last syllable of the score
1263 \newif\ifgre@endofscore%
1264 \gre@endofscorefalse%
1265
1266 % called at element level, before the final element
1267 \def\GreLastOfScore{%
1268 %\gre@localleftbox{}% For an unknown reason, if I uncomment this line, the
1269 %blank line removing algorithm (in lua) will let some blank space after the
1270 %last line... (see bug #20953)
1271 \global\gre@endofscoretrue %
1272 \GreSuppressEolCustos%
1273 \gre@debugmsg{eolshift}{set lastoflinecount to 1}%
1274 \relax%
1275 }%
1276
1277 % a flag to disable (or reenable) the left shift for first syllables of lines
1278 \newif\ifgre@bolshiftsenabled%
1279 % default state is for them to be enabled
1280 \gre@bolshiftsenabledtrue
1281
1282 \def\gresetbolshifts#1{%
1283 \IfStrEqCase{#1}{%
1284 {enable}%
1285 {\gre@bolshiftsenabledtrue}%
1286 {disable}%
1287 {\gre@bolshiftsenabledfalse}%
1288 }[% all other cases
1289 \gre@error{Unrecognized option "#1" in \protect\gresetbolshifts\MessageBreak Possible options are: 'enable' and 'disable'}%
1290 ]%
1291 }%
1292
1293 % a flag to disable (or reenable) the shift for last syllables of lines
1294 % when the shifts are enabled lyrics cannot extend under (or past) the custos at the end of a line
1295 \newif\ifgre@eolshiftsenabled%
1296 % default state is for them to be enabled
1297 \gre@eolshiftsenabledtrue
1298
1299 \def\greseteolshifts#1{%
1300 \IfStrEqCase{#1}{%
1301 {enable}%
1302 {\gre@eolshiftsenabledtrue}%
1303 {disable}%
1304 {\gre@eolshiftsenabledfalse}%
1305 }[% all other cases
1306 \gre@error{Unrecognized option "#1" in \protect\greseteolshifts\MessageBreak Possible options are: 'enable' and 'disable'}%
1307 ]%
1308 }%
1309
1310
1311 % Flag indicating if we block the custos. We just block custos at the end of a score, to prevent a bug.
1312 \newif\ifgre@blockeolcustos%
1313 \def\GreSuppressEolCustos{%
1314 \gre@blockeolcustostrue%
1315 \gre@localrightbox{}%
1316 }%
1317 \def\gre@useautoeolcustos{%
1318 \gre@trace{gre@useautoeolcustos}%
1319 \gre@blockeolcustosfalse%
1320 \gre@trace@end%
1321 }%
1322 \def\greseteolcustos#1{%
1323 \IfStrEqCase{#1}{%
1324 {manual}%
1325 {\global\let\GreResetEolCustos\GreSuppressEolCustos\relax}%
1326 {auto}%
1327 {\global\let\GreResetEolCustos\gre@useautoeolcustos\relax}%
1328 }[% all other cases
1329 \gre@error{Unrecognized option "#1" for \protect\greseteolcustos\MessageBreak Possible options are: 'manual' and 'auto'}%
1330 ]%
1331 }%
1332 \greseteolcustos{auto}%
1333
1334 \newif\ifgre@blockeolcustosbeforeeuouae%
1335 \def\greseteolcustosbeforeeuouae#1{%
1336 \IfStrEqCase{#1}{%
1337 {suppressed}%
1338 {\gre@blockeolcustosbeforeeuouaetrue\relax}%
1339 {auto}%
1340 {\gre@blockeolcustosbeforeeuouaefalse\relax}%
1341 }[% all other cases
1342 \gre@error{Unrecognized option "#1" for \protect\greseteolcustosbeforeeuouae\MessageBreak Possible options are: 'suppressed' and 'auto'}%
1343 ]%
1344 }%
1345 \greseteolcustosbeforeeuouae{suppressed}%
1346
1347 \newif\ifgre@raggedbreakbeforeeuouae%
1348 \def\gresetbreakbeforeeuouae#1{%
1349 \IfStrEqCase{#1}{%
1350 {ragged}%
1351 {\gre@raggedbreakbeforeeuouaetrue\relax}%
1352 {justified}%
1353 {\gre@raggedbreakbeforeeuouaefalse\relax}%
1354 }[% all other cases
1355 \gre@error{Unrecognized option "#1" for \protect\greseteolcustosbeforeeuouae\MessageBreak Possible options are: 'ragged' and 'justified'}%
1356 ]%
1357 }%
1358 \gresetbreakbeforeeuouae{justified}%
1359
1360 \def\GreAdHocSpaceEndOfElement#1#2#3{%
1361 \gre@skip@temp@four = \gre@space@skip@interelementspace\relax %
1362 \directlua{gregoriotex.scale_space(#1)}%
1363 \GreEndOfElement{4}{#2}{#3}%
1364 }%
1365
1366 \newif\ifgre@unbreakableendofelement %
1367 \def\gresetunisonbreakbehavior#1{%
1368 \IfStrEqCase{#1}{%
1369 {breakable}%
1370 {\global\let\gre@unbreakableendofelement@unison\gre@unbreakableendofelementfalse\relax}%
1371 {unbreakable}%
1372 {\global\let\gre@unbreakableendofelement@unison\gre@unbreakableendofelementtrue\relax}%
1373 }[% all other cases
1374 \gre@error{Unrecognized option "#1" for \protect\gresetunisonbreakbehavior\MessageBreak Possible options are: 'breakable' and 'unbreakable'}%
1375 ]%
1376 }%
1377 \gresetunisonbreakbehavior{breakable}
1378
1379 % macro to end elements, #1 is the type of space, it can be :
1380 %% 0: default space
1381 %% 1: larger space
1382 %% 2: glyph space
1383 %% 3: zero-width space
1384 %% 4: custom space
1385 % #2 is whether the space is breakable :
1386 %% 0: breakable
1387 %% 1: unbreakable
1388 %% 2: unison (breakable according to the unisonbreakbehavior setting)
1389 % #3 is the number of notes emitted in this syllable before this macro
1390 \def\GreEndOfElement#1#2#3{%
1391 \ifnum\gre@count@syllablenotes<\gre@count@unbreakabletotalnotes\relax %
1392 \gre@unbreakableendofelementtrue %
1393 \else %
1394 \ifnum#3<\gre@count@unbreakableinitialnotes\relax %
1395 \gre@unbreakableendofelementtrue %
1396 \else %
1397 \ifnum\numexpr\gre@count@syllablenotes-#3\relax<%
1398 \gre@count@unbreakablefinalnotes\relax %
1399 \gre@unbreakableendofelementtrue %
1400 \else %
1401 \ifcase#2\relax %
1402 \gre@unbreakableendofelementfalse %
1403 \or% case 1
1404 \gre@unbreakableendofelementtrue %
1405 \or% case 2
1406 \gre@unbreakableendofelement@unison %
1407 \else %
1408 \gre@error{Unrecognized breakable argument #2}%
1409 \fi %
1410 \fi %
1411 \fi %
1412 \fi %
1413 \ifgre@unbreakableendofelement %
1414 \GreNoBreak %
1415 \else %
1416 \gre@penalty{\the\gre@space@count@endofelementpenalty}%
1417 \fi %
1418 \ifcase#1\relax%
1419 \gre@skip@temp@four = \gre@space@skip@interelementspace\relax%
1420 \gre@hskip\gre@skip@temp@four %
1421 \or% case 1
1422 \gre@skip@temp@four = \gre@space@skip@largerspace\relax%
1423 \gre@hskip\gre@skip@temp@four %
1424 \or% case 2
1425 \gre@skip@temp@four = \gre@space@skip@glyphspace\relax%
1426 \gre@hskip\gre@skip@temp@four %
1427 \or% case 3
1428 \gre@skip@temp@four = \gre@space@skip@zerowidthspace\relax%
1429 \gre@hskip\gre@skip@temp@four %
1430 \or% case 4
1431 \gre@hskip\gre@skip@temp@four %
1432 \else%
1433 \gre@error{Unrecognized space type #1}%
1434 \fi%
1435 \ifgre@unbreakableendofelement %
1436 \GreNoBreak %
1437 \fi %
1438 \relax%
1439 }%
1440
1441 % puts the correct skip value into \gre@skip@temp@four for the desired type of space
1442 %% 0: default space
1443 %% 1: zero width space
1444 %% 2: space between flat or natural and a note
1445 %% 3: space between two puncta inclinata
1446 %% 7: space between a punctum inclinatum and a punctum inclinatum deminutus
1447 %% 8: space between two puncta inclinata deminuti
1448 %% 4: space between bivirga or trivirga
1449 %% 5: space between bistropha or tristropha
1450 %% 6: space after a punctum mora XXX: not used yet, not so sure it is a good idea...
1451 %% 7: space between a punctum inclinatum and a punctum inclinatum debilis
1452 %% 8: space between two puncta inclinata debilis
1453 %% 9: space before a punctum (or something else) and a punctum inclinatum
1454 %% 10: space between puncta inclinata (also debilis for now), larger ambitus (range=3rd).
1455 %% 11: space between puncta inclinata (also debilis for now), larger ambitus (range=4th or 5th)
1456 %% 12: ascending version of 3
1457 %% 13: ascending version of 7
1458 %% 14: ascending version of 10
1459 %% 15: ascending version of 11
1460 %% 16: space between a punctum inclinatum and a "no-bar" glyph one pitch below
1461 %% 17: space between a punctum inclinatum and a "no-bar" glyph two pitches below
1462 %% 18: space between a punctum inclinatum and a "no-bar" glyph three or four pitches below
1463 %% 19: space between a punctum inclinatum and a "no-bar" glyph one pitch above
1464 %% 20: space between a punctum inclinatum and a "no-bar" glyph two pitches above
1465 %% 21: space between a punctum inclinatum and a "no-bar" glyph three or four pitches above
1466 %% 22: half-space
1467 %% 23: Space between two puncta inclinata on a unison
1468 %% 24: Space before a right-leaning puncta inclinatum when the pitch is ascending (up to 4 pitches away)
1469 %% 25: Space before a left-leaning puncta inclinatum when the pitch is descending (up to 4 pitches away)
1470 %% 26: Space after after a non-punctum inclinatum and before the upright punctum inclinatum
1471 \def\gre@get@spaceskip#1{%
1472 \gre@trace{gre@get@spaceskip{#1}}%
1473 \ifcase#1%
1474 \gre@skip@temp@four = \gre@space@skip@interglyphspace\relax%
1475 \or% case 1
1476 \gre@skip@temp@four = \gre@space@dimen@zerowidthspace\relax%
1477 \or% case 2
1478 \gre@skip@temp@four = \gre@space@dimen@alterationspace\relax%
1479 \or% case 3
1480 \gre@skip@temp@four = \gre@space@skip@punctuminclinatumshift\relax%
1481 \or% case 4
1482 \gre@skip@temp@four = \gre@space@skip@bitrivirspace\relax%
1483 \or% case 5
1484 \gre@skip@temp@four = \gre@space@skip@bitristrospace\relax%
1485 \or% case 6
1486 \gre@skip@temp@four = \gre@space@skip@spaceaftersigns\relax%
1487 \or% case 7
1488 \gre@skip@temp@four = \gre@space@skip@punctuminclinatumanddebilisshift\relax%
1489 \or% case 8
1490 \gre@skip@temp@four = \gre@space@skip@punctuminclinatumdebilisshift\relax%
1491 \or% case 9
1492 \gre@skip@temp@four = \gre@space@skip@beforepunctainclinatashift\relax%
1493 \or% case 10
1494 \gre@skip@temp@four = \gre@space@skip@punctuminclinatumbigshift\relax%
1495 \or% case 11
1496 \gre@skip@temp@four = \gre@space@skip@punctuminclinatummaxshift\relax%
1497 \or% case 12 (ascending version of 3)
1498 \gre@skip@temp@four = \gre@space@skip@ascendingpunctuminclinatumshift\relax%
1499 \or% case 13 (ascending version of 7)
1500 \gre@skip@temp@four = \gre@space@skip@ascendingpunctuminclinatumanddebilisshift\relax%
1501 \or% case 14 (ascending version of 10)
1502 \gre@skip@temp@four = \gre@space@skip@ascendingpunctuminclinatumbigshift\relax%
1503 \or% case 15 (ascending version of 11)
1504 \gre@skip@temp@four = \gre@space@skip@ascendingpunctuminclinatummaxshift\relax%
1505 \or% case 16
1506 \gre@skip@temp@four = \gre@space@skip@descendinginclinatumtonobarshift\relax%
1507 \or% case 17
1508 \gre@skip@temp@four = \gre@space@skip@descendinginclinatumtonobarbigshift\relax%
1509 \or% case 18
1510 \gre@skip@temp@four = \gre@space@skip@descendinginclinatumtonobarmaxshift\relax%
1511 \or% case 19
1512 \gre@skip@temp@four = \gre@space@skip@ascendinginclinatumtonobarshift\relax%
1513 \or% case 20
1514 \gre@skip@temp@four = \gre@space@skip@ascendinginclinatumtonobarbigshift\relax%
1515 \or% case 21
1516 \gre@skip@temp@four = \gre@space@skip@ascendinginclinatumtonobarmaxshift\relax%
1517 \or% case 22
1518 \gre@skip@temp@four = \gre@space@skip@halfspace\relax%
1519 \or% case 23
1520 \gre@skip@temp@four = \gre@space@skip@punctuminclinatumunisonshift\relax%
1521 \or% case 24
1522 \gre@skip@temp@four = \gre@space@skip@descendingpunctuminclinatumascendingshift\relax%
1523 \or% case 25
1524 \gre@skip@temp@four = \gre@space@skip@ascendingpunctuminclinatumdescendingshift\relax%
1525 \or% case 26
1526 \gre@skip@temp@four = \gre@space@skip@uprightpunctuminclinatumshift\relax%
1527 \else%
1528 \gre@error{Unrecognized spaceskip #1}%
1529 \fi%
1530 \gre@trace@end%
1531 }%
1532
1533 % macro to end a glyph without ending the element
1534 % see \gre@get@glyphskip for the valus of the argument
1535 \def\GreEndOfGlyph#1{%
1536 \GreNoBreak %
1537 \gre@get@spaceskip{#1}%
1538 \gre@hskip\gre@skip@temp@four %
1539 \GreNoBreak %
1540 \relax%
1541 }%
1542
1543 % The different states of line break areas:
1544 % 0: not currently in a no line break area
1545 % 1: no line break area due to translation centering
1546 % 2: no line break area due to <nlba> tag
1547 \xdef\gre@nlbstate{0}%
1548
1549 \newcount\gre@saved@prenlba@nobreakpenalty%
1550 \newcount\gre@saved@prenlba@endofwordpenalty%
1551 \newcount\gre@saved@prenlba@endofsyllablepenalty%
1552 \newcount\gre@saved@prenlba@endafterbarpenalty%
1553 \newcount\gre@saved@prenlba@endafterbaraltpenalty%
1554 \newcount\gre@saved@prenlba@endofelementpenalty%
1555 \newcount\gre@saved@prenlba@hyphenpenalty%
1556 % first argument is if if the nlba is starting in neumes or not
1557 % second argument is if it is called from translation centering or not
1558 \def\GreBeginNLBArea#1#2{%
1559 \xdef\gre@nlbinitialstate{\gre@nlbstate}%
1560 \ifnum#2=0\relax %
1561 \xdef\gre@nlbstate{2}%
1562 \else %
1563 \ifcase\gre@nlbstate %
1564 \xdef\gre@nlbstate{1}%
1565 \or %
1566 \xdef\gre@nlbstate{1}%
1567 \or %
1568 \xdef\gre@nlbstate{2}%
1569 \fi %
1570 \fi %
1571 \ifnum\gre@nlbinitialstate=0\relax %
1572 \global\gre@saved@prenlba@nobreakpenalty=\gre@space@count@nobreakpenalty\relax %
1573 \global\gre@space@count@nobreakpenalty=10001\relax %
1574 %
1575 \global\gre@saved@prenlba@endofwordpenalty=\gre@space@count@endofwordpenalty\relax %
1576 \global\gre@space@count@endofwordpenalty=10001\relax %
1577 %
1578 \global\gre@saved@prenlba@endofsyllablepenalty=\gre@space@count@endofsyllablepenalty\relax %
1579 \global\gre@space@count@endofsyllablepenalty=10001\relax %
1580 %
1581 \global\gre@saved@prenlba@endafterbarpenalty=\gre@space@count@endafterbarpenalty\relax %
1582 \global\gre@space@count@endafterbarpenalty=10001\relax %
1583 %
1584 \global\gre@saved@prenlba@endafterbaraltpenalty=\gre@space@count@endafterbaraltpenalty\relax %
1585 \global\gre@space@count@endafterbaraltpenalty=10001\relax %
1586 %
1587 \global\gre@saved@prenlba@endofelementpenalty=\gre@space@count@endofelementpenalty\relax %
1588 \global\gre@space@count@endofelementpenalty=10001\relax %
1589 %
1590 \global\gre@saved@prenlba@hyphenpenalty=\gre@space@count@hyphenpenalty\relax %
1591 \global\gre@space@count@hyphenpenalty=10001\relax %
1592 \fi %
1593 }%
1594
1595 \def\GreEndNLBArea#1#2{%
1596 \xdef\gre@nlbinitialstate{\gre@nlbstate}%
1597 \ifnum#2=0\relax %
1598 \xdef\gre@nlbstate{0}%
1599 \else %
1600 \ifcase\gre@nlbstate %
1601 \xdef\gre@nlbstate{0}%
1602 \or %
1603 \xdef\gre@nlbstate{0}%
1604 \or %
1605 \xdef\gre@nlbstate{2}%
1606 \fi %
1607 \fi %
1608 % if gre@nlbstate is not 0, then nothing should happend
1609 \ifnum\gre@nlbstate=0\relax %
1610 \ifnum\gre@nlbinitialstate=0\else %
1611 \global\gre@space@count@nobreakpenalty=\gre@saved@prenlba@nobreakpenalty\relax %
1612 \global\gre@space@count@endofwordpenalty=\gre@saved@prenlba@endofwordpenalty\relax %
1613 \global\gre@space@count@endofsyllablepenalty=\gre@saved@prenlba@endofsyllablepenalty\relax %
1614 \global\gre@space@count@endafterbarpenalty=\gre@saved@prenlba@endafterbarpenalty\relax %
1615 \global\gre@space@count@endafterbaraltpenalty=\gre@saved@prenlba@endafterbaraltpenalty\relax %
1616 \global\gre@space@count@endofelementpenalty=\gre@saved@prenlba@endofelementpenalty\relax %
1617 \global\gre@space@count@hyphenpenalty=\gre@saved@prenlba@hyphenpenalty\relax %
1618 \ifcase #1\relax % 0
1619 \gre@penalty{\the\gre@space@count@endofelementpenalty}%
1620 \or % 1
1621 \gre@penalty{\the\gre@space@count@endofsyllablepenalty}%
1622 \or % 2
1623 % end of score, no penalty needs to be added
1624 \or % 3
1625 % before bar, no penalty should to be added
1626 \fi %
1627 \fi %
1628 \fi %
1629 }%
1630
1631 \newif\ifgre@euouae@implies@nlba
1632 \gre@euouae@implies@nlbatrue
1633
1634 \def\gresetbreakineuouae#1{%
1635 \IfStrEqCase{#1}{%
1636 {allow}%
1637 {\gre@euouae@implies@nlbafalse}%
1638 {prohibit}%
1639 {\gre@euouae@implies@nlbatrue}%
1640 }[% all other cases
1641 \gre@error{Unrecognized option "#1" in \protect\gresetbreakineuouae\MessageBreak Possible options are: 'allow' and 'prohibit'}%
1642 ]%
1643 }%
1644
1645
1646 \newif\ifgre@in@euouae
1647 \gre@in@euouaefalse
1648
1649 \newif\ifgre@firstin@euouae
1650 \gre@firstin@euouaefalse
1651 \newcount\gre@lasteuouaeindex
1652 \gre@lasteuouaeindex=0
1653
1654 \def\GreBeginEUOUAE#1{%
1655 \ifgre@euouae@implies@nlba %
1656 \GreBeginNLBArea{0}{0}%
1657 \fi %
1658 \ifgre@raggedbreakbeforeeuouae %
1659 \gre@lasteuouaeindex=#1\relax %
1660 \gre@firstin@euouaetrue %
1661 \fi %
1662 \gre@in@euouaetrue %
1663 % as soon as the EUOUAE starts, we stop blocking the EOL custos that might
1664 % have been blocked on the prior syllable.
1665 \GreResetEolCustos %
1666 }
1667
1668 \def\GreEndEUOUAE#1{%
1669 \ifgre@euouae@implies@nlba %
1670 \GreEndNLBArea{#1}{0}%
1671 \fi %
1672 \gre@in@euouaefalse %
1673 \gre@firstin@euouaefalse %
1674 }
1675
1676 \input gregoriotex-symbols.tex%
1677
1678 %%%%%%%%%
1679 %% fonts
1680 %%%%%%%%%
1681
1682 \def\gretilde{%
1683 \ensuremath{\sim}%
1684 \relax %
1685 }%
1686
1687
1688 \def\gresetgregoriofont{\@ifnextchar[{\gre@setgregoriofont}{\gre@setgregoriofont[]}}%
1689 \def\gresetgregoriofontscaled{\@ifnextchar[{\gre@setgregoriofontscaled}{\gre@setgregoriofontscaled[]}}%
1690
1691 \def\gre@setgregoriofont[#1]#2{%
1692 \gre@trace{gre@setgregoriofont[#1]{#2}}%
1693 \gre@setgregoriofontscaled[#1]{#2}{100000}%
1694 \relax %
1695 \gre@trace@end%
1696 }%
1697
1698 %% font calibration distances
1699 \newdimen\gre@dimen@stafflinethicknessbase%
1700 \newdimen\gre@dimen@glyphraisebase%
1701 \newdimen\gre@dimen@interstafflinedistancebase%
1702 \newdimen\gre@dimen@inclinatumonlinemoravshiftbase%
1703 \newdimen\gre@dimen@inclinatumonlinemorahshiftbase%
1704 \newdimen\gre@dimen@inclinatumofflinemorahshiftbase%
1705
1706 \def\gre@setgregoriofontscaled[#1]#2#3{%
1707 \gre@trace{gre@setgregoriofontscaled[#1]{#2}{#3}}%
1708 \if\relax\detokenize{#1}\relax %
1709 \xdef\gre@gregoriofontname{#2}%
1710 \expandafter\xdef\csname gre@fontfactor@#2\endcsname{#3}%
1711 \gre@loadgregoriofont%
1712 \gdef\GreCPVirgaReversaAscendensOnDLine##1{##1}%
1713 \else %
1714 \xdef\gre@gregoriofontname{#2-#1}%
1715 \expandafter\xdef\csname gre@fontfactor@#2-#1\endcsname{#3}%
1716 \gre@loadgregoriofont%
1717 \gdef\GreCPVirgaReversaAscendensOnDLine##1{\GreCPVirgaReversaLongqueueAscendens}%
1718 \fi %
1719 % currently all fonts use the same calibration distances
1720 \gre@dimen@stafflinethicknessbase=1500sp\relax %
1721 \gre@dimen@glyphraisebase=-22000sp\relax%
1722 \gre@dimen@interstafflinedistancebase=30000sp\relax%
1723 \gre@dimen@inclinatumonlinemoravshiftbase=4500sp\relax%
1724 \gre@dimen@inclinatumonlinemorahshiftbase=3700sp\relax%
1725 \gre@dimen@inclinatumofflinemorahshiftbase=2500sp\relax%
1726 \gre@trace@end%
1727 }%
1728
1729 \newif\ifgre@loadholehollowfonts%
1730 \gre@loadholehollowfontstrue%
1731
1732 \def\greloadholehollowfonts#1{%
1733 \IfStrEq{#1}{true}{%
1734 \gre@loadholehollowfontstrue %
1735 }{%
1736 \gre@loadholehollowfontsfalse %
1737 }%
1738 }
1739
1740 \def\gre@loadgregoriofont{%
1741 \gre@trace{gre@loadgregoriofont}%
1742 \gre@count@temp@three = \the\gre@factor %
1743 \gre@count@temp@two = \expandafter\csname gre@fontfactor@\gre@gregoriofontname\endcsname\relax %
1744 \directlua{gregoriotex.set_font_factor([[\gre@gregoriofontname]], [[\the\gre@count@temp@two]])}%
1745 \multiply\gre@count@temp@three by \gre@count@temp@two %
1746 \global\font\gre@font@music={name:\gre@gregoriofontname} at \the\gre@count@temp@three sp\relax %
1747 \ifgre@loadholehollowfonts %
1748 \global\font\gre@font@music@hollow={name:\gre@gregoriofontname-hollow} at \the\gre@count@temp@three sp\relax %
1749 \global\font\gre@font@music@hole={name:\gre@gregoriofontname-hole} at \the\gre@count@temp@three sp\relax %
1750 \fi %
1751 \directlua{gregoriotex.check_font_version() gregoriotex.scale_score_fonts([[\the\gre@factor]])}%
1752 \relax%
1753 \gre@trace@end%
1754 }%
1755
1756 % the default gregorio font
1757 \gresetgregoriofont{greciliae}%
1758
1759 \newif\ifgre@usestylefont%
1760 \gre@usestylefontfalse%
1761
1762 % gregoriostylefont is the font used for additional glyphs
1763 \def\gre@setstylefont{%
1764 \gre@trace{gre@setstylefont}%
1765 \gre@count@temp@three = \numexpr(\gre@factor * 100000)\relax %
1766 \global\font\gre@font@style={name:greextra} at \the\gre@count@temp@three sp%
1767 {\gre@font@music\directlua{gregoriotex.check_font_version() gregoriotex.scale_score_fonts([[\the\gre@factor]])}}%
1768 \relax%
1769 \gre@trace@end%
1770 }%
1771
1772
1773 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1774 %% Master function for changing element formats
1775 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
1776
1777 \def\grechangestyle#1#2{%
1778 \@ifnextchar[{\gre@changestyle{#1}{#2}}{\gre@changestyle{#1}{#2}[\relax]}%
1779 }%
1780
1781 % because the mechanism for the defining the formats differs under LaTeX and PlainTeX the underlying function which does the work is defined in gregoriotex.sty or gregoriotex.tex respectively.
1782
1783
1784 %%%%%%%%%%%%%%%%%%%
1785 %% changing staff size
1786 %%%%%%%%%%%%%%%%%%%
1787
1788 \def\grechangestaffsize#1{%
1789 \ifnum#1<0\relax%
1790 \gre@error{Staff size must be a positive integer.}%
1791 \else%
1792 \gre@changedimenfactor{\gre@factor}{#1}%
1793 \global\gre@factor=#1\relax %
1794 \fi%
1795 \gre@loadgregoriofont%
1796 \relax %
1797 }%
1798
1799 %%%%%%%%%%%%%%%%%%%
1800 %% headers
1801 %%%%%%%%%%%%%%%%%%%
1802 \def\gresetheadercapture#1#2#3{%
1803 \directlua{gregoriotex.set_header_capture("#1","#2","#3")}%
1804 }%
1805
1806 \def\GreHeader#1#2{%
1807 \directlua{gregoriotex.capture_header("#1","#2")}%
1808 }%
1809
1810 %%%%%%%%%%%%%%%%%%%
1811 %% score including
1812 %%%%%%%%%%%%%%%%%%%
1813
1814
1815 \def\gre@maketable#1{\ifx\relax#1\else,"#1"\expandafter\gre@maketable\fi}
1816
1817 \def\gresetgregpath#1{%
1818 \def\gre@input@path{#1}%
1819 \directlua{
1820 gre_input_path = {""\expandafter\gre@maketable\gre@input@path\relax}
1821 }
1822 }
1823
1824 \ifx\gre@input@path\@undefined
1825 \let\gre@input@path\input@path
1826 \fi
1827
1828 % Flag to track compilation behavior
1829 % 0 = never compile (default)
1830 % 1 = auto compile (compile outdated scores and those lacking a compiled version)
1831 % 2 = compile all scores
1832 \def\gre@compilegabc{0}%
1833
1834 % User macro to change compilation behavior
1835 \def\gresetcompilegabc#1{%
1836 \IfStrEqCase{#1}{%
1837 {force}{\gdef\gre@compilegabc{2}}%
1838 {auto}{\gdef\gre@compilegabc{1}}%
1839 {never}{\gdef\gre@compilegabc{0}}%
1840 }[% all other cases
1841 \gre@error{Unrecognized argument for \protect\gresetcompilegabc.}%
1842 ]%
1843 }%
1844
1845 \def\gre@allowdeprecated@asboolean{\ifgre@allowdeprecated true\else false\fi}%
1846
1847 % Internal marco which includes a score when \gregorioscore is called without the optional argument. Behavior is determined by the value of \gre@compilegabc flag.
1848 %
1849 % If \gre@compilegabc is 0, then we simply try to include the file as it is given to us. This is the old behavior.
1850 %
1851 % If \gre@compilegabc is 1, tell the lua function to check that:
1852 % -- The gtex file exists.
1853 % -- The gtex file is of the correct gregoriotexapi_version.
1854 % -- The gtex file is 'newer' than it's corresponding gabc file.
1855 % If any test fails, the gabc file is (re)compiled.
1856 %
1857 % If \gre@compilegabc is 2, pass true to the lua function.
1858 % This forces gregoriotex to recompile the gabc file.
1859
1860 \def\gre@gregorioscore#1{%
1861 \begingroup%
1862 \let\input@path\gre@input@path%
1863 \ifcase\gre@compilegabc% case 0, never compile
1864 \gre@debugmsg{compile}{Refusing to compile #1}%
1865 \input #1%
1866 \or% case 1, auto compile
1867 \gre@debugmsg{compile}{Auto compile #1}%
1868 \directlua{gregoriotex.include_score([[#1]], nil, \gre@allowdeprecated@asboolean)}%
1869 \or% case 2, force compile
1870 \gre@debugmsg{compile}{Forced to compile #1}%
1871 \directlua{gregoriotex.include_score([[#1]], true, \gre@allowdeprecated@asboolean)}%
1872 \fi%
1873 \relax%
1874 \endgroup%
1875 }%
1876
1877 % The internal macro called when \gregorioscore is called with the optional argument. Behavior is determined by the value of the argument:
1878 % n - do not attempt to compile the score. Simply include it as is.
1879 % a - perform the checks to see if the score needs to be recompiled and do so only if necessary
1880 % f - force the compilation of the score before including it
1881 \def\gre@gregorioscore@option[#1]#2{%
1882 \begingroup%
1883 \let\input@path\gre@input@path%
1884 \ifx #1n\relax%
1885 \gre@debugmsg{compile}{Override not compiling #2}%
1886 \input #2%
1887 \else%
1888 \ifx #1f\relax%
1889 \gre@debugmsg{compile}{Override force compiling #2}%
1890 \directlua{gregoriotex.include_score([[#2]], true, \gre@allowdeprecated@asboolean)}%
1891 \else%
1892 \ifx #1a\relax%
1893 \gre@debugmsg{compile}{Override auto compiling #2}%
1894 \directlua{gregoriotex.include_score([[#2]], nil, \gre@allowdeprecated@asboolean)}%
1895 \else%
1896 \gre@error{Unrecognized option "#1" for \protect\includescore\MessageBreak Possible options are: 'f', 'a', and 'n'}%
1897 \fi%
1898 \fi%
1899 \fi%
1900 \relax%
1901 \endgroup%
1902 }%
1903
1904 % The main macro used by the user to input scores into the document.
1905
1906 \def\gregorioscore{\@ifnextchar[{\gre@gregorioscore@option}%
1907 {\gre@gregorioscore}%
1908 }%
1909
1910 % If called without the optional argument: '\gregorioscore{Antiphon}'
1911 % the filename will be passed to the lua function 'include_score'
1912 % which will check: whether the gtex file exists, if the API version
1913 % of the gtex file, or if the gabc file is newer than the gtex
1914 % file. If one of these tests fails, the gabc file will be
1915 % (re)compiled.
1916 % The argument may or may not include a file extension. These are all valid:
1917 % '\gregorioscore{Antiphon}' or '\gregorioscore{Antiphon.gabc}' or
1918 % '\gregorioscore{Antiphon.gtex}'
1919
1920 % If called with the optional argument: '\gregorioscore[f]{Antiphon.gtex}'
1921 % the gtex file will be forced into the document and will not be
1922 % checked by the lua function 'include_score'. This does not bypass
1923 % the API version test done by '\GregorioTeXAPIVersion'.
1924
1925 % Macros for compiling short snippets of GABC directly expressed in TeX
1926
1927 \long\def\gabcsnippet#1{%
1928 \directlua{gregoriotex.direct_gabc("\luatexluaescapestring{\unexpanded\expandafter{#1}}", nil, \gre@allowdeprecated@asboolean)}%
1929 }%
1930
1931 %%%%%%%%%%%%%%%%%%%%%%%%%%%
1932 %% some hyphen definitions
1933 %%%%%%%%%%%%%%%%%%%%%%%%%%%
1934
1935 % a zero-width hyphen, useful for fine tuning line endings. To input in gabc verb for example.
1936 \def\gre@char@zerohyph{%
1937 \hbox to 0pt{%
1938 \char\the\hyphenchar\font %
1939 \hss %
1940 }%
1941 }%
1942
1943 % a normal hyphen
1944 \def\gre@char@normalhyphen{%
1945 %-
1946 \char\the\hyphenchar\font %
1947 }%
1948
1949 % the definition that will be always used for end of lines hyphens in gregorio, except if one of the two before is explicitely used
1950 \let\GreHyph\gre@char@normalhyphen %
1951
1952 % macro to change the definition of the hyphen:
1953 \def\greseteolhyphen#1{%
1954 \IfStrEqCase{#1}{%
1955 {normal}%
1956 {\global\let\GreHyph\gre@char@normalhyphen}%
1957 {zero}%
1958 {\global\let\GreHyph\gre@char@zerohyph}%
1959 }[% all other cases
1960 \gre@error{Unrecognized option "#1" for \protect\greseteolhyphen\MessageBreak Possible options are: 'normal' and 'zero'}%
1961 ]%
1962 }%
1963
1964 % macro to force hyphenation of all syllables.
1965 \newif\ifgre@forcehyphen\gre@forcehyphenfalse%
1966 \def\gresethyphen#1{%
1967 \IfStrEqCase{#1}{%
1968 {force}%
1969 {\gre@forcehyphentrue}%
1970 {auto}%
1971 {\gre@forcehyphenfalse}%
1972 }[% all other cases
1973 \gre@error{Unrecognized option "#1" in \protect\gresethyphen\MessageBreak Possible options are: 'force' and 'auto'}%
1974 ]%
1975 }%
1976
1977 % macro called before the headers of a given inclusion
1978 \def\GreBeginHeaders{}%
1979 \long\def\grebeforeheaders#1{\def\GreBeginHeaders{#1}}%
1980
1981 % macro called after the headers of a given inclusion
1982 \def\GreEndHeaders{}%
1983 \long\def\greafterheaders#1{\def\GreEndHeaders{#1}}%
1984
1985 % We load the default space configuration.
1986 \greloadspaceconf{default}%
1987
1988 \input gregoriotex-nabc.tex