jperon / lyluatex

Alternative à lilypond-book pour lualatex
MIT License
58 stars 11 forks source link

Illegal empty scores #238

Closed uliska closed 5 years ago

uliska commented 5 years ago

Somehow related to #237 LilyPond snippets that erroneously produce no score trigger an interesting side effect that we should handle gracefully.

\documentclass{article}
\usepackage{lyluatex}

\begin{document}

\lilypond{ #(ly:message "Foo") }

\end{document}

will fail with

lyluatex.
lua:1278: attempt to index a nil value
stack traceback:
    .../uliska/texmf/tex/luatex/git-latex/lyluatex/lyluatex.lua:1278: in function 
'write_latex'
    .../uliska/texmf/tex/luatex/git-latex/lyluatex/lyluatex.lua:1193: in function 
'process'
    [\directlua]:1: in main chunk.
\ly@compilescore ...directlua {ly.score:process()}

l.7 \lilypond{ #(ly:message "Foo") }

?

The issue is that the LilyPond code produces no score. Of course this is erroneous input but we should handle it more gracefully with a meaningful message and not attempt to index a nil value.

The underlying issue is that by default LilyPond will not produce a PDF when there is no content:

\version "2.18.2"

#(display "Foo")

But

\version "2.18.2"
\include "lilypond-book-preamble.ly"
#(display "Foo")

will produce files - with the PDF being empty, without extent, and that seems to be where we get a nil value somewhere. [NOTE: I currently have no LilyPond 2.18 installed so I'm not sure if that behaves identically.]

I'm not sure about the best remedy. Probably there should be another check in is_compiled() or when checking the bounding box. From the program flow it should of course be when checking for the existence of the PDF, but maybe when checking the bounding box we have better information about the issue.

jperon commented 5 years ago

@uliska I just pushed a fix for this issue: I'm leaving the possibility to include empty scores, as it could be the result of conditional formatting etc. but I raise a warning.