I made a simple macro called \cmd{}
which detokenizes the input. I would like to print the contents exactly as shown, and it works as I desire, except that it seems to produce a space between an inputted command sequence and the curly braces.
\documentclass{article}
\newcommand{\cmd}[1]{\texttt{\detokenize{#1}}}
\begin{document}
\cmd{\test{}}
\end{document}
results in \test {}
Edit: I would like a verbatim-like macro called \cmd{}
that does the following:
\cmd{\test{}}
→ \test{}
Edit: I did try the solutions posed in Detokenizing without extra spaces?, but have had no luck. I am using LuaLaTeX.
\verb
, but this sounds like an XY problem: what exactly are you after?\detokenize
does. If your argument is a single control sequence,\string
can produce it without the space. What is your actual use case?\detokenize
is like writing tokens unexpanded to an external file and then inputting the external file under a category code régime where the space character has category code 10 (space) and all other characters have category code 12(other) and\endlinechar
has a negative value.\newlinechar
is obeyed with the writing-part. When writing a control word token, TeX automatically appends a space character. Another peculiarity of TeX's way of writing tokens is: When writing an explicit hash of category 6(parameter) that gets doubled.