I'm quite new to \LaTeX, but wanted to create a little macro much like \verb.
Specifically, I'm writing a little package, in which I would like to pass an argument (that will quite often be containing special characters like %, #, },...) to Lua. I know it's possible by defining an environment (see this question).
However, I can't find any solution to pass such an argument by a single command. At least not without first save a verbatim text to a variable and then passing it as argument, which isn't quite as practical. All \verb-related packages seem to either be focusing on the verbatim environment, or on a version allowing to use it inside a macro - which doesn't help me.
Edit: a small code snippet to clarify: I have already something like:
<package.lua>
function process(input)
-- do something with input
end
<document.tex>
\passToLua¨<some text with special characters %$[+=\#>¨
But I can't properly define a command that accepts a parameter with these special characters - ideally it would look something like the this (although I know it will probably look much uglier):
<package.sty>
\providecommand{\passToLua}[1]{ % This will need adapting as it doesn't accept %, #, ... in it's argument
\directlua{
require("package")
process([[#1]])
}
}
Anyone got an idea? A huge thanks in advance!
\newcommand\foo[1]{\directlua{s="\luaescapestring{\detokenize{#1}}"}may be what you are looking for – David Carlisle Dec 25 '22 at 21:19