My MWE below shows two files working together to create a document containing music using the lyluatex
package. Unfortunately, I've observed that if I add any comments to the contents anywhere in the file test.ly, the compilation will fail reporting an error (see log slightly cleaned up below) that leads me to believe there is a problem importing a file with comments which rely on % signs
in it. I have observed that comments are fine anywhere in the tex file though.
Module lyluatex Warning: Found something incompatible with `fragment`
(lyluatex) (or `relative`). Setting them to false.
(lyluatex) on input line 34
lyluatex.lua:841: invalid use of '%' in replacement string
stack traceback:
[C]: in function 'gsub' lyluatex.lua:841: in function 'flatten_content'
lyluatex.lua:1082: in function 'output_filename'
lyluatex.lua:531: in function 'calc_properties'
lyluatex.lua:1088: in function 'process'
[\directlua]:1: in main chunk.
\ly@compilescore ...directlua {ly.score:process()}
l.34 \end{tune}
?
Two reproduce: The following MWE is broken into 2 files:
1 - the tex file
2 - the lilypond source file being included
The code as is will compile and produce the expected pdf if compiled with lualatex (i.e. lualatex.exe" -shell-escape "test.tex"
)
test.tex
\documentclass[letter,fontsize=12pt]{article}
\usepackage{xparse} % can exclude expl3, xparse loads it
\usepackage{xpatch} % can exclude etoolbox, xpatch loads it
\usepackage{luatexbase}
\usepackage[program=lilypond]{lyluatex}
\DeclareDocumentCommand{\tune}{}
{%
\ly
}
\def\endtune
{%
\endly
}
\begin{document}
\begin{tune}
%\version "2.18.2"
\include "test.ly"
first = \transpose c d {\tune}
second = \transpose c b {\tune}
\score {
<<
\unfoldRepeats{\first\second}
>>
\layout{}
}
\end{tune}
\end{document}
test.ly
global = {
\key b \minor
\time 9/8
}
tune = \absolute {
\global
\relative c' { c8 d e f g a b c c }
\bar ":|."
}
test.ly (modified to fail)
global = {
\key b \minor
\time 9/8
}
tune = \absolute {
\global % a comment can't go here
% a comment can't seem to go here either
\relative c' { c8 d e f g a b c c }
\bar ":|."
}
I'd like to explore or learn more about why lualatex is choking on my %
when it's an expected latex special character.
lyluatex.lua
. (It looks like this file is loaded by thelyluatex.sty
LaTeX package file.)if f then ly_code = ly_code:gsub(iline, self:flatten_content(f:read('*a'))) f:close() end
gsub
is one of the functions that performs pattern matching (and substitution). In Lua, the%
has a special meaning when pattern matching is performed; e.g.,%s-
means "zero or more instances of whitespace". To process a%
character as itself, it's necessary to input it as%%
. Check if replacing single instances of%
intest.ly
with%%
lets the program compile without errors.