12

I want to add a hyperlink

\documentclass{article}

\usepackage{hyperref}

\begin{document}
\href{http://de.wikipedia.org/wiki/Hybridorbital#Beispiele}
     {http://de.wikipedia.org/wiki/Hybridorbital#Beispiele}
\end{document}

which has a # in the link, however if I enter it as \# Beispiele it won't open the link in the PDF and only if I leave the section after # will it open the page. However, I want it to open at a specific section in the webpage, which is coded by the # part.

  • Welcome to TeX.sx! Please note that you can mark inline code with back ticks like `code`. Furthermore I made a minimal working example (MWE) of your code but adding a documentclass. – Tobi Apr 2 '13 at 11:10
  • Do you really mean \\# Beispiele and not \# Beispiele (single backslash)? – Tobi Apr 2 '13 at 11:11
12

You have to prefix the hash with a backslash:

\href{http://de.wikipedia.org/wiki/Hybridorbital#Beispiele}
{http://de.wikipedia.org/wiki/Hybridorbital\#Beispiele}

Now it should work ;)

  • 2
    Note that the prefixed backslash is only necessary in the second argument which is the on to be typset by the TeX engin and therefore must respect TeX special symbols (which # is one of). The first argument is the verbatim link an though doesn’t need special cares on symbols. – Tobi Apr 2 '13 at 11:05
  • 1
    I got it now! My mistake was that I wrote \# Beispiel instead of \#Beispiel (without space in between) because I thought it wouldn't recognise the second command. – gasserv Apr 2 '13 at 11:11
8

use \url instead:

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\url{http://de.wikipedia.org/wiki/Hybridorbital#Beispiele}
\end{document}
  • 1
    Didn't think of that :) Note that \url typesets the url in typewriter font by default. – Peater de Xel Apr 2 '13 at 11:04
  • 6
    Just use \urlstyle{same} to change this behaviour. @Micha may like to add this to the answer. – Tobi Apr 2 '13 at 11:06

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.