Debian Codegraph @

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

raw
1 %GregorioTeX 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 of the glyphs and the syllables
21
22 \gre@declarefileversion{gregoriotex-syllable.tex}{6.1.0}% GREGORIO_VERSION
23
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25 %% macros for the typesetting of the different glyphs
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28 % Flag to indicate if the note is on a line or not
29 \newif\ifgre@isonaline%
30
31 % if previous syllable ends with a punctum mora
32 \newif\ifgre@lastendswithmora %
33 \gre@lastendswithmorafalse %
34
35 % if this syllable ends with a punctum mora
36 \newif\ifgre@thisendswithmora %
37 \gre@thisendswithmorafalse %
38
39 % a macro called each time we start something looking like a glyph, but not mandatorily called through the \GreGlyph macro, for example bars, flats, etc.
40
41 \newcount\gre@generate@pointandclick\gre@generate@pointandclick=0\relax %
42
43 \def\gresetpointandclick#1{%
44 \IfStrEqCase{#1}{%
45 {on}%
46 {%
47 \ifx\pdfoutput\undefined %
48 \gre@warning{Unable to enable point-and-click because \protect\pdfoutput \MessageBreak is not defined}%
49 \gre@generate@pointandclick=0\relax %
50 \else %
51 \ifnum\pdfoutput=1\relax %
52 \gre@generate@pointandclick=1\relax %
53 \else %
54 \gre@warning{Unable to enable point-and-click when not\MessageBreak generating a PDF}%
55 \gre@generate@pointandclick=0\relax %
56 \fi %
57 \fi %
58 }%
59 {off}%
60 {\gre@generate@pointandclick=0\relax}%
61 }[% all other cases
62 \gre@error{Unrecognized option "#1" for \protect\gresetpointandclick\MessageBreak Possible options are: 'on' and 'off'}%
63 ]%
64 }%
65
66 \def\gre@pointandclick#1#2{%
67 \gre@trace{gre@pointandclick{#1}{#2}}%
68 \def\gre@@arg{#2}%
69 \ifx\gre@@arg\gre@nothing %
70 #1%
71 \else %
72 \def\gre@@arg{\gre@gabcname}%
73 \ifx\gre@@arg\gre@nothing %
74 #1%
75 \else %
76 \ifnum\gre@generate@pointandclick=1\relax %
77 \gre@startlink user{%
78 /Subtype/Link/Border[0 0 0]%
79 /A<</Type/Action/S/URI/URI(textedit://\gre@gabcname:#2)>>%
80 }%
81 #1%
82 \gre@endlink %
83 \else %
84 #1%
85 \fi %
86 \fi %
87 \fi %
88 \gre@trace@end%
89 }%
90
91 \def\gre@newglyphcommon{%
92 \gre@trace{gre@newglyphcommon}%
93 \global\advance\gre@attr@glyph@id by 1\relax %
94 % first there is something we must do: setting \gre@lastoflinecount to 0 if its value is 2. The reason of this is that in ab(abzcd), we cannot let \grelastoflinecount set to 2 after the end of line... the only way I found to achieve it is to reset \grelastoflinecount to 0 after each glyph or bar.
95 \ifnum\gre@lastoflinecount=2\relax %
96 \global\gre@lastoflinecount=0\relax %
97 \fi %
98 \global\gre@skip@bar@lastskip=0pt\relax %
99 \gre@currenttextabovelines %
100 \ifcase\gre@count@lastglyphiscavum\or %
101 \global\gre@count@lastglyphiscavum=2\relax %
102 \or %
103 \global\gre@count@lastglyphiscavum=0\relax %
104 \fi %
105 \global\gre@lastendswithmorafalse %
106 \ifgre@boxing\else\ifgre@firstin@euouae %
107 \ifgre@raggedbreakbeforeeuouae %
108 \directlua{gregoriotex.save_euouae(\the\gre@lasteuouaeindex,2)}%
109 \fi %
110 \gre@firstin@euouaefalse %
111 \fi\fi %
112 \relax %
113 \gre@trace@end%
114 }%
115
116 \def\gre@endofglyphcommon{%
117 \gre@trace{gre@endofglyphcommon}%
118 \ifgre@endofscore %
119 \gre@penalty{\the\gre@space@count@finalpenalty}%
120 \gre@localleftbox{}%
121 \gre@localrightbox{}%
122 \fi %
123 \gre@trace@end%
124 }
125
126 % passes the glyph height limits:
127 % #1: the high height
128 % #2: the low height
129 \def\GreGlyphHeights#1#2{%
130 \global\setluatexattribute\gre@attr@glyph@top{#1}%
131 \global\setluatexattribute\gre@attr@glyph@bottom{#2}%
132 }%
133
134 % Flag that tells us if the current glyph is the first glyph or not.
135 \newif\ifgre@firstglyph%
136
137 % macro to typeset the glyph. attributes are :
138 % #1: character : the character that it must call
139 % #2: height : the height it must be raised : can be negative (must be calculated by a preprocessor)
140 % #3: typesets the next custos
141 % #4: type : the type of glyph, to determine the aligncenter; can be :
142 %%%%%%%% 0 : one-note glyph or more than two notes glyph except porrectus : here we must put the aligncenter in the middle of the first note
143 %%%%%%%% 1 : two notes glyph (podatus is considered as a one-note glyph) : here we put the aligncenter in the middle of the glyph
144 %%%%%%%% 2 : porrectus : has a special align center
145 %%%%%%%% 3 : initio-debilis : same as 1 but the first note is much smaller
146 %%%%%%%% 4 : case of a glyph starting with a quilisma
147 %%%%%%%% 5 : case of a glyph starting with an oriscus
148 %%%%%%%% 6 : case of a punctum inclinatum
149 %%%%%%%% 7 : case of a stropha
150 %%%%%%%% 8 : flexus with an ambitus of one
151 %%%%%%%% 9 : flexus deminutus
152 % #5 are the signs to typeset before the glyph (typically additional bars, as they must be "behind" the glyph)
153 % #6 are the signs to typeset after the glyph (almost all signs)
154 % #7 is the line:char:column for a textedit link
155 \def\GreGlyph#1#2#3#4#5#6#7{%
156 \gre@newglyphcommon %
157 % Create box containing the new glyph.
158 \setbox\gre@box@temp@width=\hbox{\gre@pointandclick{\gre@font@music #1}{#7}}%
159 \global\gre@dimen@lastglyphwidth=\wd\gre@box@temp@width %
160 % the three next lines are a trick to get the additional lines below the glyphs
161 \gre@skip@temp@one = \gre@dimen@lastglyphwidth\relax%
162 \kern\gre@skip@temp@one %
163 % #5 contains things like ledger lines, but also calls to \GreGlyphHeights
164 #5\relax %
165 \kern-\gre@skip@temp@one %
166 \gre@calculate@glyphraisevalue{#2}{0}{}%
167 \raise\gre@dimen@glyphraisevalue%
168 % Since \gre@box@temp@width was created before the calls
169 % to \GreGlyphHeights, we need to rebox it to
170 % set \gre@attr@glyph@top and \gre@attr@glyph@bottom correctly.
171 \hbox{\unhcopy\gre@box@temp@width}%
172 \ifgre@endofscore\else\ifgre@boxing\else %
173 #3%
174 \fi\fi %
175 \ifgre@firstglyph% we check if it is the first glyph
176 \gre@calculate@notesaligncenter{#4}%
177 \global\gre@firstglyphfalse%
178 \fi%
179 #6\relax %
180 \directlua{gregoriotex.adjust_line_height(\gre@insidediscretionary)}%
181 \gre@endofglyphcommon %
182 \relax%
183 }%
184
185 % this function is quite simple, it just sets \gre@box@temp@width with a box of the good width, watch the next function for the complete thing
186 % we define the different alignments possible, of course they depend on the font
187 % the first 10 (0-9) possible values are the same as in glyph
188 % see the cases below
189 % there is a tricky here : if notesaligncenter is not 0, it means that there is a flat before, so we simply add notes aligncenter
190 % #2 is 0 if we are in the context of current syllable, 1 if we are in the context of next syllable
191 \def\gre@calculate@simplenotesaligncenter#1#2{%
192 \gre@trace{gre@calculate@simplenotesaligncenter{#1}{#2}}%
193 \ifcase#1% 0: punctum
194 % one-note glyph or more than two notes glyph except porrectus : here
195 % we must put the aligncenter in the middle of the first note
196 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\GreCPPunctum}%
197 \or% 1: flexus
198 % two notes glyph (podatus is considered as a one-note glyph) : here
199 % we put the aligncenter in the middle of the glyph
200 \gre@handleclivisspecialalignment{\gre@font@music\GreCPPesQuadratumLongqueueThreeNothing}{\gre@font@music\GreCPPunctum}{#2}%
201 \or% 2: porrectus
202 % we consider it to have the same alignment as punctum
203 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\GreCPPunctum}%
204 \or% 3: initio debilis
205 % same as 1 but the first note is much smaller
206 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\GreCPPunctumDeminutus}%
207 \or% 4: glyph starting with a quilisma
208 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\GreCPQuilisma}%
209 \or% 5: glyph starting with an oriscus
210 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\GreCPAscendensOriscus}%
211 \or% 6: punctum inclinatum
212 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\GreCPDescendensPunctumInclinatum}%
213 \or% 7: stropha
214 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\GreCPStropha}%
215 \or% 8: flexus with ambitus of one
216 \gre@handleclivisspecialalignment{\gre@font@music\GreCPPesQuadratumLongqueueOneNothing}{\gre@font@music\GreCPPunctum}{#2}%
217 \or% 9: flexus deminutus
218 \gre@handleclivisspecialalignment{\gre@font@music\GreCPFlexusTwoDeminutus}{\gre@font@music\GreCPPunctum}{#2}%
219 \or% 10: virgula
220 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\gre@char@bar@virgula}%
221 \or% 11: divisio minima
222 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\gre@char@bar@divisiominima}%
223 \or% 12: divisio minor
224 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\gre@char@bar@divisiominor}%
225 \or% 13: divisio maior
226 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\gre@char@bar@divisiomaior}%
227 \or% 14: dominican bar
228 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\GreCPDivisioDominican}%
229 \or% 15: parenthesized virgula
230 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\gre@char@bar@virgulaparen}%
231 \or% 16: parenthesized divisio minima
232 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\gre@char@bar@divisiominimaparen}%
233 \or% 17: divisio finalis
234 \global\setbox\gre@box@temp@width=\hbox{\gre@fontchar@divisiofinalis}%
235 \or% 18: no note
236 \ifgre@newbarspacing%
237 \global\setbox\gre@box@temp@width=\hbox{}%
238 \else%
239 % under the old algorithm, syllables with no notes triggered a 0 in this function, so we duplicate the first case here
240 \global\setbox\gre@box@temp@width=\hbox{\gre@font@music\GreCPPunctum}%
241 \fi%
242 \fi%
243 \relax%
244 \gre@trace@end%
245 }%
246
247 % aux function to previous one: sets \gre@box@temp@width to \hbox{#1} or \hbox{#2}
248 % according to special clivis alignemt scheme. See comments of
249 % \gre@clivisalignment for more.
250 % #1 is the glyph in case we align the clivis in the "clivis" way,
251 % #2 is the glyph in case we align the clivis in the normal way
252 % Conditionals can be summed up this way:
253 % if wd(#1/2) > \gre@dimen@textaligncenter then #2
254 % else
255 % if lyrics are centered on syllables :
256 % if (\gre@dimen@textaligncenter) > \gre@space@dimen@clivisalignmentmin -> #2 else #1
257 % else:
258 % if wd(\gre@endsyllablepart) > \gre@space@dimen@clivisalignmentmin -> #2 else #1
259 %
260 % #3 is the same as #2 of previous function
261 \def\gre@handleclivisspecialalignment#1#2#3{%
262 \gre@trace{gre@handleclivisspecialalignment{#1}{#2}{#3}}%
263 \ifcase\gre@clivisalignment%
264 \global\setbox\gre@box@temp@width=\hbox{#1}%
265 \or%
266 \global\setbox\gre@box@temp@width=\hbox{#2}%
267 \or%
268 \gre@widthof{#1}%
269 \divide\gre@dimen@temp@three by 2\relax %
270 \gre@debugmsg{ifdim}{ temp@three > textaligncenter}%
271 \ifdim\gre@dimen@temp@three >\gre@dimen@textaligncenter\relax%
272 \global\setbox\gre@box@temp@width=\hbox{#2}%
273 \else%
274 \ifcase\gre@lyriccentering% 0 == syllable centering
275 \gre@debugmsg{ifdim}{ textaligncenter > clivisalignmentmin}%
276 \ifdim\gre@dimen@textaligncenter >\gre@space@dimen@clivisalignmentmin\relax%
277 \global\setbox\gre@box@temp@width=\hbox{#2}%
278 \else%
279 \global\setbox\gre@box@temp@width=\hbox{#1}%
280 \fi%
281 \else% vowel or first-letter centering
282 \ifcase#3%
283 % *always* emit end syllable part for proper determination of
284 % clivis alignment
285 \gre@widthof{\gre@endsyllablepart}%
286 \else%
287 \gre@widthof{\gre@evaluatenextsyllable{\gre@nextendsyllablepart}}%
288 \fi%
289 \gre@debugmsg{ifdim}{ temp@three > clivisalignmentmin}%
290 \ifdim\gre@dimen@temp@three >\gre@space@dimen@clivisalignmentmin\relax%
291 \global\setbox\gre@box@temp@width=\hbox{#2}%
292 \else%
293 \global\setbox\gre@box@temp@width=\hbox{#1}%
294 \fi%
295 \fi%
296 \fi%
297 \fi%
298 \gre@trace@end%
299 }%
300
301 % the "hat" function, that calls the simple function with the good argument, according to the fact that it's a flat, natural, etc.
302 % warning: the behaviour of all this is quite difficult to understand: this function is called with simple arguments (between 0 and 20) by the glyph function. In this case we add the align center of the argument to notesaligncenter ; and notesaligncenter can be already set to something by flat and natural.
303 \def\gre@calculate@notesaligncenter#1{%
304 \gre@trace{gre@calculate@notesaligncenter{#1}}%
305 \gre@calculate@simplenotesaligncenter{#1}{0}%
306 \global\advance\gre@dimen@notesaligncenter by \dimexpr(\wd\gre@box@temp@width / 2)\relax %
307 \relax %
308 \gre@trace@end%
309 }%
310
311 % this is the function that we call when we try to determine the next aligncenter of the notes.
312 % #1 is the note type
313 % #2 is the alteration type (see \gre@alteration)
314 \def\gre@calculate@nextnotesaligncenter#1#2{%
315 \gre@trace{gre@calculate@nextnotesaligncenter{#1}{#2}}%
316 \gre@calculate@simplenotesaligncenter{#1}{1}%
317 \gre@dimen@temp@five=\dimexpr(\wd\gre@box@temp@width / 2)\relax %
318 \ifcase#2\relax% 0 - none
319 \or % 1 - flat
320 \setbox\gre@box@temp@width=\hbox{\gre@fontchar@flat}%
321 \or % 2 - natural
322 \setbox\gre@box@temp@width=\hbox{\gre@fontchar@natural}%
323 \or % 3 - sharp
324 \setbox\gre@box@temp@width=\hbox{\gre@fontchar@sharp}%
325 \or % 4 - parenthesized flat
326 \setbox\gre@box@temp@width=\hbox{\gre@fontchar@flatparen}%
327 \or % 5 - parenthesized natural
328 \setbox\gre@box@temp@width=\hbox{\gre@fontchar@naturalparen}%
329 \or % 6 - parenthesized sharp
330 \setbox\gre@box@temp@width=\hbox{\gre@fontchar@sharpparen}%
331 \fi %
332 \ifnum#2>0\relax %
333 \advance\gre@dimen@temp@five by \dimexpr(\wd\gre@box@temp@width+\gre@space@dimen@alterationspace)\relax %
334 \fi %
335 \global\gre@dimen@notesaligncenter=\gre@dimen@temp@five %
336 \relax %
337 \gre@trace@end%
338 }%
339
340 % box that we will use to determine the width of the notes, to determine wether we typeset a - or not after the letters
341 \newbox\gre@box@syllablenotes%
342
343 \newif\ifgre@showlyrics%
344 \gre@showlyricstrue%
345
346 \def\gresetlyrics#1{%
347 \IfStrEqCase{#1}{%
348 {visible}{\gre@showlyricstrue}%
349 {invisible}{\gre@showlyricsfalse}%
350 }[% all other cases
351 \gre@error{Unknown option, "#1" for \protect\gresetlyrics\MessageBreak Possible options are: 'visible' and 'invisible'}%
352 ]%
353 }%
354
355 \newif\ifgre@shownotes%
356 \gre@shownotestrue%
357
358 \def\gresetnotes#1{%
359 \IfStrEqCase{#1}{%
360 {visible}{\gre@shownotestrue}%
361 {invisible}{\gre@shownotesfalse}%
362 }[% all other cases
363 \gre@error{Unknown option, "#1" for \protect\gresetnotes\MessageBreak Possible options are: 'visible' and 'invisible'}%
364 ]%
365 }%
366
367 % Macro used to fill \gre@box@syllablenotes with everything contained in #1. This
368 % saves and restores a few values so that when really typesetting #1 in \GreSyllable,
369 % the result is identical.
370 \def\gre@syllablenotes#1{%
371 \gre@trace{gre@syllablenotes{#1}}%
372 % \gre@count@lastglyphiscavum is reinitialized at each syllable...
373 % so there's a bug on g(bx)g(b)
374 \global\gre@count@lastglyphiscavum=0\relax %
375 \global\gre@firstglyphtrue%
376 \global\gre@boxingtrue%
377 \let\ifgre@saved@prenotes@lastendswithmora\ifgre@lastendswithmora%
378 \xdef\gre@saved@prenotes@lastoflinecount{\number\gre@lastoflinecount\relax }%
379 \ifgre@shownotes%
380 \setbox\gre@box@syllablenotes=\hbox{#1}%
381 \else%
382 \setbox\gre@box@syllablenotes=\box\voidb@x%
383 \fi%
384 \gre@debugmsg{spacing}{Width of notes: \the\wd\gre@box@syllablenotes}%
385 \global\gre@boxingfalse%
386 \global\gre@firstglyphtrue%
387 % now gre@lastendswithmora is true if this syllable ends with a
388 % punctum mora, but we still want to keep gre@lastendswithmora if we
389 % are on a bar, so:
390 % - we set gre@thisendswithmora to gre@lastendswithmora
391 % - when syllables will be really typeset, they will set gre@lastendswithmora
392 % again
393 \ifgre@lastendswithmora %
394 \gre@thisendswithmoratrue %
395 \else %
396 \gre@thisendswithmorafalse %
397 \fi %
398 \let\ifgre@lastendswithmora\ifgre@saved@prenotes@lastendswithmora%
399 \global\gre@lastoflinecount=\gre@saved@prenotes@lastoflinecount\relax %
400 \global\gre@count@lastglyphiscavum=0\relax %
401 \global\gre@skip@bar@lastskip=0pt\relax %
402 \global\gre@endofscorefalse %
403 \relax %
404 \gre@trace@end%
405 }%
406
407
408 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
409 %% macros for the typesetting of glyphs and notes together
410 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
411
412 \def\GreFirstWord#1{\gre@style@firstword#1\endgre@style@firstword}%
413 \def\GreFirstSyllable#1{\gre@style@firstsyllable#1\endgre@style@firstsyllable}%
414 \def\GreFirstSyllableInitial#1{\gre@style@firstsyllableinitial#1\endgre@style@firstsyllableinitial}%
415 \def\GreElision#1{\gre@style@elision#1\endgre@style@elision}%
416
417 % box that will contain the text of the syllable
418 \newbox\gre@box@syllabletext%
419
420 % count that will be 0 if in the last text there was no dash (or if it is the beginning of a word, and 1 if there was
421 %\newcount\previousdash
422
423 % Flag to track if we are boxing the syllable notes or printing them
424 \newif\ifgre@boxing%
425 \gre@boxingfalse%
426
427 %
428 % Helper macros for fixing text in rare cases
429 %
430
431 % the macro we call with all normal text
432 \def\gre@textnormal#1{%
433 #1\relax %
434 }%
435
436 % macro to specify a text which is different from #1#2#3 (of \GreSyllable). It is useful for
437 % styles, for instance with
438 %
439 % <i>ffj</i>(gh)
440 %
441 % , we will have
442 %
443 % #1 = \textit{f}
444 % #2 = \textit{f}
445 % #3 = \textit{j}
446 %
447 % and thus #1#2#3 will be \textit{f}\textit{f}\textit{j}, which won't typeset
448 % ligatures. In this example we should call \grefixedtext{\textit{ffj}}.
449 %
450 % for the argument, we have:
451 % 0: nothing
452 % 1: italic
453 % 2: bold
454 % 3: small caps
455 % 4: tt
456 % 5: ul
457 \def\GreSetFixedTextFormat#1{%
458 \ifcase#1\relax%
459 \global\let\gre@fixedtextformat\gre@textnormal %
460 \or %
461 \global\let\gre@fixedtextformat\GreItalic %
462 \or %
463 \global\let\gre@fixedtextformat\GreBold %
464 \or %
465 \global\let\gre@fixedtextformat\GreSmallCaps %
466 \or %
467 \global\let\gre@fixedtextformat\GreTypewriter %
468 \or %
469 \global\let\gre@fixedtextformat\GreUnderline %
470 \or %
471 \global\let\gre@fixedtextformat\GreColored %
472 \fi %
473 }%
474
475 % a function to cancel the previous one
476 \def\gre@unsetfixedtextformat{%
477 \gre@trace{gre@unsetfixedtextformat}%
478 \global\let\gre@fixedtextformat\gre@textnormal %
479 \gre@trace@end%
480 }%
481
482 \let\gre@fixedtextformat\gre@textnormal %
483
484 % The same but for the next syllable
485
486 \def\GreSetFixedNextTextFormat#1{%
487 \ifcase#1\relax%
488 \global\let\gre@fixednexttextformat\gre@textnormal %
489 \or %
490 \global\let\gre@fixednexttextformat\GreItalic %
491 \or %
492 \global\let\gre@fixednexttextformat\GreBold %
493 \or %
494 \global\let\gre@fixednexttextformat\GreSmallCaps %
495 \or %
496 \global\let\gre@fixednexttextformat\GreTypewriter %
497 \or %
498 \global\let\gre@fixednexttextformat\GreUnderline %
499 \or %
500 \global\let\gre@fixednexttextformat\GreColored %
501 \fi %
502 }%
503
504 % a function to cancel the previous one
505 \def\gre@unsetfixednexttextformat{%
506 \gre@trace{gre@unsetfixednexttextformat}%
507 \global\let\gre@fixednexttextformat\gre@textnormal %
508 \gre@trace@end%
509 }%
510
511 \let\gre@fixednexttextformat\gre@textnormal %
512
513 \def\GreUnstyled#1{#1}%
514
515 \newif\ifgre@forcedcentering%
516 \gre@forcedcenteringfalse%
517 \newif\ifgre@nextforcedcentering%
518 \gre@nextforcedcenteringfalse%
519
520 \def\GreGABCForceCenters{%
521 \ifgre@gabcforcecenters%
522 \gre@forcedcenteringtrue%
523 \else%
524 \gre@forcedcenteringfalse%
525 \fi%
526 }%
527
528 \def\GreGABCNextForceCenters{%
529 \ifgre@gabcforcecenters%
530 \gre@nextforcedcenteringtrue%
531 \else%
532 \gre@nextforcedcenteringfalse%
533 \fi%
534 }%
535
536 \newif\ifgre@gabcforcecenters%
537 \gre@gabcforcecenterstrue%
538
539 \def\gresetgabcforcecenters#1{%
540 \ifcase\gre@lyriccentering\or%
541 \gre@warning{\protect\gresetgabcforcecenters\space has no effect when lyrics are centered on the vowels}%
542 \fi%
543 \IfStrEqCase{#1}{%
544 {allow}%
545 {\gre@gabcforcecenterstrue}%
546 {prohibit}%
547 {\gre@gabcforcecentersfalse}%
548 }[% all other cases
549 \gre@error{Unrecognized option "#1" for \protect\gresetgabcforcecenters\MessageBreak Possible options are: 'allow' and 'prohibit'}%
550 ]%
551 }%
552
553 % #1 : the first letters of the syllable, that don't count for the alignment
554 % #2 : the middle letters of the syllable, we must align in the middle of them
555 % #3 : the end letters, they don't count
556 % #4 : the very first letter
557 % #5 : all the letters after the first letter
558 \def\GreSetThisSyllable#1#2#3#4#5{%
559 \ifgre@forcedcentering%
560 \gdef\gre@firstsyllablepart{#1}%
561 \gdef\gre@middlesyllablepart{#2}%
562 \gdef\gre@endsyllablepart{#3}%
563 \else%
564 \ifcase\gre@lyriccentering% 0 - syllable centering
565 \gdef\gre@firstsyllablepart{}%
566 \gdef\gre@middlesyllablepart{#1#2#3}%
567 \gdef\gre@endsyllablepart{}%
568 \or % 1 - vowel centering
569 \gdef\gre@firstsyllablepart{#1}%
570 \gdef\gre@middlesyllablepart{#2}%
571 \gdef\gre@endsyllablepart{#3}%
572 \or % 2 - first-letter centering
573 \gdef\gre@firstsyllablepart{}%
574 \gdef\gre@middlesyllablepart{#4}%
575 \gdef\gre@endsyllablepart{#5}%
576 \fi %
577 \fi%
578 \gre@forcedcenteringfalse%
579 }%
580
581 \def\GreSetNextSyllable#1#2#3#4#5{%
582 \ifgre@nextforcedcentering%
583 \gdef\gre@nextfirstsyllablepart{#1}%
584 \gdef\gre@nextmiddlesyllablepart{#2}%
585 \gdef\gre@nextendsyllablepart{#3}%
586 \else%
587 \ifcase\gre@lyriccentering% 0 - syllable centering
588 \gdef\gre@nextfirstsyllablepart{}%
589 \gdef\gre@nextmiddlesyllablepart{#1#2#3}%
590 \gdef\gre@nextendsyllablepart{}%
591 \or % 1 - vowel centering
592 \gdef\gre@nextfirstsyllablepart{#1}%
593 \gdef\gre@nextmiddlesyllablepart{#2}%
594 \gdef\gre@nextendsyllablepart{#3}%
595 \or % 2 - first-letter centering
596 \gdef\gre@nextfirstsyllablepart{}%
597 \gdef\gre@nextmiddlesyllablepart{#4}%
598 \gdef\gre@nextendsyllablepart{#5}%
599 \fi %
600 \fi%
601 \gre@nextforcedcenteringfalse%
602 }%
603
604 %%%%%%%%%%%%%%%
605 %% Lyric centering
606 %%%%%%%%%%%%%%%
607
608 \def\gresetlyriccentering#1{%
609 \IfStrEqCase{#1}{%
610 {vowel}%
611 {\xdef\gre@lyriccentering{1}}%
612 {syllable}%
613 {\xdef\gre@lyriccentering{0}}%
614 {firstletter}%
615 {\xdef\gre@lyriccentering{2}}%
616 }[% all other cases
617 \gre@error{Unrecognized option "#1" for \protect\gresetlyriccentering\MessageBreak Possible options are: 'vowel', 'syllable' and 'firstletter'}%
618 ]%
619 }%
620
621 \xdef\gre@lyriccentering{1}%
622
623
624 %% options about clivis centering scheme. Clivis are usually aligned by their
625 %% center, which is different from most neumes. Gregorio has three modes:
626 %% 0. always align clivis this way
627 %% 1. never align clivis this way, align on first punctum
628 %% 2. align clivis this way, except if:
629 %% - notes would go left of text
630 %% - consonants after vowels are larger than \gre@space@dimen@clivisalignmentmin
631 \newcount\gre@clivisalignment%
632 %% by default we use the mode 2, it seems closest to Solesmes books
633 \gre@clivisalignment=2%
634
635
636 \def\gresetclivisalignment#1{%
637 \IfStrEqCase{#1}{%
638 {always}%
639 {\global\gre@clivisalignment=0\relax}%
640 {never}%
641 {\global\gre@clivisalignment=1\relax}%
642 {special}%
643 {\global\gre@clivisalignment=2\relax}%
644 }[% all other cases
645 \gre@error{Unrecognized option "#1" for \protect\gresetclivisalignment\MessageBreak Possible options are 'always', 'never', and 'special'}%
646 ]%
647 }%
648
649
650 \newif\ifgre@forceemptyfirstsyllablehyphen%
651 \gre@forceemptyfirstsyllablehyphentrue%
652 \def\gresetemptyfirstsyllablehyphen#1{%
653 \IfStrEqCase{#1}{%
654 {auto}%
655 {\gre@forceemptyfirstsyllablehyphenfalse}%
656 {force}%
657 {\gre@forceemptyfirstsyllablehyphentrue}%
658 }[% all other cases
659 \gre@error{Unrecognized option "#1" for \protect\gresetemptyfirstsyllablehyphen\MessageBreak Possible options are 'auto' and 'force'}%
660 ]%
661 }%
662
663 \newif\ifgre@evaluatingnextsyllable%
664 \gre@evaluatingnextsyllablefalse%
665 \def\gre@evaluatenextsyllable#1{%
666 \gre@trace{gre@evaluatenextsyllable{#1}}%
667 \gre@evaluatingnextsyllabletrue%
668 #1%
669 \gre@evaluatingnextsyllablefalse%
670 \gre@trace@end%
671 }%
672
673 \newif\ifgre@showhyphenafterthissyllable%
674 \def\GreForceHyphen{%
675 \ifgre@evaluatingnextsyllable%
676 -%
677 \else%
678 \global\gre@showhyphenafterthissyllabletrue%
679 \gre@debugmsg{hyphen}{Forcing hyphen in gabc}%
680 \fi%
681 }%
682 \def\GreEmptyFirstSyllableHyphen{\ifgre@forceemptyfirstsyllablehyphen\GreForceHyphen\fi}%
683
684 % if an hyphen maybe be added by lua for this syllable. When syllable is not end of word and
685 % no hyphen is added by TeX.
686 \newif\ifgre@possibleluahyphenafterthissyllable
687 \gre@possibleluahyphenafterthissyllablefalse
688
689 \newcount\gre@count@unbreakabletotalnotes %
690 \newcount\gre@count@unbreakableinitialnotes %
691 \newcount\gre@count@unbreakablefinalnotes %
692 % #1 : minimum notes in the syllable before the syllable may be split across lines
693 % #2 : minimum notes to keep together at the start of a syllable
694 % #3 : minimum notes to keep together at the end of a syllable
695 \def\gresetunbreakablesyllablenotes#1#2#3{%
696 \gre@count@unbreakabletotalnotes=\number#1\relax %
697 \gre@count@unbreakableinitialnotes=\number#2\relax %
698 \gre@count@unbreakablefinalnotes=\number#3\relax %
699 }%
700 \gresetunbreakablesyllablenotes{10}{4}{4}%
701
702 \newcount\gre@count@syllablenotes %
703 \def\GreSyllableNoteCount#1{%
704 \gre@count@syllablenotes=\number#1\relax %
705 }%
706
707 \newif\ifgre@rewritesyllables %
708 \gre@rewritesyllablestrue %
709 \def\gresetsyllablerewriting#1{%
710 \IfStrEqCase{#1}{%
711 {auto}%
712 {\gre@rewritesyllablestrue}%
713 {off}%
714 {\gre@rewritesyllablesfalse}%
715 }[% all other cases
716 \gre@error{Unrecognized option "#1" for \protect\gresetsyllablerewriting\MessageBreak Possible options are 'auto' and 'off'}%
717 ]%
718 }%
719
720 % Performs #1 if the syllable should be rewitten, else #2
721 \newif\ifgre@rewritethissyllable %
722 \def\gre@if@rewritesyllable#1#2{%
723 \gre@trace{gre@if@rewritesyllable{#1}{#2}}%
724 \gre@rewritethissyllablefalse %
725 \ifgre@rewritesyllables\relax %
726 \gre@debugmsg{syllablerewriting}{1}%
727 \ifnum\gre@insidediscretionary=0\relax %
728 \gre@debugmsg{syllablerewriting}{2}%
729 \ifgre@showhyphenafterthissyllable\else %
730 \gre@debugmsg{syllablerewriting}{3}%
731 \ifgre@possibleluahyphenafterthissyllable\relax %
732 \gre@debugmsg{syllablerewriting}{4}%
733 \ifx\gre@syllable@next\GreSyllable %
734 \gre@debugmsg{syllablerewriting}{5}%
735 \ifcase\directlua{gregoriotex.is_last_syllable_on_line()}\else %
736 \gre@debugmsg{syllablerewriting}{6}%
737 \gre@rewritethissyllabletrue %
738 \fi %
739 \fi %
740 \fi %
741 \fi %
742 \fi %
743 \fi %
744 \gre@debugmsg{syllablerewriting}{X}%
745 \ifgre@rewritethissyllable %
746 #1%
747 \else %
748 #2%
749 \fi %
750 \gre@trace@end%
751 }%
752
753 \let\gre@saved@syllable@endsyllablepart\gre@nothing\relax %
754 \let\gre@saved@syllable@fixedtextformat\gre@textnormal\relax %
755 \let\gre@saved@syllable@pointandclick\gre@nothing\relax %
756 \def\gre@push@endsyllable#1{%
757 \gre@trace{gre@push@endsyllable{#1}}%
758 \let\gre@saved@syllable@endsyllablepart\gre@nothing\relax %
759 \let\gre@saved@syllable@fixedtextformat\gre@textnormal\relax %
760 \let\gre@saved@syllable@pointandclick\gre@nothing\relax %
761 \gre@if@rewritesyllable{%
762 \let\gre@saved@syllable@endsyllablepart\gre@endsyllablepart\relax %
763 \let\gre@saved@syllable@fixedtextformat\gre@fixedtextformat\relax %
764 \xdef\gre@saved@syllable@pointandclick{#1}%
765 }{}%
766 \relax %
767 \gre@trace@end%
768 }%
769
770 \def\gre@emit@syllabletext#1{%
771 \gre@trace{gre@emit@syllabletext{#1}}%
772 \ifx\gre@saved@syllable@endsyllablepart\gre@nothing %
773 \gre@fixedtextformat{#1}%
774 \else %
775 \ifx\gre@saved@syllable@fixedtextformat\gre@fixedtextformat %
776 \gre@debugmsg{syllablerewriting}{merging format when prepending previous last syllable part}%
777 \gre@fixedtextformat{\gre@pointandclick{\gre@saved@syllable@endsyllablepart}{\gre@saved@syllable@pointandclick}#1}%
778 \else %
779 \gre@debugmsg{syllablerewriting}{prepending previous last syllable part}%
780 \gre@saved@syllable@fixedtextformat{\gre@pointandclick{\gre@saved@syllable@endsyllablepart}{\gre@saved@syllable@pointandclick}}%
781 \gre@fixedtextformat{#1}%
782 \fi %
783 \fi %
784 \relax %
785 \gre@trace@end%
786 }%
787
788 \def\gre@emit@endsyllablepart{%
789 \gre@trace{gre@emit@endsyllablepart}%
790 \gre@if@rewritesyllable{}{%
791 \gre@debugmsg{syllablerewriting}{not rewriting syllable}%
792 \gre@endsyllablepart %
793 }%
794 \relax %
795 \gre@trace@end%
796 }%
797
798 \def\gre@emit@endsyllablepartfornextsyllable{%
799 \gre@trace{gre@emit@endsyllablepartfornextsyllable}%
800 \gre@if@rewritesyllable{%
801 \gre@endsyllablepart %
802 }{}%
803 \relax %
804 \gre@trace@end%
805 }%
806
807 \newif\ifgre@textcleared%
808
809 \def\GreClearSyllableText{%
810 \gre@textclearedtrue%
811 }%
812
813 \def\gre@arg@oftwo@first#1#2{#1}%
814 \def\gre@arg@oftwo@second#1#2{#2}%
815
816 %% general macro : it will typeset the syllable : arguments are :
817 % #1 : macro setting the letters of this syllable
818 % #2 : reserved (unused)
819 % #3 : control sequence for styling the hyphen
820 % #4 : end of word : if it is 0 it means it is not an end of word, if it is 1 it is
821 % TODO: find another system for the end syllable
822 % #9 : glyphs : all the notes
823 % the three next parameters are to put an hyphen if necessary, they can be empty for end of words
824 % #5 : macros setting next syllable letters of the next syllable
825 % #6 : the line:char:column for a textedit link
826 % #7 : alignment type of the first next glyph (this is a pair: alignment type and alteration type)
827 % #8 : other macros (translation, double text, etc.) that don't fit in the limitation of the number of arguments
828 %% with a special option for #7 : if it is a bar, we don't put a space at the end
829 %% at the end we wall \greendofword or \gre@endofsyllable with #7, to reduce the space in case of a flat or natural
830 \def\GreSyllable#1#2#3#4#5#6#7#8#9{%
831 \gre@textclearedfalse%
832 \def\gre@syllable@args{{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}%
833 \futurelet\gre@syllable@next\gre@syllable@expand%
834 }%
835 \def\gre@syllable@expand{%
836 \gre@trace{gre@syllable@expand}%
837 \expandafter\gre@syllable@act\gre@syllable@args%
838 \gre@trace@end%
839 }%
840 \def\gre@syllable@act#1#2#3#4#5#6#7#8#9{%
841 \gre@trace{gre@syllable@act{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}%
842 \gre@debugmsg{general}{}%
843 \gre@debugmsg{general}{New syllable: \expandafter\unexpanded{#1}}%
844 \gre@debugmsg{general}{}%
845 % This needs to be calculated early for syllable rewriting, the value
846 % will be refined later on
847 \ifcase#4 %
848 \global\gre@possibleluahyphenafterthissyllabletrue %
849 \else %
850 \global\gre@possibleluahyphenafterthissyllablefalse %
851 \fi %
852 \global\advance\gre@attr@syllable@id by 1\relax %
853 \gre@showhyphenafterthissyllablefalse%
854 \ifcase#4\ifgre@forcehyphen%
855 \gre@debugmsg{hyphen}{Forcing hyphen}%
856 \gre@showhyphenafterthissyllabletrue%
857 \fi\fi%
858 #1%
859 \gre@firstglyphtrue%
860 \gre@dimen@bolextra = 0pt\relax%
861 \gre@calculate@textaligncenter{\gre@saved@syllable@endsyllablepart}{\gre@firstsyllablepart}{\gre@middlesyllablepart}{0}% we first get the width between the alignment point and the end of the syllable
862 % Before measuring the notes, save the alteration id. We will
863 % restore it later, so that the measured notes and the actual notes
864 % have the same alteration ids, if any.
865 \edef\gre@saved@attr@alteration@id{\number\gre@attr@alteration@id\relax}%
866 \gre@syllablenotes{#9}% we put the notes in a box, so that we have the width of it
867 % now we calculate the begin difference, that is to say \gre@dimen@notesaligncenter - \gre@dimen@textaligncenter
868 \gre@dimen@begindifference=\dimexpr(\gre@dimen@notesaligncenter - \gre@dimen@textaligncenter)\relax %
869 % Now, let's go for something I took years to figure out: we want to align
870 % scores on the notes (see https://github.com/gregorio-project/gregorio/issues/221)
871 % but it means we have to shift lines starting by text by \gre@dimen@bolshift
872 % sadly, we cannot do that in TeX, we can't just say that. But, the way TeX
873 % handles this with usual spaces, is that it ignores all spaces at beginning
874 % of lines. To use this, we just \kern\gre@dimen@bolshift right, this will be
875 % ignored at beginning of line, then \hbox{} that will break the "ignorance"
876 % of spaces, then \kern\gre@dimen@bolshift left, which will not be ignored.
877 % So, at beginning of lines, we will have shifted left, and in middle of lines
878 % we will have shifted right and left, thus cancelling... Very easy trick, but
879 % took me years to find it!
880 \gre@debugmsg{bolshift}{Current glyph: \the\gre@attr@glyph@id}%
881 % we only want to execute these shifts if the clef is being shown
882 % if no clef is being shown, then there is no space under the clef for the
883 % lyrics to invade
884 \ifgre@showclef%
885 \ifgre@bolshiftsenabled%
886 \gre@calculate@bolshift{\gre@dimen@begindifference}%
887 % we don't want to shift right on the first syllable of the score
888 % because the printing of the initial clef, initial, and/or the staff lines
889 % will have already broken TeX's ignorance of spaces.
890 \ifgre@beginningofscore%
891 \gre@beginningofscorefalse%
892 \else%
893 % we don't want to shift right inside a discretionary
894 \ifnum\gre@insidediscretionary=0\relax%
895 \kern\gre@dimen@bolshift\relax%
896 \fi%
897 \fi%
898 \GreNoBreak %
899 \hbox to 0pt{}%
900 \GreNoBreak %
901 \kern-\gre@dimen@bolshift\relax%
902 \fi%
903 \else%
904 % if there is no clef, we still need to break TeX's ignorance of spaces at
905 % the beginning of a line so that the alterations, which would otherwise be
906 % ignored in positioning the syllable, don't stick out into margin
907 \GreNoBreak %
908 \hbox to 0pt{}%
909 \GreNoBreak %
910 \fi %
911 % by default, gre@attr@dash will be 2
912 \gre@attr@dash=2\relax %
913 #5%
914 % if the next glyph has an alteration, check if it is suppressed;
915 % if so, pretend there's no alteration
916 \def\gre@nextalignment{\gre@arg@oftwo@first#7}%
917 \def\gre@nextalteration{\gre@arg@oftwo@second#7}%
918 \ifnum\gre@nextalteration>0\relax
919 \gre@alteration@isvisible{1}{\gre@nextalteration}% if the notes contain an alteration, the id was incremented, so this checks the alteration after the notes
920 \ifgre@alteration@isvisible
921 \else
922 \def\gre@nextalteration{0}%
923 \fi
924 \fi
925 % now we can restore the alteration id to typeset the notes for real
926 \global\gre@attr@alteration@id=\gre@saved@attr@alteration@id\relax %
927 \gre@calculate@nextbegindifference{\gre@emit@endsyllablepartfornextsyllable}{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart}}{\gre@evaluatenextsyllable{\gre@nextmiddlesyllablepart}}{\gre@evaluatenextsyllable{\gre@nextendsyllablepart}}{\gre@nextalignment}{\gre@nextalteration}%
928 \gre@unsetfixednexttextformat %
929 \ifgre@showlyrics%
930 \setbox\gre@box@syllabletext=\hbox{%
931 \IfSubStr{\gre@debug}{,notespacing,}%
932 % when debugging we add a zero-width line to mark the syllable bound
933 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
934 {}% do nothing if not debugging
935 \gre@emit@syllabletext{\gre@pointandclick{\gre@firstsyllablepart\gre@middlesyllablepart\gre@emit@endsyllablepart}{#6}}%
936 \IfSubStr{\gre@debug}{,notespacing,}%
937 % when debugging we add a zero-width line to mark the syllable bound
938 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
939 {}% do nothing if not debugging
940 }%
941 \else%
942 \setbox\gre@box@syllabletext=\box\voidb@x%
943 \fi%
944 \gre@calculate@enddifference{\wd\gre@box@syllablenotes}{\wd\gre@box@syllabletext}{\gre@dimen@textaligncenter}{\gre@dimen@notesaligncenter}{1}%
945 % gre@count@temp@one holds 1 if next is a bar, 2 if an alteration, else 0
946 \gre@count@temp@one=0%
947 \ifnum\gre@nextalteration=0\relax %
948 \ifnum\gre@nextalignment>9\relax %
949 \gre@count@temp@one=1\relax %
950 \fi %
951 \else %
952 \gre@count@temp@one=2\relax %
953 \fi %
954 \gre@debugmsg{spacing}{ gre@count@temp@one = \the\gre@count@temp@one}%
955 \gre@calculate@syllablefinalskip{#4}{\gre@count@temp@one}%
956 \ifcase#4 %
957 % we enter here if the end of word is 0, so we must determine if we need to type a dash here
958 \gre@skip@temp@one = \gre@skip@syllablefinalskip\relax%
959 \gre@debugmsg{ifdim}{ enddifference > 0pt}%
960 \ifdim\gre@dimen@enddifference >0pt\relax%
961 \advance\gre@skip@temp@one by \gre@dimen@enddifference\relax%
962 \fi %
963 \gre@debugmsg{ifdim}{ nextbegindifference > 0pt}%
964 \ifdim\gre@skip@nextbegindifference >0pt\relax%
965 \advance\gre@skip@temp@one by \gre@skip@nextbegindifference\relax%
966 \fi %
967 %
968 % then we compare it with \gre@space@dimen@maximumspacewithoutdash, if it is larger, we add a dash
969 %
970 \gre@debugmsg{ifdim}{ temp@skip@one > maximumspacewithoutdash}%
971 \ifdim\gre@skip@temp@one > \gre@space@dimen@maximumspacewithoutdash\relax%
972 \gre@debugmsg{hyphen}{spacing requires hyphen}%
973 \gre@showhyphenafterthissyllabletrue%
974 \fi %
975 \fi% ficase#4
976 \ifgre@showhyphenafterthissyllable\relax%
977 \global\gre@possibleluahyphenafterthissyllablefalse %
978 \gre@debugmsg{hyphen}{Showing the hyphen}%
979 % if it's the last syllable of line, the hyphen will be \GreHyph
980 \ifnum\gre@lastoflinecount=1\relax %
981 \ifgre@showlyrics%
982 \setbox\gre@box@syllabletext=\hbox{%
983 \IfSubStr{\gre@debug}{,notespacing,}%
984 % when debugging we add a zero-width line to mark the syllable bound
985 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
986 {}% do nothing if not debugging
987 \gre@emit@syllabletext{\gre@pointandclick{\gre@firstsyllablepart\gre@middlesyllablepart\gre@emit@endsyllablepart#3{\GreHyph}\relax}{#6}}%
988 \IfSubStr{\gre@debug}{,notespacing,}%
989 % when debugging we add a zero-width line to mark the syllable bound
990 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
991 {}% do nothing if not debugging
992 }%
993 \else%
994 \setbox\gre@box@syllabletext=\box\voidb@x%
995 \fi%
996 \else %
997 \ifgre@showlyrics%
998 \setbox\gre@box@syllabletext=\hbox{%
999 \IfSubStr{\gre@debug}{,notespacing,}%
1000 % when debugging we add a zero-width line to mark the syllable bound
1001 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1002 {}% do nothing if not debugging
1003 \gre@emit@syllabletext{\gre@pointandclick{\gre@firstsyllablepart\gre@middlesyllablepart\gre@emit@endsyllablepart#3{-}}{#6}}%
1004 \IfSubStr{\gre@debug}{,notespacing,}%
1005 % when debugging we add a zero-width line to mark the syllable bound
1006 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1007 {}% do nothing if not debugging
1008 }%
1009 \else%
1010 \setbox\gre@box@syllabletext=\box\voidb@x%
1011 \fi%
1012 \fi %
1013 % recomputing end difference and final skip with the final hyphen
1014 \gre@calculate@nextbegindifference{\gre@emit@endsyllablepartfornextsyllable}{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart}}{\gre@evaluatenextsyllable{\gre@nextmiddlesyllablepart}}{\gre@evaluatenextsyllable{\gre@nextendsyllablepart}}{\gre@nextalignment}{\gre@nextalteration}%
1015 \gre@calculate@enddifference{\wd\gre@box@syllablenotes}{\wd\gre@box@syllabletext}{\gre@dimen@textaligncenter}{\gre@dimen@notesaligncenter}{0}%
1016 \gre@calculate@syllablefinalskip{#4}{\gre@count@temp@one}%
1017 \else %
1018 \ifcase#4 %
1019 \global\gre@possibleluahyphenafterthissyllabletrue %
1020 \gre@debugmsg{hyphen}{No hyphen}%
1021 \gre@attr@dash=1\relax % in this particular case where it is not the end of a word and we haven't put a dash, we set potentital dash to 1
1022 % we rebuild this box, in order it to have the attribute
1023 \ifgre@showlyrics%
1024 \setbox\gre@box@syllabletext=\hbox{%
1025 \IfSubStr{\gre@debug}{,notespacing,}%
1026 % when debugging we add a zero-width line to mark the syllable bound
1027 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1028 {}% do nothing if not debugging
1029 \gre@emit@syllabletext{\gre@pointandclick{\gre@firstsyllablepart\gre@middlesyllablepart\gre@emit@endsyllablepart}{#6}}%
1030 \IfSubStr{\gre@debug}{,notespacing,}%
1031 % when debugging we add a zero-width line to mark the syllable bound
1032 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1033 {}% do nothing if not debugging
1034 }%
1035 \else%
1036 \setbox\gre@box@syllabletext=\box\voidb@x%
1037 \fi%
1038 \else %
1039 \global\gre@possibleluahyphenafterthissyllablefalse %
1040 \fi %
1041 \fi%
1042 \ifgre@textcleared%
1043 \gre@clearsyllable{note}%
1044 \fi%
1045 % then we reuse temp, we assign to it the \gre@dimen@begindifference, but only if it is positive, else it is 0
1046 \gre@debugmsg{ifdim}{ begindifference > 0pt}%
1047 \ifdim\gre@dimen@begindifference > 0 pt\relax%
1048 \gre@skip@temp@one = \gre@dimen@begindifference\relax%
1049 \kern\gre@skip@temp@one %
1050 \fi%
1051 #8\relax %
1052 \raise\gre@dimen@textlower%
1053 \copy\gre@box@syllabletext %
1054 \ifgre@mustdotranslationcenterend%
1055 % case of end of translation centering, we do it after the typesetting of the text
1056 \gre@dotranslationcenterend %
1057 \gre@mustdotranslationcenterendfalse%
1058 \fi %
1059 \gre@skip@temp@one = -\wd\gre@box@syllabletext %
1060 \kern\gre@skip@temp@one%
1061 \gre@skip@temp@one = -\gre@dimen@begindifference\relax%
1062 \kern\gre@skip@temp@one %
1063 % here we need to unset \gre@attr@dash for the typesetting of notes
1064 \gre@attr@dash=0\relax %
1065 \GreNoBreak % no line breaks between text and notes
1066 \ifgre@shownotes%
1067 \IfSubStr{\gre@debug}{,notespacing,}%
1068 % when debugging we add a zero-width line to mark the syllable bound
1069 {\raise 12pt\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1070 {}% do nothing if not debugging
1071 #9% we do that instead of \unhbox\Syllablnotes, because it would not set the \localrightbox
1072 \IfSubStr{\gre@debug}{,notespacing,}%
1073 % when debugging we add a zero-width line to mark the syllable bound
1074 {\raise 12pt\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1075 {}% do nothing if not debugging
1076 \fi%
1077 \GreNoBreak % no line breaks between notes and end of syllable skips
1078 \gre@debugmsg{ifdim}{ enddifference < 0pt}%
1079 \ifdim\gre@dimen@enddifference <0pt\relax%
1080 %% important, else we are not really at the end of the syllable
1081 \kern -\gre@dimen@enddifference\relax%
1082 \GreNoBreak %
1083 \fi%
1084 % we call end of syllable
1085 \gre@syllable@end{\gre@nextalignment}{\gre@nextalteration}{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart\gre@nextmiddlesyllablepart\gre@nextendsyllablepart}}{#4}%
1086 \gre@push@endsyllable{#6}\relax %
1087 \global\gre@dimen@notesaligncenter=0pt\relax% very important, see flat and natural
1088 \gre@unsetfixedtextformat %
1089 \ifgre@blockeolcustos\ifnum\gre@insidediscretionary=0\relax %
1090 \gre@localrightbox{}%
1091 \fi\fi %
1092 \relax %
1093 \gre@trace@end%
1094 }%
1095
1096 % #1 is the id of the euouae block (assigned by the C code)
1097 % #2 is whether there is a line break between here and the actuall beginning of
1098 % the euouae block. 1 if there is a linebreak, 0 in the general case.
1099 \def\GreNextSyllableBeginsEUOUAE#1#2{%
1100 \GreNoBreak %
1101 \ifgre@blockeolcustosbeforeeuouae %
1102 \GreSuppressEolCustos %
1103 \fi %
1104 \ifgre@raggedbreakbeforeeuouae %
1105 \directlua{gregoriotex.save_euouae(#1,1)}%
1106 \ifcase#2\ifcase\directlua{gregoriotex.is_ypos_different(#1)}\relax%
1107 \gre@newlinecommon{1}{1}%
1108 \fi\fi %
1109 \fi %
1110 \relax %
1111 }%
1112
1113 % #1 is the id of the euouae block (assigned by the C code)
1114 % #2 is whether there is a line break between here and the actuall beginning of
1115 % the euouae block. 1 if there is a linebreak, 0 in the general case.
1116 \def\GreLastSyllableBeforeEUOUAE#1#2{%
1117 \ifcase#2\ifcase\directlua{gregoriotex.is_ypos_different(#1)}\relax%
1118 \GreLastOfLine%
1119 \fi\fi %
1120 }%
1121
1122 %% @desc Macro to make a few checks and call the right macros between
1123 %% \endbeforebar, \endofword, \endofsyllable
1124 %% @arg#1 next syllable alignment type (#7:1 of \GreSyllable)
1125 %% @arg#2 next syllable alteration type (#7:2 of \GreSyllable)
1126 %% @arg#3 next syllable text
1127 %% @arg#4 end of word or not (#4 of \GreSyllable)
1128 \def\gre@syllable@end#1#2#3#4{%
1129 \gre@trace{gre@syllable@end{#1}{#2}{#3}{#4}}%
1130 % gre@count@temp@one holds 0 if next is a not bar, 1 if it is
1131 \gre@count@temp@one=0%
1132 \ifnum#2=0\relax %
1133 \ifnum#1>9\relax %
1134 \gre@count@temp@one=1%
1135 \fi %
1136 \fi %
1137 \gre@debugmsg{syllablespacing}{ gre@count@temp@one = \the\gre@count@temp@one}%
1138 \ifnum\gre@count@temp@one=1\relax %
1139 \ifnum\gre@lastoflinecount=1\relax %
1140 \gre@endofsyllable{0}{1}{1}%
1141 \else %
1142 % otherwise we call it with 1 only if there is no letters after (we can see it with nextbegindifference)
1143 \setbox\gre@box@temp@width=\hbox{#3}%
1144 \ifdim\wd\gre@box@temp@width=0pt\relax%
1145 \gre@endofsyllable{0}{1}{1}%
1146 \else %
1147 \gre@endofsyllable{1}{1}{1}%
1148 \fi %
1149 \fi %
1150 \else %
1151 \ifnum\gre@lastoflinecount=1\relax %
1152 \global\gre@lastoflinecount=2\relax %
1153 \fi %
1154 \gre@debugmsg{syllablespacing}{ calling endofsyllable with #4}%
1155 \gre@endofsyllable{1}{#4}{0}%
1156 \fi %
1157 \gre@trace@end%
1158 }
1159
1160 %% @desc Macro called at end of a syllable, adds a penalty and a space
1161 %% @arg#1 0 to only add the penalty, 1 otherwise
1162 %% @arg#2 0 if end of syllable, 1 if end of word
1163 %% @arg#3 1 if next syllable is a bar, 0 otherwise
1164 %%
1165 \def\gre@endofsyllable#1#2#3{%
1166 \gre@trace{gre@endofsyllable{#1}{#2}{#3}}%
1167 \ifgre@eolshiftsenabled%
1168 %this shift will shorten the line somewhat to allow the lyrics to extend under the custos should TeX decide to insert a line break after the syllable being ended
1169 \GreNoBreak%
1170 \gre@calculate@eolshift{\gre@dimen@enddifference}%
1171 \kern -\gre@dimen@eolshift\relax%
1172 \fi%
1173 \ifnum#3=1\relax %
1174 \GreNoBreak %
1175 \gre@debugmsg{syllablespacing}{ set penalty \the\gre@space@count@nobreakpenalty}%
1176 \else %
1177 \gre@count@temp@one=0\relax %
1178 \gre@if@rewritesyllable{%
1179 \GreNoBreak%
1180 }{%
1181 \ifnum#2=1\relax %
1182 \gre@penalty{\the\gre@space@count@endofwordpenalty}%
1183 \gre@debugmsg{syllablespacing}{ set penalty \the\gre@space@count@endofwordpenalty}%
1184 \else %
1185 \gre@penalty{\the\gre@space@count@endofsyllablepenalty}%
1186 \gre@debugmsg{syllablespacing}{ set penalty \the\gre@space@count@endofsyllablepenalty}%
1187 \fi %
1188 }%
1189 \gre@count@temp@one=0\relax %
1190 \fi %
1191 \ifgre@eolshiftsenabled%
1192 %If the above penalties don't result in a line break, then we need to undo the eolshift to prevent the next syllable from overlapping with this one. If the line break did occur, then this shift will occur at the beginning of a line and thus will be ignored automatically by TeX.
1193 \kern \gre@dimen@eolshift\relax%
1194 \GreNoBreak%
1195 \fi%
1196 \ifnum#1=1\relax %
1197 \ifgre@newbarspacing%
1198 %the new bar spacing algorithms take care of this for us when the next syllable is a bar
1199 \relax%
1200 \else%
1201 \gre@hskip\gre@skip@syllablefinalskip\relax%
1202 \fi%
1203 \ifnum#3=1\relax %
1204 \GreNoBreak %
1205 \else%
1206 \ifgre@newbarspacing%
1207 %the new bar spacing algorithm still needs the syllablefinalskip when the next syllable is not a bar
1208 \gre@hskip\gre@skip@syllablefinalskip\relax%
1209 \fi%
1210 \fi %
1211 \fi %
1212 \relax%
1213 \gre@trace@end%
1214 }%
1215
1216 \def\gresetbarspacing#1{%
1217 \IfStrEqCase{#1}{%
1218 {new}%
1219 {%
1220 \gre@newbarspacingtrue%
1221 \let\GreNoNoteSyllable\GreBarSyllable%
1222 }%
1223 {old}%
1224 {%
1225 \gre@newbarspacingfalse%
1226 \let\GreNoNoteSyllable\GreSyllable%
1227 }%
1228 }[% all other cases
1229 \gre@error{Unrecognized option "#1" for \protect\gresetbarspacing\MessageBreak Possible options are: 'new' and 'old'}%
1230 ]%
1231 }%
1232
1233 % macro to save new lines in bar syllables. With the new bar spacing algorithm, we
1234 % cannot allow (::z) to end the line right after the bar, so we just save the
1235 % end of line for later.
1236 \xdef\gre@newlinearg{-1}
1237 \gdef\gre@newlinecommondelayed#1#2{%
1238 \gre@trace{gre@newlinecommondelayed{#1}{#2}}%
1239 \xdef\gre@newlinearg{#1}%
1240 \gre@trace@end%
1241 }
1242
1243 %a macro to typeset a syllable with only a bar inside
1244 \def\GreBarSyllable#1#2#3#4#5#6#7#8#9{%
1245 \gre@trace{GreBarSyllable{#1}{#2}{#3}{#4}{#5}{#6}{#7}{#8}{#9}}%
1246 \gre@textclearedfalse%
1247 \gre@debugmsg{general}{}%
1248 \gre@debugmsg{general}{New bar syllable}%
1249 \gre@debugmsg{general}{}%
1250 \global\advance\gre@attr@syllable@id by 1\relax %
1251 \gre@possibleluahyphenafterthissyllablefalse %
1252 \gre@showhyphenafterthissyllablefalse %
1253 % the algorithm of this function is *extremely* complex, and has been much painful to write... good luck to understand.
1254 % the main goal is, when there is no text under the bar, to put the bar in the middle of the space between the last note of the previous syllable and the first note of the next syllable. But there are limits : a bar can't go very far above text. For example if there is "nuncncncncn" with a punctum on the u, the bar can't go above the fourth n, the most far position is the position where the end of the bar is above the end of the word. The same limitation applies for the syllable after the bar.
1255 % there are two different cases that have almost nothing in common : the case where there is something written under the bar, and the case where there is nothing.
1256 % first of all we need to calculate previousenddifference, begindifference, enddifference and nextbegindifference.
1257 #1%
1258 \gre@calculate@textaligncenter{\gre@saved@syllable@endsyllablepart}{\gre@firstsyllablepart}{\gre@middlesyllablepart}{0}%
1259 \ifgre@showlyrics%
1260 \setbox\gre@box@syllabletext=\hbox{%
1261 \IfSubStr{\gre@debug}{,barspacing,}%
1262 % when debugging we add a zero-width line to mark the syllable bound
1263 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1264 {}% do nothing if not debugging
1265 \gre@emit@syllabletext{\gre@pointandclick{\gre@firstsyllablepart\gre@middlesyllablepart\gre@emit@endsyllablepart}{#6}}%
1266 \IfSubStr{\gre@debug}{,barspacing,}%
1267 % when debugging we add a zero-width line to mark the syllable bound
1268 {\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1269 {}% do nothing if not debugging
1270 }%
1271 \else%
1272 \setbox\gre@box@syllabletext=\box\voidb@x%
1273 \fi%
1274 \gre@debugmsg{barspacing}{Width of bar text: \the\wd\gre@box@syllabletext}%
1275 \global\let\gre@saved@prelinedelay@newlinecommon\gre@newlinecommon %
1276 \global\let\gre@newlinecommon\gre@newlinecommondelayed %
1277 \xdef\gre@newlinearg{-1}%
1278 \gre@syllablenotes{#9}%
1279 \gre@debugmsg{barspacing}{Width of bar line: \the\wd\gre@box@syllablenotes}%
1280 \gre@dimen@notesaligncenter=\dimexpr(\wd\gre@box@syllablenotes / 2)\relax %
1281 \gre@dimen@begindifference=\dimexpr(\gre@dimen@notesaligncenter - \gre@dimen@textaligncenter)\relax%
1282 \gre@calculate@enddifference{\wd\gre@box@syllablenotes}{\wd\gre@box@syllabletext}{\gre@dimen@textaligncenter}{\gre@dimen@notesaligncenter}{1}%
1283 #5%
1284 % if the next glyph has an alteration, check if it is suppressed;
1285 % if so, pretend there's no alteration
1286 \def\gre@nextalignment{\gre@arg@oftwo@first#7}%
1287 \def\gre@nextalteration{\gre@arg@oftwo@second#7}%
1288 \ifnum\gre@nextalteration>0\relax
1289 \gre@alteration@isvisible{1}{\gre@nextalteration}%
1290 \ifgre@alteration@isvisible
1291 \else
1292 \def\gre@nextalteration{0}%
1293 \fi
1294 \fi
1295 \gre@calculate@nextbegindifference{\gre@emit@endsyllablepartfornextsyllable}{\gre@evaluatenextsyllable{\gre@nextfirstsyllablepart}}{\gre@evaluatenextsyllable{\gre@nextmiddlesyllablepart}}{\gre@evaluatenextsyllable{\gre@nextendsyllablepart}}{\gre@nextalignment}{\gre@nextalteration}%
1296 \gre@unsetfixednexttextformat %
1297 \gre@debugmsg{barspacing}{previousenddifference: \the\gre@dimen@previousenddifference}%
1298 \gre@debugmsg{barspacing}{begindifference: \the\gre@dimen@begindifference}%
1299 \gre@debugmsg{barspacing}{enddifference: \the\gre@dimen@enddifference}%
1300 \gre@debugmsg{barspacing}{nextbegindifference: \the\gre@skip@nextbegindifference}%
1301 \ifgre@newbarspacing%
1302 %
1303 % New bar spacing algorithm
1304 %
1305 \gre@calculate@barposition{#4}{\gre@nextalteration}%
1306 \ifgre@textcleared%
1307 \gre@clearsyllable{bar}%
1308 \fi%
1309 %now we can place the text and bar
1310 %we're going to use the bar line to control positioning, so we need to start by getting to the end of the notes of the previous syllable
1311 \ifdim\gre@dimen@adjustedpreviousenddifference < 0pt\relax%
1312 %we need to move back to where the previous notes ended
1313 \kern\gre@dimen@adjustedpreviousenddifference\relax%
1314 \fi%
1315 \GreNoBreak %
1316 %move to the beginning of the text
1317 \gre@hskip\glueexpr(\gre@skip@bar@allocation/2% right from end of previous notes to nominal middle of bar line
1318 +\gre@dimen@bar@shift% from nominal middle of bar line to actual middle
1319 -\wd\gre@box@syllablenotes/2% back up to beginning of bar line
1320 +\gre@dimen@begindifference% from beginning of bar line to beginning of text
1321 +\gre@space@skip@bar@rubber)\relax % the rubber component
1322 \GreNoBreak %
1323 % all that extra stuff (translations and the like)
1324 #8%
1325 \GreNoBreak %
1326 %print the text, the raise is in case of a translation
1327 \raise\gre@dimen@textlower \copy\gre@box@syllabletext%
1328 %and the code which handles translation centering
1329 \ifgre@mustdotranslationcenterend%
1330 % case of end of translation centering, we do it after the typesetting of the text
1331 \gre@dotranslationcenterend %
1332 \gre@mustdotranslationcenterendfalse%
1333 \fi %
1334 %move back to the beginning of the bar line
1335 \kern\dimexpr(\gre@dimen@enddifference% move from end of text to end of bar line
1336 -\wd\gre@box@syllablenotes)\relax % back up from end of bar line to beginning
1337 \GreNoBreak%
1338 \ifgre@shownotes%
1339 \IfSubStr{\gre@debug}{,barspacing,}%
1340 % when debugging we add a zero-width line to mark the syllable bound
1341 {\raise 12pt\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1342 {}% do nothing if not debugging
1343 #9%
1344 \IfSubStr{\gre@debug}{,barspacing,}%
1345 % when debugging we add a zero-width line to mark the syllable bound
1346 {\raise 12pt\hbox to 0pt{\rule{0.4pt}{12pt}\hss}}%
1347 {}% do nothing if not debugging
1348 \fi%
1349 \global\let\gre@newlinecommon\gre@saved@prelinedelay@newlinecommon %
1350 \GreNoBreak%
1351 % get into position to place the penalty
1352 \ifdim\gre@dimen@enddifference < 0pt\relax%
1353 % the text extends past the notes, so we need to get to the end of the text
1354 \kern-\gre@dimen@enddifference%
1355 \GreNoBreak%
1356 \fi%
1357 \ifgre@eolshiftsenabled%
1358 \ifgre@endofscore%
1359 \kern\glueexpr(-\gre@skip@bar@lastskip)\relax%
1360 \else%
1361 %this shift will shorten the line somewhat to allow the lyrics to extend under the custos should TeX decide to insert a line break after the syllable being ended
1362 \gre@calculate@eolshift{\dimexpr(\gre@dimen@enddifference-\gre@skip@bar@lastskip)\relax }%
1363 \gre@debugmsg{barspacing}{End of line shift: \the\gre@dimen@eolshift}%
1364 \ifdim\gre@dimen@eolshift<\gre@skip@bar@lastskip %
1365 \gre@dimen@eolshift=\gre@skip@bar@lastskip\relax %
1366 \fi %
1367 \kern\glueexpr(-\gre@dimen@eolshift)\relax%
1368 \fi%
1369 \fi%
1370 % gre@count@temp@one is "forced end of line or last of score"
1371 \gre@count@temp@one=0\relax %
1372 \ifnum\gre@newlinearg=-1\else %
1373 \gre@count@temp@one=1\relax %
1374 \fi %
1375 \ifnum\gre@lastoflinecount=1\relax %
1376 \gre@count@temp@one=1\relax %
1377 \fi %
1378 \ifgre@endofscore %
1379 \gre@count@temp@one=1\relax %
1380 \fi %
1381 % if no end of line or end of score
1382 \ifnum\gre@count@temp@one=0\relax %
1383 % add the penalty
1384 \gre@debugmsg{barspacing}{after bar penalty: \the\gre@space@count@endafterbarpenalty}%
1385 \gre@penalty{\the\gre@space@count@endafterbarpenalty}%
1386 \ifgre@eolshiftsenabled%
1387 \ifgre@endofscore\else%
1388 %If the above penalties don't result in a line break, then we need to undo the eolshift to prevent the next syllable from overlapping with this one. If the line break did occur, then this shift will occur at the beginning of a line and thus will be ignored automatically by TeX.
1389 \kern \dimexpr(\gre@dimen@eolshift)\relax%
1390 \GreNoBreak%
1391 \fi%
1392 \fi%
1393 \ifdim\gre@dimen@enddifference < 0pt\relax%
1394 %undo the earlier shift
1395 \kern\gre@dimen@enddifference%
1396 \GreNoBreak%
1397 \fi%
1398 % adjustment for alterations:
1399 \kern-\gre@skip@alterationshift %
1400 %move to the beginning of the notes of the next syllable
1401 \gre@hskip\glueexpr(-\wd\gre@box@syllablenotes/2% back up to middle of notes
1402 -\gre@dimen@bar@shift% go back from actual middle to nominal middle of bar line
1403 +\gre@skip@bar@allocation/2% go from nominal middle to the start of the next notes
1404 +\gre@space@skip@bar@rubber)\relax % the rubber component
1405 \ifdim\gre@skip@nextbegindifference < 0pt\relax%
1406 %we need to move back to where the text for the next syllable should start
1407 \GreNoBreak %
1408 \kern\gre@skip@nextbegindifference\relax%
1409 \fi%
1410 \else %
1411 \ifgre@endofscore %
1412 \gre@localleftbox{}%
1413 \gre@debugmsg{barspacing}{after bar penalty: \gre@space@count@endafterbarpenalty}%
1414 \gre@penalty{\the\gre@space@count@finalpenalty}%
1415 \else %
1416 \ifnum\gre@newlinearg=-1\else %
1417 \gre@debugmsg{barspacing}{calling new line with argument: \gre@newlinearg}%
1418 \gre@newlinecommon{\gre@newlinearg}{1}%
1419 \fi %
1420 \fi %
1421 \fi%
1422 \else%
1423 %
1424 % Old spacing algorithm
1425 %
1426 %This is the old algorithm. I've kept it in case people still want to use it.
1427 \gre@punctummoraadjustment%
1428 \ifgre@textcleared%
1429 \gre@clearsyllable{bar}%
1430 \fi%
1431 % then we check if there is something to write
1432 \global\let\gre@newlinecommon\gre@saved@prelinedelay@newlinecommon %
1433 \gre@debugmsg{ifdim}{ wd(gre@box@syllabletext) = 0pt}%
1434 \ifdim\wd\gre@box@syllabletext = 0 pt\relax %
1435 % the most difficult case : when there is nothing to write
1436 % first we need to determine the real space that there will be between the notes. Here again it is not so simple... let's consider these two kinds of spaces :
1437 %% 1/ the minimal space between a note and the bar + the width of the bar + the minimal space between the bar and the note (that's the global idea, in fact there are nuances) : we assign skip@temp@three to it
1438 %% 2/ enddifference + begindifference + space between notes and word : we assign skip@temp@two to it
1439 \gre@skip@temp@three=\glueexpr(\gre@space@skip@notebarspace %
1440 + \gre@space@skip@notebarspace %
1441 + \wd\gre@box@syllablenotes)\relax %
1442 % now let's get skip@temp@two
1443 \gre@debugmsg{ifdim}{ nextbegindifference < 0pt}%
1444 \ifdim\gre@skip@nextbegindifference < 0 pt\relax%
1445 \gre@skip@temp@two=-\gre@skip@nextbegindifference\relax%
1446 \else %
1447 \gre@skip@temp@two=0 pt\relax%
1448 \fi %
1449 \gre@debugmsg{ifdim}{ adjustedpreviousenddifference < 0pt}%
1450 \ifdim\gre@dimen@adjustedpreviousenddifference < 0 pt\relax%
1451 \advance\gre@skip@temp@two by %
1452 \glueexpr(-\gre@dimen@adjustedpreviousenddifference %
1453 + \gre@space@skip@interwordspacetext)\relax%
1454 \else %
1455 \advance\gre@skip@temp@two by \gre@space@skip@interwordspacenotes\relax%
1456 \fi%
1457 % we take the max of it, then we divide it by two and we substract half of the width of the bar
1458 \gre@debugmsg{ifdim}{ temp@skip@three < temp@skip@two}%
1459 \ifdim\gre@skip@temp@three <\gre@skip@temp@two %
1460 \gre@skip@temp@three=\gre@skip@temp@two %
1461 \fi %
1462 \divide\gre@skip@temp@three by 2\relax %
1463 \advance\gre@skip@temp@three by \dimexpr(\wd\gre@box@syllablenotes / -2)\relax %
1464 % now we have our skipone
1465 \gre@skip@temp@two=\gre@skip@temp@three %
1466 \gre@debugmsg{ifdim}{ adjustedpreviousenddifference < 0pt}%
1467 \ifdim\gre@dimen@adjustedpreviousenddifference < 0 pt\relax%
1468 \advance\gre@skip@temp@two by \gre@dimen@adjustedpreviousenddifference\relax%
1469 \fi %
1470 \GreNoBreak %
1471 \gre@debugmsg{ifdim}{ temp@skip@two > -wd(gre@box@syllablenotes)}%
1472 \ifdim\gre@skip@temp@two > -\wd\gre@box@syllablenotes %
1473 \kern\gre@skip@temp@two %
1474 \else %
1475 \gre@skip@temp@one = -\wd\gre@box@syllablenotes %
1476 \kern\gre@skip@temp@one%
1477 \fi %
1478 \GreNoBreak %
1479 #8\relax %
1480 \ifgre@mustdotranslationcenterend%
1481 % case of end of translation centering, we do it after the typesetting of the text
1482 \gre@dotranslationcenterend %
1483 \gre@mustdotranslationcenterendfalse%
1484 \fi %
1485 \ifgre@shownotes%
1486 #9\relax %
1487 \fi%
1488 \gre@penalty{\the\gre@space@count@endafterbaraltpenalty }% TODO: isn't it a bit buggy?
1489 % end of same code as syllable
1490 \ifnum\gre@lastoflinecount=1\relax %
1491 \global\gre@lastoflinecount=2\relax %
1492 \else %
1493 \gre@debugmsg{ifdim}{ temp@skip@two < -wd(gre@box@syllablenotes)}%
1494 \ifdim\gre@skip@temp@two < -\wd\gre@box@syllablenotes %
1495 \gre@debugmsg{ifdim}{ nextbegindifference > 0pt}%
1496 \ifdim\gre@skip@nextbegindifference > 0 pt\relax%
1497 \gre@skip@temp@one = \gre@space@skip@interwordspacetext\relax%
1498 \gre@hskip\gre@skip@temp@one %
1499 \else % \ifdim\gre@skip@nextbegindifference > 0 pt
1500 \gre@skip@temp@one = \gre@space@skip@interwordspacetext\relax%
1501 \gre@hskip\gre@skip@temp@one %
1502 \fi %
1503 \else %
1504 \gre@skip@temp@two=\gre@skip@temp@three %
1505 \gre@debugmsg{ifdim}{ nextbegindifference < 0pt}%
1506 \ifdim\gre@skip@nextbegindifference < 0 pt\relax%
1507 \advance\gre@skip@temp@two by \gre@skip@nextbegindifference\relax%
1508 \fi %
1509 \gre@debugmsg{ifdim}{ temp@skip@two > -wd(gre@box@syllablenotes)}%
1510 \ifdim\gre@skip@temp@two > -\wd\gre@box@syllablenotes %
1511 \kern\gre@skip@temp@two %
1512 \else % \ifdim\gre@dimen@temp@five > -\wd\gre@box@syllablenotes
1513 \gre@skip@temp@one = -\wd\gre@box@syllablenotes %
1514 \gre@hskip\gre@skip@temp@one %
1515 \fi %
1516 \fi %
1517 \fi %
1518 % then the most simple : the case where there is something to write under the bar. We just need to adjust the spaces.
1519 \else %ifdim\wd\gre@box@syllabletext = 0 pt
1520 #8\relax %
1521 \raise\gre@dimen@textlower \copy\gre@box@syllabletext %
1522 \ifgre@mustdotranslationcenterend%
1523 % case of end of translation centering, we do it after the typesetting of the text
1524 \gre@dotranslationcenterend %
1525 \gre@mustdotranslationcenterendfalse%
1526 \fi %
1527 \gre@skip@temp@one = -\wd\gre@box@syllabletext %
1528 \kern\gre@skip@temp@one %
1529 \gre@skip@temp@one = -\gre@dimen@begindifference\relax%
1530 \kern\gre@skip@temp@one %
1531 \ifgre@shownotes%
1532 #9%
1533 \fi%
1534 \gre@debugmsg{ifdim}{ enddifference < 0pt}%
1535 \ifdim\gre@dimen@enddifference <0pt\relax%
1536 %% important, else we are not really at the end of the syllable
1537 \gre@skip@temp@one = -\gre@dimen@enddifference\relax%
1538 \kern\gre@skip@temp@one %
1539 \fi%
1540 % end of same code as syllable
1541 \ifnum\gre@lastoflinecount=1\relax %
1542 \global\gre@lastoflinecount=2\relax %
1543 \gre@endafterbar{0}%
1544 \else %
1545 \global\gre@lastoflinecount=0\relax %
1546 \gre@endafterbar{1}%
1547 \fi %
1548 %and that's it !!
1549 \fi %
1550 \fi%
1551 \gre@push@endsyllable{#6}\relax %
1552 \global\gre@dimen@notesaligncenter= 0 pt\relax % very important, see flat and natural
1553 \gre@unsetfixedtextformat %
1554 \ifgre@blockeolcustos\ifnum\gre@insidediscretionary=0\relax %
1555 \gre@localrightbox{}%
1556 \fi\fi %
1557 \relax%
1558 \gre@trace@end%
1559 }
1560
1561 \newif\ifgre@newbarspacing%
1562 \gre@newbarspacingtrue%
1563 % the new bar spacing algorithm treats no note syllables as BarSyllables, while the old algorithm treated them as regular syllables. In order to allow for this variant, we define NoNoteSyllable which aliases to the appropriate function
1564 \let\GreNoNoteSyllable\GreBarSyllable%
1565
1566 %% internal macro to set the first syllable text after all parts are known
1567 %% #1 - First part of the syllable (before the vowel)
1568 %% #2 - Middle part of the syllable (the vowel)
1569 %% #3 - Last part of the syllable (after the vowel)
1570 %% #4 - First letter of the syllable
1571 %% #5 - Everything after the first letter of the syllable
1572 %% #6 - Macros to run after the text is emitted
1573 \def\gre@setfirstsyllabletext#1#2#3#4#5#6{%
1574 \gre@trace{gre@setfirstsyllabletext{#1}{#2}{#3}{#4}{#5}{#6}}%
1575 \def\gre@opening@syllabletext{%
1576 \GreSetThisSyllable{#1}{#2}{#3}%
1577 {\GreFirstWord{\GreFirstSyllable{\GreFirstSyllableInitial{#4}}}}%
1578 {\GreFirstWord{\GreFirstSyllable{#5}}}%
1579 #6\relax %
1580 }%
1581 \gre@trace@end%
1582 }%
1583
1584 \newcount\gre@count@initiallines
1585 \def\gresetinitiallines#1{%
1586 \IfInteger{#1}%
1587 {%
1588 \ifnum#1>-1\relax%
1589 \gre@count@initiallines=#1\relax%
1590 \else%
1591 \gre@error{The argument for \protect\gresetinitiallines\space must be positive}%
1592 \fi%
1593 }%
1594 {\gre@error{\protect\gresetinitiallines\space takes a positive integer argument}}%
1595 }%
1596 \gresetinitiallines{1}% default to one-line initials
1597
1598 %% sets the first syllable text
1599 %% #1 - Initial
1600 %% #2 - First letter after the initial
1601 %% #3 - everything else in the syllable
1602 %% #4 - Three syllable parts when there is a separated initial
1603 %% #5 - Three syllable parts where there is no separated initial
1604 %% #6 - Extra macros to run if there is an initial
1605 \def\GreSetFirstSyllableText#1#2#3#4#5#6{%
1606 \gre@printcommentary%
1607 \ifcase\gre@count@initiallines\relax % no initial
1608 \gre@noinitial %
1609 \gre@setfirstsyllabletext#5{#1}{#2#3}{}%
1610 \else % regular initial
1611 \gre@setinitial{#1}%
1612 \gre@setfirstsyllabletext#4{#2}{#3}{#6}%
1613 \fi %
1614 }%
1615
1616 \def\GreSetNoFirstSyllableText{%
1617 \gre@noinitial %
1618 \gre@setfirstsyllabletext{}{}{}{}{}{}%
1619 }%
1620
1621 \def\GreUpcomingNewLineForcesCustos#1{%
1622 \ifcase#1\relax % 0 - forced off
1623 \GreSuppressEolCustos %
1624 \or % 1 - forced on
1625 \gre@useautoeolcustos %
1626 \GreNextCustos{\gre@nextcustospitch}{\gre@nextcustosalteration}%
1627 \fi %
1628 }%
1629
1630 %% opens a score
1631 %% #1 - macros rendering the things after the initial but before the notes
1632 %% #2 - macros rendering the things after starting notes but before the syllable
1633 %% #3 - macros rendering the things before the initial
1634 %% #4 - control sequence for the syllable
1635 %% #5 - macros rendering the first syllable; should emit the initial and
1636 %% populate \gre@opening@syllabletext (even if that should be empty)
1637 \def\GreScoreOpening#1#2#3#4#5{%
1638 #3\relax % fixed styles, etc.
1639 #5\relax % should emit the initial
1640 #1\relax % score reference, voice info, etc.
1641 #2\relax % initial clef, etc.
1642 #4{\gre@opening@syllabletext}%
1643 }%