%GregorioTeX file.
%
% Copyright (C) 2010-2016 The Gregorio Project (see CONTRIBUTORS.md)
%
% This file is part of Gregorio.
%
% Gregorio is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Gregorio is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Gregorio.  If not, see <http://www.gnu.org/licenses/>.

% this file contains definitions of spaces and penalties

%% First, the penalties

% penalty to force a break on a new line
\xdef\grenewlinepenalty{-10001}%
% penalty to prevent a line break
\xdef\grenobreakpenalty{10001}%
% penalty at the end of a syllable which is the end of a word
\xdef\greendofwordpenalty{-100}%
% penalty at the end of a syllable which is not the end of a word
\xdef\greendofsyllablepenalty{-50}%
% penalty at the end of a syllable which is just a bar, with something printed
% under it
\xdef\greendafterbarpenalty{-200}%
% penalty right after a bar with nothing printed
\xdef\greendafterbaraltpenalty{-200}%
% penalty at the end of the score
\xdef\grefinalpenalty{0}%
% penalty at the end of a breakable neumatic element (typically at a space
% between elements)
\xdef\greendofelementpenalty{-50}%
% hyphenpenalty will be used in discretionaries, in Gregorio this is used for
% a bar with clef change for example. It also set \exhyphenpenalty. It should
% be close to \greendafterbarpenalty
\xdef\grehyphenpenalty{-200}%
% broken penalty is the vertical penalty inserted after a break on a clef change
% I'm not sure it should be set, but it might be useful...
\xdef\grebrokenpenalty{0}%

%% These macro enable the tuning of linepenalty, tolerance, pretolerance
%% and emergencystretch
\def\grelooseness{-1}%
\def\gretolerance{9000}%
% Workaround for bug 842 (http://tracker.luatex.org/view.php?id=842)
% see http://tug.org/pipermail/luatex/2013-July/004516.html
% The idea is that we use discretionaries (explicit hyphens, though more than hyphens in our case) for clef changes, and we need to give them a special penalty, which is not taken into account if pretolerance is > -1 on LuaTeX < 0.80. For a more detailed explanation see http://tug.org/pipermail/luatex/2013-July/004516.html.
\ifnum\the\luatexversion < 78\relax %
	\global\def\grepretolerance{-1}%
\else %
	\global\def\grepretolerance{\pretolerance}%
\fi %
\def\greemergencystretch{\emergencystretch}%
% By default, we don't care if a line of score is alone on the page,
% if you think it is bad, you can modify the two following values. Assigning
% 10000 to them will prevent all orphaned lines (this will certainly improve
% some spacings a lot).
\def\grewidowpenalty{0}%
\def\greclubpenalty{0}%



%%%%%%%%%%%%%%%%%%%
%% And finally, all the spacings:
%%%%%%%%%%%%%%%%%%%

%This count tells gregoriotex what \gre@factor the below values correspond to.
%% All the following values correspond to a gre@factor of 17.  At this size the scores should be approximately the size usually seen in a gradual.
%% If you’re creating your own space configuration file, you may set this to some other value, should you so desire.
\greconffactor=17%

% the additional width of the additional lines (compared to the width of the glyph they're associated with)
\grecreatedim{additionallineswidth}{0.14584 cm}{scalable}%
% width of the additional lines, used only for the custos (maybe should depend on the width of the custos...)
% the width is the one for the custos at end of lines, the line for custos in the middle of a score is the same
% multiplied by 2.
\grecreatedim{additionalcustoslineswidth}{0.09114 cm}{scalable}%
% null space
\grecreatedim{zerowidthspace}{0 cm}{scalable}%
% space between glyphs in the same element
\grecreatedim{interglyphspace}{0.06927 cm plus 0.00363 cm minus 0.00363 cm}{scalable}%
% space between an alteration (flat or natural) and the next glyph
\grecreatedim{alterationspace}{0.07747 cm}{scalable}%
% space between a clef and a flat (for clefs with flat)
\grecreatedim{clefflatspace}{0.05469 cm plus 0.00638 cm minus 0.00638 cm}{scalable}%
% space before a choral sign
\grecreatedim{beforelowchoralsignspace}{0.04556 cm plus 0.00638 cm minus 0.00638 cm}{scalable}%
% when bolshifts are enabled, minimal space between a clef at the beginning of the line and a leading alteration glyph (should be larger than clefflatspace so that a flatted clef can be distinguished from a flat which is part of the first glyph on a line, but also smaller than spaceafterlineclef, the distance from the clef to the first notes)
\grecreatedim{beforealterationspace}{0.1 cm}{scalable}%
% half-space between elements
\grecreatedim{halfspace}{0.03463 cm plus 0.00091 cm minus 0.00182 cm}{scalable}%
% space between elements
\grecreatedim{interelementspace}{0.06927 cm plus 0.00182 cm minus 0.00363 cm}{scalable}%
% larger space between elements
\grecreatedim{largerspace}{0.10938 cm plus 0.01822 cm minus 0.00911 cm}{scalable}%
% space between elements in ancient notation
\grecreatedim{nabcinterelementspace}{0.06927 cm plus 0.00182 cm minus 0.00363 cm}{scalable}%
% larger space between elements in ancient notation
\grecreatedim{nabclargerspace}{0.10938 cm plus 0.01822 cm minus 0.00911 cm}{scalable}%
% space between elements which has the size of a note
\grecreatedim{glyphspace}{0.21877 cm plus 0.01822 cm minus 0.01822 cm}{scalable}%
% space before in-line custos
\grecreatedim{spacebeforeinlinecustos}{0 cm plus 0 cm minus 0 cm}{scalable}%
% space before end-of-line custos
\grecreatedim{spacebeforeeolcustos}{0.3 cm plus 0 cm minus 0 cm}{scalable}%
% space before punctum mora and augmentum duplex
\grecreatedim{spacebeforesigns}{0.050 cm plus 0.004 cm minus 0.004 cm}{scalable}%
% when a syllable is shifted left because of a preceding punctum mora, moraadjustmentbar is
% also added. Use it to make the syllable a bit further from the punctum mora if you want.
% This version is the general case.
\grecreatedim{moraadjustment}{0.050 cm}{scalable}%
% This version is for when punctum mora is before a bar.
\grecreatedim{moraadjustmentbar}{0 cm}{scalable}%
% space after punctum mora and augmentum duplex
\grecreatedim{spaceaftersigns}{0.08203 cm plus 0.0082 cm minus 0.0082 cm}{scalable}%
% space after a clef at the beginning of a line
\grecreatedim{spaceafterlineclef}{0.27345 cm plus 0.14584 cm minus 0.01367 cm}{scalable}%
% minimal space between notes of different words
\grecreatedim{interwordspacenotes}{0.27 cm plus 0.15 cm minus 0.05 cm}{scalable}%
% minimal space between notes of the same syllable.
\grecreatedim{intersyllablespacenotes}{0.24 cm}{scalable}%
% stretching added in the case where the text of two syllables of the same word are
% separated with an automatic hyphen
\grecreatedim{intersyllablespacestretchhyphen}{0cm plus 0.05cm}{scalable}%
% minimal space between letters of different words. Makes sense to have
% the same plus and minus as interwordspacenotes.
\grecreatedim{interwordspacetext}{0.38 cm plus 0.15 cm minus 0.05 cm}{scalable}%
% Versions of interword spaces for euouae blocks
\grecreatedim{interwordspacenotes@euouae}{0.19 cm plus 0.1 cm minus 0.05 cm}{scalable}%
\grecreatedim{interwordspacetext@euouae}{0.27 cm plus 0.1 cm minus 0.05 cm}{scalable}%
% versions of note spaces when the first note of the second syllable is an alteration
% those are used in euouae blocks
\grecreatedim{interwordspacenotes@alteration}{0.1 cm plus 0.07 cm minus 0.01 cm}{scalable}%
\grecreatedim{intersyllablespacenotes@alteration}{0.1 cm}{scalable}%
% space between notes of a bivirga or trivirga
\grecreatedim{bitrivirspace}{0.06927 cm plus 0.00182 cm minus 0.00546 cm}{scalable}%
% space between notes of a bistropha or tristrophae
\grecreatedim{bitristrospace}{0.06927 cm plus 0.00182 cm minus 0.00546 cm}{scalable}%
%
%%%%%%%%%%%%%%%%%%%%
% puncta inclinata %
%%%%%%%%%%%%%%%%%%%%
%
% space between two punctum inclinatum
\grecreatedim{punctuminclinatumshift}{-0.03918 cm plus 0.0009 cm minus 0.0009 cm}{scalable}%
% space before puncta inclinata
\grecreatedim{beforepunctainclinatashift}{0.05286 cm plus 0.00728 cm minus 0.00455 cm}{scalable}%
% space between a punctum inclinatum and a punctum inclinatum deminutus
\grecreatedim{punctuminclinatumanddebilisshift}{-0.02278 cm plus 0.0009 cm minus 0.0009 cm}{scalable}%
% space between two punctum inclinatum deminutus
\grecreatedim{punctuminclinatumdebilisshift}{-0.00728 cm plus 0.0009 cm minus 0.0009 cm}{scalable}%
% space between puncta inclinata, larger ambitus (range=3rd)
\grecreatedim{punctuminclinatumbigshift}{0.07565 cm plus 0.0009 cm minus 0.0009 cm}{scalable}%
% space between puncta inclinata, larger ambitus (range=4th or 5th)
\grecreatedim{punctuminclinatummaxshift}{0.17865 cm plus 0.0009 cm minus 0.0009 cm}{scalable}%
% space between two ascending punctum inclinatum
\grecreatedim{ascendingpunctuminclinatumshift}{-0.07918 cm plus 0.0009 cm minus 0.0009 cm}{scalable}%
% space between a punctum inclinatum and a punctum inclinatum deminutus, ascending
\grecreatedim{ascendingpunctuminclinatumanddebilisshift}{-0.06278 cm plus 0.0009 cm minus 0.0009 cm}{scalable}%
% space between ascending puncta inclinata, larger ambitus (range=3rd)
\grecreatedim{ascendingpunctuminclinatumbigshift}{-0.00435 cm plus 0.0009 cm minus 0.0009 cm}{scalable}%
% space between ascending puncta inclinata, larger ambitus (range=4th or 5th)
\grecreatedim{ascendingpunctuminclinatummaxshift}{0.09865 cm plus 0.0009 cm minus 0.0009 cm}{scalable}%
% space between a punctum inclinatum and a no-bar glyph one pitch below
\grecreatedim{descendinginclinatumtonobarshift}{-0.00073 cm plus 0.00363 cm minus 0.00363 cm}{scalable}%
% space between a punctum inclinatum and a no-bar glyph two pitches below
\grecreatedim{descendinginclinatumtonobarbigshift}{0.10927 cm plus 0.00363 cm minus 0.00363 cm}{scalable}%
% space between a punctum inclinatum and a no-bar glyph three or four pitches below
\grecreatedim{descendinginclinatumtonobarmaxshift}{0.23927 cm plus 0.00363 cm minus 0.00363 cm}{scalable}%
% space between a punctum inclinatum and a no-bar glyph one pitch above
\grecreatedim{ascendinginclinatumtonobarshift}{-0.02473 cm plus 0.00363 cm minus 0.00363 cm}{scalable}%
% space between a punctum inclinatum and a no-bar glyph two pitches above
\grecreatedim{ascendinginclinatumtonobarbigshift}{0.04427 cm plus 0.00363 cm minus 0.00363 cm}{scalable}%
% space between a punctum inclinatum and a no-bar glyph three or four pitches above
\grecreatedim{ascendinginclinatumtonobarmaxshift}{0.12927 cm plus 0.00363 cm minus 0.00363 cm}{scalable}%
%
%%%%%%%%
% bars %
%%%%%%%%
%
% bars inside syllables
%
\grecreatedim{bar@virgula}{0.1823 cm plus 0.22787 cm minus 0.00469 cm}{scalable}%
\grecreatedim{bar@minima}{0.1823 cm plus 0.22787 cm minus 0.00469 cm}{scalable}%
\grecreatedim{bar@minor}{0.1823 cm plus 0.22787 cm minus 0.00469 cm}{scalable}%
% dominican bars
\grecreatedim{bar@dominican}{0.1823 cm plus 0.22787 cm minus 0.00469 cm}{scalable}%
\grecreatedim{bar@maior}{0.1823 cm plus 0.22787 cm minus 0.00469 cm}{scalable}%
\grecreatedim{bar@finalis}{0.1823 cm plus 0.22787 cm minus 0.00469 cm}{scalable}%
% space added before the final divisio finalis (old bar spacing algorithm only)
\grecreatedim{bar@finalfinalis}{0.29169 cm plus 0.07292 cm minus 0.27345 cm}{scalable}%
%
% bars having their own syllable, with text associated (new bar spacing algorithm only)
% plus or minus here will trigger some problems
%
\grecreatedim{bar@virgula@standalone@text}{0.2323 cm}{scalable}%
\grecreatedim{bar@minima@standalone@text}{0.2323 cm}{scalable}%
\grecreatedim{bar@minor@standalone@text}{0.2323 cm}{scalable}%
\grecreatedim{bar@dominican@standalone@text}{0.2323 cm}{scalable}%
\grecreatedim{bar@maior@standalone@text}{0.2323 cm}{scalable}%
\grecreatedim{bar@finalis@standalone@text}{0.2323 cm}{scalable}%
% actual space before divisio finalis, not additional one
\grecreatedim{bar@finalfinalis@standalone@text}{0.29169 cm}{scalable}%
%
% bars having their own syllable, with no text associated (new bar spacing algorithm only)
%
\grecreatedim{bar@virgula@standalone@notext}{0.2323 cm}{scalable}%
\grecreatedim{bar@minima@standalone@notext}{0.2323 cm}{scalable}%
\grecreatedim{bar@minor@standalone@notext}{0.2323 cm}{scalable}%
\grecreatedim{bar@dominican@standalone@notext}{0.2323 cm}{scalable}%
\grecreatedim{bar@maior@standalone@notext}{0.2323 cm}{scalable}%
\grecreatedim{bar@finalis@standalone@notext}{0.2323 cm}{scalable}%
\grecreatedim{bar@finalfinalis@standalone@notext}{0.29169 cm}{scalable}%
%
% minimal space between letters of different syllable texts for text around bars
% (new bar spacing algorithm only)
\grecreatedim{interwordspacetext@bars}{0.15 cm}{scalable}%
% minimal space between letters of different syllable texts for text around bars,
% euouae context
\grecreatedim{interwordspacetext@bars@euouae}{0.15 cm}{scalable}%
\grecreatedim{interwordspacetext@bars@notext}{0.4 cm}{scalable}%
% minimal space between letters of different syllable texts for text around bars,
% euouae context
\grecreatedim{interwordspacetext@bars@notext@euouae}{0.3 cm}{scalable}%
% rubber length that will be added around bars in new bar spacing algorithm
\grecreatedim{bar@rubber}{0 cm plus 0.22787 cm minus 0.02 cm}{scalable}%
% additional space that will appear around bars that are preceded by a custos and followed by a key.
\grecreatedim{spacearoundclefbars}{0.03645 cm plus 0.00455 cm minus 0.0009 cm}{scalable}%
% space between the text of previous syllable and text associated with a bar (old bar spacing algorithm only)
\grecreatedim{textbartextspace}{0.24611 cm plus 0.13672 cm minus 0.04921 cm}{scalable}%
% minimal space between a note and a bar (old algorithm only)
\grecreatedim{notebarspace}{0.31903 cm plus 0.27345 cm minus 0.02824 cm}{scalable}%
% Maximum offset between a bar and its associated text when the text goes left of the bar (new bar spacing algorithm only)
\grecreatedim{maxbaroffsettextleft}{0.6 cm}{scalable}%
% Same as maxbaroffsettextleft when text goes right of the bar
\grecreatedim{maxbaroffsettextright}{0 cm}{scalable}%
% Maximum offset between a no-bar (i.e. something like `text()` in gabc) and its associated text when the text goes left of the no-bar (new bar spacing algorithm only)
\grecreatedim{maxbaroffsettextleft@nobar}{12 cm}{scalable}%
% Same as maxbaroffsettextleft@nobar when text goes right of the no-bar
\grecreatedim{maxbaroffsettextright@nobar}{12 cm}{scalable}%
% Space between the two bars of a divisio finalis
% Maximum offset between a bar and its associated text when the text goes left of the bar and the bar terminates a line (i.e. something line `text(::z)` in gabc) (new bar spacing algorithm only)
\grecreatedim{maxbaroffsettextleft@eol}{0.0 cm}{scalable}%
% Same as maxbaroffsettextleft@eol when text goes right of the bar
\grecreatedim{maxbaroffsettextright@eol}{0 cm}{scalable}%
\grecreatedim{divisiofinalissep}{0.1094 cm}{scalable}%
%
%
% maximal space between two syllables for which we consider a dash is not needed
\grecreatedim{maximumspacewithoutdash}{0 cm}{scalable}%
% an extensible space for the beginning of lines
\grecreatedim{afterclefnospace}{0 cm plus 0.27345 cm minus 0 cm}{scalable}%
% space between the initial and the beginning of the score
\grecreatedim{afterinitialshift}{0.2457 cm}{scalable}%
% space before the initial
\grecreatedim{beforeinitialshift}{0.2457 cm}{scalable}%
% when bolshifts are enabled, minimum space between beginning of line and first syllable text
\grecreatedim{minimalspaceatlinebeginning}{0.05 cm}{scalable}%
% space to force the initial width to.  Ignored when 0.
\grecreatedim{manualinitialwidth}{0 cm}{scalable}%
% distance to move the initial up by
\grecreatedim{initialraise}{0 cm}{scalable}%
% Space between lines in the annotation
\grecreatedim{annotationseparation}{0.05cm}{scalable}%
% Amount to raise (positive) or lower (negative) the annotations from the default position
\grecreatedim{annotationraise}{0cm}{scalable}%
% Space between lines in the commentary
\grecreatedim{commentaryseparation}{0.05cm}{scalable}%
% Amount to raise (positive) or lower (negative) the commentary from the default position (base line of bottom commentary aligned with top line of staff)
\grecreatedim{commentaryraise}{0.2cm}{scalable}%
% space at the beginning of the lines if there is no clef
\grecreatedim{noclefspace}{0.1 cm}{scalable}%
% space around a clef change
\grecreatedim{clefchangespace}{0.01768 cm plus 0.00175 cm minus 0.01768 cm}{scalable}%
% When \gre@clivisalignment is 2, this distance is the maximum length of the consonants after vowels for which the clivis will be aligned on its center.
\grecreatedim{clivisalignmentmin}{0.3 cm}{scalable}%

%%%%%%%%%%%%%%%%%%
% vertical spaces
%%%%%%%%%%%%%%%%%%

% the amount to shift down:
% (a) low choral signs that are not lower than the note, regardless of whether
%     it's on a line or in a space
% (b) high choral signs and low choral signs that are lower than the note which
%     are in a space
\grecreatedim{choralsigndownshift}{0.00911 cm}{scalable}%
% the amount to shift up:
% (a) high choral signs and low choral signs that are lower than the note which
%     are on a line
\grecreatedim{choralsignupshift}{0.04556 cm}{scalable}%
% the space for the translation
\grecreatedim{translationheight}{0.5 cm}{scalable}%
%the space above the lines
\grecreatedim{spaceabovelines}{0.45576 cm plus 0.36461 cm minus 0.09114 cm}{scalable}%
% this counter is the threshold above which we start accounting notes above
% lines for additional space above lines. For instance with a threshold of
% 2, notes with a pitch of k and l will not interfere with the space above
% lines
\grechangecount{additionaltopspacethreshold}{2}%
% same, for notes taken into account for alt text vertical position
\grechangecount{additionaltopspacealtthreshold}{0}%
%the space between the lines and the bottom of the text
\grecreatedim{spacelinestext}{0.60617 cm}{scalable}%
%the space beneath the text
\grecreatedim{spacebeneathtext}{0 cm}{scalable}%
% height of the text above the note line
\grecreatedim{abovelinestextraise}{-0.1 cm}{scalable}%
% height that is added at the top of the lines if there is text above the lines (it must be bigger than the text for it to be taken into consideration)
\grecreatedim{abovelinestextheight}{0.3 cm}{scalable}%
% an additional shift you can give to the brace above the bars if you don't like it
\grecreatedim{braceshift}{0 cm}{scalable}%
% a shift you can give to the accentus above the curly brace
\grecreatedim{curlybraceaccentusshift}{-0.05 cm}{scalable}%
% the amount to shift the over slur up
\grecreatedim{overslurshift}{0.05000 cm}{scalable}%
% the amount to shift the under slur up
\grecreatedim{underslurshift}{0.01000 cm}{scalable}%
% shift for a horizontal episema over a note in a low position in the space
\grecreatedim{overhepisemalowshift}{0.02287 cm}{scalable}%
% shift for a horizontal episema over a note in a high position in the space
\grecreatedim{overhepisemahighshift}{0.10066 cm}{scalable}%
% shift for a horizontal episema under a note in a low position in the space
\grecreatedim{underhepisemalowshift}{0.02763 cm}{scalable}%
% shift for a horizontal episema under a note in a high position in the space
\grecreatedim{underhepisemahighshift}{0.10981 cm}{scalable}%
% shift for a horizontal episema in the middle of a space
\grecreatedim{hepisemamiddleshift}{0.07206 cm}{scalable}%
% shift for a vertical episema in a low position in the space
\grecreatedim{vepisemalowshift}{-0.01262 cm}{scalable}%
% shift for a vertical episema in a high position in the space
\grecreatedim{vepisemahighshift}{0.06634 cm}{scalable}%
% shift for a punctum mora for a note on a line
\grecreatedim{linepunctummorashift}{-0.06314 cm}{scalable}%
% shift for a punctum mora for a note in a space
\grecreatedim{spacepunctummorashift}{-0.02013 cm}{scalable}%
% shift for a punctum mora for the second note (in a space) of a pes with ambitus one
\grecreatedim{spaceamonepespunctummorashift}{0.00183 cm}{scalable}%
% shift for a punctum mora for the second note in a porrectus, on a line
\grecreatedim{lineporrectuspunctummorashift}{0.04575 cm}{scalable}%
% shift for a punctum mora for the second note in a porrectus, in a space
\grecreatedim{spaceporrectuspunctummorashift}{0.00000 cm}{scalable}%
% shift for a rare sign
\grecreatedim{raresignshift}{0.18302 cm}{scalable}%
%
