%% Generated by lilypond-book
%% Options: [exampleindent=10.16\mm,indent=0\mm,line-width=160\mm,paper-height=845.047\pt,paper-width=597.508\pt,papersize='(cons (* 597.508 pt) (* 845.047 pt))]
\include "lilypond-book-preamble.ly"


% ****************************************************************
% Start cut-&-pastable-section
% ****************************************************************

#(ly:set-option 'eps-box-padding 3.000000)



\paper {
  #(set-paper-size '(cons (* 597.508 pt) (* 845.047 pt)))
  indent = 0\mm
  line-width = 160\mm
  % offset the left padding, also add 1mm as lilypond creates cropped
  % images with a little space on the right
  line-width = #(- line-width (* mm  3.000000) (* mm 1))
}

\layout {
  
}




% ****************************************************************
% ly snippet:
% ****************************************************************
\sourcefilename "snippets/horizontally-aligning-custom-dynamics-like--pi--f-.ly"
\sourcefileline 0
%% DO NOT EDIT this file manually; it was automatically
%% generated from the LilyPond Wiki
%% (https://wiki.lilypond.community).
%%
%% Make any changes in the Wiki itself, or in
%% `Documentation/snippets/new/`, then run
%% `scripts/auxiliar/makelsr.pl`.
%%
%% This file is in the public domain.

\version "2.24.0"

\header {
%% Translation of GIT committish: 1abe87de51b9b00a391da1be4cf4b5ebe4021ca9
  texidocfr = "
Certaines indications de nuance requièrent un complément textuel, comme
« sempre @strong{pp} ». Dans la mesure où les nuances sont
habituellement centrées sous la note, le @emph{pp} se trouvera
repoussé loin après la note à laquelle il s'applique.

Différentes approches permettent de correctement aligner horizontalement
ce « sempre @strong{pp} » comme s'il ne s'agissait que d'un simple
@emph{pp} :

@itemize
@item
Un simple @code{\\once \\override DynamicText.X-offset = #-9.2} avant la
note considérée de telle sorte que la nuance soit décalée manuellement à
la bonne place. Inconvénient : il faut le faire manuellement à chaque
fois qu'intervient ce @emph{markup}.

@item
L'intégration d'un rembourrage (@code{#:hspace 7.1}) à la définition de
cette nuance personnalisée afin qu'une fois centrée par LilyPond elle
soit correctement alignée. Inconvénient : le rembourrage occupera
exactement cet espace et ne permettra à aucun autre @emph{markup} ou
nuance d'apparaître à cet endroit.

@item
L'application d'un décalage au script de nuance
@code{\\once \\override @dots{} .X-offset = @dots{}}. Inconvénient : là
aussi il faut le faire à chaque fois.

@item
L'attribution arbitraire d'une dimension à 0 du texte additionnel à
l'aide d'un @code{#:with-dimensions '(0 . 0) '(0 . 0)}. Inconvénient :
LilyPond considère que « sempre » n'occupe pas d'espace, et donc pourra
mettre à cet endroit d'autres éléments, ce qui pourrait générer des
collisions qui ne seront pas détectées par les routines @emph{ad hoc}.
D'autre part, il semble persister un espacement, ce qui laisse
l'impression d'un alignement différent en l'absence de texte
additionnel.

@item
L'ajout, explicite, du décalage directement dans la fonction Scheme du
script de nuance.

@item
La définition d'un alignement explicite au sein du script de nuance.
Ceci ne sera suivi d'effet, par défaut, qu'en jouant sur
@code{X-offset}. Inconvénient : il faut définir
@code{DynamicText.X-offset}, ce qui s'appliquera à toutes les nuances
textuelles. Par ailleurs, l'alignement sera réalisé sur le bord droit du
texte additionnel, non sur le milieu de @emph{pp}.
@end itemize
"

  doctitlefr = "Alignement de nuances personnalisées comme « più f »"

  categories = "Expressive marks, Tweaks and overrides"

  texidoc = "
Some dynamic expressions involve additional text, like @qq{sempre
@strong{pp}}. Since dynamics are usually centered under the note, the
\\pp would be displayed way after the note it applies to.

To correctly align the @qq{sempre @strong{pp}} horizontally so that it is
aligned as if it were only the \\pp, there are several approaches:

@itemize
@item
Simply use @code{\\once \\override DynamicText.X-offset = #-9.2} before
the note with the dynamics to manually shift it to the correct
position. Drawback: This has to be done manually each time you use that
dynamic markup...
@item
Add some padding (@code{#:hspace 7.1}) into the definition of your
custom dynamic mark so that after LilyPond center-aligns it, it is
already correctly aligned. Drawback: The padding really takes up that
space and does not allow any other markup or dynamics to be shown in
that position.
@item
Shift the dynamic script @code{\\once \\override ... .X-offset = ...}.
Drawback: @code{\\once \\override} is needed for every invocation!
@item
Set the dimensions of the additional text to@tie{}0 (using
@code{#:with-dimensions '(0@tie{}.@tie{}0) '(0@tie{}.@tie{}0)}).
Drawback: For LilyPond, @qq{sempre} has no extent now. This means it might
put other stuff there, causing collisions (which are not detected by
LilyPond's collision detection algorithm!). There also seems to be some
spacing, so it is not exactly the same alignment as without the
additional text.
@item
Add an explicit shift directly inside the scheme function for the
dynamic script.
@item
Set an explicit alignment inside the dynamic script. By default, this
won't have any effect, only if one sets @code{X-offset}! Drawback: One
needs to set @code{DynamicText.X-offset}, which will apply to all
dynamic texts! Also, it is aligned at the right edge of the additional
text, not at the center of \\pp.
@end itemize
"

  doctitle = "Horizontally aligning custom dynamics like @qq{più f}"
} % begin verbatim


\paper {
  ragged-right = ##f
  indent = 5\cm
}

% Solution 1: Using a simple markup with a particular halign value
% Drawback: It's a markup, not a dynamic command, so \dynamicDown
%           etc. will have no effect
semppMarkup = \markup { \halign #1.4 \italic "sempre" \dynamic "pp" }

% Solution 2: Using a dynamic script & shifting with
%             \once \override ...X-offset = ..
% Drawback: \once \override needed for every invocation
semppK =
#(make-dynamic-script
  (markup #:line
          (#:normal-text
           #:italic "sempre"
           #:dynamic "pp")))

% Solution 3: Padding the dynamic script so the center-alignment
%             puts it at the correct position
% Drawback: the padding really reserves the space, nothing else can be there
semppT =
#(make-dynamic-script
  (markup #:line
          (#:normal-text
           #:italic "sempre"
           #:dynamic "pp"
           #:hspace 7.1)))

% Solution 4: Dynamic, setting the dimensions of the additional text to 0
% Drawback: To lilypond "sempre" has no extent, so it might put
%           other stuff there => collisions
% Drawback: Also, there seems to be some spacing, so it's not exactly the
%           same alignment as without the additional text
semppM =
#(make-dynamic-script
  (markup #:line
          (#:with-dimensions '(0 . 0) '(0 . 0)
                             #:right-align
                             #:normal-text
                             #:italic "sempre"
                             #:dynamic "pp")))

% Solution 5: Dynamic with explicit shifting inside the scheme function
semppG =
#(make-dynamic-script
  (markup #:hspace 0
          #:translate '(-18.85 . 0)
          #:line (#:normal-text
                  #:italic "sempre"
                  #:dynamic "pp")))

% Solution 6: Dynamic with explicit alignment. This has only effect
%             if one sets X-offset!
% Drawback: One needs to set DynamicText.X-offset!
% Drawback: Aligned at the right edge of the additional text,
%           not at the center of pp
semppMII =
#(make-dynamic-script
  (markup #:line (#:right-align
                  #:normal-text
                  #:italic "sempre"
                  #:dynamic "pp")))

\new StaffGroup <<
  \new Staff \with { instrumentName = "standard" }
    \relative c'' {
      \key es \major
      c4\pp c\p c c | c\ff c c\pp c
    }
  \new Staff \with {instrumentName = "normal markup" }
    \relative c'' {
      \key es \major
      c4-\semppMarkup c\p c c | c\ff c c-\semppMarkup c
    }
  \new Staff \with { instrumentName = "explicit shifting" }
    \relative c'' {
      \key es \major
      \once \override DynamicText.X-offset = #-9.2
      c4\semppK c\p c c
      c4\ff c
      \once \override DynamicText.X-offset = #-9.2
      c4\semppK c
    }
  \new Staff \with { instrumentName = "right padding" }
    \relative c'' {
      \key es \major
      c4\semppT c\p c c | c\ff c c\semppT c
    }
  \new Staff \with { instrumentName = "set dimension to zero" }
    \relative c'' {
      \key es \major
      c4\semppM c\p c c | c\ff c c\semppM c
    }
  \new Staff \with { instrumentName = "shift inside dynamics" }
    \relative c'' {
      \key es \major
      c4\semppG c\p c c | c\ff c c\semppG c
    }
  \new Staff \with { instrumentName = "alignment inside dynamics" }
    \relative c'' {
      \key es \major
      \override DynamicText.X-offset = #-1
      c4\semppMII c\p c c | c\ff c c\semppMII c
    }
>>

\layout { \override Staff.InstrumentName.self-alignment-X = #LEFT }



% ****************************************************************
% end ly snippet
% ****************************************************************
