9

I ran into this with the package lilyglyphs but I'm not sure whose fault this error is.

When I compile the following with lualatex:

\documentclass{article}
\usepackage{csquotes}
\MakeOuterQuote{"}
\EnableQuotes
\begin{document}
\directlua{print("hello")}
\end{document}

I get an error saying

\directlua]:1: unexpected symbol near '\'.
l.6 \directlua{print("hello")}

Now suppose that I do not directly write \directlua in my document, but I include a package that does it internally. Such as

\documentclass{article}
\usepackage{fontspec, csquotes, lilyglyphs}
\MakeOuterQuote{"}
\EnableQuotes
\begin{document}
\wholeNote
\end{document}

I have no knowledge why compilation fails, because the error now becomes

! Missing number, treated as zero.
<to be read again>
\begingroup
l.7 \end
      {document}

From my user point of view I did nothing wrong, because I'm using the public API provided by the packages. The csquotes documentation specifically says:

Note that all characters are automatically checked for validity as they are allocated. This package will reject characters which are unsuitable as active quotes... In sum, the following characters will be considered as reserved by this package:

 A–Z a–z 0–9 . , ; : ! ? ' - # $ % & ^ _ ` ~ \ @ * { } [ ]

So my question is whose fault is this error?

  • My fault, the user's fault, because I should have known (but how?) that even though the quote is not listed as unsuitable in the csquotes manual, it actually is?
  • The fault of the implementation or documentation of csquotes for failing to mention " as unsuitable?
  • The fault of the implementation of the \directlua command because it doesn't prevent LaTeX catcode changes/active characters from impacting its argument?
  • A shortcoming of TeX itself because of its global state based architecture?
14

Your first example and your second are actually quite different errors. The first is your fault (see Davids answer), but the second is a bug in lilyglyphs lua code.

But the problem is not the quote in \directlua. As the command is defined in lilyglyphs the catcode of the " is frozen there and so not problematic.

lilyglyphs uses tex.sprint to print the char, and the argument contains a ". As tex.sprint uses by default the current active catcode regime this explodes. You can tell tex.sprint to use another catcode table. (I'm not quite sure if \CatcodeTableLaTeX I used the best one, but it works):

\documentclass{article}

\usepackage{fontspec, csquotes,lilyglyphs}

%copied from lilyglyphs
\begin{luacode}
documentdata = documentdata or { }

local stringformat = string.format
local texsprint = tex.sprint
local slot_of_name = luaotfload.aux.slot_of_name

documentdata.fontchar = function (chr)
local chr = slot_of_name(font.current(), chr, false)
if chr and type(chr) == "number" then
texsprint
 (\the\CatcodeTableLaTeX, 
  stringformat ([[\char"%X"]], chr))
end
end
\end{luacode}

\MakeOuterQuote{"}
\EnableQuotes

\begin{document}

\wholeNote

\end{document}
10

Sorry but since you ask, I'd say it was your fault:-)

Having made a character active you should have known to make it safe before passing to Lua.

For example:

\documentclass{article}
\usepackage{csquotes}
\MakeOuterQuote{"}
\EnableQuotes
\begin{document}
\directlua{print(\string"hello\string")}
\end{document}

See Ulrike's answer for the second example.

  • Please consider the second part of the question when I use a package, and I have no knowledge of it using \directlua. Of course in the first example it's my fault. – marczellm May 3 '17 at 8:56
  • OK, obviously we created the corresponding questions at the same time ;-) The problem is in the package implementation, but I don't know how to fix it. The actual invocation is \directlua{documentdata.fontchar "#1"} – uli_1973 May 3 '17 at 9:05
  • but is there any situation where it is useful to have LaTeX active characters alter the code sent to the Lua interpreter? is this a feature or a bug of LuaTeX? – marczellm May 3 '17 at 9:11
  • @marczellm I was going to answer the second part, but got called to a meeting, will update the answer in a bit, it doesn't seem particularly related to the first part – David Carlisle May 3 '17 at 9:15
  • 1
    @marczellm expansion is a feature that is it a general tex feature that active characters work just like normal macros if ~ is act,ive then \def~{zzz} and \def\foo{zzz} are essentially the same and you would expect \directlua{~} and \directlua{\foo} to be the same, as they are. – David Carlisle May 3 '17 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.