Illegal parameter number in definition

1,239

Why don't use

\documentclass{article}

\usepackage{hyperref}

\begin{document}
\url{https://docs.oracle.com/javase/8/docs/technotes/guides/collections/designfaq.html#a14}
\end{document}

But take care! Shorten your link or use \href with a good description, because such a long link makes the document looks bad.

Share:
1,239
mrbela
Author by

mrbela

Updated on April 26, 2020

Comments

  • mrbela
    mrbela over 3 years

    I found a nice solution to edit the look of hyperlinks, but I have another problem:

    \documentclass{article}
    
    \usepackage{hyperref}
    \newcommand{\link}[1]{\href{#1}{#1}}
    
    \begin{document}
    
    % error: Illegal parameter number in definition of \Hy@tempa. ...tes/guides/collections/designfaq.html#a14}
    \link{https://docs.oracle.com/javase/8/docs/technotes/guides/collections/designfaq.html#a14}
    %   \href{https://docs.oracle.com/javase/8/docs/technotes/guides/collections/designfaq.html#a14}{Test}
    
    \end{document}
    

    Why does \link{...} not work? Exact the same url does work with \href{...}{...}.

    Thank you for your help!!

    • Admin
      Admin over 4 years
      You have \url for this
    • Ulrike Fischer
      Ulrike Fischer over 4 years
      You shouldn't put a full url in an argument. hyperref then no longer can do its catcode magic. There is a reason why the "nice" solution got only one upvote, and my answer got accepted.
    • Admin
      Admin over 4 years
      If you replace the # in the URL by \# it works.
  • mrbela
    mrbela over 4 years
    I need a description, so I wanted to use something like \newcommand{\link}[2]{\href{#1}{#2}}, but the \link does not work at all.. But a direct call with the same URL and description works with \href. What's the reason for this?
  • Admin
    Admin over 4 years
    @mrbela Well, description of tex.stackexchange.com, for example, should be TeX.SE or TeX.SX or TeX StackExchange, but not tex.stackexchange.com itself. It is not a description anymore
  • Ulrich Diez
    Ulrich Diez over 4 years
    @mrbela So the syntax of \link would be the same as the syntax of \href. If you insist in having the thing named \link, you can "copy" the\href-macro via \let\link=\href. By the way: The reason why using the \link-macro does not work out as expected is: Both \url and \href change the category-code-régime (e.g., the catcode of #) before LaTeX reads their arguments from the .tex-input-file and tokenizes them. This change of category-code-régime is outmaneuvered by having LaTeX read and tokenize the arguments for the \link-macro under unchanged category-code régime.