From 38731a4a8500c67e5e24c9bc0c3dd687f903664e Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Thu, 3 May 2018 16:40:37 +0000 Subject: lyluatex in luatex, per wl 12 Apr 2018 07:14:26 git-svn-id: svn://tug.org/texlive/trunk@47584 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty | 242 +++++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty (limited to 'Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty') diff --git a/Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty b/Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty new file mode 100644 index 00000000000..b8f15831531 --- /dev/null +++ b/Master/texmf-dist/tex/luatex/lyluatex/lyluatex.sty @@ -0,0 +1,242 @@ +%Lyluatex LaTeX style. +% +% Copyright (C) 2015-2018 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 + +% Dependencies +\RequirePackage{luatexbase} +\RequirePackage{luaotfload} +\RequirePackage{xkeyval} +\RequirePackage{graphicx} +\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 +\catcode`-=11 +\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 + +%\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}% +} + +% 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]] + )}% +} + +% Commands to print verbatim content of the score +\newcommand\lysetverbenv[2]{% + \directlua{ly.verbenv = { + '\luatexluaescapestring{\detokenize{#1}}', + '\luatexluaescapestring{\detokenize{#2}}' + }}% +} + +% Parametrized command and environment for included LilyPond fragment +\newenvironment{ly}[1][noarg]{% + \edef\options{#1}% + \directlua{ly.env_begin([[#1]])}% +}{% + \directlua{ly.env_end()}% +} + +\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 -- cgit v1.2.3