1

The following is the code of the file temptest.sty

\ProvidesPackage{temptest}
\RequirePackage{amsmath,amssymb}
\RequirePackage{xkeyval}
\RequirePackage{luacode}
\begin{luacode*}
function myfunc(m,n)
    m=m or ''
  n=n or ''
return (m .. n)
end
\end{luacode*}
% ========= KEY DEFINITIONS =========
\define@key{luatest}{label}{\def\luatst@label{#1}}
% ========= KEY DEFAULTS =========
\setkeys{luatest}{label=$xyz$}%
% ========= Defining Command =========
\newcommand{\luaTest}[2][]{%
  \setkeys{luatest}{#1}
  \directlua{tex.sprint(myfunc(\luastringN{#2},'\luatst@label'))}}%
\endinput

The following is the code of test.tex file.

\documentclass{article}
\usepackage{temptest}
\begin{document}
\luaTest[label=$(\\mathbb{R}{,} 3)$]{some string }
\end{document}

It works fine and give the expected output. However I am facing two issues.

1.The backslash needs to be escaped as it is escape character in lua.

2.The comma should be written in curly braces (probably because it might take the text following after comma as an argument to lua function).

Accordingly my queries are:

1.Can I use some macro like \luastringN for writing \ instead of \\?

2.Can I simply type , instead of {,}?

The basic question is how to pass string with escape characters and comma through xkeyval package while compiling the document with LuaLaTeX?

1 Answer 1

3

Your first point is easy to fix. Just store \luastringN{#1} in your key code instead of #1 (I'm using it inside of \edef giving better robustness, now you could also use a macro parameter in your value, it has to stay valid TeX code though).

I'm afraid there's nothing you can do about the comma hiding, it's the separator for different keys of xkeyval (and (almost, YaX can be weird) all the other key=value packages). But you could at least wrap the entire value in {} instead of just the comma (that way you don't change the math category of it, {,} is an atom and has other spacing than just ,).

\documentclass{article}

\makeatletter
\RequirePackage{amsmath,amssymb}
\RequirePackage{xkeyval}
\RequirePackage{luacode}
\begin{luacode*}
function myfunc(m,n)
  m=m or ''
  n=n or ''
  return (m .. n)
end
\end{luacode*}

% ========= KEY DEFINITIONS =========
\define@key{luatest}{label}{\edef\luatst@label{\luastringN{#1}}}
% ========= KEY DEFAULTS =========
\setkeys{luatest}{label=$xyz$}%
% ========= Defining Command =========
\newcommand{\luaTest}[2][]{%
  \setkeys{luatest}{#1}
  \directlua{tex.sprint(myfunc(\luastringN{#2},\luatst@label))}}%
\makeatother

\begin{document}
\luaTest[label={$(\mathbb{R}, 3)$}]{some string }
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .