unwanted space after a command

Hartmut Henkel hartmut_henkel at gmx.de
Mon Oct 25 16:43:38 CEST 2021


Hi Gary,

On Mon, 25 Oct 2021, Gray, Gary L. wrote:
> I have defined several commands that look like:
>
> \providecommand{\fn}[1]{\textcolor{DarkOrange3}{\texttt{\detokenize{#1}}}}
>
> to use when entering computer code in documents for the classes I
> teach. I like the command because it allows me to put underscores or
> anything else I need in it. The command works nicely if I do something
> like:
>
> \fn{legendreP(n,x)}
>
> but if I have a backslash in the command, an extra space is added
> after the command. For example, with
>
> \fn{w = A\b}.
>
> there is a space between the "b" and the period. How can I define a
> command like this that doesn't add that extra space?

e. g.,

\documentclass{article}
\usepackage{color}
\providecommand{\fn}[1]{\textcolor{red}{\texttt{\detokenize{#1}\unskip}}}
\begin{document}
\fn{legendreP(n,x)}
\fn{w = A\b}.
\end{document}

...but not checked what's the cause of the space, in \detokenize.

Best Regards, Hartmut


More information about the texhax mailing list.