summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex')
-rw-r--r--Master/texmf-dist/tex/latex/lyluatex/lyluatex.sty293
1 files changed, 222 insertions, 71 deletions
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