Skip to content

Commit

Permalink
'margin' parameter for ly and \lily (doesn't work!)
Browse files Browse the repository at this point in the history
Deals with #23

I'm trying to pass a 'margin' value into the lilypond_fragment_header function,
as a first step towards implementing proper alignment of full-width scores.

However, using this code the `left_margin` argument reaching
`lilypond_header_fragment` is not 50 or another value given as option
but `true`.
  • Loading branch information
uliska committed Jan 17, 2018
1 parent a381f6b commit b74dc79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 8 additions & 6 deletions lyluatex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ function hash_output_filename(ly_code, line_width, staffsize)
return TMP..'/'..filename
end

function lilypond_fragment(ly_code, line_width, staffsize)
function lilypond_fragment(ly_code, line_width, staffsize, left_margin)
line_width, staffsize = extract_size_arguments(line_width, staffsize)
ly_code = ly_code:gsub('\\par ', '\n'):gsub('\\([^%s]*) %-([^%s])', '\\%1-%2')
local output = hash_output_filename(ly_code, line_width, staffsize)
if not lfs.isfile(output..'-systems.tex') then
run_lilypond(lilypond_fragment_header(staffsize, line_width)..'\n'..ly_code, output, true)
run_lilypond(lilypond_fragment_header(staffsize, line_width, left_margin)..'\n'..ly_code, output, true)
end
write_tex(output, staffsize)
end


function lilypond_file(input_file, currfiledir, line_width, staffsize, fullpage)
function lilypond_file(input_file, currfiledir, line_width, staffsize, left_margin, fullpage)
line_width, staffsize = extract_size_arguments(line_width, staffsize)
filename = splitext(input_file, 'ly')
input_file = currfiledir..filename..'.ly'
Expand All @@ -84,7 +84,7 @@ function lilypond_file(input_file, currfiledir, line_width, staffsize, fullpage)
i:write('\\includepdf[pages=-]{'..output..'}')
i:close()
else
run_lilypond(lilypond_fragment_header(staffsize, line_width)..'\n'..ly_code, output, true, dirname(input_file))
run_lilypond(lilypond_fragment_header(staffsize, line_width, left_margin)..'\n'..ly_code, output, true, dirname(input_file))
end
end
write_tex(output, staffsize)
Expand All @@ -106,7 +106,7 @@ function run_lilypond(ly_code, output, eps, include)
end


function lilypond_fragment_header(staffsize, line_width)
function lilypond_fragment_header(staffsize, line_width, left_margin)
return string.format(
[[%%File header
\version "2.18.2"
Expand Down Expand Up @@ -139,12 +139,14 @@ function lilypond_fragment_header(staffsize, line_width)
\paper{
indent = 0\mm
line-width = %s\%s
left-margin = %s\pt
}
%%Follows original score
]],
staffsize,
line_width.n, line_width.u
line_width.n, line_width.u,
left_margin
)
end

Expand Down
7 changes: 6 additions & 1 deletion lyluatex.sty
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ dofile(kpse.find_file("lyluatex.lua"))}
lilypond_fragment(
"\luatexluaescapestring{\unexpanded\expandafter{\BODY}}",
'\localwidth',
\luatexluaescapestring{\localstaffsize}
\luatexluaescapestring{\localstaffsize},
\localmargin
)%
}%
}
Expand All @@ -87,10 +88,12 @@ dofile(kpse.find_file("lyluatex.lua"))}
staffsize=\staffsize%
,line-width=\lilywidth%
,program=\lyluatex@program%
,margin=50%
][other-options][1]{%
\directlua{ly_define_program("\luatexluaescapestring{\commandkey{program}}")}%
\def\localstaffsize{\commandkey{staffsize}}%
\def\localwidth{\commandkey{line-width}}%
\def\localmargin{\commandkey{margin}}
\begin{compilerly}%
{#1}
\end{compilerly}%
Expand All @@ -101,10 +104,12 @@ dofile(kpse.find_file("lyluatex.lua"))}
staffsize=\staffsize%
,line-width=\lilywidth%
,program=\lyluatex@program%
,margin=50%
][other-options]{%
\directlua{ly_define_program("\luatexluaescapestring{\commandkey{program}}")}%
\def\localstaffsize{\commandkey{staffsize}}%
\def\localwidth{\commandkey{line-width}}%
\def\localmargin{\commandkey{margin}}
\compilerly%
}{%
\endcompilerly%
Expand Down

0 comments on commit b74dc79

Please sign in to comment.