[luatex] newlines in key-value list

Ulrike Fischer luatex at nililand.de
Sat Mar 19 18:04:25 CET 2011


Am Fri, 18 Mar 2011 20:26:49 +0100 schrieb Paul Isambert:

> Le 18/03/2011 17:22, Ulrike Fischer a écrit :
>> In the following example using the variable A to get a key val list
>> gives and error (` color` not a key). Obviously because of the
>> newline in the string definition (B works fine). How can I avoid it?
>>
>>
>> \documentclass{scrartcl}
>> \usepackage{chessboard}
>> \usepackage{luacode}
>> \begin{document}
>> \begin{luacode}
>>
>> A=[[color=green,
>>      color=red]]
>>
>> B=[[color=green, color=red]]
>> \end{luacode}
>>
>> \chessboard[\directlua{tex.sprint(A)}]
>>
>> \chessboard[\directlua{tex.sprint(B)}]
>>
>> \end{document}
> 
> 
> I'd say use a real table in Lua, and traverse it, but you're probably 
> using strings for some good reason, 

Actually I do have a real table. And some of the entries are
key-val-combinations I wanted to test. And I use [[..]] to avoid to
long lines.

Meanwhile I have understood what's going on: lua use newline (\n,
^^J) at the end of the lines. ^^J has catcode 12 (and when printed
(using OT1-encoding) gives the Omega mentioned the line break
discussion some weeks ago).

I would get the same problem with A=[[text \n text]], while A=[[text
\r text]] would work fine. 

So I think the best is to change the catcode of ^^J when I want to
use such strings:

\documentclass{scrartcl}

\usepackage{chessboard}
\usepackage{luacode,luatexbase,listings}

\newluatexcatcodetable\nlspcatcodes

\begingroup
\catcode`\^^J=10 %
\luatexsavecatcodetable\nlspcatcodes
\endgroup

\newluatexcatcodetable\nlakcatcodes
\begingroup
\catcode`\^^J=\active %
\gdef^^J{\newline}
\luatexsavecatcodetable\nlakcatcodes
\endgroup

\begin{document}

\begin{luacode*}

A="color=green,\n addpieces=Ke1"

B=[[color=green,
    addpieces=Ke1]]


\end{luacode*}

\chessboard[\directlua{tex.sprint(luatexbase.catcodetables.nlspcatcodes,
A)}]
\chessboard[\directlua{tex.sprint(luatexbase.catcodetables.nlspcatcodes,
B)}]

\begin{lstlisting}[escapeinside={[}{]},escapebegin={[},escapeend={]}]
\chessboard[\directlua{tex.sprint(luatexbase.catcodetables.nlakcatcodes,A)}]
\chessboard[\directlua{tex.sprint(luatexbase.catcodetables.nlspcatcodes,A)}]
\end{lstlisting}

\end{document} 



-- 
Ulrike Fischer 



More information about the luatex mailing list