Generalhyperref | Ampersand Problem in URL

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
apollo_el
Posts: 9
Joined: Sat Sep 17, 2011 12:16 am

hyperref | Ampersand Problem in URL

Post by apollo_el »

Greetings,

I need to have an ampersand (&) in my url. I have to escape it by \& to be able to compile my latex code. When I produce the .pdf file with the clickable hyperlink, in the url the whole \& is shown and destroys the link.
Anybody knows a workaround?

i.e. I would like to have:

Code: Select all

\href{http://whatever.something.com/getFile.py/access?contribId=34&sessionId=12&resId=0&materialId=slides&confId=1234}{mytextgoeshere}
Regards

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

hyperref | Ampersand Problem in URL

Post by localghost »

Somehow I don't see the problem.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{hyperref}

\begin{document}
  \href{http://www.latex-community.org/forum/viewtopic.php?f=5&t=15253}{Your question on \LaTeX-Community}
\end{document}
So you better provide a proper minimal example that clearly shows the problem.


Thorsten
apollo_el
Posts: 9
Joined: Sat Sep 17, 2011 12:16 am

hyperref | Ampersand Problem in URL

Post by apollo_el »

Thank you for your prompt reply. What you suggest above works for me, as well. Hence, I followed your advice. I minimized my code, for obvious reasons:

Code: Select all

\documentclass[11pt,a4paper]{moderncv}
% character encoding
\usepackage[utf8]{inputenc} 

\usepackage{hyperref} 

% moderncv themes
\moderncvtheme[blue]{casual}                 
               

% adjust the page margins
\usepackage[scale=0.8]{geometry}

% personal data
\firstname{John}
\familyname{Doe}

\begin{document}
\maketitle

\section{Interests}
\cvitem{}{\href{http://www.latex-community.org/forum/viewtopic.php?f=5&t=15253}{Your question on \LaTeX-Community}}

\end{document}

Replacing the above url link with something that does not contain "&", i.e. \href{http://www.latex-community.org/forum/vi ... }....poses no problems when compiling.

p.s. I am using this: http://www.ctan.org/tex-archive/macros/ ... b/moderncv

I hope my question is more clear now. Any ideas?

Thanks in advance
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

hyperref | Ampersand Problem in URL

Post by localghost »

Now an then you should listen to the compiler and what it tells you in the log file. When processing your example, I get a clear error message.

Code: Select all

! LaTeX Error: Option clash for package hyperref.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.18 \begin{document}
This is caused by the fact that you load the hyperref package. The package is already loaded by the class. If you drop it, things will work flawlessly.
apollo_el
Posts: 9
Joined: Sat Sep 17, 2011 12:16 am

Re: hyperref | Ampersand Problem in URL

Post by apollo_el »

No Sir. I beg to differ. This aint the problem.
I actually included the \hyperref just to put things on the same footing, compared to your previous example.
Dropping it makes no difference, at least in my case.

Speaking of listening to the compiler, now and then, this is what it gives me:


Package hyperref Warning: Option `pdfstartpage' has already been used,
(hyperref) setting the option has no effect on input line 18.

Runaway argument?
http://www.latex-community.org/forum/vi ... 5\@endpbox
! Forbidden control sequence found while scanning use of \href@split.
<inserted text>
\par
l.22 ...15253}{Your question on \LaTeX-Community}}

?

Perhaps somebody who can understand what the compiler wants, could enlighten me.

Cheers
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

hyperref | Ampersand Problem in URL

Post by localghost »

The first part you cited is part of a warning. I also get four of them. But the second part of your citation is part of an error message (obviously different to mine). Dropping hyperref makes compilation run smoothly. I recommend to update your TeX system.
apollo_el
Posts: 9
Joined: Sat Sep 17, 2011 12:16 am

hyperref | Ampersand Problem in URL

Post by apollo_el »

Today, I figured this out, thus I'm replying to this post, for any future readers. The problem was with PCTeX 6.1, which was using an old (2007) version of the hyperref package. I downloaded the latest one from http://www.tug.org/applications/hyperref/ (the TDS format), and copied pasted the files to their respective locations. After that, it was a matter of using "\&" in the url, i.e.:

Code: Select all

\href{http://www.latex-community.org/forum/viewtopic.php?f=5\&t=15253}{Your question on \LaTeX-Community}
"! Forbidden control sequence found while scanning use of \href@split."
This issue has been reported in the past and one of the authors of the hyperref package replied (for example) here:

http://newsgroups.derkeiler.com/Archive ... 00978.html

In case you get another error during compilation, about save_size exceeded....just change the value to a higher one, in the texmf.cnf file of your LaTeX distribution and save. In my case, I had to change it to:

save_size = 50000 % for saving values outside current group

to compile w/o any errors. And...voila it works now.
Post Reply