summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/lyluatex/lyluatex.sty
blob: 5b7eff0fb375d3a23aad298236096acec2225b8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
\ProvidesPackage{lyluatex}

% Dépendances
\RequirePackage{luatexbase}
\RequirePackage{luaotfload}
\RequirePackage{kvoptions}
\RequirePackage{graphicx}
\RequirePackage{keycommand}
\RequirePackage{environ}
\RequirePackage{currfile}
\RequirePackage{pdfpages}
% 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
\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}
    )%
}%
}

% Inclusion d'un fragment intégré au document (environnement de base)
\NewEnviron{compilerly}{%
\directlua{%
    direct_ly(
        "\luatexluaescapestring{\unexpanded\expandafter{\BODY}}",
        '\localwidth',
        \luatexluaescapestring{\localstaffsize}
    )%
}%
}

% 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}%
}

\newkeyenvironment{ly}[staffsize=\staffsize][autres]{%
\def\localstaffsize{\commandkey{staffsize}}%
\compilerly%
}{%
\endcompilerly%
}

% 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}
\let\endlilypond\endly