6

How do I place the url:

https://en.wikipedia.org/wiki/Ugarit#/media/File:Ugarit_02.jpg

into a PDF:

\href{https://en.wikipedia.org/wiki/Ugarit#/media/File:Ugarit_02.jpg}{Loris Romito}

I end up with errors like this, which are not overly helpful:

618: Illegal parameter number in definition of \iterate.
Jay
  • 815
  • 2
    Welcome to TeX.SX!! Rather than posting code fragments it is better to give a full minimal working example. Your code works for me so the problem is in something else that you are doing and we have to guess what that is. A MWE should start with a \documentclass command, have a minimal preamble and then \begin{document}...\end{document}. The code should compile and be as small as possible to demonstrate your problem. Cutting your code down to a MWE may well reveal what your problem actually is. –  Apr 27 '17 at 00:15
  • @Andrew The code should NOT compile in this case. It should produce the error the OP wants help with. – cfr Apr 27 '17 at 01:07
  • @cfr True...my standard comment for this says this but, with edits, it was too long to fix in the comment box so I deleted this clause... –  Apr 27 '17 at 02:45
  • 1
    Try `#' It's what I use in \href. – John Kormylo Apr 27 '17 at 03:38
  • The documentation for href implies that all escaping is turned off within the url parameter, so I was unsure what should or shouldn't be escaped. I thought I tried that, i'll try it again. – Jay Apr 27 '17 at 05:37
  • 1
    @Jacob: When I try your code snippet as-is in a minimal example, I get no error and the URL is properly sourced when I click on the hyperlinked text. So, perhaps you need to provide more information for us to replicate the issue... – Werner Apr 27 '17 at 06:15
  • It's probably easier just to use bit.ly or similar service to redirect to the tricky url. – Seamus Apr 27 '17 at 08:11
  • Almost same question as Having trouble with Tikz and Beamer - TeX - LaTeX Stack Exchange except that this one also have catcode issue, and escaping the # happens to solve both. – user202729 Jul 29 '22 at 05:02

2 Answers2

12

You are using the \href in the argument of some other command. This will break as \href no longer can change the catcode of the #. The exact error message depends on the outer command, but will normally report an Illegal parameter. In such cases you can excape the #:

\documentclass{article}
\usepackage{hyperref}
\begin{document}

%works fine:
\href{https://en.wikipedia.org/wiki/Ugarit#/media/File:Ugarit_02.jpg}{Loris Romito}

%fails:
%\textbf{\href{https://en.wikipedia.org/wiki/Ugarit#/media/File:Ugarit_02.jpg}{Loris Romito}}

%workaround: escape the #:
\textbf{\href{https://en.wikipedia.org/wiki/Ugarit\#/media/File:Ugarit_02.jpg}{Loris Romito}}

\end{document}
Ulrike Fischer
  • 327,261
  • Is there somewhere I can find a list of these illegal parameters? I'm not sure how to handle this for dynamic URLs. – Akaisteph7 Jan 17 '23 at 21:06
-1

You can try with "url" or "breakurl" package and the tag is \url{...}, all the special characters are allowed for web link. And these packages having support with "hyperref" package...

cgnieder
  • 66,645
MadyYuvi
  • 13,693
  • 1
    That does not solve the problem of the question: he already uses a command allowing special characters in urls as you can see in hyperref's \href macro. But try this: \documentclass{article} \usepackage{url} \begin{document} \textbf{\url{http://www.foo.de/#bla}}} \end{document} and you'll see that \url has the same problem when used inside another macro… – cgnieder Apr 28 '17 at 08:23