I see this code in the book's source "The Not So Short Introduction to LaTeX":

\newcommand{\CTANref}{\begingroup \urlstyle{tt}\Url}     %
  1. Why is there no \endgroup in CTANref?
  2. Is \def\CTAN|#1| same as \def\CTAN[#1]?
  3. Why use \def and \newcommand both? Couldn't \newcommand at both places have worked?
  4. How can I implement the above using just one macro?
  • 2
    you can not define a command with | delimited arguments using \newcommand Commented May 17, 2023 at 10:28
  • I wouldn't take this code as a model for something, there is no real reason visible why a delimited argument is used here. Commented May 17, 2023 at 13:10
  • There are 2 delimited arguments here. After some experimentation, I found out how \def delimited arguments work. If I use \def\CTAN|#1|, I have to use \CTAN|someting| to expand it, if I use \def\CTAN<#1<, I have to use \CTAN<something<. But I still don't get it how \CTANref|CTAN://#1| works. Its like CTAN://#1 is an argument to \CTANref, and yet that it has not been defined to take in any arguments. Could you throw some light on it?
    – fishfin
    Commented May 18, 2023 at 3:46

1 Answer 1


The reason is that \Url will provide the missing \endgroup.

One sees in url.sty the definition of \url:

\def\DeclareUrlCommand#1#2{\def#1{\leavevmode\begingroup #2\Url}}

% Sample (and default) configuration:

which means it does


The code you quote is modeled on this. The actual \endgroup comes from \Url@z in particular. Check url.sty source code.

  • I looked into url.sty, but I did not understand much, I have not mastered TeX enough. For now however, this is sufficient for me to know \endgroup happened becasue \Url provided it internally, and \leavevmode and \Url@z are my pointers for the future.
    – fishfin
    Commented May 18, 2023 at 3:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .