From a77f7d3afb1f5e076c5190ab9c84372e72dd67ba Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Tue, 28 May 2019 21:25:42 +0000 Subject: lyluatex (28may19) git-svn-id: svn://tug.org/texlive/trunk@51252 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty | 150 ++++++++++++++++----- 1 file changed, 114 insertions(+), 36 deletions(-) (limited to 'Master/texmf-dist/tex') diff --git a/Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty b/Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty index b8f15831531..f0d70d9878c 100644 --- a/Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty +++ b/Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty @@ -1,11 +1,11 @@ %Lyluatex LaTeX style. % -% Copyright (C) 2015-2018 jperon and others (see CONTRIBUTORS.md) +% Copyright (C) 2015-2019 jperon and others (see CONTRIBUTORS.md) % License: MIT % This file is part of lyluatex. \NeedsTeXFormat{LaTeX2e}% -\ProvidesPackage{lyluatex}[2018/03/12 v1.0b] %%LYLUATEX_DATE LYLUATEX_VERSION +\ProvidesPackage{lyluatex}[2019/05/27 v1.0f] %%LYLUATEX_DATE LYLUATEX_VERSION % Dependencies \RequirePackage{luatexbase} @@ -16,6 +16,7 @@ \RequirePackage{environ} \RequirePackage{currfile} \RequirePackage{pdfpages} +\IfFileExists{varwidth.sty}{\RequirePackage{varwidth}}{} \RequirePackage{metalogo} \newcommand{\lyluatex}{\textit{ly}\LuaTeX} @@ -23,37 +24,62 @@ \edef\ly@false{false}\def\ly@istwosided{\if@twoside\else\ly@false\fi} \savecatcodetable 40 +% Copied from ifnextok.sty. +% We use \providecommand instead of \newcommand and \def in order +% to avoid overriding ifnextok if it is already loaded. +\providecommand{\IfNextToken}[3]{% + \let\nextok@match= #1% + \def\nextok@if{#2}\def\nextok@else{#3}% + \futurelet\@let@token\nextok@decide% +} +\providecommand\nextok@decide{% + \ifx\@let@token\nextok@match + \expandafter\nextok@if + \else + \expandafter\nextok@else + \fi% +} + % Options \catcode`-=11 \directlua{ - ly = require(kpse.find_file("lyluatex.lua") or "lyluatex.lua") - ly.declare_package_options({ + local _opt = require( + kpse.find_file("lyluatex-options.lua") or "lyluatex-options.lua" + ) + ly_opts = _opt.Opts:new('ly_opts', { ['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}, + ['extra-bottom-margin'] = {'0', _opt.is_dim}, + ['extra-top-margin'] = {'0', _opt.is_dim}, + ['fix_badly_cropped_staffgroup_brackets'] = {'false', 'true', ''}, + ['nofix_badly_cropped_staffgroup_brackets'] = {'default', _opt.is_neg}, + ['force-compilation'] = {'false', 'true', ''}, ['fragment'] = {'', 'false', 'true'}, - ['nofragment'] = {'default', ly.is_neg}, + ['nofragment'] = {'default', _opt.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}, + ['gutter'] = {'.4in', _opt.is_dim}, + ['exampleindent'] = {'gutter', _opt.is_alias}, + ['leftgutter'] = {'', _opt.is_dim}, ['rightgutter'] = {'', _opt.is_dim}, + ['hpadding'] = {'0.75ex', _opt.is_dim}, + ['include_after_body'] = {'false'}, + ['include_before_body'] = {'false'}, + ['include_footer'] = {'false'}, + ['include_header'] = {'false'}, ['includepaths'] = {'./'}, - ['indent'] = {'', ly.is_dim}, - ['noindent'] = {'default', ly.is_neg}, + ['indent'] = {'', _opt.is_dim}, + ['noindent'] = {'default', _opt.is_neg}, ['insert'] = {'', 'systems', 'fullpage', 'inline', 'bare-inline'}, ['intertext'] = {''}, ['label'] = {'false'}, ['labelprefix'] = {'ly_'}, - ['line-width'] = {[[\linewidth]], ly.is_dim}, + ['line-width'] = {[[\linewidth]], _opt.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}, + ['max-protrusion'] = {[[\maxdimen]], _opt.is_dim}, + ['max-left-protrusion'] = {'', _opt.is_dim}, + ['max-right-protrusion'] = {'', _opt.is_dim}, ['noclef'] = {'false', 'true', ''}, ['nostaff'] = {'false', 'true', ''}, ['nostaffsymbol'] = {'false', 'true', ''}, @@ -61,32 +87,37 @@ ['notiming'] = {'false', 'true', ''}, ['notimesig'] = {'false', 'true', ''}, ['optimize-pdf'] = {'false', 'true', ''}, - ['paperwidth'] = {[[\paperwidth]], ly.is_dim}, - ['paperheight'] = {[[\paperheight]], ly.is_dim}, + ['paperwidth'] = {[[\paperwidth]], _opt.is_dim}, + ['paperheight'] = {[[\paperheight]], _opt.is_dim}, ['papersize'] = {'false'}, ['pass-fonts'] = {'false', 'true', ''}, ['current-font'] = {}, ['current-font-as-main'] = {'false', 'true', ''}, ['rmfamily'] = {}, ['sffamily'] = {}, ['ttfamily'] = {}, ['print-page-number'] = {'false', 'true', ''}, + ['first-page-number'] = {'false', ''}, + ['print-first-page-number'] = {'true', 'false', ''}, ['print-only'] = {''}, + ['do-not-print'] = {''}, ['printfilename'] = {'false', 'true', ''}, ['program'] = {'lilypond'}, - ['protrusion'] = {'', ly.is_dim}, - ['noprotrusion'] = {'default', ly.is_neg}, + ['protrusion'] = {'', _opt.is_dim}, + ['noprotrusion'] = {'default', _opt.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}, + ['noragged-right'] = {'default', _opt.is_neg}, + ['relative'] = {'false', _opt.is_num}, + ['norelative'] = {'default', _opt.is_neg}, ['showfailed'] = {'false', 'true' ,''}, - ['staffsize'] = {'0', ly.is_dim}, - ['inline-staffsize'] = {'0', ly.is_dim}, + ['staffsize'] = {'0', _opt.is_dim}, + ['inline-staffsize'] = {'0', _opt.is_dim}, + ['system-count'] = {'0', _opt.is_dim}, ['tmpdir'] = {'tmp-ly'}, ['twoside'] = {'\ly@istwosided', 'false', 'true', ''}, ['verbatim'] = {'false', 'true', ''}, - ['voffset'] = {'0pt', ly.is_dim}, + ['voffset'] = {'0pt', _opt.is_dim}, ['valign'] = {'center', 'top', 'bottom'}, + ['write-headers'] = {'false'}, % MusicXML options ['absolute'] = {'false', 'true', ''}, ['language'] = {'false'}, @@ -100,7 +131,9 @@ }) } \directlua{ - if ly.get_option('cleantmp') then + ly = require(kpse.find_file("lyluatex.lua") or "lyluatex.lua") + ly.make_list_file() + if ly_opts.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 @@ -125,7 +158,7 @@ } % Command to change options during the document -\newcommand{\lysetoption}[2]{\directlua{ly.set_property([[#1]], [[#2]])}} +\newcommand{\lysetoption}[2]{\directlua{ly_opts:set_option([[#1]], [[#2]])}} % How the filename of a score will look like (if printed) \newcommand{\lyFilename}[1]{\noindent #1\par\bigskip} @@ -141,7 +174,7 @@ % *current* font for optional use. \newcommand{\ly@currentfonts}{% \begingroup% - \directlua{ly.set_property('current-font', ly.get_font_family(font.current()))}% + \directlua{ly_opts:set_option('current-font', ly.get_font_family(font.current()))}% \rmfamily \edef\rmfamilyid{\fontid\font}% \sffamily \edef\sffamilyid{\fontid\font}% \ttfamily \edef\ttfamilyid{\fontid\font}% @@ -156,8 +189,8 @@ \newcommand*{\ly@compilescore}[1]{% \ly@setunits% \directlua{ - ly.set_property('currfiledir', [[\currfiledir]]) - ly.set_property('twoside', '\ly@istwosided') + ly_opts:set_option('currfiledir', [[\currfiledir]]) + ly_opts:set_option('twoside', '\ly@istwosided') #1 ly.newpage_if_fullpage() }% @@ -187,10 +220,31 @@ \newcommand\lyscorebegin{\directlua{ly.buffenv_begin()}} \newcommand\lyscoreend{\directlua{ly.buffenv_end()}} \newenvironment{ly@bufferenv}{% + \directlua{ + ly.insert_inline = string.match([[\options]], 'insert.*inline') + if ly.insert_inline then + if ly.varwidth_available then + tex.print([[ + \string\begin{varwidth}{\string\linewidth} + ]]) + else + ly.insert_inline = false + ly.err( + [[You have required 'insert=inline' with lilypond environment, + but package 'varwidth' wasn't found; either install it, or disable + this option.]] + ) + end + end + } \lyscorebegin% }{% \lyscoreend% \ly@compilescore{ly.fragment(ly.score_content, [[\options]])}% + \hspace{0pt}\\ + \directlua{ + if ly.insert_inline then tex.print([[\string\end{varwidth}]]) end + }% } \NewEnviron{ly@compilely}{% @@ -208,15 +262,39 @@ }}% } +% Environments to record custom headers and footers to be included in fragments +\newenvironment{lysavefrag}[1]{% + \edef\filename{#1} + \lyscorebegin% +}{% + \lyscoreend% + \directlua{ly.write_to_file('\filename'..'.ly', table.concat(ly.score_content,'\string\n'))}% +} + +% Commands to transform or define lilypond environments so that it isn't necessary to add empty []. +\def\lyenv#1{% + \expandafter\let\csname ly@env@#1\expandafter\endcsname\csname #1\endcsname% + \expandafter\let\csname ly@env@end#1\expandafter\endcsname\csname end#1\endcsname% + \expandafter\def\csname #1\endcsname{\IfNextToken[{\csname ly@env@#1\endcsname}{\csname ly@env@#1\endcsname[]}}% +} +\long\def\lynewenvironment#1{\@ifnextchar[{\ly@newenv@a{#1}}{\ly@newenv@a{#1}[0]}} +\long\def\ly@newenv@a#1[#2]{\@ifnextchar[{\ly@newenv@b{#1}{#2}}{\ly@newenv@b{#1}{#2}[]}} +\long\def\ly@newenv@b#1#2[#3]#4#5{% + \newenvironment{#1}[#2][#3]{#4}{#5} + \lyenv{#1} +} + % Parametrized command and environment for included LilyPond fragment -\newenvironment{ly}[1][noarg]{% +\lynewenvironment{ly}[1][noarg]{% \edef\options{#1}% - \directlua{ly.env_begin([[#1]])}% + \directlua{ly.state = 'env'}% + \ly@bufferenv% }{% - \directlua{ly.env_end()}% + \endly@bufferenv% } -\newcommand*{\lily}[2][]{% + +\newcommand{\lily}[2][]{% \edef\options{#1}% \let\ly@oldrepeat\repeat\def\repeat{}% Fix #51 \directlua{ly.state = 'cmd'}% -- cgit v1.2.3