The minimal example below should replace all # characters with another symbol. This works well if I use \#
to escape it, but the user should later be able to enter it directly, e.g. to enter hash tags.
I understand that # is a special character, but I'd like a solution without tinkering with character classes and patching macros (we need it # as special character at the same time to get the parameter value).
FYI: The overall goal of this is a package to create "Share on Twitter" links.
\documentclass{minimal}
\usepackage{luacode}
\newcommand{\Test}[1]{
\luaexec{
local x = string.gsub("#1", "\#", "+")
tex.print(x)
}
}
\begin{document}
\Test{With backslash: \#} % Yields "Wit backslash: +"
\Test{Without backslash: #} % Yields "Without backslash: + +"
\end{document}