summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-03-13 22:07:05 +0000
committerKarl Berry <karl@freefriends.org>2018-03-13 22:07:05 +0000
commitb5f3209624cdaeceec32d0878fc3bfa5b3585670 (patch)
treec5c457a935ea3bbda4e98d9a80ab3bbc6366af82
parent60225bd10db8028303b99b5992eb3c9d60e89763 (diff)
lyluatex (13mar18)
git-svn-id: svn://tug.org/texlive/trunk@46952 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/Contributors.md7
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/LICENSE3
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/README.md70
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/latexmkrc2
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/ly/eight-systems.ly13
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/ly/fonts.ly20
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/lyluatex.pdfbin147110 -> 1666763 bytes
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/lyluatex.tex2245
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/lyluatexbase.cls38
-rw-r--r--Master/texmf-dist/doc/support/lyluatex/lyluatexmanual.cls30
-rwxr-xr-xMaster/texmf-dist/scripts/lyluatex/lyluatex.lua1498
-rw-r--r--Master/texmf-dist/tex/latex/lyluatex/lyluatex.sty293
-rwxr-xr-xMaster/tlpkg/libexec/ctan2tds1
13 files changed, 3938 insertions, 282 deletions
diff --git a/Master/texmf-dist/doc/support/lyluatex/Contributors.md b/Master/texmf-dist/doc/support/lyluatex/Contributors.md
new file mode 100644
index 00000000000..574ecf10a5c
--- /dev/null
+++ b/Master/texmf-dist/doc/support/lyluatex/Contributors.md
@@ -0,0 +1,7 @@
+## Authors
+
+Lyluatex is developped by:
+
+- [Fr. Jacques Peron](mailto:catacolp@hotmail.com);
+- Urs Liska;
+- Br. Samuel Springuel.
diff --git a/Master/texmf-dist/doc/support/lyluatex/LICENSE b/Master/texmf-dist/doc/support/lyluatex/LICENSE
index 7dc50b19781..3054be29583 100644
--- a/Master/texmf-dist/doc/support/lyluatex/LICENSE
+++ b/Master/texmf-dist/doc/support/lyluatex/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2015 jperon
+Copyright (c) 2015--2018 jperon and others
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-
diff --git a/Master/texmf-dist/doc/support/lyluatex/README.md b/Master/texmf-dist/doc/support/lyluatex/README.md
index d331ae9a6c2..4d9f3690e52 100644
--- a/Master/texmf-dist/doc/support/lyluatex/README.md
+++ b/Master/texmf-dist/doc/support/lyluatex/README.md
@@ -1,3 +1,4 @@
+Main author: [Fr. Jacques Peron](mailto:cataclop@hotmail.com)
This material is subject to the MIT license.
# Lyluatex
@@ -5,60 +6,81 @@ This material is subject to the MIT license.
In the preable of your document, include the package `lyluatex`:
- \usepackage{lyluatex}
+```TeX
+\usepackage{lyluatex}
+```
The `program` option permits the definition of an alternative path to
`lilypond`, for example:
- \usepackage[program=/opt/lilypond-dev/lilypond]{lyluatex}
+```TeX
+\usepackage[program=/opt/lilypond-dev/lilypond]{lyluatex}
+```
Thereafter, you can include a lilypond file with the command:
- \includely[staffsize=17]{PATH/TO/THE/FILE}
+```TeX
+\lilypondfile[staffsize=17]{PATH/TO/THE/FILE}
+```
The argument `staffsize`, which is optional, changes the size of the score. You
can change the size for all the subsequent scores in a document by placing the
following command before your first include statement to be so affected:
- \def\staffsize{24}
+```TeX
+\lysetoption{staffsize}{24}
+```
Next, you simply need to compile the document normally with the command
`lualatex -shell-escape` :
- lualatex -shell-escape DOCUMENT.TEX
+```bash
+lualatex -shell-escape DOCUMENT.TEX
+```
-Another "more secure" option is to add `lilypond` to default allowed commands :
+Another "more secure" option is to add `lilypond` and `gs` to default allowed commands :
- shell_escape_commands=$(kpsewhich -expand-var '$shell_escape_commands'),lilypond lualatex DOCUMENT.TEX
+```bash
+shell_escape_commands=$(kpsewhich -expand-var '$shell_escape_commands'),lilypond,gs lualatex DOCUMENT.TEX
+```
On systems with low RAM, when working on big documents, you could encounter
*buffer overflows* in `lilypond` calls. In that case, first compile with option
`-draftmode`, then compile again without this option.
-You can also input music directly into your docoment with the `ly` environment.
+You can also input music directly into your docoment with the `lilypond` environment.
This is only recommended for relatively short snippets. For example:
- \begin{ly}
- \relative c' { c d e f g a b c }
- \end{ly}
+```TeX
+\begin{lilypond}
+\relative c' { c d e f g a b c }
+\end{lilypond}
+```
Finally, for truly short snippets, there is also the `\lily` command. Example:
- \lily[staffsize=12]{c' d' g'}
-
-**Nota bene:** The `\lily` command *does not* support blocks of LilyPond code
-with explicit `\score` blocks. Such code must be included with the `ly`
-environment or as a separate file.
+```TeX
+\lilypond[staffsize=12]{c' d' g'}
+```
+**Nota bene:** The `\lilypond` command *does not* support blocks of LilyPond
+code with explicit `\score` blocks. Such code must be included with the
+`lilypond` environment or as a separate file.
## Migration from `lilypond-book`
-In order to facilitate the migration from `lilypond-book`, `lyluatex` defines
-the command `\lilypondfile` with the same arguments as `\includely`. There is
-also the environment `lilypond` which is the same as `ly`, and the command
-`\lilypond` should work as with `lilypond-book`.
+In order to facilitate the migration from `lilypond-book`, `\lilypondfile`,
+the environment `lilypond` and the command `\lilypond` should work nearly
+as with `lilypond-book` ; for even more identical behaviour, call `lyluatex`
+like follows:
+
+```TeX
+\usepackage[program=/opt/lilypond-dev/lilypond]{lyluatex}
+```
+
+That way, documents typeset with `lilypond-book` can be adapted to use
+`lyluatex` without much difficulty.
+
+# Credits
-In this manner, documents typeset with `lilypond-book` can be adapted to use
-`lyluatex` without much difficulty. Just keep in mind that apart from the
-`staffsize` parameter, the optional parameters that `lilypond-book` supports are
-not supported by `lyluatex` (at least for now).
+Cf. [Contributors.md](Contributors.md)
diff --git a/Master/texmf-dist/doc/support/lyluatex/latexmkrc b/Master/texmf-dist/doc/support/lyluatex/latexmkrc
new file mode 100644
index 00000000000..d6544121699
--- /dev/null
+++ b/Master/texmf-dist/doc/support/lyluatex/latexmkrc
@@ -0,0 +1,2 @@
+$pdf_mode="1";
+$pdflatex="lualatex --shell-escape %O %S";
diff --git a/Master/texmf-dist/doc/support/lyluatex/ly/eight-systems.ly b/Master/texmf-dist/doc/support/lyluatex/ly/eight-systems.ly
new file mode 100644
index 00000000000..3cb8a992077
--- /dev/null
+++ b/Master/texmf-dist/doc/support/lyluatex/ly/eight-systems.ly
@@ -0,0 +1,13 @@
+\version "2.18"
+
+\relative c' {
+ \omit Staff.TimeSignature
+ c1 \break
+ d1 \break
+ e1 \break
+ f1 \break
+ g1 \break
+ a1 \break
+ b1 \break
+ c1 \break
+}
diff --git a/Master/texmf-dist/doc/support/lyluatex/ly/fonts.ly b/Master/texmf-dist/doc/support/lyluatex/ly/fonts.ly
new file mode 100644
index 00000000000..47892b07e4a
--- /dev/null
+++ b/Master/texmf-dist/doc/support/lyluatex/ly/fonts.ly
@@ -0,0 +1,20 @@
+\version "2.18"
+
+mel = {
+ \set Staff.instrumentName = "First violin"
+ \tempo \markup \typewriter Allegro
+ c' d' e' f'
+ g' a' b' c''
+ \mark \markup \sans "Sans Mark"
+}
+
+lyr = \lyricmode {
+ do re mi fa so -- la si -- do
+}
+
+\score {
+ <<
+ \new Staff \new Voice = "mel" \mel
+ \new Lyrics \lyricsto "mel" \lyr
+ >>
+}
diff --git a/Master/texmf-dist/doc/support/lyluatex/lyluatex.pdf b/Master/texmf-dist/doc/support/lyluatex/lyluatex.pdf
index 4aec47a4d69..ea4de76b24f 100644
--- a/Master/texmf-dist/doc/support/lyluatex/lyluatex.pdf
+++ b/Master/texmf-dist/doc/support/lyluatex/lyluatex.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/support/lyluatex/lyluatex.tex b/Master/texmf-dist/doc/support/lyluatex/lyluatex.tex
index c9a53bb017f..b36e17ff5f5 100644
--- a/Master/texmf-dist/doc/support/lyluatex/lyluatex.tex
+++ b/Master/texmf-dist/doc/support/lyluatex/lyluatex.tex
@@ -1,8 +1,8 @@
\PassOptionsToPackage{unicode=true}{hyperref} % options for packages loaded elsewhere
\PassOptionsToPackage{hyphens}{url}
%
-\documentclass[]{article}
-\usepackage{lmodern}
+\documentclass[]{lyluatexmanual}
+\usepackage[]{libertine}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
\usepackage{fixltx2e} % provides \textsubscript
@@ -29,9 +29,48 @@
}
\usepackage{hyperref}
\hypersetup{
+ pdfauthor={Fr. Jacques Peron; Urs Liska; Br. Samuel Springuel},
pdfborder={0 0 0},
breaklinks=true}
\urlstyle{same} % don't use monospace font for urls
+\usepackage{color}
+\usepackage{fancyvrb}
+\newcommand{\VerbBar}{|}
+\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
+\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
+% Add ',fontsize=\small' for more characters per line
+\newenvironment{Shaded}{}{}
+\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{#1}}}
+\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{#1}}
+\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}}
+\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}}
+\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}}
+\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{#1}}
+\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
+\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
+\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
+\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
+\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{#1}}
+\newcommand{\ImportTok}[1]{#1}
+\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{#1}}}
+\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{#1}}}
+\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
+\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
+\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{#1}}
+\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{#1}}
+\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{#1}}
+\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{#1}}}
+\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
+\newcommand{\BuiltInTok}[1]{#1}
+\newcommand{\ExtensionTok}[1]{#1}
+\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{#1}}
+\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{#1}}
+\newcommand{\RegionMarkerTok}[1]{#1}
+\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
+\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
+\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{#1}}}
+\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{#1}}}
+\newcommand{\NormalTok}[1]{#1}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
@@ -52,101 +91,2191 @@
\makeatother
+\title{\lyluatex}
+\providecommand{\subtitle}[1]{}
+\subtitle{1.0b}
+\author{Fr. Jacques Peron \and Urs Liska \and Br. Samuel Springuel}
\date{}
\begin{document}
+\maketitle
-\hypertarget{lyluatex}{%
-\section{Lyluatex}\label{lyluatex}}
+{
+\setcounter{tocdepth}{4}
+\tableofcontents
+}
+\hypertarget{introduction}{%
+\section{Introduction}\label{introduction}}
+
+\lyluatex~is a \LaTeX~package that manages the inclusion of musical
+scores in \LaTeX~documents. It uses the GNU LilyPond\footnote{\url{http://lilypond.org}}
+score writer to produce beautiful music elements in beautifully typeset
+text documents. \lyluatex~supports a wide range of use cases and lends
+itself equally well to authoring musicological texts with music examples
+and preparing musical editions with interspersed text parts, to creating
+song booklets used in service and to provide work sheets for teaching
+and exams.
+
+\lyluatex~is inspired by and provides a fully compatible drop-in
+replacement to
+\href{http://lilypond.org/doc/v2.18/Documentation/usage/invoking-lilypond_002dbook.html}{lilypond-book},
+a \LaTeX~document preprocessor shipping with LilyPond. However, thanks
+to the use of \LuaLaTeX~it can overcome substantial limitations of the
+scripted solution, and it actually is a \emph{superset} of
+\texttt{lilypond-book}, providing numerous additional features.
+
+\lyluatex's main features include:
+
+\begin{itemize}
+\tightlist
+\item
+ Using LilyPond to compile musical scores directly from within the
+ \LaTeX~run
+\item
+ Intelligent caching of engraved scores, avoiding recompilation when
+ possible
+\item
+ Matching of layout and appearance to perfectly fit the scores into the
+ text document
+\item
+ Comprehensive configuration through global and per-score options
+\end{itemize}
+
+\hypertarget{installation}{%
+\subsection{Installation}\label{installation}}
+
+\hypertarget{for-a-single-document}{%
+\subsubsection{For a single document}\label{for-a-single-document}}
+
+Copy \texttt{lyluatex.sty} and \texttt{lyluatex.lua} into the folder
+containing the document you wish to typeset.
+
+\hypertarget{for-all-documents-compiled-with-your-latex-distribution}{%
+\subsubsection{For all documents compiled with your LaTeX
+distribution}\label{for-all-documents-compiled-with-your-latex-distribution}}
+
+\hypertarget{texlive-version}{%
+\paragraph{TeXLive version}\label{texlive-version}}
+
+Just run this command~:
+
+\begin{verbatim}
+tlmgr install lyluatex
+\end{verbatim}
+
+\hypertarget{latest-version}{%
+\paragraph{Latest version}\label{latest-version}}
+
+Copy \texttt{lyluatex.sty} and \texttt{lyluatex.lua} from this
+repository into your \texttt{TEXMF} tree, or clone this repostory into
+your \texttt{TEXMF} tree using Git, then run \texttt{mktexlsr}. Note
+that in this case your local copy will shadow the version possibly
+installed in your \TeX~distribution.
\hypertarget{usage}{%
-\subsection{Usage}\label{usage}}
+\section{Usage}\label{usage}}
+
+\lyluatex~is loaded with the command
+\texttt{\textbackslash{}usepackage\{lyluatex\}} which also accepts a
+number of \texttt{key=value} options. Their general use is described in
+the \protect\hyperlink{option-handling}{Option Handling} section below.
+
+By default \lyluatex~invokes LilyPond simply as \texttt{lilypond}. If
+LilyPond is installed in another location or a specific version of
+LilyPond should be used the invocation is controlled with the
+\option{program} option, see \protect\hyperlink{program}{The LilyPond
+Executable}.
+
+\lyIssue{Note:} \lyluatex~can only be used with \LuaLaTeX, and compiling
+with any other \LaTeX~engine will fail.
+
+\lyIssue{Note:} In order to avoid unexpected behaviour it is strongly
+suggested that documents are generally compiled from their actual
+directory, i.e.~without referring to it through a path.
+
+\lyIssue{NOTE:} \lyluatex~requires that \LuaLaTeX~is started with the
+\texttt{-\/-shell-escape} command line option to enable the execution of
+arbitrary shell commands, which is necessary to let LilyPond compile the
+inserted scores on-the-fly and to perform some auxiliary shell
+operations. However, this opens a significant security hole, and only
+fully trusted input files should be compiled. You may mitigate (but not
+totally remove) this security hole by adding \texttt{lilypond} and
+\texttt{gs} to \texttt{shell\_escape\_commands}, and using
+\texttt{-\/-shell-restricted} instead of \texttt{-\/-shell-escape}: look
+at the documentation of your \TeX~distribution. For example, on Debian
+Linux with TeXLive:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\ExtensionTok{%}\NormalTok{ export shell_escape_commands=}\VariableTok{$(}\ExtensionTok{kpsewhich}\NormalTok{ -expand-var }\StringTok{'$shell_escape_commands'}\VariableTok{)}\NormalTok{,lilypond,gs}
+\ExtensionTok{%}\NormalTok{ lualatex --shell-restricted DOCUMENT.tex}
+\end{Highlighting}
+\end{Shaded}
+
+\hypertarget{basic-operation}{%
+\subsection{Basic Operation}\label{basic-operation}}
+
+Once \lyluatex~is loaded it provides commands and environments to
+include musical scores and score fragments which are produced using the
+GNU LilyPond score writer. They are encoded in LilyPond input language,
+either directly in the \texttt{.tex} document or in referenced
+standalone files. \lyluatex~will automatically take care of compiling
+the scores if necessary -- making use of an intelligent caching
+mechanism --, and it will match the score's layout to that of the text
+document. \lyluatex~will produce PDF image files which are automatically
+included within the current paragraph, in their own paragraphs or as
+full pages.
+
+\lyluatex~aims at being an upwards-compatible drop-in replacement for
+the \highlight{lilypond-book} preprocessor shipping with
+LilyPond.\footnote{\url{http://lilypond.org/doc/v2.18/Documentation/usage/lilypond_002dbook}}
+which means that any documents prepared for use with
+\texttt{lilypond-book} should be directly usable with \lyluatex, with
+some caveats:
+
+\begin{itemize}
+\tightlist
+\item
+ \option{fragment} is the default: see
+ \protect\hyperlink{autowrap}{Automatic wrapping} for more details
+ about this;
+\item
+ \lyluatex~has an option \option{insert}, which defaults to
+ \option{systems} for \cmd{begin\{lilypond\}} \cmd{end\{lilypond\}},
+ but to \option{inline} for \cmd{lilypond}; the last one by default
+ reduces staff size and includes only the first system if there are
+ several ones;
+\item
+ \cmd{musicxmlfile} has \option{no-articulation-directions},
+ \option{no-beaming}, \option{no-page-layout} and
+ \option{no-rest-positions} set to \texttt{true} by default, to
+ increase chances of getting something acceptable. Nevertheless, please
+ read the note about this command below.
+\end{itemize}
+
+So, if you want \lyluatex~to mimic as much as possible
+\highlight{lilypond-book}, you should load it with options as follows:
+\cmd{usepackage[nofragment, insert=systems]\{lyluatex\}}.
+
+\lyMargin{lilypond\index{lilypond}}
+
+The basic mode of inserting scores into text documents is the
+\texttt{lilypond} environment:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\FunctionTok{\textbackslash{}begin}\KeywordTok{\{}\NormalTok{lilypond}\KeywordTok{\}}
+\FunctionTok{music}\NormalTok{ = }\FunctionTok{\textbackslash{}relative} \KeywordTok{\{}
+\NormalTok{ c d e}
+\KeywordTok{\}}
+
+\KeywordTok{\textbackslash{}score} \KeywordTok{\{}
+ \KeywordTok{\textbackslash{}new} \DataTypeTok{ChoirStaff}\NormalTok{ \textbackslash{}with}\KeywordTok{ \{}
+ \DataTypeTok{instrumentName}\NormalTok{ = "}\StringTok{2 Fl."}
+ \KeywordTok{\}} \KeywordTok{<<}
+ \KeywordTok{\textbackslash{}new} \DataTypeTok{Staff} \FunctionTok{\textbackslash{}transpose c c'} \FunctionTok{\textbackslash{}music}
+ \KeywordTok{\textbackslash{}new} \DataTypeTok{Staff} \KeywordTok{\{}
+ \FunctionTok{\textbackslash{}clef bass}
+ \FunctionTok{\textbackslash{}music}
+ \KeywordTok{\}}
+ \KeywordTok{>>}
+\KeywordTok{\}}
+\FunctionTok{\textbackslash{}end}\KeywordTok{\{}\NormalTok{lilypond}\KeywordTok{\}}
+\end{Highlighting}
+\end{Shaded}
+
+\begin{lilypond}
+
+music = \relative {
+ c d e
+}
+
+\score {
+ \new ChoirStaff \with {
+ instrumentName = "2 Fl."
+ } <<
+ \new Staff \transpose c c' \music
+ \new Staff {
+ \clef bass
+ \music
+ }
+ >>
+}
+\end{lilypond}
+
+\lyluatex~will now collect the given content and wrap it in additional
+LilyPond code to create the layout and appearance according to the text
+document and the user's configuration. The resulting file is compiled
+with LilyPond and saved in a temporary directory, from where it is
+included in the text document. A hash value including the full content
+and all options will be used to determine if the score has already been
+compiled earlier, so unnecessary recompilations are avoided.
+
+\lyCmd{lilypond}
+
+Very short fragments of LilyPond code can be entered inline using the
+\cmd{lilypond} command:
+\texttt{\textbackslash{}lilypond\{\ c\textquotesingle{}\ d\textquotesingle{}\ e\textquotesingle{}\ \}}
+\lilypond{ c' d' e' } Fragments specified with \cmd{lilypond} are by
+default inserted as \emph{inline} scores with a smaller staff size. For
+further information about the different insertion modes read the section
+about \protect\hyperlink{insertion-mode}{insertion modes}.
+
+\lyCmd{lilypondfile}
+
+External files of arbitrary complexity can be referenced with
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\FunctionTok{\textbackslash{}lilypondfile}\KeywordTok{\{}\NormalTok{path/to/file}\KeywordTok{\}}
+\end{Highlighting}
+\end{Shaded}
+
+Absolute and relative paths can be given. Relative paths are searched in
+the following order:
+
+\begin{itemize}
+\tightlist
+\item
+ relative to the current file's directory
+\item
+ relative to all given include paths (see
+ \protect\hyperlink{include-paths}{LilyPond Include Paths}))
+\item
+ relative to all paths visible to \LaTeX~(like the package search)
+\end{itemize}
+
+\lyCmd{musicxmlfile}\label{musicxml} Finally there is a command to
+include scores encoded as \href{https://www.musicxml.com/}{MusicXML}
+files. These will be converted to LilyPond input by LilyPond's
+\texttt{musicxml2ly} script and then compiled by LilyPond.
+
+\lyIssue{Note:}
+
+This command has been added to provide compatibility with
+\texttt{lilypond-book}, but it is discouraged to use it since its use
+implies substantial problems:
+
+\begin{itemize}
+\tightlist
+\item
+ The conversion process with \texttt{musicxml2ly} is somewhat fragile
+ and can crash in unpredictable ways due to encoding problems between
+ various versions of Python and Lua involved
+\item
+ \texttt{musicxml2ly} itself doesn't provide totally reliable
+ conversion results, even if the conversion reports successful
+ operation. In this case LilyPond may produce inferior results or may
+ fail to compile the score completely
+\end{itemize}
+
+If there is the need to include music scores that are only available as
+MusicXML files it will nearly always be the better option to
+independently convert the source using \texttt{musicxml2ly} and then
+manually post-process the resulting Lilypond input files.
+
+\hypertarget{option-handling}{%
+\subsection{Option Handling}\label{option-handling}}
+
+All aspects of \lyluatex's behaviour can be configured in detail through
+\emph{options}. Through a unified interface all options can be set as
+\emph{package options} or as \emph{local options}, and they can be
+changed anywhere in the document. Note that not each approach is
+suitable for every option: the option to clean the temporary directory
+only makes sense as a package option for example, or you can't
+reasonably apply a label other than locally to a single score.
+
+All options are \texttt{key=value} options, and options that are
+\emph{not} set explicitly will use their default value which is
+documented with each option. Boolean options don't have to be set to
+\texttt{true} explicitly, using the option alone will do that as well,
+for example: \texttt{{[}debug=true{]}} is equivalent to
+\texttt{{[}debug{]}}.
+
+Options can be unset (i.e.~reset to their default value) through the
+syntax \texttt{key=}. This can for example be used to use the default
+value locally when a value has been specified globally.
+
+Some options are complemented by a corresponding
+\texttt{no\textless{}option\textgreater{}}. Using this alternative is
+equivalent to setting an option to \texttt{false}: \texttt{nofragment}
+is the same as \texttt{fragment=false}.
+
+Finally it has to be mentioned that some options have side-effects on
+other options. For example, setting \texttt{indent} to some value
+implicitly will set \texttt{autoindent=false}, or
+\texttt{max-protrusion} will define \texttt{max-left-protrusion} and
+\texttt{max-right-protrusion} if these are not set explicitly.
+
+\lyMargin{Package Options\index{Package Options}}
+
+Options can be set globally through package options, which are used with
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\BuiltInTok{\textbackslash{}usepackage}\NormalTok{[key1=value1,key2]\{}\ExtensionTok{lyluatex}\NormalTok{\}}
+\end{Highlighting}
+\end{Shaded}
+
+\lyMargin{Local Options\index{Local Options}}
+
+Options can also be applied on a per-score basis through optional
+arguments to the individual command or environments:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\FunctionTok{\textbackslash{}lilypondfile}\NormalTok{[key1=value1]\{path/to/file.ly\}}
+
+\FunctionTok{\textbackslash{}lilypond}\NormalTok{[key1=value1]\{ c' d' e' \}}
+
+\KeywordTok{\textbackslash{}begin}\NormalTok{\{}\ExtensionTok{lilypond}\NormalTok{\}[key1=value1]}
+\NormalTok{\{}
+\NormalTok{ c' d' e'}
+\NormalTok{\}}
+\KeywordTok{\textbackslash{}end}\NormalTok{\{}\ExtensionTok{lilypond}\NormalTok{\}}
+\end{Highlighting}
+\end{Shaded}
+
+\lyCmd{lysetoption}
+
+At any place in the document the value of an option can be changed using
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\FunctionTok{\textbackslash{}lysetoption}\NormalTok{\{key\}\{new-value\}}
+\end{Highlighting}
+\end{Shaded}
+
+The option will take effect from now on as a package option until it is
+changed again. Note that this may or may not make sense with a given
+option. For example the \option{tmpdir} option should only be modified
+in very special and sophisticated set-ups.
+
+Local options will override this value as with package options.
+
+\hypertarget{insertion-mode}{%
+\subsection{System-by-System, Fullpage, and Inline Scores (Insertion
+Mode)}\label{insertion-mode}}
+
+\lyOption{insert}{systems}
+
+Scores can be included in documents in three basic modes:
+system-by-system, fullpage, and inline. The system-by-system mode is the
+default and includes a score as a sequence of images, one for each
+system. This allows \LaTeX~to have the systems flow over page breaks and
+to adjust the space between systems to vertically justify the systems on
+the page.
+
+Insertion mode can be controlled with the \option{insert} option, whose
+valid values are \option{systems} (default), \option{fullpage},
+\option{inline}, and \option{bare-inline}.
+
+\hypertarget{system-by-system}{%
+\subsubsection{System-by-System}\label{system-by-system}}
+
+\lyMargin{\texttt{insert=systems}}
+
+With this default option each score is compiled as a sequence of PDF
+files representing one system each. By default the systems are separated
+by a paragraph and a variable skip depending on the staffsize.
+
+\lyCmd{betweenLilyPondSystem}
+
+However, if a macro \cmd{betweenLilyPondSystem} is defined it will be
+expanded between each system. This macro is documented in
+\href{http://lilypond.org/doc/v2.18/Documentation/usage/latex}{LilyPond
+documentation}. It must accept one argument, which will be the number of
+systems already printed in the score (`1' after the first system). With
+this information it is possible to respond individually to systems (e.g.
+``print a horizontal rule after each third system'' or ``force page
+breaks after the third and seventh system''). But a more typical use
+case is to insert different space between the systems or using simple
+line breaks while ignoring the system count:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\FunctionTok{\textbackslash{}newcommand}\NormalTok{\{}\ExtensionTok{\textbackslash{}betweenLilyPondSystem}\NormalTok{\}[1]\{}\FunctionTok{\textbackslash{}linebreak}\NormalTok{\}}
+\end{Highlighting}
+\end{Shaded}
+
+\lyCmd{preLilyPondExample, \cmd{postLilyPondExample}}
+
+If either of these macros is defined it will be expanded immediately
+before or after the score; this may for example be used to wrap the
+example in environments, though there probably are better ways to do so.
+With \option{verbatim}, \cmd{preLilyPondExample} will take place after
+the verbatim block, just before the score.
+
+\lyMargin{Examples:}
+
+For a demonstration of the system-by-system options see
+\protect\hyperlink{insert-systems}{Insert Systems}.
+
+\hypertarget{fullpage}{%
+\subsubsection{Fullpage}\label{fullpage}}
+
+\lyMargin{\texttt{insert=fullpage}}
+
+With \option{insert} set to \texttt{fullpage} the score is compiled to a
+single PDF file that is included through \cmd{includepdf}. The layout of
+such scores can be configured through a number of
+\protect\hyperlink{alignment}{alignment options}.
+
+\lyOption{fullpagestyle}{}
+
+\lyOption{print-page-number}{false}
+
+These two options work together basically deciding who is responsible
+for printing headers and footers, LilyPond or \LaTeX.
+\option{fullpagestyle} is equivalent to \LaTeX's \cmd{pagestyle} and
+accepts anything that the current pagestyle can be set to. By default
+the current pagestyle will be continued throughout the score.
+\emph{NOTE:} This is different from the usual behaviour of
+\cmd{includepdf} which sets the pagestyle to \texttt{empty}. So by
+default \LaTeX~will continue to print headers and footers, including
+page numbers.
+
+\option{print-page-number} decides whether LilyPond prints page numbers
+in the score. By default this is set to \texttt{false}, so the default
+setting of these two options means that LilyPond does \emph{not} print
+page numbers while \LaTeX~continues to print headers and footers.
+
+\hypertarget{inline}{%
+\subsubsection{Inline}\label{inline}}
+
+\lyMargin{\texttt{insert=inline|bare-inline}}
+
+With \option{insert=inline} or \option{insert=bare-inline} scores can be
+included \emph{within} paragraphs. They are basically the same with
+regard to the inclusion, but \texttt{bare-inline} implicitly sets the
+\option{nostaff} option to suppress staff symbol, time signature and
+clef.
+
+\lyOption{inline-staffsize}{default}
+
+By default the staff size of inline scores is determined as 2/3 of the
+default staff size of regular scores, so the effective size of an inline
+score will depend both on the text's font size and the current
+\option{staffsize} setting. The \option{inline-staffsize} option sets an
+absolute staffsize in \texttt{pt} (omitting the ``\texttt{pt}'').
+
+\lyOption{valign}{center}
+
+Controls the vertical alignment of the score against the current line of
+text. The default value \texttt{center} will align the vertical center
+of the image to a virtual line \texttt{1/2em} above the baseline of the
+text. \texttt{top} will align the top edge of the image with the
+X-height of the text (actually: \texttt{1em} above the baseline).
+\texttt{bottom} aligns the bottom of the image with the text baseline.
+
+\emph{Note:} The alignment works with the edges of the \emph{image
+file}, there is no notion of an ``optical'' center or aligning with the
+staff lines.
+
+\lyOption{voffset}{0pt}
+
+Can be used to \emph{add} a vertical offset to the automatic alignment.
+
+\lyOption{hpadding}{0.75ex}
+
+Inserts some space to the left and right of the included score (except
+at line start or end).
+
+\lyMargin{Examples:}
+
+Examples can be found in \protect\hyperlink{insert-inline}{Insert
+Inline}.
+
+\hypertarget{choosing-systemspages}{%
+\subsubsection{Choosing Systems/Pages}\label{choosing-systemspages}}
+
+\lyOption{print-only}{}
+
+With the option \option{print-only} it is possible to choose which pages
+or systems of a score will be included in the document. This can for
+example be used to comment on individual parts of a score without having
+to specify them -- potentially redundantly -- as separate scores.
+Another use case is printing a selection of scores from a PDF containing
+multiple scores, such as a song book for example.
+
+Depending on the setting of the \option{insert} option this will affect
+systems or pages. The selection of systems/pages can be specified as
+
+\begin{itemize}
+\tightlist
+\item
+ \texttt{\textless{}empty\textgreater{}} (default): include the whole
+ score
+\item
+ a single number: include a single page/system
+\item
+ a range of numbers: include a range of pages/systems \texttt{\{M-N\}}
+ or \texttt{\{N-M\}} (to print backwards)
+\item
+ the special range \texttt{N-}, including all systems/pages from N
+ throughout the end
+\item
+ a comma-separated list of numbers or ranges
+ \texttt{\{A,B\ ,\ C,D-E,\ F,\ C-\ B\}} (freely mixed, in arbitrary
+ order)
+\end{itemize}
+
+\lyIssue{Note:}
+
+It is the user's responsibility to only request pages/systems that are
+actually present in the score, otherwise \LaTeX~will raise an error.
+
+\lyMargin{Examples:}
+
+Usage examples for this option can be found in
+\protect\hyperlink{print-only}{Choosing Systems}.
+
+\hypertarget{score-layout}{%
+\subsection{Score Layout}\label{score-layout}}
+
+One of the most obvious features of \lyluatex~is its ability to
+configure the layout and appearance of LilyPond scores from within the
+\texttt{.tex} document. Without further configuration \lyluatex~will try
+to match the score as closely as possible to the layout of the
+surrounding text, but there are numerous options to tweak the layout in
+detail.
+
+\hypertarget{dimensions}{%
+\subsubsection{Dimensions}\label{dimensions}}
+
+If not stated otherwise dimensions can be given in arbitrary \TeX~units,
+e.g. \texttt{200pt}, \texttt{1ex} or \texttt{3cm} or as \TeX~lengths,
+e.g. \texttt{0.4\textbackslash{}textwidth}.
+
+\hypertarget{general}{%
+\paragraph{General}\label{general}}
+
+\lyOption{line-width}{default}
+
+Set the line width of the score. By default this exactly matches the
+current actual line width of the text, which also works in multicolumn
+settings. See \protect\hyperlink{alignment}{Alignment} for a discussion
+of the details of the alignment of staves to the text.
+
+\lyOption{staffsize}{default}
+
+Set the staffsize of the score. By default
+(\texttt{{[}staffsize=default{]}}, \texttt{{[}staffsize{]}} or simply
+omitted) this is calculated relative to the size of the current text
+font, so it will give a consistent relation to the text at any font
+size. Absolute sizes can be given as a number, which is interpreted as
+\texttt{pt}. For example LilyPond's own default staff size is
+\texttt{20}.
+
+\lyOption{ragged-right}{default}
+
+Set the score to ragged-right systems. By default, single-system scores
+will not be justified but printed at their ``natural'' width, while
+scores with multiple systems by default will be justified. With this
+option set to true, all systems are printed at their natural width; with
+this option set to false, all systems are justified (even for
+single-system scores). \option{noragged-right} is equivalent to
+\option{raggedright=false}.
+
+\lyOption{indent}{}
+
+Defines indentation of first system (same as LilyPond's
+\texttt{indent}). By default, with \option{insert=fullpage}, scores are
+indented; otherwise, they aren't. \option{noindent} is equivalent to
+\option{indent=0pt}. Please also see the section about
+\protect\hyperlink{indent}{Dynamic Indentation}.
+
+\lyOption{quote}{false}
+
+This option, which is there for compatibility with
+\texttt{lilypond-book}, reduces line length of a music snippet by
+\(2×0.4\,in\) and puts the output into a quotation block. The value
+\(0.4\,in\) can be controlled with following options.
+
+This option isn't intended to be used with \cmd{insert=fullpage}, and
+won't give a good result with it.
+
+\lyOption{gutter, leftgutter, rightgutter, exampleindent}{$0.4\,in$}
+
+\option{leftgutter} control the supplementary left margin of a
+``quoted'' score, \option{rightgutter} the right margin. If not set,
+they're automatically set to \option{gutter} value;
+\option{exampleindent} is an alias for \option{gutter} (for
+compatibility with \texttt{lilypond-book}).
+
+\hypertarget{fullpage-1}{%
+\paragraph{Fullpage}\label{fullpage-1}}
+
+There are several options that can change the basic page layout of
+full-page scores. However, by default all these options inherit their
+values from the \texttt{.tex} document, and there should very rarely be
+the need to explicitly change the values for these options.
+
+\lyOption{papersize}{default}
+
+By default the LilyPond score will have the same paper size as the text
+document, but it is possible to override this with the
+\option{papersize} option. It accepts any paper sizes that are
+predefined in LilyPond\footnote{see the manual page at
+ \url{http://lilypond.org/doc/v2.18/Documentation/notation/predefined-paper-sizes}},
+it is not possible to use custom paper sizes.
+
+\lyOption{paperwidth}{\cmd{paperwidth}}
+
+\lyOption{paperheight}{\cmd{paperheight}}
+
+\lyOption{twoside}{default}
+
+\lyIssue{Note:}
+
+If \option{papersize} is set, any values of \option{paperheight} and
+\option{paperwidth} are ignored.
+
+\hypertarget{alignment}{%
+\subsubsection{Alignment}\label{alignment}}
+
+\hypertarget{protrusion}{%
+\paragraph{Protrusion (system-by-system Scores)}\label{protrusion}}
+
+The reference for the horizontal alignment of scores included
+system-by-system is the \emph{staff symbol}. By default \lyluatex~aligns
+the two ends of the staff symbol with the current \cmd{linewidth}, and
+any score items that exceed the staff lines to the left or right will
+protrude into the page margin(s):
+
+\begin{lilypond}[nofragment,
+print-only=1]
+{
+ \set Staff.instrumentName = "Vl."
+ \shape #'((0 . 0)(0 . 0)(3 . 0)(4 . 0)) Tie
+ c'1 ~ \break c'
+}
+\end{lilypond}
+
+This is also how LilyPond handles margins (and the only option when
+including scores with \option{insert=fullpage}). However,
+\lyluatex~provides a configurable limit to guard against excessive
+protrusion. By default this is effectively ``disabled'' by being set to
+the length \cmd{maxdimen}, so protruding elements may be cut off at the
+page border:
+
+\begin{lilypond}[nofragment,
+print-only=1]
+{
+ \set Staff.instrumentName = "Violin one, with damper"
+ \shape #'((0 . 0)(0 . 0)(30 . 0)(24 . 2)) Tie
+ c'1 ~ \break c'
+}
+\end{lilypond}
+
+\lyOption{max-protrusion}{\cmd{maxdimen}}\lyOption{max-left-protrusion}{default}\lyOption{max-right-protrusion}{default}
+
+These options set the protrusion limit. If either of the \texttt{-left-}
+or \texttt{-right-} options is unset then the value will be taken from
+\texttt{max-dimension}. Note that this is not a fixed value for the
+protrusion but a \emph{limit}, so it will only have an effect when the
+actual protrusion of the score exceeds the limit. In a way it can be
+understood as a dynamic variant of the \option{quote} option, something
+like a ``fence''. The following two scores have the same
+\option{max-left-protrusion=1cm}, but only the second is modified.
+
+\begin{lilypond}[nofragment,%
+max-left-protrusion=1cm,
+print-only=1]
+{
+ \set Staff.instrumentName = "Vl. 1"
+ c'1 ~ \break c'
+}
+\end{lilypond}
+
+\begin{lilypond}[nofragment,%
+print-only=1,
+max-left-protrusion=1cm]
+{
+ \set Staff.instrumentName = "Violin one"
+ c'1 ~ \break c'
+}
+\end{lilypond}
+
+When the protrusion limit kicks in the score will be offset to the right
+by the appropriate amount, and if necessary it will be shortened to
+accomodate the right edge with its individual protrusion limit.
+\lyluatex~will automatically ensure both that the staff line doesn't
+exceed the text and that the protruding elements don't exceed the limit.
+The following three scores demonstrate that behaviour with
+\option{max-protrusion=1cm}.
+
+The first score has elements that protrude less than the limit, so
+nothing is modified:
+
+\begin{lilypond}[nofragment,%
+max-protrusion=1cm,
+print-only=1]
+{
+ \set Staff.instrumentName = "Vl. 1"
+ c'1 ~ \break
+ \once \override Score.RehearsalMark.break-visibility = ##(#t #t #t)
+ \mark \default
+ c'
+}
+\end{lilypond}
+
+In the second score the longer instrument name makes the system shift to
+the right. The rehearsal mark still protrudes into the margin but is
+below the threshold. The score will automatically be recompiled with a
+narrower line width to ensure the staff lines don't protrude into the
+right margin.
+
+\begin{lilypond}[nofragment,%
+max-protrusion=1cm,
+print-only=1]
+{
+ \set Staff.instrumentName = "Violin 1"
+ c'1 ~ \break
+ \once \override Score.RehearsalMark.break-visibility = ##(#t #t #t)
+ \mark \default
+ c'
+}
+\end{lilypond}
+
+In a third score the tie has been tweaked to protrude into the margin
+and exceed the limit. As a result the score is narrowed even further,
+also shifting the \emph{right} margin.
+
+\begin{lilypond}[nofragment,%
+max-protrusion=1cm,
+print-only=1]
+{
+ \set Staff.instrumentName = "Violin 1"
+ \shape #'((0 . 0)(0 . 0)(3 . 0)(12 . 0)) Tie
+ c'1 ~ \break
+ \once \override Score.RehearsalMark.break-visibility = ##(#t #t #t)
+ \mark \default
+ c'
+}
+\end{lilypond}
+
+Note that this is not achieved by \emph{scaling} the \textsc{pdf} file
+but by actually \emph{recompiling} the score with modified
+\option{line-width}, thus keeping the correct staffsize. A warning
+message will inform about that fact on the console and in the log file.
+
+Note further that in the final example the score is short enough to fit
+on the line even with the horizontal offset, so in this case there is no
+need to recompile a shortened version:
+
+\begin{lilypond}[nofragment,%
+max-left-protrusion=1cm]
+{
+ \set Staff.instrumentName = "Violin one, with damper"
+ c'1
+}
+\end{lilypond}
+
+\lyMargin{Negative max-protrusion}
+
+The protrusion limits can also be set to \emph{negative} lengths, which
+makes them behave similar to using the \option{quote} option. However,
+there is a substantial difference between the two: using \option{quote}
+will apply a fixed indent, and the reference will again be the staff
+lines. Any protrusion will be considered from that reference point, so
+protruding elements will protrude into the margins, starting from the
+indent. Using a negative protrusion limit instead will prevent
+\emph{any} part of the score to exceed that value. Twe following three
+scores demonstrate the difference: the first has
+\option{quote, gutter=0.4in} while the second has
+\option{max-protrusion=-0.4in} set. The third has the same protrusion
+limit as the second but no protruding elements.
+
+\begin{lilypond}[nofragment,%
+quote,
+print-only=1]
+{
+ \set Staff.instrumentName = "Vl. 1"
+ c'1 ~ \break c'
+}
+\end{lilypond}
+
+\begin{lilypond}[nofragment,%
+max-protrusion=-0.4in,
+print-only=1]
+{
+ \set Staff.instrumentName = "Vl. 1"
+ c'1 ~ \break c'1
+}
+\end{lilypond}
+
+\begin{lilypond}[nofragment,%
+max-protrusion=-0.4in,
+print-only=1]
+{
+ c'1 ~ \break c'1
+}
+\end{lilypond}
+
+\hypertarget{indent}{%
+\paragraph{Managing indentation}\label{indent}}
+
+\lyOption{indent}{false}
+
+As mentioned above \option{indent} controls the indentation of the first
+system in a score. However, \lyluatex~provides smart dynamic indent
+handling for \option{insert=systems} that goes beyond simply setting the
+\texttt{indent} in the LilyPond score.
+
+\lyMargin{Deactivating indent}
+
+The indent is deactivated if one of the following condition is true:
+
+\begin{itemize}
+\tightlist
+\item
+ The score consists of a single system
+\item
+ Only the first system of a score is printed using
+ \option{print-only=true}
+\item
+ \option{print-only} is set so the first system of a score is printed
+ but not in the first position.
+\end{itemize}
+
+In the first case the score is simply shifted left, but in the other
+cases the score is recompiled to avoid a ``hole'' at the right edge.
+
+\lyOption{autoindent}{true}
+
+When \option{autoindent} is active protrusion handling will be modified.
+If a given protrusion limit is exceeded \lyluatex~will not reduce the
+\option{line-width} of the \emph{whole} score but add an indent. This is
+because in many cases it is the \emph{first} system of a score that
+contains significant protruding elements. If after application of the
+indent the protrusion limit is still exceeded due to other systems the
+line width is only reduced by the necessary amount and the indent
+adjusted accordingly.
+
+\option{autoindent} is active by default but will be deactivated if
+\option{indent} is set.
+
+\option{autoindent} will also be applied when a given indent is
+deactivated as described in the previous paragraph. This is done in
+order to avoid the whole score to be narrowed because of the deactivated
+indent.
+
+\lyIssue{Note:}
+
+Handling automatic indent requires up to three recompilations of a
+score, but it will only be applied when a protrusion limit is given and
+exceeded. Intermediate scores are cached and won't be unnecessarily
+recompiled.
+
+\lyIssue{NOTE:}
+
+Cacluations regarding automatic indent rely on the High Resolution
+Bounding Box retrieved from the final PDF file of the score. This is
+done using Ghostscript with the \texttt{gs} invocation. If this should
+not be available a low resolution bounding box is used instead, which
+can lead to rounding errors. Note that under certain circumstandes these
+rounding errors may not only lead to less accurate alignment but to
+wrong decisions in the alignment process. If you encounter wrong results
+please try to create a Minimal Working Example and submit it to
+\lyluatex's issue tracker\footnote{\url{https://github.com/jperon/lyluatex/issues}}.
+
+\lyMargin{Examples:}
+
+A comprehensive set of examples demonstrating the dynamic indent
+behaviour is available in \protect\hyperlink{dynamic-indent}{Dynamic
+Indent}.
+
+\hypertarget{vertical-alignment-of-fullpage-scores}{%
+\paragraph{Vertical Alignment of Fullpage
+Scores}\label{vertical-alignment-of-fullpage-scores}}
+
+\lyOption{fullpagealign}{crop|staffline}
+
+Controls how the top and bottom margins of a score are calculated. With
+\texttt{crop} LilyPond's \texttt{margin} paper variables are simply set
+to those of the \LaTeX~document, while \texttt{staffline} pursues a
+different approach that makes the outermost \emph{stafflines} align with
+the margin of the text's type area.
+
+With \texttt{crop} the pages may look somewhat uneven because the top
+and bottom systems are often pushed inside the page because the
+\emph{extremal} score items are aligned to the text. With
+\texttt{staffline} on the other hand it may happen that score items
+protrude too much into the vertical margins.
+
+\lyIssue{NOTE:}
+
+The \option{fullpagealign=staffline} option is highly experimental and
+has to be used with care. While positioning the extremal staves works
+perfectly the approach may confuse LilyPond's overall spacing
+algorithms. The \texttt{stretchability} parameters of
+\texttt{top-system-spacing}, \texttt{top-markup-spacing}, and
+\texttt{last-bottom-spacing} are forced to \texttt{0}, which seems to
+``unbalance'' the mutual stretches of vertical spacing. When scores
+appear compressed it is possible to experiment with (a combination of)
+explicitly setting \texttt{max-systems-per-page}, \texttt{page-count},
+or -- if everything else fails -- by including manual page breaks in the
+score.
+
+Another issue with \option{fullpagealign=staffline} is that it doesn't
+work properly with \option{print-page-number}. If these two options are
+set LilyPond will print the page numbers at the top of the paper,
+without a margin. But when aligning the stafflines to the type area one
+will usually want to have \LaTeX~print the page headers and footers
+anyway.
+
+\lyOption{extra-bottom-margin}{0}
+
+\lyOption{extra-top-margin}{0}
+
+These options may be used to add (or remove) some space to the vertical
+margins of fullpage scores. This can be used to create a vertical
+``indent'' or to adjust for scores with unusually large vertical
+protrusion. \emph{Note:} This setting affects a whole score and can't be
+applied to individual pages (which is a limitaion with LilyPond).
+
+\hypertarget{score-options}{%
+\subsection{Score Options}\label{score-options}}
+
+\hypertarget{autowrap}{%
+\subsubsection{Automatic Wrapping of Music Expressions}\label{autowrap}}
+
+\lyOption{fragment}{true}
+
+With this option set to \option{true}, the input code is wrapped between
+\texttt{\{\ \}}, so that you can directly enter simple code, for
+example:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\FunctionTok{\textbackslash{}lilypond}\NormalTok{\{a' b' c'\}}
+\end{Highlighting}
+\end{Shaded}
+
+This option defaults to \texttt{true} with \cmd{lilypond} and
+\texttt{lilypond} environment, to \texttt{false} with
+\cmd{lilypondfile}. It will be automatically disabled if a
+\texttt{\textbackslash{}book}, \texttt{\textbackslash{}header},
+\texttt{\textbackslash{}layout}, \texttt{\textbackslash{}paper} or
+\texttt{\textbackslash{}score} block is found within the input code; but
+in some cases, it will be necessary to explicitly disable it with
+\option{fragment=false} or its equivalent \option{nofragment}.
+
+\option{nofragment} and \option{relative} are mutually exclusive; the
+locally-defined option will take precedence over the globally-defined
+one, and if both are defined at the same level, the result will be
+random.
+
+\hypertarget{font-handling}{%
+\subsubsection{Font Handling}\label{font-handling}}
+
+\lyOption{pass-fonts}{false}
+
+Use the text document's fonts in the LilyPond score.
+
+The choice of fonts is arguably the most obvious factor in the
+appearance of any document, be it text or music. In text documents with
+interspersed scores the text fonts should be consistent between text and
+music sections. \lyluatex~can handle this automatically by passing the
+used text fonts to LilyPond, so the user doesn't have to worry about
+keeping the scores' fonts in sync with the text document.
+
+The following steps are taken when \option{pass-fonts} is \texttt{true}:
+Before generating any score \lyluatex~retrieves the currently defined
+fonts for \cmd{rmfamily}, \cmd{sffamily}, and \cmd{ttfamily}, as well as
+the font that is currently in use for typesetting. These fonts are
+included in the score compiled by LilyPond, but if the LilyPond input
+explicitly defines fonts in a \cmd{paper \{\}} block this takes
+precedence over the automatically transferred fonts.
+
+\lyIssue{Note:}
+
+So far only the font \emph{family} is used by LilyPond, but it is
+intended to add support for OpenType features in the future.
+
+\lyIssue{Note:}
+
+LilyPond handles font selection differently from \LuaTeX~and can only
+look up fonts that are installed as system fonts. For any font that is
+installed in the \texttt{texmf} tree LilyPond will use an arbitrary
+fallback font. Therefore \option{pass-fonts} defaults to \texttt{false}.
+
+\lyOption{current-font-as-main}{false}
+
+Use the font family \emph{currently} used for typesetting as LilyPond's
+main font.
+
+By default \option{pass-fonts} matches, roman, sans, and mono fonts, but
+with \option{current-font-as-main=false} the font that is
+\emph{currently} used for typesetting is passed to LilyPond as its
+``main'' roman font. This ensures that the score's main font is
+consistent with the surrounding text. However, this behaviour may not be
+desirable because it effectively removes the roman font from the
+LilyPond score, and it may make the \emph{scores} look inconsistent with
+each other. Therefore \lyluatex~by default passes the text document's
+three font families to their directy LilyPond counterparts.
+
+\lyOption{rmfamily}{}\lyOption{sffamily}{}\lyOption{ttfamily}{}
+
+The roman, sans, and mono fonts can also be specified explicitly to be
+passed into the LilyPond document independently from the text document's
+fonts. If \emph{any} of these options is set \option{pass-fonts} is
+implicitly set to \texttt{true}. Note that in this case for families
+that are \emph{not} set explicitly the current text document fonts are
+used.
+
+If \option{rmfamily} is set explicitly then
+\option{current-font-as-main} is implicitly disabled.
+
+\lyMargin{Examples:}
+
+Demonstrations of the different font handling features are available in
+\protect\hyperlink{fonts}{Font Handling}.
+
+\hypertarget{staff-display}{%
+\subsubsection{Staff Display}\label{staff-display}}
+
+There are a number of options that directly affect how staves are
+displayed, basically removing parts of the staff elements. The options
+can be freely combined, and a few presets have been prepared.
+
+\lyOption{noclef}{false}
+
+Don't print clefs.
+
+\lyOption{notimesig}{false}
+
+Don't print time signatures.
+
+\lyOption{nostaffsymbol}{false}
+
+Don't print staff lines.
+
+\lyOption{notiming}{false}
+
+Don't use any timing information, e.g.~don't print automatic barlines.
+
+\lyOption{notime}{false}
+
+Preset: don't print time signatures and don't use timing
+(\texttt{lilypond-book} option).
+
+\lyOption{nostaff}{false}
+
+Preset: suppress staff lines, clefs, and time signatures (but do use
+timing).
+
+Note that there is no option to suppress key signatures since a key
+signature is not \emph{implicitly} printed. \emph{If} there should be
+the need to \emph{have} a key signature and at the same time suppress
+it, it's reasonable to expect this to be explicitly done in the LilyPond
+code.
+
+\hypertarget{relative}{%
+\subsubsection{Relative or Absolute Pitches}\label{relative}}
+
+By default LilyPond input is parsed as-is with regard to pitches. That
+means pitches are treated as absolute pitches except if the music is
+wrapped in a \cmd{relative} clause.
+
+\lyOption{relative}{0}
+
+With the \option{relative} option set the LilyPond input is parsed in
+\emph{relative} mode, with the option value specifying the starting
+pitch. Zero (or an empty value) takes the ``middle C'' as the origin,
+positive integers refer to the number of octaves upwards, negative
+integers to downward octaves.
+
+\lyIssue{Note:}
+
+This deviates from LilyPond's usual behaviour: in LilyPond the
+``natural'' \texttt{c} corresponds to C3 in MIDI terminology, while
+\texttt{relative=0} refers to C4 instead. This is in accordance with the
+use in lilypond-book.
+
+\lyIssue{Note:}
-In the preable of your document, include the package \texttt{lyluatex}:
+\option{relative} is only allowed when the content is automatically
+wrapped in a music expression (as described in
+\protect\hyperlink{autowrap}{Automatic Wrapping}).
+
+\hypertarget{language}{%
+\subsubsection{Input Language}\label{language}}
+
+\lyOption{language}{}
+
+Specify the language for LilyPond input, defaulting to LilyPond's
+default language Dutch.
+
+\hypertarget{labels}{%
+\subsubsection{Labels}\label{labels}}
+
+\lyOption{label}{}
+
+If the \option{label} option is set a \cmd{label} is inserted directly
+before the image. The label name is prepended with the value of the
+\option{labelprefix} option, so any references to the score have to take
+that into account.
+
+\lyIssue{Note:}
+
+It should be obvious but \option{label} can only be used as a
+\emph{local} option since multiple identical labels will trigger
+\LaTeX~errors.
+
+\lyOption{labelprefix}{ly\_}
+
+Sets the prefix to be prepended to each label.
+
+\hypertarget{printing-the-filename}{%
+\subsubsection{Printing the Filename}\label{printing-the-filename}}
+
+For scores included by \cmd{lilypondfile} it is possible to print the
+filename before the score. This is activated by the
+
+\lyOption{printfilename}{false}
+
+option. It will print the actual filename only, without any path
+information.
+
+By default the filename is printed in its own unindented paragraph,
+including \cmd{bigskip} between the text and the score. However, the
+appearance can be modified by renewing the command
+
+\lyCmd{lyFilename}
+
+The following redefinition removes any indent and prints the text in
+monospace:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\FunctionTok{\textbackslash{}renewcommand}\NormalTok{\{}\ExtensionTok{\textbackslash{}lyFilename}\NormalTok{\}[1]\{}\CommentTok{%}
+\FunctionTok{\textbackslash{}noindent} \FunctionTok{\textbackslash{}texttt}\NormalTok{\{#1\}}\FunctionTok{\textbackslash{}par\textbackslash{}bigskip}\CommentTok{%}
+\NormalTok{\}}
+\end{Highlighting}
+\end{Shaded}
+
+\hypertarget{printing-lilypond-code}{%
+\subsubsection{Printing LilyPond Code}\label{printing-lilypond-code}}
+
+\lyOption{verbatim}{false}
+
+Depending on the use case it may be desired to not only include the
+score into the document but to also print the LilyPond input verbatim.
+This can be achieved by setting the \option{verbatim} option to
+\texttt{true}. In this case first the input code will be printed in a
+\texttt{verbatim} environment, followed by the score.
+
+\lyIssue{Note:}
+
+Please note that input from LilyPond fragments entered with the
+\cmd{lilypond} command will be printed on a single line. But as such
+fragments are intended to contain short snippets anyway this shouldn't
+be an issue.
+
+\lyMargin{Partial printing}
+
+If the LilyPond input contains a comment with the character sequence
+\texttt{\%\ begin\ verbatim} then everything up to and including this
+comment will \emph{not} be printed verbatim (but still used for
+engraving the score). If after that \texttt{\%\ end\ verbatim} is found
+then the remainder of the input will be skipped too, otherwise the code
+is printed to the end.
+
+\lyOption{addversion}{false}
+
+If \option{addversion} is set the LilyPond version used to compile the
+current score is printed before the verbatim input code.
+
+\lyOption{intertext}{}
+
+If \option{intertext} is set to a string its value will be printed
+between the verbatim code and the score.
+
+\lyCmd{lyIntertext}
+
+By default the intertext will be printed in its own paragraph, with a
+\cmd{bigskip} glue space between it and the score. The appearance is
+controlled by the macro \cmd{lyIntertext}, and by renewing this macro
+the appearance can be modified. The following redefinition removes any
+indent and prints the text blue:
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\FunctionTok{\textbackslash{}renewcommand}\NormalTok{\{}\ExtensionTok{\textbackslash{}lyIntertext}\NormalTok{\}[1]\{}\CommentTok{%}
+\FunctionTok{\textbackslash{}noindent} \FunctionTok{\textbackslash{}textcolor}\NormalTok{\{blue\}\{#1\}}\FunctionTok{\textbackslash{}par\textbackslash{}bigskip}\CommentTok{%}
+\NormalTok{\}}
+\end{Highlighting}
+\end{Shaded}
+
+\lyMargin{Syntax Highlighting}
+
+By default printed LilyPond code will be wrapped in a \option{verbatim}
+environment. It is possible to change the way how the code is wrapped
+through the command
+
+\lyCmd{lysetverbenv}
+
+which works very much like \cmd{newenvironment} and expects the code to
+be inserted before and after the LilyPond code as its two arguments.
+Typical use cases would be to enable some syntax highlighting, although
+it may also be of interest to wrap the \texttt{verbatim} environment
+into a \texttt{quote} environment.
+
+So far no proper syntax highlighting for LilyPond is available in
+\LaTeX~(which is why it is not switched on by default), and the closest
+match today is to use the \texttt{TeX} highlighting of the
+\option{minted} package.
+
+\begin{Shaded}
+\begin{Highlighting}[]
+\CommentTok{% In the document header:}
+\BuiltInTok{\textbackslash{}usepackage}\NormalTok{\{}\ExtensionTok{minted}\NormalTok{\}}
+
+\CommentTok{% anywhere in the header or the body:}
+\FunctionTok{\textbackslash{}lysetverbenv}\NormalTok{\{}\KeywordTok{\textbackslash{}begin}\NormalTok{\{}\ExtensionTok{minted}\NormalTok{\}\{TeX\}\}\{\textbackslash{}end\{minted\}\}}
+\end{Highlighting}
+\end{Shaded}
+
+\hypertarget{miscellaneous-options}{%
+\subsection{Miscellaneous Options}\label{miscellaneous-options}}
+
+\hypertarget{include-paths}{%
+\subsubsection{Include Paths}\label{include-paths}}
+
+When referencing external files with \cmd{lilypondfile}
+\lyluatex~understands absolute and relative paths. By default, relative
+paths are considered relative not to the current \texttt{.tex}
+document's directory, but to the \emph{current working directory}, which
+is one reason why it's strongly recommended to launch \LuaLaTeX~from the
+document's directory. Additionally, \lyluatex~will find any file that is
+visible to \LaTeX~itself, i.e.~all files in the \texttt{\textsc{texmf}}
+tree. A special case are paths that start with a tilde
+(\textasciitilde). This tilde (which has to be input as
+\cmd{string\textasciitilde} in \LaTeX) will be expanded to the user's
+\texttt{HOME} directory, which should work equally in UNIX/Linux and
+Windows.
+
+\lyOption{includepaths}{./}
+
+With the \option{includepaths} option a comma-separated list of search
+paths can be specified. These paths will be used by \lyluatex~to locate
+external files, and relative paths are searched for in the following
+order:
+
+\begin{itemize}
+\tightlist
+\item
+ relative to the current \texttt{.tex} file's directory (i. e. the file
+ from which the score is included)
+\item
+ relative to each \texttt{includepath}, in the order of their
+ definition in the list
+\item
+ using \LaTeX's search mechanism
+\end{itemize}
+
+Additionally the list of include paths is passed to LilyPond's include
+path, so they can be used for including files from within the LilyPond
+code. Paths starting with the tilde will implicitly be expanded to
+absolute paths in that process.
+
+\hypertarget{program}{%
+\subsubsection{LilyPond Executable}\label{program}}
+
+By default \lyluatex~will invoke LilyPond through the \texttt{lilypond}
+command, which will work in many situations for default installations.
+However, in order to accomodate specific installations (Windows?) or to
+use specific versions of LilyPond the command to be used can be
+specified with the
+
+\lyOption{program}{lilypond}
+
+option. If given this must point to a valid LilyPond \emph{executable}
+(and not, say, to the installation directory). If LilyPond can be
+started the version string will be printed to the console for every
+score, otherwise an error is raised, as is described in
+\protect\hyperlink{lilypond-failures}{Handling LilyPond Failures}.
+
+\lyOption{ly-version}{2.18.2} The LilyPond version to be written to the
+generated LilyPond code. This option is partially redundant with the
+\option{program} option but may serve as a guard against using outdated
+LilyPond versions. This can for example be relevant when sharing
+documents and \option{program} is set to its default \texttt{lilypond},
+which may be something different on another computer.
+
+\hypertarget{temporary-directory-for-scores}{%
+\subsubsection{Temporary Directory for
+Scores}\label{temporary-directory-for-scores}}
+
+\lyluatex~uses a temporary directory to store LilyPond scores. For each
+score a unique name will be created using its \emph{content} and the
+state of all options. LilyPond will only be invoked to compile a score
+when no corresponding file is present in the temporary directory, an
+approach that avoids unnecessary recompilation while ensuring that any
+updates to the content or the parameters of a score will trigger a new
+score.
+
+\lyOption{tmpdir}{tmp-ly}
+
+The directory that is used for this purpose can be set with the
+\option{tmpdir} option. Its value is a relative path starting from the
+\emph{current working directory}, i.e.~the directory from which
+\LuaLaTeX~has been started, not necessarily that of the \texttt{.tex}
+document. Note that for several reasons it is strongly suggested to
+always compile documents from their own directory.
+
+\lyOption{cleantmp}{false}
+
+While the caching mechanism is great for avoiding redundant LilyPond
+compilations it can quickly produce a significant number of unused score
+files since \emph{any} change will cause a new set of image files to be
+generated. Therefore the \option{cleantmp} option can be used to trigger
+some garbage collection after the \LaTeX~document has been completed.
+
+\lyluatex~writes a \texttt{\textless{}documentname\textgreater{}.list}
+log file to the temporary directory, listing the hashed filenames of all
+scores produced in the document. If the score has been given a
+\option{label} (see \protect\hyperlink{labels}{Labels}) or if it is
+generated from an external file this information is added to the list
+entry for use in any later inspection.
+
+With the \option{cleantmp} option in place \lyluatex~will remove
+\emph{all} files that have not been generated from the current document.
+Note that this will also remove scores that may become useful again in
+the future if changes to the document will be reverted (for example if a
+document is created for different output formats). But of course these
+will simply be regenerated when necessary.
+
+When the temporary directory is shared by several documents purging
+files might remove scores needed by \emph{other} documents. Therefore
+\lyluatex~will read \emph{all}
+\texttt{\textless{}documentname\textgreater{}.list} files and only
+remove scores that are not referenced by \emph{any} list file.
+
+\hypertarget{pdf-optimization}{%
+\subsubsection{PDF optimization}\label{pdf-optimization}}
+
+\lyOption{optimize-pdf}{false}
+
+If set to \texttt{true}, each included pdf will be optimized by
+\texttt{ghostscript} before inclusion. It's set to \texttt{false} by
+default, because it's time consuming, and it loses information about the
+fonts.
+
+\hypertarget{lilypond-failures}{%
+\subsubsection{Handling LilyPond Failures}\label{lilypond-failures}}
+
+Compiling a score with LilyPond can produce several types of problems
+which will be detected and handled (if possible) by \lyluatex. The most
+basic problem is when LilyPond can't be started at all. \lyluatex~will
+correctly determine and report an error if \LuaLaTeX~has been started
+without the \option{--shell-escape} option or if the \option{program}
+option doesn't point to a valid LilyPond executable.
+
+Two other situations that are correctly recognized are when LilyPond
+\emph{reports} a compilation failure but still produces a (potentially
+useful) score, and when LilyPond actually fails to engrave a score. How
+this is handled is controlled by the \option{debug} and
+\option{showfailed} options.
+
+\lyOption{debug}{false}
+
+If LilyPond reports an error and \option{debug} is set to \texttt{true}
+then \lyluatex~will save both the generated LilyPond code and the
+complete log output to a \texttt{.ly} and a \texttt{.log} file in the
+temporary directory. The file names are printed to the console for easy
+reference. Otherwise only a general warning will be issued. This will
+happen regardless of whether a score file is produced or not. In
+addition \lyluatex~will usually delete intermediate files that are not
+useful for later compilations but keep them all when \option{debug} is
+active.
+
+\lyOption{showfailed}{false}
+
+If LilyPond failed to produce a score and \option{showfailed} is set to
+\texttt{false} then the \LaTeX~compilation will stop with an error. This
+error can be skipped, but nothing will be included in the document. If
+on the other hand \option{showfailed} is set to \texttt{true} only a
+warning is issued and a box with an informative text is typeset into the
+resulting document.
+
+\hypertarget{musicxml-options}{%
+\subsection{MusicXML options}\label{musicxml-options}}
+
+\lyOption{xml2ly}{musicxml2ly}
+
+This option does the same for \texttt{\textbackslash{}musicxmlfile} as
+\option{program} for \texttt{\textbackslash{}lilypondfile}.
+
+\lyOption{language}{}\lyOption{absolute, lxml, verbose}{false}\lyOption{
+no-articulation-directions, no-beaming, no-page-layout, no-rest-positions
+}{true}
+
+All those options control the corresponding \texttt{musicxml2ly}
+switches; please refer to
+\href{http://lilypond.org/doc/v2.18/Documentation/usage/invoking-musicxml2ly}{\texttt{musicxml2ly}
+documentation} for more information.
+
+\hypertarget{using-in-classes-or-style-files}{%
+\section{\texorpdfstring{Using \lyluatex~in Classes or Style
+Files}{Using ~in Classes or Style Files}}\label{using-in-classes-or-style-files}}
+
+\hypertarget{wrapping-commands}{%
+\subsection{\texorpdfstring{Wrapping
+\lyluatex~commands}{Wrapping ~commands}}\label{wrapping-commands}}
+
+\cmd{lilypond} and \highlight{lilypond} are aliases for a command and an
+environment that \lyluatex~defines internally, respectively \cmd{lily}
+and \highlight{ly}.
+
+\cmd{lily} can be wrapped within another command in an usual way; but
+\highlight{ly} is quite a special environments, which makes it a bit
+unusual to wrap. You'll find more about this point in
+\protect\hyperlink{wrappingcommands}{Wrapping Commands}
+
+\hypertarget{providing-raw-filenames}{%
+\subsection{Providing Raw filenames}\label{providing-raw-filenames}}
+
+\lyluatex's default mode of operations is to directly insert scores into
+the document. For this the generated PDF files of the scores are
+transparently wrapped in \cmd{includegraphics} or \cmd{includepdf}
+commands and given appropriate layout.
+
+\lyOption{raw-pdf}{false}
+
+However, for more control over the placement and handling of the scores,
+especially for package developers, \option{raw-pdf} provides the option
+to make available the raw file name(s) to be processed and wrapped at
+will. When \option{raw-pdf} is set \lyluatex~will implicitly and
+temporarily define a command
+
+\lyCmd{lyscore}
+
+taking one mandatory argument, which may be empty. In this case
+\cmd{lyscore\{\}} expands to the filename of the first system of the
+score while \cmd{lyscore\{N\}} will return the filename of the N-th
+system. The special keywords \cmd{lyscore\{nsystems\}} and
+\cmd{lyscore\{hoffset\}} return the number of systems in the score and
+\texttt{\textless{}hoffset\textgreater{}pt} as a distance to be applied
+to handle protrusion.
+
+Additionally any \lyluatex~option can be used to retrieve the
+corresponding given or calculated value. For example
+\cmd{lyscore\{valign\}} will return \texttt{top}, \texttt{center}, or
+\texttt{bottom}. By accessing these options it is possible to make use
+of information that is not part of the actual generated score but that
+would otherwise be used by \lyluatex's \LaTeX~wrapping.
+
+\lyMargin{Examples:}
+
+Examples on how raw filenames can be wrapped in secondary commands can
+be found in \protect\hyperlink{insert-raw-pdf}{Wrapping Raw PDF
+Filenames}.
+
+\printindex\addcontentsline{toc}{section}{Index}
+
+\hypertarget{examples}{%
+\section{Examples}\label{examples}}
+
+Those examples and others may be found in
+\href{https://github.com/jperon/lyluatex/}{the package repository}.
+
+\addcontentsline{toc}{subsection}{Insert Systems}
+\hypertarget{insert-systems}{}
+
+\section*{Insert System-by-System}
+
+By default scores defined by the \option{lilypond} environment or the \cmd{lilypondfile} command are inserted as a sequence of systems.
+
+\lyluatex\ determines the vertical space between the systems as a flexible length calculated from the \emph{staff size} of the score (as opposed to from the font size) to produce an regular-looking vertical spacing:
+
+\begin{lilypond}[]
+{
+ \repeat unfold 30 { c' d' e' d' }
+}
+\end{lilypond}
+
+The following score has a significantly smaller staff size, and consequently the inter-system space is reduced:
+
+\begin{lilypond}[staffsize=12]
+{
+ \repeat unfold 36 { c' d' e' d' }
+}
+\end{lilypond}
+
+\subsection*{Before and After the Score}
+
+\cmd{preLilyPondExample} and \cmd{postLilyPondExample} allow some code to be printed before and after the score. This may for example be used to wrap the resulting score in an environment. In the following example rules are printed:
+
+\def\preLilyPondExample{%
+\par\bigskip
+\noindent Before the score:
+\par\medskip\hrule\par\medskip}
+\def\postLilyPondExample{%
+\par\bigskip
+\hrule\par\medskip\noindent After the score
+\par\bigskip}
\begin{verbatim}
-\usepackage{lyluatex}
+ \newcommand{\preLilyPondExample}{%
+ \par\bigskip
+ \noindent Before the score:
+ \par\medskip\hrule\par\medskip}
+
+ \newcommand{\postLilyPondExample}{%
+ \par\bigskip
+ \hrule\par\medskip\noindent After the score
+ \par\bigskip}
\end{verbatim}
-The \texttt{program} option permits the definition of an alternative
-path to \texttt{lilypond}, for example:
+\begin{lilypond}[]
+{
+ \repeat unfold 30 { c' d' e' d' }
+}
+\end{lilypond}
+
+\subsection*{Configuring the Inter-System Content}
+
+\let\preLilyPondExample\undefined
+\let\postLilyPondExample\undefined
+
+Using \cmd{betweenLilyPondSystem} it is possible to define a macro that is
+expanded between each system pair. It is given the index of the previous system
+as an argument to work with. The following example simply prints that index
+between the systems, but with some programming more complicated and useful
+things could be done, for example printing a rule after every third system or
+conditionally insert a page break.
+
+\def\betweenLilyPondSystem#1{%
+\begin{center}
+System #1
+\end{center}
+}
+
+\begin{verbatim}
+ \newcommand{\betweenLilyPondSystem}[1]{%
+ \begin{center}
+ System #1
+ \end{center}
+ }
+\end{verbatim}
+
+\bigskip
+
+\begin{lilypond}[]
+{
+ \repeat unfold 30 { c' d' e' d' }
+}
+\end{lilypond}
+
+\let\betweenLilyPondSystem\undefined
+
+
+
+\addcontentsline{toc}{subsection}{Insert Inline}
+\hypertarget{insert-inline}{}
+
+\section*{Insert Scores Inline}
+
+With the \option{insert=inline} option it is simple to insert arbitrary
+notational fragments in the \lilypond{ e'8 d'16 e' } continuous text of a
+document. By default the staffsize is scaled to be 2/3 of the staffsize a
+regular score would have at this point. This means if the \option{staffsize}
+option is modified globally or locally then the staffsize of the inline score is
+changed too.
+
+In order to make the size of inline scores independent from the regular
+staffsize the option \option{inline-staffsize} can be used the same way as
+\option{staffsize}. \lilypond[inline-staffsize=8]{ e'8 d'16 e' } has the inline
+staffsize manually set to \texttt{8}.
+
+\paragraph{Alignment and padding} By default inline scores are vertically
+centered to a line 1/2em above the text's baseline. \lilypond[valign=top]{ e'8
+d'16 e' } but the score can also be aligned \lilypond[valign=bottom]{ e'8 d'16
+e' } to the top or the baseline of the text.
+
+Unfortunately this can only consider the borders of the \emph{image} and not
+those of the \emph{score} or the staff lines. To alleviate this situation a
+specific vertical offset can be given with \option{voffset=-3pt} (or any other
+\TeX\ lengths). This offset is calculated after the alignment.
+\lilypond[valign=bottom,voffset=-6pt]{ e'8 d'16 e' } is inserted with
+\option{valign=bottom,voffset=-4pt}.
+
+Horizontally inline scores are padded by \option{hpadding=0.75ex} -- except if
+they happen to appear at the beginning or end of a line, as can be seen in the
+last score in the previous paragraph. \lilypond[hpadding=2em]{ e'8 d'16 e' }
+Increasing the \option{hpadding} will ensure more space around the score.
+
+\paragraph{Bare Inline scores} \option{insert=bare-inline} will remove all the
+staff elements (staff symbol, time signature, clef) by implicitly applying
+\option{nostaff}, which is most useful for including notational symbols like
+characters in the paragraph.
+\lilypond[insert=bare-inline,%
+inline-staffsize=14,%
+voffset=-1pt,%
+hpadding=0.25ex%
+]{s2.\startTrillSpan s4\stopTrillSpan}
+This actually works like the \option{lilyglyphs}
+package\footnote{\url{https://github.com/uliska/lilyglyphs}} but with the
+possibility of inserting arbitrary LilyPond material without having to prepare
+precompiled PDF images.
+
+
+
+\addcontentsline{toc}{subsection}{Choosing Systems}
+\hypertarget{print-only}{}
+
+\def\postLilyPondExample{\par\bigskip\hrule\par\bigskip}
+
+\section*{Print only Selected Systems or Pages}
+
+The \texttt{print-only} option allows to limit the printed systems or pages from
+a score. A typical use case is to print a score interspersed with comments. The
+advantage of this approach is that the score is compiled only once while the
+individual systems are simply reused by \LaTeX.
+
+Throughout this document we'll demonstrate the different options to
+select systems from the following score:
+
+\lilypondfile[verbatim]{eight-systems.ly}
+
+The simplest selection is a single system: \texttt{print-only=4}
+
+\lilypondfile[print-only=4]{eight-systems.ly}
+
+Ranges are also possible: \texttt{print-only=3-5}, with the special form of
+\texttt{print-only=6-} which prints from the given system throughout the end of
+the score. Negative ranges can be given with \texttt{print-only=7-5}
+
+\lilypondfile[print-only=3-5]{eight-systems.ly}
+
+\lilypondfile[print-only=6-]{eight-systems.ly}
+
+\lilypondfile[print-only=7-5]{eight-systems.ly}
+
+With a comma-separated list an arbitrary sequence of systems can be specified.
+The list has to be enclosed in curly brackets: \texttt{print-only={4,1,2}}
+
+\lilypondfile[print-only={4,1,2}]{eight-systems.ly}
+
+Each element of the list can include any of the forms described above:\\
+\texttt{print-only={3,5-7,4,7-}}
+
+\lilypondfile[print-only={3,5-7,4,7-}]{eight-systems.ly}
+
+The functionality is identical with fullpage scores where the selection applies
+to \emph{pages} instead. This can for example be used when the “score” file
+contains a number of individual pieces (e.g. songs for a song book), and
+individual selections are to be printed.
+
+Systems have some specific behaviour with regard to \emph{indent}, but this is demonstrated in its own file \texttt{dynamic-indent.tex}.
+
+\let\postLilyPondExample\undefined
+
+
+
+\addcontentsline{toc}{subsection}{Dynamic Indent Handling}
+\hypertarget{dynamic-indent}{}
+
+\def\postLilyPondExample{\par\bigskip\hrule\par\bigskip}
+
+\section*{Dynamic Indent}
+
+This document demonstrates the use of \texttt{indent} and \texttt{autoindent},
+partially in combination with \texttt{print-only}.
+
+\texttt{indent=1cm} indents the first line, but if the resulting score contains
+only one system this indent is suppressed (issuing a warning on the console):
+
+\begin{lilypond}[indent=1cm]
+ \set Staff.instrumentName = "Violin"
+ \repeat unfold 12 { c' d' e' d' }
+\end{lilypond}
+
+\begin{lilypond}[indent=1cm]
+ {
+ \set Staff.instrumentName = "Violin"
+ c' d' e' d'
+ }
+\end{lilypond}
+
+If the output of a score which contains more than one system is limited to the
+first system using \texttt{print-only=1} then the indent is removed but the
+score is recompiled to ensure a full-length system. The following score shows
+the two-system score from above (with \texttt{indent=1cm}), limited to its first
+system:
+
+\begin{lilypond}[indent=1cm,print-only=1]
+ \set Staff.instrumentName = "Violin"
+ \repeat unfold 12 { c' d' e' d' }
+\end{lilypond}
+
+Note that this behaviour also applies when \texttt{print-only} causes the first
+system to be printed at another position, e.g. with \texttt{print-only={3,1,2}}.
+In this case the indent of the first system is suppressed in order to avoid a
+“hole”. Of course this is a corner case, but might be useful when a score
+consists of separate entities (examples, exercises) per system.
+
+\begin{lilypond}[indent=1cm,print-only={3,1,2},max-protrusion=0.5cm]
+ \repeat unfold 25 { c' d' e' d' }
+\end{lilypond}
+
+If a protrusion limit has been set with \texttt{max-protrusion=0.5cm} and the
+score exceeds that limit in spite of \texttt{indent=1cm} then the whole score
+will appropriately be narrowed:
+
+\begin{lilypond}[indent=1cm,max-protrusion=0.5cm]
+ \set Staff.instrumentName = "Violin I. and II."
+ \repeat unfold 11 { c' d' e' d' }
+\end{lilypond}
+
+
+This doesn't really look good because the indentation of the second system
+wouldn't have been necessary since only the first system exceeds the protrusion
+limit. The solution to this situation is the option \texttt{autoindent} which
+handles the indentation \emph{automatically} and set the indent to a value that
+will make the \emph{first} system fit into the protrusion limit and leave the
+remaining systems unchanged:
+
+\begin{lilypond}[autoindent=true,max-protrusion=0.5cm]
+ \set Staff.instrumentName = "Violin I. and II."
+ \repeat unfold 11 { c' d' e' d' }
+\end{lilypond}
+
+
+However, if the protrusion limit is not only exceeded by the \emph{first} system
+(which should be the typical case due to the instrument name) \texttt{lyluatex}
+will deal with the situation by narrowing the \emph{whole} score by the
+appropriate amount and adjusting the indent of the first system so all systems
+will just fit into the protrusion limit:
+
+\begin{lilypond}[autoindent=true,max-protrusion=0.5cm]
+ \set Staff.instrumentName = "Violin I. and II."
+ \set Staff.shortInstrumentName = "Violin I/II"
+ \repeat unfold 11 { c' d' e' d' }
+\end{lilypond}
+
+There is one special case to be mentioned. As described above the indent is
+deactivated if the first system of a score is printed at a later position.
+However, if this score will exceed the left protrusion limit \texttt{autoindent}
+will be automatically activated to avoid having the \emph{whole} score narrowed:
+
+\begin{lilypond}[indent=1cm,print-only={3,1,2},max-protrusion=0.5cm]
+ \set Staff.instrumentName = "Violin"
+ \repeat unfold 25 { c' d' e' d' }
+\end{lilypond}
+
+\paragraph{Right protrusion}
+The dynamic handling of (automatic) indent also works correctly when there is
+protrusion handling to the right. The following score has the ties manually
+shaped to exceed the staff symbol by 10, and 7 staff spaces, and
+\texttt{max-protrusion=1cm} .
+
+\begin{lilypond}[nofragment,max-protrusion=1cm,]
+{
+ \set Staff.instrumentName = "Violin 1 & 2"
+ \set Staff.shortInstrumentName = "Vl 1 & 2"
+ \shape #'((0 . 0)(0 . 0)(3 . 0)(10 . 0)) Tie
+ c'1 ~ \break
+ \shape #'((0 . 0)(0 . 0)(3 . 0)(7 . 0)) Tie
+ c' ~ \break
+ c'
+}
+\end{lilypond}
+
+
+\paragraph{Performance considerations}
+The handling of indent suppression may require up to four compilations of the
+score, but these are handled automatically, and the resulting intermediate
+stages of the score are cached just like the scores actually used in the
+document.
+
+The \texttt{autoindent} option is active by default but will be deactivated if
+\texttt{indent} is set explicitly. It has to be noted that this option will add
+more LilyPond compilations and therefore compilation time. But it will only
+apply and be executed if the score exceeds the protrusion limit, so it can only
+occur in circumstances where multiple LilyPond runs are expected anyway.
+
+\let\postLilyPondExample\undefined
+
+
+
+\addcontentsline{toc}{subsection}{Font Handling}
+\hypertarget{fonts}{}
+
+\defaultfontfeatures{Ligatures=TeX,Numbers=OldStyle,Scale=MatchLowercase}
+\setmainfont{Linux Libertine O}
+\setsansfont[BoldFont={Linux Biolinum O Bold}]{Linux Biolinum O}
+\setmonofont{Inconsolata}
+
+\section*{Font Handling}
+
+To demonstrate the font handling features of \lyluatex\ we will repeatedly
+include the following score from an external file. It includes roman (lyrics,
+instrument name), sans (rehearsal mark), and mono (tempo) text, first using
+LilyPond's built-in default fonts.
+
+\lilypondfile[verbatim]{fonts}
+
+\bigskip
+The current document uses \option{fontspec} to set roman font to \emph{Linux
+Libertine O}, sans font to \emph{Linux Biolinum O}, and mono font to
+\emph{Inconsolata}. So if you compile this document yourself and don't have
+these fonts installed you will receive unexpected results.
+
+\subsection*{Passing Document Fonts to Score}
+
+With \option{pass-fonts} the currently active font families for roman, sans, and
+mono fonts are passed to LilyPond in order to achieve the most coherent
+appearance between text and music.
+
+\bigskip
+
+\lilypondfile[pass-fonts]{fonts}
+
+\bigskip
+Note that LilyPond loads fonts differently than \LaTeX\ and can only make use of
+fonts installed as system fonts, fonts that are only installed through a \LaTeX\
+distribution are not accessible to it. That means that if the document fonts are
+not installed system-wide (e.\,g. the default fonts) LilyPond will use rather
+ugly fallback fonts. This can't be demonstrated here but the section about
+explicitly setting font families will include an example.
+
+The inherent problem of fallback fonts, especially with \LaTeX's default
+settings, is the reason \option{pass-fonts} is inactive by default. But the
+general recommendation is to set \option{pass-fonts} as package option if the
+text document uses fonts that are available to LilyPond.
+
+\bigskip
+
+\sffamily \option{current-font-as-main} will use the font that is
+\emph{currently} used for typesetting as LilyPond's main (roman) font. This can
+make sure that the score's main font (and roman is usually the font used most in
+scores) matches the surrounding text. Note that this might produce surprising
+behaviour if it is not clear that the current font has changed, and it will
+effectively suppress the original roman font from the score if the current font
+is one of the two others. Additionally this \emph{may} introduce an
+inconsistency not between the score and the surrounding text but between
+different scores in a document. For all these reasons the option is by default
+set to \texttt{false}.
+
+\bigskip
+\lilypondfile[pass-fonts,current-font-as-main]{fonts}
+
+\subsection*{Setting Score Fonts Explicitly}
+
+With \option{rmfamily}, \option{sffamily}, and \option{ttfamily} specific
+families can be set to arbitrary fonts, independently from the text document.
+For the following score \option{ttfamily=\{TeXGyre Adventor\}} is
+used.\footnote{Note that this font (which is included in TeXLive) has to be
+installed if you want to successfully compile this document.} Note that this
+implicitly sets \option{pass-fonts=true}, and \emph{Linux Libertine O} and
+\emph{Linux Biolinum O} are used from the text document.
+
+\bigskip
+\lilypondfile[ttfamily={TeXGyre Adventor}]{fonts}
+
+\highlight{NOTE:} when \option{rmfamily} is set explicitly
+\option{current-font-as-main} is forced to \texttt{false} to ensure that the
+roman font is actually used. The next score sets \option{rmfamily=\{TeXGyre
+Adventor\}} and \option{current-font-as-main}, and despite the current font still being \cmd{sffamily}
+\emph{Adventor} is used as the score's main font:
+
+\bigskip
+\lilypondfile[current-font-as-main,rmfamily={TeXGyre Adventor}]{fonts}
+
+\subsection*{LilyPond's Font Fallback}
+
+If unavailable fonts are set in a LilyPond document they will \emph{silently} be
+replaced with fallback fonts that tend to cause ugly results. This will be shown
+by setting \option{rmfamily=FantasyFontOne}, \option{sffamily=FantasyFontTwo},
+and \option{tfamily=FantasyFontThree}:
+
+\bigskip
+\lilypondfile[rmfamily=FantasyFontOne,%
+sffamily=FantasyFontTwo,%
+ttfamily=FantasyFontThree]{fonts}
+
+This can happen in several contexts: apart from compiling the document on a
+different computer where the used fonts are missing it is most likely to occur
+with the \option{pass-fonts} option, when the text document uses internal
+\LaTeX\ fonts. Note in particular that this may happen implicitly when only one
+family is specified explicitly with an option and the other families are passed
+from the text document.
+
+
+
+\addcontentsline{toc}{subsection}{Wrapping Commands}
+\hypertarget{wrappingcommands}{}
+
+\section*{Wrapping Commands}
+
+\cmd{lily} can be wrapped within another command as usual:
\begin{verbatim}
-\usepackage[program=/opt/lilypond-dev/lilypond]{lyluatex}
+\newcommand\mylily[2][1]{\lily[inline-staffsize=10, #1]{#2}}
+
+This is \mylily[voffset=10pt]{a' b' c''} an example.
\end{verbatim}
-Thereafter, you can include a lilypond file with the command:
+\newcommand\mylily[2][1]{\lily[inline-staffsize=10, #1]{#2}}
+
+This is \mylily[voffset=10pt]{a' b' c''} an example.
+
+It's possible to wrap \highlight{ly} within and environment, but there are
+several drawbacks:
+\begin{itemize}
+ \item this custom environment cannot have optional parameters. To be more
+ precise, if it has only optional parameters, it will be necessary to add \verb`[]`
+ after \verb`\begin{MY_ENV}` if no parameter is specified ; so they're not
+ optional any more…
+ \item to call \highlight{ly}, you'll have to:
+ \begin{itemize}
+ \item either write \verb`\begin{ly}[] \end{ly}` (which works with
+ \verb`\begin{lilypond}[]` \verb`\end{lilypond}` too) ;
+ \item or use the \TeX\ primitives \verb`\ly \endly` (not only for \highlight{ly},
+ but also for other environments).
+ \end{itemize}
+\end{itemize}
\begin{verbatim}
-\includely[staffsize=17]{PATH/TO/THE/FILE}
+\newenvironment{myly}{%
+ This is \emph{my} lilypond environment.
+ \begin{ly}[]%
+}{%
+ \end{ly}
+}
+
+\begin{myly}
+ a b c
+\end{myly}
\end{verbatim}
-The argument \texttt{staffsize}, which is optional, changes the size of
-the score. You can change the size for all the subsequent scores in a
-document by placing the following command before your first include
-statement to be so affected:
+\newenvironment{myly}{%
+ This is \emph{my} lilypond environment.
+ \begin{ly}[]%
+}{%
+ \end{ly}
+}
+
+\begin{myly}
+ a b c
+\end{myly}
\begin{verbatim}
-\def\staffsize{24}
+\newenvironment{lyfigure}[2][]{%
+\edef\mycaption{#2}
+\begin{figure}
+\begin{center}
+ \begin{lilypond}[#1]%
+}{%
+ \end{lilypond}
+ \caption{\mycaption}
+\end{center}
+\end{figure}
+}
+
+\begin{lyfigure}{caption}
+a' b' c
+d' e' f
+\end{lyfigure}
\end{verbatim}
-Next, you simply need to compile the document normally with the command
-\texttt{lualatex\ -shell-escape}~:
+\newenvironment{lyfigure}[2][]{%
+\edef\mycaption{#2}
+\begin{figure}
+\begin{center}
+ \begin{lilypond}[#1]%
+}{%
+ \end{lilypond}
+ \caption{\mycaption}
+\end{center}
+\end{figure}
+}
+
+\begin{lyfigure}{caption}
+a' b' c
+d' e' f
+\end{lyfigure}
\begin{verbatim}
-lualatex -shell-escape DOCUMENT.TEX
+\newenvironment{lyotherfigure}[1][]{%
+\edef\option{#1}
+\figure
+\center
+ \ly
+}{%
+ \endly%
+ \def\empty{}\ifx\option\empty\else\caption{\option}\fi
+\endcenter
+\endfigure
+}
+
+\begin{lyotherfigure}[]
+d' e' f
+a' b' c
+\end{lyotherfigure}
\end{verbatim}
-Another ``more secure'' option is to add \texttt{lilypond} to default
-allowed commands~:
+\newenvironment{lyotherfigure}[1][]{%
+\edef\option{#1}
+\figure
+\center
+ \ly
+}{%
+ \endly%
+ \def\empty{}\ifx\option\empty\else\caption{\option}\fi
+\endcenter
+\endfigure
+}
+
+\begin{lyotherfigure}[]
+d' e' f
+a' b' c
+\end{lyotherfigure}
+
+
+
+\addcontentsline{toc}{subsection}{Wrapping Raw PDF Filenames}
+\hypertarget{insert-raw-pdf}{}
+
+\section*{Wrapping Raw PDF Filenames}
+
+With the \option{raw-pdf} option it is possible to create wrapping commands that
+circumvent \lyluatex's layout considerations by working with the raw PDF
+filename of the generated score. This is especially useful for developing
+packages or personal class and style files. For this scores generated with
+\option{raw-pdf} define a command \cmd{lyscore} that can be used in the wrapping
+commands or environments.
+
+All examples in this document could also be realized using “default” \lyluatex\
+without \option{raw-pdf}, but they are intended to show how this low-level
+access can be used to retrieve the information from the generated score in order
+to build custom versions of commands that don't have to adhere to \lyluatex's
+pre-built strategies of including the score in the document
+
+The easiest way to use a “raw” score is to simply access \cmd{lyscore} in a
+command and pass it to an \cmd{includegraphics} macro:
\begin{verbatim}
-shell_escape_commands=$(kpsewhich -expand-var '$shell_escape_commands'),lilypond lualatex DOCUMENT.TEX
+ \newcommand\lilyinline[2][]{%
+ \lily[raw-pdf,%
+ insert=bare-inline,%
+ inline-staffsize=8,%
+ hpadding=0.25ex,#1]{
+ \omit Stem
+ #2}%
+ \includegraphics{\lyscore{}}%
+ }
\end{verbatim}
-On systems with low RAM, when working on big documents, you could
-encounter \emph{buffer overflows} in \texttt{lilypond} calls. In that
-case, first compile with option \texttt{-draftmode}, then compile again
-without this option.
+\newcommand\lilyinline[2][]{%
+\lily[raw-pdf,insert=bare-inline,inline-staffsize=8,hpadding=0.25ex,#1]{
+ \omit Stem
+ #2}%
+\includegraphics{\lyscore{}}%
+}
+
+This basically is a way to provide pre-configured commands. In this case
+\lilyinline{ c'8 d' c' d'} it is used to pre-configure an inline
+type, entered as \verb+\lilyinline{ c'8 d' c' d'}+.
-You can also input music directly into your docoment with the
-\texttt{ly} environment. This is only recommended for relatively short
-snippets. For example:
+
+\bigskip \cmd{lyscore} takes one mandatory argument which can be empty -- as in
+the example above --, receive a number, one of the keywords \texttt{nsystems}
+and \texttt{hoffset}, or any of the score's options. If passed a number it will
+return the filename of the N-th system. With \texttt{nsystems} the number of
+systems in the generated score will be returned, while \texttt{hoffset}
+generates the code that shifts the score to the left to accommodate protrusion.
+
+The following example takes an optional argument with options that are passed to
+\lyluatex, and one mandatory argument which expects the system to be used. It
+prints the given system centered in a figure and uses the file name as the
+caption and makes use of the score's \texttt{label}. Figure \ref{centered} shows
+the centering of a short fragment, figure \ref{fifth} the selection of the fifth
+system from a larger score.
\begin{verbatim}
-\begin{ly}
-\relative c' { c d e f g a b c }
-\end{ly}
+ \newenvironment{centeredlilypondsystem}[2][]{%
+ \def\usesystem{#2}
+ \begin{figure}
+ \begin{center}
+ \begin{lilypond}[raw-pdf,#1]%
+ }{%
+ \end{lilypond}
+ \includegraphics{\lyscore{\usesystem}}
+ \caption{\lyscore{\usesystem}.pdf}
+ \label{\lyscore{label}}
+ \end{center}
+ \end{figure}
+ }
+
+ \begin{centeredlilypondsystem}[label=centered]{1}
+ c'1 d' e'
+ \end{centeredlilypondsystem}
+
+ \begin{centeredlilypondsystem}[label=fifth]{5}
+ \repeat unfold 8 { c'1 \break }
+ \end{centeredlilypondsystem}
\end{verbatim}
-Finally, for truly short snippets, there is also the
-\texttt{\textbackslash{}lily} command. Example:
+\newenvironment{centeredlilypondsystem}[2][]{%
+\def\usesystem{#2}
+\begin{figure}
+\begin{center}
+ \begin{lilypond}[raw-pdf,#1]%
+}{%
+ \end{lilypond}
+ \includegraphics{\lyscore{\usesystem}}
+ \caption{\lyscore{\usesystem}.pdf}
+ \label{\lyscore{label}}
+\end{center}
+\end{figure}
+}
+
+\begin{centeredlilypondsystem}[label=centered]{1}
+c'1 d' e'
+\end{centeredlilypondsystem}
+
+\begin{centeredlilypondsystem}[label=fifth]{5}
+\repeat unfold 8 { c'1 \break }
+\end{centeredlilypondsystem}
+
+
+Finally there's an example showing how to iterate over the systems of a score
+using \cmd{foreach} from the \option{pgffor} package. It iterates over all the
+systems in the given score, prints them using the protrusion adjustment seen
+before, and if the system is the third it prints this information, otherwise
+just a line break:
\begin{verbatim}
-\lily[staffsize=12]{c' d' g'}
+\newcommand\myforlily[2][]{%
+\lily[insert=systems,raw-pdf,#1]{#2}%
+\foreach \n in {1,...,\lyscore{nsystems}}%
+ {\noindent\hspace*{\lyscore{hoffset}}\includegraphics{\lyscore{\n}}%
+ \ifthenelse{\equal{\n}{3}}{\par Third system\par}{\\}
+ }%
+}
+
+\myforlily[staffsize=24]{
+\set Staff.instrumentName = "Vl. "
+\repeat unfold 4 { c'1 \break } }
\end{verbatim}
-\textbf{Nota bene:} The \texttt{\textbackslash{}lily} command \emph{does
-not} support blocks of LilyPond code with explicit
-\texttt{\textbackslash{}score} blocks. Such code must be included with
-the \texttt{ly} environment or as a separate file.
-
-\hypertarget{migration-from-lilypond-book}{%
-\subsection{\texorpdfstring{Migration from
-\texttt{lilypond-book}}{Migration from lilypond-book}}\label{migration-from-lilypond-book}}
-
-In order to facilitate the migration from \texttt{lilypond-book},
-\texttt{lyluatex} defines the command
-\texttt{\textbackslash{}lilypondfile} with the same arguments as
-\texttt{\textbackslash{}includely}. There is also the environment
-\texttt{lilypond} which is the same as \texttt{ly}, and the command
-\texttt{\textbackslash{}lilypond} should work as with
-\texttt{lilypond-book}.
-
-In this manner, documents typeset with \texttt{lilypond-book} can be
-adapted to use \texttt{lyluatex} without much difficulty. Just keep in
-mind that apart from the \texttt{staffsize} parameter, the optional
-parameters that \texttt{lilypond-book} supports are not supported by
-\texttt{lyluatex} (at least for now).
+\newcommand\myforlily[2][]{%
+\lily[insert=systems,raw-pdf,#1]{#2}%
+\foreach \n in {1,...,\lyscore{nsystems}}%
+ {\noindent\hspace*{\lyscore{hoffset}}\includegraphics{\lyscore{\n}}%
+ \ifthenelse{\equal{\n}{3}}{\par\bigskip Third system\par\bigskip}{\\}
+ }%
+}
+
+\myforlily[staffsize=24]{
+\set Staff.instrumentName = "Vl. "
+\repeat unfold 4 { c'1 \break } }
+
+
\end{document}
diff --git a/Master/texmf-dist/doc/support/lyluatex/lyluatexbase.cls b/Master/texmf-dist/doc/support/lyluatex/lyluatexbase.cls
new file mode 100644
index 00000000000..48d6040c055
--- /dev/null
+++ b/Master/texmf-dist/doc/support/lyluatex/lyluatexbase.cls
@@ -0,0 +1,38 @@
+%Lyluatex LaTeX class.
+%
+% Copyright (C) 2015-2018 jperon and others (see CONTRIBUTORS.md)
+% License: MIT
+% This file is part of lyluatex.
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesClass{lyluatexbase}[2018/03/12 v1.0b] %%LYLUATEX_DATE LYLUATEX_VERSION
+
+\LoadClass[DIV=11]{scrartcl}
+\RequirePackage{lyluatex}
+\RequirePackage{blindtext}
+\RequirePackage{libertine}
+\RequirePackage{listings}
+\RequirePackage{minted}
+\RequirePackage{pgffor}
+\RequirePackage[colorlinks=true]{hyperref}
+\lysetoption{includepaths}{./, ly/}
+
+
+% Common formatting elements for manual and examples
+\usepackage{xcolor}
+\newcommand{\highlight}[1]{\textcolor{blue}{#1}}
+\newcommand{\cmd}[1]{\highlight{\texttt{\textbackslash #1}}}
+\newcommand{\option}[1]{\highlight{\texttt{#1}}}
+\newcommand{\lyMargin}[1]{%
+
+\medskip
+\hspace*{-1em}%
+\noindent%
+\highlight{#1}
+\nopagebreak
+}
+
+\newcommand{\lyOption}[2]{\lyMargin{\texttt{#1} {\small \emph{(#2)}}\index{#1}}}
+\newcommand{\lyCmd}[1]{%
+\lyMargin{\texttt{\textbackslash #1}\index{\textbackslash #1}}}
+\newcommand{\lyIssue}[1]{\lyMargin{\textbf{\textcolor{red}{#1}}}}
diff --git a/Master/texmf-dist/doc/support/lyluatex/lyluatexmanual.cls b/Master/texmf-dist/doc/support/lyluatex/lyluatexmanual.cls
new file mode 100644
index 00000000000..5bd075e8d52
--- /dev/null
+++ b/Master/texmf-dist/doc/support/lyluatex/lyluatexmanual.cls
@@ -0,0 +1,30 @@
+%Lyluatex LaTeX class for the manual.
+%
+% Copyright (C) 2015-2018 jperon and others (see CONTRIBUTORS.md)
+% License: MIT
+% This file is part of lyluatex.
+
+\NeedsTeXFormat{LaTeX2e}
+\ProvidesClass{lyluatexmanual}[2018/03/12 v1.0b] %%LYLUATEX_DATE LYLUATEX_VERSION
+
+\LoadClass{lyluatexbase}
+
+\RequirePackage{fontspec}
+\RequirePackage{microtype}
+\RequirePackage{libertine}
+\setmonofont[Scale=MatchLowercase,StylisticSet=1]{InconsolataN}
+\defaultfontfeatures{
+ Ligatures=TeX,
+ Scale=MatchLowercase,
+ Numbers=Proportional,
+ Numbers=OldStyle
+}
+\frenchspacing
+
+\RequirePackage{makeidx}
+\makeindex
+
+\newcommand{\linkexample}[2]{
+ \addcontentsline{toc}{subsection}{#2}
+ \hypertarget{#1}{}
+}
diff --git a/Master/texmf-dist/scripts/lyluatex/lyluatex.lua b/Master/texmf-dist/scripts/lyluatex/lyluatex.lua
index bf9b29579d4..fd54cd22c87 100755
--- a/Master/texmf-dist/scripts/lyluatex/lyluatex.lua
+++ b/Master/texmf-dist/scripts/lyluatex/lyluatex.lua
@@ -1,195 +1,1439 @@
+-- luacheck: ignore ly log self luatexbase internalversion font fonts tex token kpse status
local err, warn, info, log = luatexbase.provides_module({
name = "lyluatex",
- version = '0',
- greinternalversion = internalversion,
- date = "2017/12/05",
+ version = '1.0b', --LYLUATEX_VERSION
+ date = "2018/03/12", --LYLUATEX_DATE
description = "Module lyluatex.",
- author = "The Gregorio Project − Jacques Peron <cataclop@hotmail.com>",
- copyright = "2008-2017 - The Gregorio Project",
+ author = "The Gregorio Project − (see Contributors.md)",
+ copyright = "2015-2018 - jperon and others",
license = "MIT",
})
local md5 = require 'md5'
+local lfs = require 'lfs'
+local latex = {}
+local ly = {}
+local obj = {}
+local Score = {}
-LILYPOND = 'lilypond'
-TMP = 'tmp_ly'
-N = 0
+local FILELIST
+local OPTIONS = {}
+local DIM_OPTIONS = {
+ 'extra-bottom-margin',
+ 'extra-top-margin',
+ 'gutter',
+ 'hpadding',
+ 'indent',
+ 'leftgutter',
+ 'line-width',
+ 'max-protrusion',
+ 'max-left-protrusion',
+ 'max-right-protrusion',
+ 'rightgutter',
+ 'paperwidth',
+ 'paperheight',
+ 'voffset'
+}
+local HASHIGNORE = {
+ 'autoindent',
+ 'cleantmp',
+ 'hpadding',
+ 'max-left-protrusion',
+ 'max-right-protrusion',
+ 'print-only',
+ 'valign',
+ 'voffset'
+}
+local MXML_OPTIONS = {
+ 'absolute',
+ 'language',
+ 'lxml',
+ 'no-articulation-directions',
+ 'no-beaming',
+ 'no-page-layout',
+ 'no-rest-positions',
+ 'verbose',
+}
+local TEXINFO_OPTIONS = {'doctitle', 'nogettext', 'texidoc'}
+local TEX_UNITS = {'bp', 'cc', 'cm', 'dd', 'in', 'mm', 'pc', 'pt', 'sp', 'em', 'ex'}
+local LY_HEAD = [[
+%%File header
+\version "<<<version>>>"
+<<<language>>>
+
+<<<preamble>>>
+
+#(define inside-lyluatex #t)
+#(set-global-staff-size <<<staffsize>>>)
+
+\header {
+ copyright = ""
+ tagline = ##f
+}
+\paper{
+ <<<paper>>>
+ two-sided = ##<<<twoside>>>
+ line-width = <<<linewidth>>>\pt
+ <<<indent>>>
+ <<<raggedright>>>
+ <<<fonts>>>
+}
+\layout{
+ <<<staffprops>>>
+}
+
+%%Follows original score
+]]
-function ly_definir_programme(lilypond)
- if lilypond then LILYPOND = lilypond end
+--[[ ========================== Helper functions ========================== ]]
+-- dirty fix as info doesn't work as expected
+local oldinfo = info
+function info(...)
+ print('\n(lyluatex)', string.format(...))
+ oldinfo(...)
+end
+-- debug acts as info if [debug] is specified
+local function debug(...)
+ if Score.debug then info(...) end
end
-function contenuIntegral(contenu)
- local content =""
- for i, Line in ipairs(contenu:explode('\n')) do
- if Line:find("^%s*[^%%]*\\include") then
- local i = io.open(Line:gsub('%s*\\include%s*"(.*)"%s*$', "%1"), 'r')
- if i then
- content = content .. contenuIntegral(i:read('*a'))
- else
- content = content .. Line .. "\n"
- end
- else
- content = content .. Line .. "\n"
- end
+local function contains(table_var, value)
+ for _, v in pairs(table_var) do
+ if v == value then return true
+ elseif v == 'false' and value == false then return true
+ end
end
- return content
end
-function direct_ly(ly, largeur, facteur)
- N = N + 1
- largeur = {['n'] = largeur:match('%d+'), ['u'] = largeur:match('%a+')}
- facteur = calcul_facteur(facteur)
- ly = ly:gsub('\\par ', '\n'):gsub('\\([^%s]*) %-([^%s])', '\\%1-%2')
- local sortie =
- TMP..'/'..string.gsub(md5.sumhexa(contenuIntegral(ly))..'-'..facteur..'-'..largeur.n..largeur.u, '%.', '-')
- if not lfs.isfile(sortie..'-systems.tex') then
- compiler_ly(entete_lilypond(facteur, largeur)..'\n'..ly, sortie, true)
+local function contains_key(table_var, key)
+ for k in pairs(table_var) do
+ if k == key then return true end
end
- retour_tex(sortie, facteur)
end
-function inclure_ly(entree, currfiledir, largeur, facteur, pleinepage)
- largeur = {['n'] = largeur:match('%d+'), ['u'] = largeur:match('%a+')}
- facteur = calcul_facteur(facteur)
- nom = splitext(entree, 'ly')
- entree = currfiledir..nom..'.ly'
- if not lfs.isfile(entree) then entree = kpse.find_file(nom..'.ly') end
- if not lfs.isfile(entree) then err("Le fichier %s.ly n'existe pas.", nom) end
- local i = io.open(entree, 'r')
- ly = i:read('*a')
- i:close()
- local sortie = TMP..'/'..string.gsub(md5.sumhexa(contenuIntegral(ly))..'-'..facteur..'-'..largeur.n..largeur.u..'-', '%.', '-')
- if pleinepage then sortie = sortie..'-pleinepage' end
- if not lfs.isfile(sortie..'-systems.tex') then
- if pleinepage then
- compiler_ly(ly, sortie, false, dirname(entree))
- i = io.open(sortie..'-systems.tex', 'w')
- i:write('\\includepdf[pages=-]{'..sortie..'}')
- i:close()
+local function convert_unit(value)
+ if not value then return 0
+ elseif value == '' then return false
+ elseif value:match('\\') then
+ local n, u = value:match('^%d*%.?%d*'), value:match('%a+')
+ if n == '' then n = 1 end
+ return tonumber(n) * tex.dimen[u] / tex.sp("1pt")
+ else return ('%f'):format(tonumber(value) or tex.sp(value) / tex.sp("1pt"))
+ end
+end
+
+
+local function dirname(str) return str:gsub("(.*/)(.*)", "%1") or '' end
+
+
+local function extract_includepaths(includepaths)
+ includepaths = includepaths:explode(',')
+ local cfd = Score.currfiledir:gsub('^$', './')
+ table.insert(includepaths, 1, cfd)
+ for i, path in ipairs(includepaths) do
+ -- delete initial space (in case someone puts a space after the comma)
+ includepaths[i] = path:gsub('^ ', ''):gsub('^~', os.getenv("HOME"))
+ end
+ return includepaths
+end
+
+
+local fontdata = fonts.hashes.identifiers
+local function fontinfo(id) return fontdata[id] or font.fonts[id] end
+
+
+local function font_default_staffsize()
+ return fontinfo(font.current()).size/39321.6
+end
+
+
+local function locate(file, includepaths, ext)
+ local result
+ for _, d in ipairs(extract_includepaths(includepaths)) do
+ if d:sub(-1) ~= '/' then d = d..'/' end
+ result = d..file
+ if lfs.isfile(result) then break end
+ end
+ if not lfs.isfile(result) and ext and file:match('%.[^%.]+$') ~= ext then return locate(file..ext, includepaths) end
+ if not lfs.isfile(result) then result = kpse.find_file(file) end
+ return result
+end
+
+
+local function max(a, b)
+ a, b = tonumber(a), tonumber(b)
+ if a > b then return a else return b end
+end
+
+
+local function min(a, b)
+ a, b = tonumber(a), tonumber(b)
+ if a < b then return a else return b end
+end
+
+
+local function mkdirs(str)
+ local path = '.'
+ for dir in str:gmatch('([^%/]+)') do
+ path = path .. '/' .. dir
+ lfs.mkdir(path)
+ end
+end
+
+
+local function orderedpairs(t)
+ local key
+ local i = 0
+ local orderedIndex = {}
+ for k in pairs(t) do table.insert(orderedIndex, k) end
+ table.sort(orderedIndex)
+ return function ()
+ i = i + 1
+ key = orderedIndex[i]
+ if key then return key, t[key] end
+ end
+end
+
+
+local function process_options(k, v)
+ if k == '' or k == 'noarg' then return end
+ if not contains_key(OPTIONS, k) then err('Unknown option: '..k) end
+ -- aliases
+ if OPTIONS[k] and OPTIONS[k][2] == ly.is_alias then
+ if OPTIONS[k][1] == v then return
+ else k = OPTIONS[k][1]
+ end
+ end
+ -- boolean
+ if v == 'false' then v = false end
+ -- negation (for example, noindent is the negation of indent)
+ if ly.is_neg(k) then
+ if v ~= nil and v ~= 'default' then
+ k = k:gsub('^no(.*)', '%1')
+ v = not v
+ else return
+ end
+ end
+ return k, v
+end
+
+
+local function range_parse(range, nsystems)
+ local num = tonumber(range)
+ if num then return {num} end
+ -- if nsystems is set, we have insert=systems
+ if nsystems ~= 0 and range:sub(-1) == '-' then range = range..nsystems end
+ if not range:match('^%d+%s*-%s*%d*$') then
+ warn([[
+Invalid value '%s' for item
+in list of page ranges. Possible entries:
+- Single number
+- Range (M-N, N-M or N-)
+This item will be skipped!
+]],
+ range
+ )
+ return
+ end
+ local result = {}
+ local from, to = tonumber(range:match('^%d+')), tonumber(range:match('%d+$'))
+ if to then
+ local dir
+ if from <= to then dir = 1 else dir = -1 end
+ for i = from, to, dir do table.insert(result, i) end
+ return result
+ else return {range} -- N- with insert=fullpage
+ end
+end
+
+
+local function readlinematching(s, f)
+ if f then
+ local result = ''
+ while result and not result:find(s) do result = f:read() end
+ f:close()
+ return result
+ end
+end
+
+
+local function set_lyscore(score)
+ ly.score = score
+ ly.score.nsystems = ly.score:count_systems()
+ if score.insert ~= 'fullpage' then -- systems and inline
+ local hoffset = ly.score.protrusion or 0
+ if hoffset == '' then hoffset = 0 end
+ ly.score.hoffset = hoffset..'pt'
+ for s = 1, ly.score.nsystems do
+ table.insert(ly.score, ly.score.output..'-'..s)
+ end
+ else ly.score[1] = ly.score.output
+ end
+end
+
+
+local function splitext(str, ext) return str:match('(.*)%.'..ext..'$') or str end
+
+
+--[[ ================ Bounding box calculations =========================== ]]
+
+local bbox = {}
+function bbox.get(filename, line_width)
+ return bbox.read(filename) or bbox.parse(filename, line_width)
+end
+
+function bbox.parse(filename, line_width)
+ -- get BoundingBox from EPS file
+ local bbline = readlinematching('^%%%%BoundingBox', io.open(filename..'.eps', 'r'))
+ if not bbline then return end
+ local x_1, y_1, x_2, y_2 = bbline:match('(%--%d+)%s(%--%d+)%s(%--%d+)%s(%--%d+)')
+ -- try to get HiResBoundingBox from PDF (if 'gs' works)
+ bbline = readlinematching(
+ '^%%%%HiResBoundingBox',
+ io.popen('gs -sDEVICE=bbox -q -dBATCH -dNOPAUSE '..filename..'.pdf 2>&1', 'r')
+ )
+ if bbline then
+ local pbb = bbline:gmatch('(%d+%.%d+)')
+ -- The HiRes BoundingBox retrieved from the PDF differs from the
+ -- BoundingBox present in the EPS file. In the PDF (0|0) is the
+ -- Lower Left corner while in the EPS (0|0) represents the top
+ -- edge at the start of the staff symbol.
+ -- Therefore we shift the HiRes results by the (truncated)
+ -- points of the EPS bounding box.
+ x_1, y_1, x_2, y_2 = pbb() + x_1, pbb() + y_1, pbb() + x_1, pbb() + y_1
+ else warn([[gs couldn't be launched; there could be rounding errors.]])
+ end
+ local bb = {
+ ['protrusion'] = -convert_unit(("%fbp"):format(x_1)),
+ ['r_protrusion'] = convert_unit(("%fbp"):format(x_2)) - line_width,
+ ['width'] = convert_unit(("%fbp"):format(x_2)),
+ ['height'] = convert_unit(("%fbp"):format(y_2)) - convert_unit(("%fbp"):format(y_1))
+ }
+ obj.serialize(bb, filename..'.bbox')
+ return bb
+end
+
+function bbox.read(f) return obj.deserialize(f..'.bbox') end
+
+
+--[[ =============== Functions that output LaTeX code ===================== ]]
+
+function latex.filename(printfilename, insert, input_file)
+ if printfilename and input_file then
+ if insert ~= 'systems' then
+ warn('`printfilename` only works with `insert=systems`')
else
- compiler_ly(entete_lilypond(facteur, largeur)..'\n'..ly, sortie, true, dirname(entree))
+ local filename = input_file:gsub("(.*/)(.*)", "\\lyFilename{%2}\\par")
+ tex.sprint(filename)
+ end
+ end
+end
+
+function latex.fullpagestyle(style, ppn)
+ local function texoutput(s) tex.sprint('\\includepdfset{pagecommand='..s..'}%') end
+ if style == '' then
+ if ppn then texoutput('\\thispagestyle{empty}')
+ else texoutput('')
end
+ else texoutput('\\thispagestyle{'..style..'}')
end
- retour_tex(sortie, facteur)
end
+function latex.includeinline(pdfname, height, valign, hpadding, voffset)
+ local v_base
+ if valign == 'bottom' then v_base = 0
+ elseif valign == 'top' then v_base = convert_unit('1em') - height
+ else v_base = (convert_unit('1em') - height) / 2
+ end
+ tex.sprint(
+ string.format(
+ [[\hspace{%fpt}\raisebox{%fpt}{\includegraphics{%s-1.pdf}}\hspace{%fpt}]],
+ hpadding, v_base + voffset, pdfname, hpadding
+ )
+ )
+end
-function compiler_ly(ly, sortie, eps, include)
- mkdirs(dirname(sortie))
- local commande = LILYPOND.." "..
- "-dno-point-and-click "..
- "-djob-count=2 "..
- "-ddelete-intermediate-files "
- if eps then commande = commande.."-dbackend=eps " end
- if include then commande = commande.."-I '"..lfs.currentdir().."/"..include.."' " end
- commande = commande.."-o "..sortie.." -"
- local p = io.popen(commande, 'w')
- p:write(ly)
- p:close()
+function latex.includepdf(pdfname, range, papersize)
+ local noautoscale = ''
+ if papersize then noautoscale = 'noautoscale' end
+ tex.sprint(string.format(
+ [[\includepdf[pages={%s},%s]{%s}]],
+ table.concat(range, ','), noautoscale, pdfname
+ ))
+end
+
+function latex.includesystems(filename, range, protrusion, gutter, staffsize, indent_offset)
+ local h_offset = protrusion + indent_offset
+ local texoutput = '\\ifx\\preLilyPondExample\\undefined\\else\\preLilyPondExample\\fi\n'
+ texoutput = texoutput..'\\par\n'
+ for index, system in pairs(range) do
+ if not lfs.isfile(filename..'-'..system..'.pdf') then break end
+ texoutput = texoutput..
+ string.format([[
+\noindent\hspace*{%fpt}\includegraphics{%s}%%
+]],
+ h_offset + gutter, filename..'-'..system
+ )
+ if index < #range then
+ texoutput = texoutput..
+ string.format([[
+\ifx\betweenLilyPondSystem\undefined\par\vspace{%fpt plus %fpt minus %fpt}%%
+\else\betweenLilyPondSystem{%s}\fi%%
+]],
+ staffsize / 4, staffsize / 12, staffsize / 16,
+ index
+ )
+ end
+ end
+ texoutput = texoutput..'\n\\ifx\\postLilyPondExample\\undefined\\else\\postLilyPondExample\\fi'
+ tex.sprint(texoutput:explode('\n'))
end
+function latex.label(label, labelprefix)
+ if label then tex.sprint('\\label{'..labelprefix..label..'}%%') end
+end
-function entete_lilypond(facteur, largeur)
- return string.format(
-[[%%En-tête
-\version "2.18.2"
-#(define default-toplevel-book-handler
- print-book-with-defaults-as-systems )
-#(define toplevel-book-handler
- (lambda ( . rest)
- (set! output-empty-score-list #f)
- (apply print-book-with-defaults rest)))
+ly.verbenv = {[[\begin{verbatim}]], [[\end{verbatim}]]}
+function latex.verbatim(verbatim, ly_code, intertext, version)
+ if verbatim then
+ if version then tex.sprint('\\lyVersion{'..version..'}') end
+ local content = table.concat(ly_code:explode('\n'), '\n'):gsub(
+ '.*%%%s*begin verbatim', ''):gsub(
+ '%%%s*end verbatim.*', '')
+ --[[ We unfortunately need an external file,
+ as verbatim environments are quite special. ]]
+ local fname = ly.get_option('tmpdir')..'/verb.tex'
+ local f = io.open(fname, 'w')
+ f:write(
+ ly.verbenv[1]..'\n'..
+ content..
+ '\n'..ly.verbenv[2]:gsub([[\end {]], [[\end{]])..'\n'
+ )
+ f:close()
+ tex.sprint('\\input{'..fname..'}')
+ if intertext then tex.sprint('\\lyIntertext{'..intertext..'}') end
+ end
+end
-#(define toplevel-music-handler
- (lambda ( . rest)
- (apply collect-music-for-book rest)))
-#(define toplevel-score-handler
- (lambda ( . rest)
- (apply collect-scores-for-book rest)))
+--[[ =============== Functions that operate on objects ==================== ]]
-#(define toplevel-text-handler
- (lambda ( . rest)
- (apply collect-scores-for-book rest)))
+function obj.deserialize(f) if lfs.isfile(f) then return dofile(f) end end
+function obj.serialize(o, f)
+ f = io.open(f, 'w')
+ if not f then return end
+ f:write('local o = '..obj.str(o)..'\nreturn o')
+ f:close()
+end
-#(set-global-staff-size %s)
+function obj.str(o)
+ if type(o) == "number" then return o
+ elseif type(o) == "string" then return string.format("%q", o)
+ elseif type(o) == "table" then
+ local r = '{\n'
+ for k, v in pairs(o) do r = r.." ["..obj.str(k).."] = "..obj.str(v)..",\n" end
+ return r.."}\n"
+ else error("cannot convert " .. type(o).." to string")
+ end
+end
-%%Paramètres de la partition
-\paper{
- indent = 0\mm
- line-width = %s\%s
-}
+--[[ =============================== Classes =============================== ]]
+
+-- Score class
+function Score:new(ly_code, options, input_file)
+ local o = options or {}
+ setmetatable(o, self)
+ self.__index = self
+ o.output_names = {}
+ o.input_file = input_file
+ o.ly_code = ly_code
+ return o
+end
+
+function Score:bbox(system)
+ if system then
+ if not self.bboxes then
+ self.bboxes = {}
+ for i = 1, self:count_systems() do
+ table.insert(self.bboxes, bbox.get(self.output..'-'..i, self['line-width']))
+ end
+ end
+ return self.bboxes[system]
+ else
+ if not self.bbox then self.bbox = bbox.get(self.output, self['line-width']) end
+ return self.bbox
+ end
+end
+
+function Score:calc_properties()
+ self:calc_staff_properties()
+ -- fragment and relative
+ if self.relative and not self.fragment then
+ -- local option takes precedence over global option
+ if Score.fragment then self.relative = false end
+ end
+ if self.relative then
+ self.fragment = 'true' -- yes, here we need a string, not a bool
+ if self.relative == '' then self.relative = 1
+ else self.relative = tonumber(self.relative)
+ end
+ end
+ if self.fragment == '' then
+ -- by default, included files shouldn't be fragments
+ if ly.state == 'file' then self.fragment = false end
+ end
+ -- default insertion mode
+ if self.insert == '' then
+ if ly.state == 'cmd' then self.insert = 'inline'
+ else self.insert = 'systems'
+ end
+ end
+ -- staffsize
+ self.staffsize = tonumber(self.staffsize)
+ if self.staffsize == 0 then self.staffsize = font_default_staffsize() end
+ if self.insert == 'inline' or self.insert == 'bare-inline' then
+ local inline_staffsize = tonumber(self['inline-staffsize'])
+ if inline_staffsize == 0 then inline_staffsize = self.staffsize / 1.5 end
+ self.staffsize = inline_staffsize
+ end
+ -- dimensions that can be given by LaTeX
+ for _, dimension in pairs(DIM_OPTIONS) do
+ self[dimension] = convert_unit(self[dimension])
+ end
+ self['max-left-protrusion'] = self['max-left-protrusion'] or self['max-protrusion']
+ self['max-right-protrusion'] = self['max-right-protrusion'] or self['max-protrusion']
+ if self.quote then
+ self.leftgutter = self.leftgutter or self.gutter
+ self.rightgutter = self.rightgutter or self.gutter
+ self['line-width'] = self['line-width'] - self.leftgutter - self.rightgutter
+ else
+ self.leftgutter = 0
+ self.rightgutter = 0
+ end
+ -- store for comparing protrusion against
+ self.original_lw = self['line-width']
+ self.original_indent = self.indent
+ -- explicit indent disables autoindent
+ if self.indent then self.autoindent = false end
+ -- score fonts
+ if self['current-font-as-main'] then self.rmfamily = self['current-font'] end
+ -- LilyPond version
+ if self.addversion then self.addversion = self:lilypond_version(true) end
+ -- temporary file name
+ self.output = self:output_filename()
+end
+
+function Score:calc_range()
+ local nsystems = self:count_systems(true)
+ if self['print-only'] == '' then
+ if nsystems == 0 then self['print-only'] = '1-'
+ else self['print-only'] = '1-'..nsystems
+ end
+ end
+ local result = {}
+ if tonumber(self['print-only']) then result = {self['print-only']}
+ else
+ for _, r in pairs(self['print-only']:explode(',')) do
+ local range = range_parse(r:gsub('^%s', ''):gsub('%s$', ''), nsystems)
+ if range then
+ for _, v in pairs(range) do table.insert(result, v) end
+ end
+ end
+ end
+ return result
+end
+
+function Score:calc_staff_properties()
+ -- preset for bare notation symbols in inline images
+ if self.insert == 'bare-inline' then self.nostaff = 'true' end
+ -- handle meta properties
+ if self.notime then
+ self.notimesig = 'true'
+ self.notiming = 'true'
+ end
+ if self.nostaff then
+ self.nostaffsymbol = 'true'
+ self.notimesig = 'true'
+ -- do *not* suppress timing
+ self.noclef = 'true'
+ end
+end
+
+function Score:check_compilation()
+ local debug_msg, doc_debug_msg
+ if self.debug then
+ debug_msg = string.format([[
+Please check the log file
+and the generated LilyPond code in
+%s
+%s
+]],
+ self.output..'.log', self.output..'.ly'
+ )
+ doc_debug_msg = [[
+A log file and a LilyPond file have been written.\\
+See log for details.]]
+ else
+ debug_msg = [[
+If you need more information
+than the above message,
+please retry with option debug=true.
+]]
+ doc_debug_msg = "Re-run with \\texttt{debug} option to investigate."
+ end
+ if self.fragment then
+ local frag_msg = '\n'..[[
+As the input code has been automatically wrapped
+with a music expression, you may try repeating
+with the `nofragment` option.]]
+ debug_msg = debug_msg..frag_msg
+ doc_debug_msg = doc_debug_msg..frag_msg
+ end
+
+ if self:is_compiled() then
+ if self.lilypond_error then
+ warn([[
-%%Partition originale
+LilyPond reported a failed compilation but
+produced a score. %s
]],
-facteur,
-largeur.n, largeur.u
-)
+ debug_msg
+ )
+ end
+ -- we do have *a* score (although labeled as failed by LilyPond)
+ return true
+ else
+ self:clean_failed_compilation()
+ if self.showfailed then
+ tex.sprint(string.format([[
+\begin{quote}
+\minibox[frame]{LilyPond failed to compile a score.\\
+%s}
+\end{quote}
+
+]],
+ doc_debug_msg
+ ))
+ warn([[
+
+LilyPond failed to compile the score.
+%s
+]],
+ debug_msg
+ )
+ else
+ err([[
+
+LilyPond failed to compile the score.
+%s
+]],
+ debug_msg
+ )
+ end
+ -- We don't have any compiled score
+ return false
+ end
end
+function Score:check_indent(lp)
+ local nsystems = self:count_systems()
-function calcul_facteur(facteur)
- if facteur == 0 then facteur = fontinfo(font.current()).size/39321.6 end
- return facteur
+ local function handle_autoindent()
+ self.indent_offset = 0
+ if lp.shorten > 0 then
+ if not self.indent or self.indent == 0 then
+ self.indent = lp.overflow_left
+ lp.shorten = max(lp.shorten - lp.overflow_left, 0)
+ else
+ self.indent = max(self.indent - lp.overflow_left, 0)
+ end
+ lp.changed_indent = true
+ end
+ end
+
+ local function handle_indent()
+ if not self.indent_offset then
+ -- First step: deactivate indent
+ self.indent_offset = 0
+ if self:count_systems() > 1 then
+ -- only recompile if the *original* score has more than 1 system
+ self.indent = 0
+ lp.changed_indent = true
+ end
+ info('Deactivate indentation because of system selection')
+ elseif lp.shorten > 0 then
+ self.indent = 0
+ self.autoindent = true
+ -- lp.changed_indent = true
+ handle_autoindent()
+ info('Deactivated indent causes protrusion.')
+ end
+ end
+
+ local function regular_score()
+ -- score without any indent or with the first system
+ -- printed regularly, with others following.
+ return not self.original_indent or
+ nsystems > 1 and #self.range > 1 and self.range[1] == 1
+ end
+
+ local function simple_noindent()
+ -- score with indent and only one system
+ return self.original_indent and nsystems == 1
+ end
+
+ if simple_noindent() then
+ self.indent_offset = -self.indent
+ warn('Deactivate indent for single-system score.')
+ elseif self.autoindent then handle_autoindent()
+ elseif regular_score() then self.indent_offset = 0
+ else handle_indent()
+ end
end
+function Score:check_properties()
+ local unexpected = false
+ for k, _ in orderedpairs(OPTIONS) do
+ if self[k] == 'default' then
+ self[k] = OPTIONS[k][1] or nil
+ unexpected = not self[k]
+ end
+ if not contains(OPTIONS[k], self[k]) and OPTIONS[k][2] then
+ if type(OPTIONS[k][2]) == 'function' then OPTIONS[k][2](k, self[k])
+ else unexpected = true
+ end
+ end
+ if unexpected then
+ err([[
+Unexpected value "%s" for option %s:
+authorized values are "%s"
+]],
+ self[k], k, table.concat(OPTIONS[k], ', ')
+ )
+ end
+ end
+ for _, k in pairs(TEXINFO_OPTIONS) do
+ if self[k] then info([[Option %s is specific to Texinfo: ignoring it.]], k) end
+ end
+ if self.fragment then
+ if (self.input_file or
+ self.ly_code:find([[\book]]) or
+ self.ly_code:find([[\header]]) or
+ self.ly_code:find([[\layout]]) or
+ self.ly_code:find([[\paper]]) or
+ self.ly_code:find([[\score]])
+ ) then
+ warn([[
+Found something incompatible with `fragment`
+(or `relative`). Setting them to false.
+]]
+ )
+ self.fragment = false
+ self.relative = false
+ end
+ end
+end
-function retour_tex(sortie, facteur)
- local i = io.open(sortie..'-systems.tex', 'r')
- local contenu = i:read("*all")
- i:close()
- local texoutput, nbre = contenu:gsub([[\includegraphics{]],
- [[\includegraphics{]]..dirname(sortie))
- tex.print(([[\noindent]]..texoutput):explode('\n'))
+function Score:check_protrusion(bbox_func)
+ self.range = self:calc_range()
+ if self.insert ~= 'systems' then return self:is_compiled() end
+ local bb = bbox_func(self.output, self['line-width'])
+ if not bb then return end
+ -- line_props lp
+ local lp = {}
+ -- Determine offset due to left protrusion
+ lp.overflow_left = max(bb.protrusion - math.floor(self['max-left-protrusion']), 0)
+ self.protrusion_left = lp.overflow_left - bb.protrusion
+ -- Determine further line properties
+ lp.stave_extent = lp.overflow_left + min(self['line-width'], bb.width)
+ lp.available = self.original_lw + self['max-right-protrusion']
+ lp.total_extent = lp.stave_extent + bb.r_protrusion
+ -- Check if stafflines protrude into the right margin after offsetting
+ -- Note: we can't *reliably* determine this with ragged one-system scores,
+ -- possibly resulting in unnecessarily short lines when right protrusion is
+ -- present
+ lp.stave_overflow_right = max(lp.stave_extent - self.original_lw, 0)
+ -- Check if image as a whole protrudes over max-right-protrusion
+ lp.overflow_right = max(lp.total_extent - lp.available, 0)
+ lp.shorten = max(lp.stave_overflow_right, lp.overflow_right)
+ lp.changed_indent = false
+ self:check_indent(lp, bb)
+ if lp.shorten > 0 or lp.changed_indent then
+ self['line-width'] = self['line-width'] - lp.shorten
+ -- recalculate hash to reflect the reduced line-width
+ if lp.shorten > 0 then
+ info('Compiled score exceeds protrusion limit(s)')
+ end
+ if lp.changed_indent then info([[Adjusted indent.]]) end
+ self.output = self:output_filename()
+ warn('Recompile or reuse cached score')
+ return
+ else return true
+ end
+end
+
+function Score:clean_failed_compilation()
+ for file in lfs.dir(self.tmpdir) do
+ local filename = self.tmpdir..'/'..file
+ if filename:find(self.output) then os.remove(filename) end
+ end
+end
+
+function Score:content()
+ local n = ''
+ if self.relative then
+ self.fragment = 'true' -- in case it would serve later
+ if self.relative < 0 then
+ for _ = -1, self.relative, -1 do n = n..',' end
+ elseif self.relative > 0 then
+ for _ = 1, self.relative do n = n.."'" end
+ end
+ return string.format([[\relative c%s {%s}]], n, self.ly_code)
+ elseif self.fragment then return [[{]]..self.ly_code..[[}]]
+ else return self.ly_code
+ end
+end
+
+function Score:count_systems(force)
+ if force or not self.system_count then
+ local f = io.open(self.output..'-systems.count', 'r')
+ if f then
+ self.system_count = tonumber(f:read('*all'))
+ f:close()
+ else self.system_count = 0
+ end
+ end
+ return self.system_count
+end
+
+function Score:delete_intermediate_files()
+ for _, filename in pairs(self.output_names) do
+ if self.insert == 'fullpage' then os.remove(filename..'.ps')
+ else
+ for i = 1, self:count_systems() do os.remove(filename..'-'..i..'.eps') end
+ os.remove(filename..'-systems.tex')
+ os.remove(filename..'-systems.texi')
+ os.remove(filename..'.eps')
+ os.remove(filename..'.pdf')
+ end
+ end
+end
+
+function Score:flatten_content(ly_code)
+ --[[ Produce a flattend string from the original content,
+ including referenced files (if they can be opened.
+ Other files (from LilyPond's include path) are considered
+ irrelevant for the purpose of a hashsum.) --]]
+ local f
+ local includepaths = self.includepaths
+ if self.input_file then includepaths = self.includepaths..','..dirname(self.input_file) end
+ for iline in ly_code:gmatch('\\include%s*"[^"]*"') do
+ f = io.open(locate(iline:match('\\include%s*"([^"]*)"'), includepaths, '.ly') or '')
+ if f then
+ ly_code = ly_code:gsub(iline, self:flatten_content(f:read('*a')))
+ f:close()
+ end
+ end
+ return ly_code
+end
+
+function Score:header()
+ local header = LY_HEAD
+ for element in LY_HEAD:gmatch('<<<(%w+)>>>') do
+ header = header:gsub('<<<'..element..'>>>', self['ly_'..element](self) or '')
+ end
+ return header
+end
+
+function Score:is_compiled()
+ return lfs.isfile(self.output..'.pdf') or self:count_systems(true) ~= 0
end
+function Score:is_odd_page() return tex.count['c@page'] % 2 == 1 end
+
+function Score:lilypond_cmd(ly_code)
+ local input, mode = '-s -', 'w'
+ if self.debug then
+ local f = io.open(self.output..'.ly', 'w')
+ f:write(ly_code)
+ f:close()
+ input = self.output..".ly 2>&1"
+ mode = 'r'
+ end
+ local cmd = self.program.." "..
+ "-dno-point-and-click "..
+ "-djob-count=2 "..
+ "-dno-delete-intermediate-files "
+ if self.input_file then
+ cmd = cmd..'-I "'..dirname(self.input_file):gsub('%./', lfs.currentdir()..'/')..'" '
+ end
+ for _, dir in ipairs(extract_includepaths(self.includepaths)) do
+ cmd = cmd..'-I "'..dir:gsub('^%./', lfs.currentdir()..'/')..'" '
+ end
+ cmd = cmd..'-o "'..self.output..'" '..input
+ debug("Command:\n"..cmd)
+ return cmd, mode
+end
-function dirname(str)
- if str:match(".-/.-") then
- local name = string.gsub(str, "(.*/)(.*)", "%1")
- return name
+function Score:lilypond_version(number)
+ local result = readlinematching('GNU LilyPond', io.popen(self.program..' --version', 'r'))
+ if result then
+ if number then return result:match('%d+%.%d+%.?%d*')
+ else
+ info(
+ "Compiling score %s with LilyPond executable '%s'.",
+ self.output, self.program
+ )
+ debug(result)
+ end
else
- return ''
+ err([[
+LilyPond could not be started.
+Please check that LuaLaTeX is started with the
+--shell-escape option, and that 'program'
+points to a valid LilyPond executable.
+]]
+ )
end
end
+function Score:ly_fonts()
+ if self['pass-fonts'] then
+ return string.format([[
+#(define fonts
+ (make-pango-font-tree "%s"
+ "%s"
+ "%s"
+ (/ staff-height pt 20)))
+]],
+ self.rmfamily,
+ self.sffamily,
+ self.ttfamily
+ )
+ end
+end
+
+function Score:ly_indent()
+ if not (self.indent == false and self.insert == 'fullpage') then
+ return [[indent = ]]..(self.indent or 0)..[[\pt]]
+ end
+end
+
+function Score:ly_language()
+ if self.language then return '\\language "'..self.language..'"' end
+end
+
+function Score:ly_linewidth() return self['line-width'] end
+
+function Score:ly_staffsize() return self.staffsize end
-function splitext(str, ext)
- if str:match(".-%..-") then
- local name = string.gsub(str, "(.*)(%." .. ext .. ")", "%1")
- return name
+function Score:ly_margins()
+ local tex_top = self['extra-top-margin'] + self:tex_margin_top()
+ local tex_bottom = self['extra-bottom-margin'] + self:tex_margin_bottom()
+ if self.fullpagealign == 'crop' then
+ return string.format([[
+top-margin = %s\pt
+bottom-margin = %s\pt
+inner-margin = %s\pt
+left-margin = %s\pt
+]],
+ tex_top, tex_bottom, self:tex_margin_inner(), self:tex_margin_left()
+ )
+ elseif self.fullpagealign == 'staffline' then
+ local top_distance = 4 * tex_top / self.staffsize + 2
+ local bottom_distance = 4 * tex_bottom / self.staffsize + 2
+ return string.format([[
+top-margin = 0\pt
+bottom-margin = 0\pt
+inner-margin = %s\pt
+left-margin = %s\pt
+top-system-spacing =
+ #'((basic-distance . %s)
+ (minimum-distance . %s)
+ (padding . 0)
+ (stretchability . 0))
+top-markup-spacing =
+ #'((basic-distance . %s)
+ (minimum-distance . %s)
+ (padding . 0)
+ (stretchability . 0))
+last-bottom-spacing =
+ #'((basic-distance . %s)
+ (minimum-distance . %s)
+ (padding . 0)
+ (stretchability . 0))
+]],
+ self:tex_margin_inner(),
+ self:tex_margin_left(),
+ top_distance,
+ top_distance,
+ top_distance,
+ top_distance,
+ bottom_distance,
+ bottom_distance
+ )
else
- return str
+ err([[
+Invalid argument for option 'fullpagealign'.
+Allowed: 'crop', 'staffline'.
+Given: %s
+]],
+ self.fullpagealign
+ )
end
end
+function Score:ly_paper()
+ local papersize = '#(set-paper-size "'..(self.papersize or 'lyluatexfmt')..'")'
+ if self.insert == 'fullpage' then
+ local ppn = 'f'
+ if self['print-page-number'] then ppn = 't' end
+ return string.format([[
+%s
+print-page-number = ##%s
+print-first-page-number = ##t
+first-page-number = %s
+%s]],
+ papersize, ppn, tex.count['c@page'], self:ly_margins()
+ )
+ elseif self.papersize then return papersize
+ end
+end
-function mkdirs(str)
- path = '.'
- for dir in string.gmatch(str, '([^%/]+)') do
- path = path .. '/' .. dir
- lfs.mkdir(path)
+function Score:ly_preamble()
+ if self.insert == 'fullpage' then
+ return string.format(
+ [[#(set! paper-alist (cons '("lyluatexfmt" . (cons (* %s pt) (* %s pt))) paper-alist))]],
+ self.paperwidth, self.paperheight
+ )
+ else return [[\include "lilypond-book-preamble.ly"]]
+ end
+end
+
+function Score:ly_raggedright()
+ if not self['ragged-right'] == 'default' then
+ if self['ragged-right'] then return 'ragged-right = ##t'
+ else return 'ragged-right = ##f'
+ end
end
end
+function Score:ly_staffprops()
+ local clef, timing, timesig, staff = '', '', '', ''
+ if self.noclef then clef = [[\context { \Staff \remove "Clef_engraver" }]] end
+ if self.notiming then timing = [[\context { \Score timing = ##f }]] end
+ if self.notimesig then timesig = [[\context { \Staff \remove "Time_signature_engraver" }]] end
+ if self.nostaffsymbol then staff = [[\context { \Staff \remove "Staff_symbol_engraver" }]] end
+ return string.format('%s\n%s\n%s\n%s', clef, timing, timesig, staff)
+end
+
+function Score:ly_twoside() if self.twoside then return 't' else return 'f' end end
-local fontdata = fonts.hashes.identifiers
-function fontinfo(id)
- local f = fontdata[id]
- if f then
- return f
+function Score:ly_version() return self['ly-version'] end
+
+function Score:optimize_pdf()
+ if not self['optimize-pdf'] then return end
+ local pdf2ps, ps2pdf, path
+ for file in lfs.dir(self.tmpdir) do
+ path = self.tmpdir..'/'..file
+ if path:match(self.output) and path:sub(-4) == '.pdf' then
+ pdf2ps = io.popen(
+ 'gs -q -sDEVICE=ps2write -sOutputFile=- -dNOPAUSE '..path..' -c quit',
+ 'r'
+ )
+ ps2pdf = io.popen(
+ 'gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile='..path..'-gs -',
+ 'w'
+ )
+ if pdf2ps then
+ ps2pdf:write(pdf2ps:read('*a'))
+ pdf2ps:close()
+ ps2pdf:close()
+ os.rename(path..'-gs', path)
+ else
+ warn(
+ [[You have asked for pdf optimization, but gs wasn't found.]]
+ )
+ end
+ end
+ end
+end
+
+function Score:output_filename()
+ local properties = ''
+ for k, _ in orderedpairs(OPTIONS) do
+ if (not contains(HASHIGNORE, k)) and self[k] and type(self[k]) ~= 'function' then
+ properties = properties..'\n'..k..'\t'..self[k]
+ end
+ end
+ if self.insert == 'fullpage' then
+ properties = properties..
+ self:tex_margin_top()..self:tex_margin_bottom()..
+ self:tex_margin_left()..self:tex_margin_right()
+ end
+ local filename = md5.sumhexa(self:flatten_content(self.ly_code)..properties)
+ return self.tmpdir..'/'..filename
+end
+
+function Score:process()
+ self:check_properties()
+ self:calc_properties()
+ -- with bbox.read check_ptrotrusion will only execute with
+ -- a prior compilation, otherwise it will be ignored
+ local do_compile = not self:check_protrusion(bbox.read)
+ if do_compile then
+ repeat
+ self:run_lilypond(self:header()..self:content())
+ if self:is_compiled() then table.insert(self.output_names, self.output)
+ else
+ self:clean_failed_compilation()
+ break
+ end
+ until self:check_protrusion(bbox.get)
+ self:optimize_pdf()
+ else table.insert(self.output_names, self.output)
+ end
+ set_lyscore(self)
+ if not self['raw-pdf'] then self:write_latex(do_compile) end
+ self:write_to_filelist()
+ if not self.debug then self:delete_intermediate_files() end
+end
+
+function Score:run_lilypond(ly_code)
+ if self:is_compiled() then return end
+ mkdirs(dirname(self.output))
+ self:lilypond_version()
+ local p = io.popen(self:lilypond_cmd(ly_code))
+ if self.debug then
+ local f = io.open(self.output..".log", 'w')
+ f:write(p:read('*a'))
+ f:close()
+ else p:write(ly_code)
+ end
+ self.lilypond_error = not p:close()
+end
+
+function Score:tex_margin_bottom()
+ self._tex_margin_bottom = self._tex_margin_bottom or
+ convert_unit(tex.dimen.paperheight..'sp')
+ - self:tex_margin_top()
+ - convert_unit(tex.dimen.textheight..'sp')
+ return self._tex_margin_bottom
+end
+
+function Score:tex_margin_inner()
+ self._tex_margin_inner = self._tex_margin_inner or
+ convert_unit((
+ tex.sp('1in') + tex.dimen.oddsidemargin + tex.dimen.hoffset
+ )..'sp')
+ return self._tex_margin_inner
+end
+
+function Score:tex_margin_outer()
+ self._tex_margin_outer = self._tex_margin_outer or
+ convert_unit((tex.dimen.paperwidth - tex.dimen.textwidth)..'sp')
+ - self:tex_margin_inner()
+ return self._tex_margin_outer
+end
+
+function Score:tex_margin_left()
+ if self:is_odd_page() then return self:tex_margin_inner()
+ else return self:tex_margin_outer()
+ end
+end
+
+function Score:tex_margin_right()
+ if self:is_odd_page() then return self:tex_margin_outer()
+ else return self:tex_margin_inner()
+ end
+end
+
+function Score:tex_margin_top()
+ self._tex_margin_top = self._tex_margin_top or
+ convert_unit((
+ tex.sp('1in') + tex.dimen.voffset + tex.dimen.topmargin
+ + tex.dimen.headheight + tex.dimen.headsep
+ )..'sp')
+ return self._tex_margin_top
+end
+
+function Score:write_latex(do_compile)
+ latex.filename(self.printfilename, self.insert, self.input_file)
+ latex.verbatim(self.verbatim, self.ly_code, self.intertext, self.addversion)
+ if do_compile and not self:check_compilation() then return end
+ --[[ Now we know there is a proper score --]]
+ latex.fullpagestyle(self.fullpagestyle, self['print-page-number'])
+ latex.label(self.label, self.labelprefix)
+ if self.insert == 'fullpage' then
+ latex.includepdf(self.output, self.range, self.papersize)
+ elseif self.insert == 'systems' then
+ latex.includesystems(
+ self.output, self.range, self.protrusion_left,
+ self.leftgutter, self.staffsize, self.indent_offset
+ )
+ else -- inline
+ if self:count_systems() > 1 then
+ warn([[
+Score with more than one system included inline.
+This will probably cause bad output.]]
+ )
+ end
+ latex.includeinline(
+ self.output, self:bbox(1).height, self.valign, self.hpadding, self.voffset
+ )
+ end
+end
+
+function Score:write_to_filelist()
+ local f = io.open(FILELIST, 'a')
+ for _, file in pairs(self.output_names) do
+ local _, filename = file:match('(./+)(.*)')
+ f:write(filename, '\t', self.input_file or '', '\t', self.label or '', '\n')
+ end
+ f:close()
+end
+
+
+--[[ ========================== Public functions ========================== ]]
+
+ly.score_content = {}
+function ly.buffenv_begin()
+
+ function ly.buffenv(line)
+ table.insert(ly.score_content, line)
+ if line:find([[\end{%w+}]]) then return end
+ return ''
+ end
+
+ ly.score_content = {}
+ luatexbase.add_to_callback('process_input_buffer', ly.buffenv, 'readline')
+end
+
+
+function ly.buffenv_end()
+ luatexbase.remove_from_callback('process_input_buffer', 'readline')
+ table.remove(ly.score_content)
+end
+
+
+function ly.clean_tmp_dir()
+ local hash, file_is_used
+ local hash_list = {}
+ for file in lfs.dir(Score.tmpdir) do
+ if file:sub(-5, -1) == '.list' then
+ local i = io.open(Score.tmpdir..'/'..file)
+ for _, line in ipairs(i:read('*a'):explode('\n')) do
+ hash = line:explode('\t')[1]
+ if hash ~= '' then table.insert(hash_list, hash) end
+ end
+ i:close()
+ end
+ end
+ for file in lfs.dir(Score.tmpdir) do
+ if file ~= '.' and file ~= '..' and file:sub(-5, -1) ~= '.list' then
+ for _, lhash in ipairs(hash_list) do
+ file_is_used = file:find(lhash)
+ if file_is_used then break end
+ end
+ if not file_is_used then os.remove(Score.tmpdir..'/'..file) end
+ end
+ end
+end
+
+
+function ly.conclusion_text()
+ info([[
+Output written on %s.pdf.
+Transcript written on %s.log.
+]],
+ tex.jobname, tex.jobname
+ )
+end
+
+
+function ly.declare_package_options(options)
+ OPTIONS = options
+ local exopt = ''
+ for k, v in pairs(options) do
+ tex.sprint(string.format([[
+\DeclareOptionX{%s}{\directlua{
+ ly.set_property('%s', '\luatexluaescapestring{#1}')
+}}%%
+]],
+ k, k
+ ))
+ exopt = exopt..k..'='..(v[1] or '')..','
+ end
+ tex.sprint([[\ExecuteOptionsX{]]..exopt..[[}%%]], [[\ProcessOptionsX]])
+ mkdirs(options.tmpdir[1])
+ FILELIST = options.tmpdir[1]..'/'..splitext(status.log_name, 'log')..'.list'
+ os.remove(FILELIST)
+end
+
+
+function ly.env_begin(opts)
+ ly.state = 'env'
+ ly.env_no_args = opts == 'noarg'
+ if ly.env_no_args then tex.sprint(40, [[\ly@compilely]])
+ else tex.sprint(40, [[\ly@bufferenv]])
+ end
+end
+
+
+function ly.env_end()
+ if ly.env_no_args then tex.sprint(40, [[\endly@compilely]])
+ else tex.sprint(40, [[\endly@bufferenv]])
+ end
+end
+
+
+function ly.file(input_file, options)
+ --[[ Here, we only take in account global option includepaths,
+ as it really doesn't mean anything as a local option. ]]
+ local file = locate(input_file, Score.includepaths, '.ly')
+ options = ly.set_local_options(options)
+ if not file then err("File %s doesn't exist.", input_file) end
+ local i = io.open(file, 'r')
+ ly.score = Score:new(i:read('*a'), options, file)
+ i:close()
+end
+
+
+function ly.file_musicxml(input_file, options)
+ --[[ Here, we only take in account global option includepaths,
+ as it really doesn't mean anything as a local option. ]]
+ local file = locate(input_file, Score.includepaths, '.xml')
+ options = ly.set_local_options(options)
+ if not file then err("File %s doesn't exist.", input_file) end
+ local xmlopts = ''
+ for _, opt in pairs(MXML_OPTIONS) do
+ if options[opt] ~= nil then
+ if options[opt] then xmlopts = xmlopts..' --'..opt
+ if options[opt] ~= 'true' and options[opt] ~= '' then
+ xmlopts = xmlopts..' '..options[opt]
+ end
+ end
+ elseif ly.get_option(opt) then xmlopts = xmlopts..' --'..opt
+ end
+ end
+ local i = io.popen(ly.get_option('xml2ly')..' --out=-'..xmlopts..' "'..file..'"', 'r')
+ if not i then
+ err([[
+LilyPond could not be started.
+Please check that LuaLaTeX is started with the
+--shell-escape option.
+]]
+ )
+ end
+ ly.score = Score:new(i:read('*a'), options, file)
+ i:close()
+end
+
+
+function ly.fragment(ly_code, options)
+ options = ly.set_local_options(options)
+ if type(ly_code) == 'string' then
+ ly_code = ly_code:gsub('\\par ', '\n'):gsub('\\([^%s]*) %-([^%s])', '\\%1-%2')
+ else ly_code = table.concat(ly_code, '\n')
+ end
+ ly.score = Score:new(ly_code, options)
+end
+
+
+function ly.get_font_family(font_id)
+ return fontinfo(font_id).shared.rawdata.metadata['familyname']
+end
+
+
+function ly.get_option(opt) return Score[opt] end
+
+
+function ly.is_alias() end
+
+
+function ly.is_dim(k, v)
+ if v == '' or v == false or tonumber(v) then return true end
+ local n, sl, u = v:match('^%d*%.?%d*'), v:match('\\'), v:match('%a+')
+ -- a value of number - backslash - length is a dimension
+ -- invalid input will be prevented in by the LaTeX parser already
+ if n and sl and u then return true end
+ if n and contains(TEX_UNITS, u) then return true end
+ err([[
+Unexpected value "%s" for dimension %s:
+should be either a number (for example "12"),
+a number with unit, without space ("12pt"),
+or a (multiplied) TeX length (".8\linewidth")
+]],
+ v, k
+ )
+end
+
+
+function ly.is_neg(k, _)
+ local _, i = k:find('^no')
+ return i and contains_key(OPTIONS, k:sub(i + 1))
+end
+
+
+function ly.is_num(_, v) return v == '' or tonumber(v) end
+
+
+function ly.newpage_if_fullpage()
+ if ly.score.insert == 'fullpage' then tex.sprint([[\newpage]]) end
+end
+
+
+function ly.set_fonts(rm, sf, tt)
+if ly.score.rmfamily..ly.score.sffamily..ly.score.ttfamily ~= '' then
+ ly.score['pass-fonts'] = 'true'
+ info("At least one font family set explicitly. Activate 'pass-fonts'")
+end
+ if ly.score.rmfamily == '' then ly.score.rmfamily = ly.get_font_family(rm)
+ else
+ -- if explicitly set don't override rmfamily with 'current' font
+ if ly.score['current-font-as-main'] then
+ info("rmfamily set explicitly. Deactivate 'current-font-as-main'")
+ end
+ ly.score['current-font-as-main'] = false
+ end
+ if ly.score.sffamily == '' then ly.score.sffamily = ly.get_font_family(sf) end
+ if ly.score.ttfamily == '' then ly.score.ttfamily = ly.get_font_family(tt) end
+end
+
+function ly.set_local_options(opts)
+ local options = {}
+ local next_opt = opts:gmatch('([^,]+)') -- iterator over options
+ for opt in next_opt do
+ local k, v = opt:match('([^=]+)=?(.*)')
+ if k then
+ if v and v:sub(1, 1) == '{' then -- handle keys with {multiple, values}
+ while v:sub(-1) ~= '}' do v = v..','..next_opt() end
+ v = v:sub(2, -2) -- remove { }
+ end
+ k, v = process_options(k:gsub('^%s', ''), v:gsub('^%s', ''))
+ if k then
+ if options[k] then err('Option %s is set two times for the same score.', k)
+ else options[k] = v
+ end
+ end
+ end
end
- return font.fonts[id]
+ return options
+end
+
+
+function ly.set_property(k, v)
+ k, v = process_options(k, v)
+ if k then Score[k] = v end
end
-mkdirs(TMP)
+return ly
diff --git a/Master/texmf-dist/tex/latex/lyluatex/lyluatex.sty b/Master/texmf-dist/tex/latex/lyluatex/lyluatex.sty
index 5b7eff0fb37..b8f15831531 100644
--- a/Master/texmf-dist/tex/latex/lyluatex/lyluatex.sty
+++ b/Master/texmf-dist/tex/latex/lyluatex/lyluatex.sty
@@ -1,91 +1,242 @@
-\ProvidesPackage{lyluatex}
+%Lyluatex LaTeX style.
+%
+% Copyright (C) 2015-2018 jperon and others (see CONTRIBUTORS.md)
+% License: MIT
+% This file is part of lyluatex.
-% Dépendances
+\NeedsTeXFormat{LaTeX2e}%
+\ProvidesPackage{lyluatex}[2018/03/12 v1.0b] %%LYLUATEX_DATE LYLUATEX_VERSION
+
+% Dependencies
\RequirePackage{luatexbase}
\RequirePackage{luaotfload}
-\RequirePackage{kvoptions}
+\RequirePackage{xkeyval}
\RequirePackage{graphicx}
-\RequirePackage{keycommand}
+\RequirePackage{minibox}
\RequirePackage{environ}
\RequirePackage{currfile}
\RequirePackage{pdfpages}
+
+\RequirePackage{metalogo}
+\newcommand{\lyluatex}{\textit{ly}\LuaTeX}
+
+\edef\ly@false{false}\def\ly@istwosided{\if@twoside\else\ly@false\fi}
+\savecatcodetable 40
+
% Options
-\DeclareStringOption[lilypond]{program}[lilypond]
-\DeclareStringOption[default]{line-width}[lilypond]
-\newcommand{\pt}{pt}
-\newcommand{\mm}{mm}
-\newcommand{\cm}{cm}
-\ProcessKeyvalOptions*
-% Script lua
-\directlua{dofile(kpse.find_file("lyluatex.lua"))}
-\directlua{LILYPOND = '\lyluatex@program'}
-
-\def\defaultwidth{default}
\catcode`-=11
-\ifx\lyluatex@line-width\defaultwidth
-\catcode`-=12
-% Une tricherie un peu sale pour récupérer la largeur de ligne
-\let\bs\textbackslash
-{\catcode`p=12 \catcode`t=12 \gdef\un#1pt{#1}}
-\newcommand*{\largeur}{[[\directlua{tex.print(\expandafter\un\the\linewidth - 10)}pt]]}
-\else
-\catcode`-=11
-\directlua{print('test:','\lyluatex@line-width')}
-\let\largeur\lyluatex@line-width
+\directlua{
+ ly = require(kpse.find_file("lyluatex.lua") or "lyluatex.lua")
+ ly.declare_package_options({
+ ['addversion'] = {'false', 'true', ''},
+ ['autoindent'] = {'true', 'false', ''},
+ ['cleantmp'] = {'false', 'true', ''},
+ ['currfiledir'] = {},
+ ['debug'] = {'false', 'true', ''},
+ ['extra-bottom-margin'] = {'0', ly.is_dim},
+ ['extra-top-margin'] = {'0', ly.is_dim},
+ ['fragment'] = {'', 'false', 'true'},
+ ['nofragment'] = {'default', ly.is_neg},
+ ['fullpagealign'] = {'crop', 'staffline'},
+ ['fullpagestyle'] = {''},
+ ['gutter'] = {'.4in', ly.is_dim},
+ ['exampleindent'] = {'gutter', ly.is_alias},
+ ['leftgutter'] = {'', ly.is_dim}, ['rightgutter'] = {'', ly.is_dim},
+ ['hpadding'] = {'0.75ex', ly.is_dim},
+ ['includepaths'] = {'./'},
+ ['indent'] = {'', ly.is_dim},
+ ['noindent'] = {'default', ly.is_neg},
+ ['insert'] = {'', 'systems', 'fullpage', 'inline', 'bare-inline'},
+ ['intertext'] = {''},
+ ['label'] = {'false'}, ['labelprefix'] = {'ly_'},
+ ['line-width'] = {[[\linewidth]], ly.is_dim},
+ ['ly-version'] = {'2.18.2'},
+ ['max-protrusion'] = {[[\maxdimen]], ly.is_dim},
+ ['max-left-protrusion'] = {'', ly.is_dim},
+ ['max-right-protrusion'] = {'', ly.is_dim},
+ ['noclef'] = {'false', 'true', ''},
+ ['nostaff'] = {'false', 'true', ''},
+ ['nostaffsymbol'] = {'false', 'true', ''},
+ ['notime'] = {'false', 'true', ''},
+ ['notiming'] = {'false', 'true', ''},
+ ['notimesig'] = {'false', 'true', ''},
+ ['optimize-pdf'] = {'false', 'true', ''},
+ ['paperwidth'] = {[[\paperwidth]], ly.is_dim},
+ ['paperheight'] = {[[\paperheight]], ly.is_dim},
+ ['papersize'] = {'false'},
+ ['pass-fonts'] = {'false', 'true', ''},
+ ['current-font'] = {}, ['current-font-as-main'] = {'false', 'true', ''},
+ ['rmfamily'] = {}, ['sffamily'] = {}, ['ttfamily'] = {},
+ ['print-page-number'] = {'false', 'true', ''},
+ ['print-only'] = {''},
+ ['printfilename'] = {'false', 'true', ''},
+ ['program'] = {'lilypond'},
+ ['protrusion'] = {'', ly.is_dim},
+ ['noprotrusion'] = {'default', ly.is_neg},
+ ['raw-pdf'] = {'false', 'true', ''},
+ ['quote'] = {'false', 'true', ''},
+ ['ragged-right'] = {'default', 'true', 'false', ''},
+ ['noragged-right'] = {'default', ly.is_neg},
+ ['relative'] = {'false', ly.is_num},
+ ['norelative'] = {'default', ly.is_neg},
+ ['showfailed'] = {'false', 'true' ,''},
+ ['staffsize'] = {'0', ly.is_dim},
+ ['inline-staffsize'] = {'0', ly.is_dim},
+ ['tmpdir'] = {'tmp-ly'},
+ ['twoside'] = {'\ly@istwosided', 'false', 'true', ''},
+ ['verbatim'] = {'false', 'true', ''},
+ ['voffset'] = {'0pt', ly.is_dim},
+ ['valign'] = {'center', 'top', 'bottom'},
+ % MusicXML options
+ ['absolute'] = {'false', 'true', ''},
+ ['language'] = {'false'},
+ ['lxml'] = {'false', 'true'},
+ ['no-articulation-directions'] = {'true', 'false', ''},
+ ['no-beaming'] = {'true', 'false', ''},
+ ['no-page-layout'] = {'true', 'false', ''},
+ ['no-rest-positions'] = {'true', 'false', ''},
+ ['verbose'] = {'false', 'true', ''},
+ ['xml2ly'] = {'musicxml2ly'},
+ })
+}
+\directlua{
+ if ly.get_option('cleantmp') then
+ luatexbase.add_to_callback('stop_run', ly.clean_tmp_dir, 'lyluatex cleantmp')
+ luatexbase.add_to_callback('stop_run', ly.conclusion_text, 'lyluatex conclusion')
+ end
+}
\catcode`-=12
-\fi
-% Taille des partitions
-% Si la valeur est 0, elle sera automatiquement calculée
-% à partir de la taille de police.
-\def\staffsize{0}
-\let\localstaffsize\staffsize
-\let\localwidth\largeur
-
-
-% Commandes principales
-% Inclusion d'un fichier ly
-\newkeycommand*\includely[fullpage=false,staffsize=\staffsize,line-width=\largeur][autres][1]{%
-\directlua{%
- inclure_ly(
- "\luatexluaescapestring{#1}",
- "\luatexluaescapestring{\currfiledir}",
- '\commandkey{line-width}',
- \luatexluaescapestring{\commandkey{staffsize}},
- \commandkey{fullpage}
- )%
-}%
+
+%\directlua{ly.TWOSIDE = 'f'}
+
+\newcommand{\ly@setunits}{%
+ \let\ly@old@in\in\protected\def\in{in}%
+ \let\ly@old@pt\pt\protected\def\pt{pt}%
+ \let\ly@old@mm\mm\protected\def\mm{mm}%
+ \let\ly@old@cm\cm\protected\def\cm{cm}%
+ \let\ly@old@hfuzz\hfuzz\setlength{\hfuzz}{\maxdimen}%
+}
+\newcommand{\ly@resetunits}{%
+ \let\in\ly@old@in%
+ \let\pt\ly@old@pt%
+ \let\mm\ly@old@mm%
+ \let\cm\ly@old@cm%
+ \setlength{\hfuzz}{\ly@old@hfuzz}%
}
-% Inclusion d'un fragment intégré au document (environnement de base)
-\NewEnviron{compilerly}{%
-\directlua{%
- direct_ly(
- "\luatexluaescapestring{\unexpanded\expandafter{\BODY}}",
- '\localwidth',
- \luatexluaescapestring{\localstaffsize}
- )%
-}%
+% Command to change options during the document
+\newcommand{\lysetoption}[2]{\directlua{ly.set_property([[#1]], [[#2]])}}
+
+% How the filename of a score will look like (if printed)
+\newcommand{\lyFilename}[1]{\noindent #1\par\bigskip}
+
+% Appearance of verbatim 'intertext' (if printed)
+\newcommand{\lyIntertext}[1]{\noindent #1\par\bigskip}
+
+% Appearance of LilyPond version (if printed)
+\newcommand{\lyVersion}[1]{\noindent {\footnotesize\emph{(GNU LilyPond #1)}\par}\bigskip}
+
+% Retrieve the three main font families (rm, sf, tt)
+% and store them as options. Additionally store the
+% *current* font for optional use.
+\newcommand{\ly@currentfonts}{%
+ \begingroup%
+ \directlua{ly.set_property('current-font', ly.get_font_family(font.current()))}%
+ \rmfamily \edef\rmfamilyid{\fontid\font}%
+ \sffamily \edef\sffamilyid{\fontid\font}%
+ \ttfamily \edef\ttfamilyid{\fontid\font}%
+ % Set font families to those of the document
+ % that haven't been set explicitly as options.
+ \directlua{ly.set_fonts(\rmfamilyid, \sffamilyid, \ttfamilyid)}%
+ \endgroup%
+}
+
+% Main commands
+% Score processing
+\newcommand*{\ly@compilescore}[1]{%
+ \ly@setunits%
+ \directlua{
+ ly.set_property('currfiledir', [[\currfiledir]])
+ ly.set_property('twoside', '\ly@istwosided')
+ #1
+ ly.newpage_if_fullpage()
+ }%
+ \ly@resetunits%
+ \ly@currentfonts%
+ \directlua{ly.score:process()}%
+}
+
+% Inclusion of a .ly file
+\newcommand*\includely[2][]{%
+ \directlua{ly.state = 'file'}%
+ \ly@compilescore{ly.file(
+ '\luatexluaescapestring{#2}', [[#1]]
+ )}%
+}
+
+% Inclusion of a musicxml file
+\newcommand*\musicxmlfile[2][]{%
+ \directlua{ly.state = 'file'}%
+ \ly@compilescore{ly.file_musicxml(
+ '\luatexluaescapestring{#2}', [[#1]]
+ )}
+}
+
+% Base environments to include a LilyPond fragment integrated into
+% the document.
+\newcommand\lyscorebegin{\directlua{ly.buffenv_begin()}}
+\newcommand\lyscoreend{\directlua{ly.buffenv_end()}}
+\newenvironment{ly@bufferenv}{%
+ \lyscorebegin%
+}{%
+ \lyscoreend%
+ \ly@compilescore{ly.fragment(ly.score_content, [[\options]])}%
+}
+
+\NewEnviron{ly@compilely}{%
+ \ly@compilescore{ly.fragment(
+ '\luatexluaescapestring{\unexpanded\expandafter{\BODY}}',
+ [[\options]]
+ )}%
}
-% Commande et environnement avec paramètres
-\newkeycommand{\lily}[staffsize=\staffsize,line-width=\largeur][autres][1]{%
-\def\localstaffsize{\commandkey{staffsize}}%
-\def\localwidth{\commandkey{line-width}}%
-\begin{compilerly}%
-{#1}
-\end{compilerly}%
+% Commands to print verbatim content of the score
+\newcommand\lysetverbenv[2]{%
+ \directlua{ly.verbenv = {
+ '\luatexluaescapestring{\detokenize{#1}}',
+ '\luatexluaescapestring{\detokenize{#2}}'
+ }}%
}
-\newkeyenvironment{ly}[staffsize=\staffsize][autres]{%
-\def\localstaffsize{\commandkey{staffsize}}%
-\compilerly%
+% Parametrized command and environment for included LilyPond fragment
+\newenvironment{ly}[1][noarg]{%
+ \edef\options{#1}%
+ \directlua{ly.env_begin([[#1]])}%
}{%
-\endcompilerly%
+ \directlua{ly.env_end()}%
}
-% Commandes pour la compatibilité avec lilypond-book
-\let\lilypondfile\includely
-\protected\def\lilypond{\def\reserved@a{lilypond}%
- \ifx\reserved@a\@currenvir \expandafter \ly
- \else \expandafter\lily \fi}
+\newcommand*{\lily}[2][]{%
+ \edef\options{#1}%
+ \let\ly@oldrepeat\repeat\def\repeat{}% Fix #51
+ \directlua{ly.state = 'cmd'}%
+ \begin{ly@compilely}%
+ #2
+ \end{ly@compilely}%
+ \let\repeat\ly@oldrepeat%
+}
+
+\newcommand{\lyscore}[1]{\directlua{
+ local i = tonumber('#1') or '#1'
+ if i == '' then i = 1 end
+ tex.sprint(ly.score[i] or '')
+}}
+
+% Commands for compatibility with lilypond-book
+\let\lilypondfile\includely%
+\protected\def\lilypond{%
+ \def\reserved@a{lilypond}%
+ \ifx\reserved@a\@currenvir\expandafter\ly%
+ \else\expandafter\lily\fi%
+}%
\let\endlilypond\endly
diff --git a/Master/tlpkg/libexec/ctan2tds b/Master/tlpkg/libexec/ctan2tds
index 16555faf803..11087d6d091 100755
--- a/Master/tlpkg/libexec/ctan2tds
+++ b/Master/tlpkg/libexec/ctan2tds
@@ -1730,6 +1730,7 @@ $standardtex
'luatexko', '\.lua|' . $standardtex,
'luatodonotes','\.lua|' . $standardtex,
'luaxml', '\.lua|' . $standardtex,
+ 'lyluatex', '\.sty', # not *.cls
'magyar', 'NULL', # do not install in runtime, conflicts with babel
'manjutex', '\.sty|\.clo|\.ldf|\.cls|\.def|\.fd$|manju.tex',
'math-e', 'NULL',