I have a command:


and another


They don't work with



  • Commands like \url change the catcode of % at execution and change back after they finish the job. Maybe you can do the same thing.
    – Symbol 1
    Mar 4 at 15:46

As @Symbol 1 suggested in a comment, changing the catcode of % before the argument is absorbed is essential. And then making sure it is changed back when done, is equally essential.

\newcommand{\code}{\catcode`\%=12 \codeaux}

Test% if these print or not

enter image description here

The alternative approach is to use grouping to negate the catcode change upon exit:

\newcommand{\code}{\begingroup\catcode`\%=12 \codeaux}

Test% if these print or not
  • 1
    it should be \newcommand\codeaux[1]{\endgroup\texttt{\detokenize{#1}}}. Your version doesn't close the group. Mar 4 at 16:04
  • Should there be an \endgroup in codeaux? If so, the change back is unnecessary. Also, why not simply use \verb".."? Mar 4 at 16:07
  • @HerbSchulz Yes, thanks. Mar 4 at 16:10
  • @UlrikeFischer yes, will fix Mar 4 at 16:10
  • So is this then the response to the first part of my question: ```\newcommand{\help}[2]{\href{rdocumentation.org/packages/#1/functions/#2}{\code{?}\code{#2}}}}``
    – mk9y
    Mar 5 at 1:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.