2

I am trying to include link in my references. The link contains % character in it. In order for % to behave as normal character I am escaping it with \ character. But I am getting an

! Missing $ inserted.
<inserted text>
$
l.614 ...ia.org/wiki/Shamir\%27s_Secret_Sharing''}

error.

Here is the line that is producing this error

\hyperref[shamir]{''http://en.wikipedia.org/wiki/Shamir\%27s_Secret_Sharing''}

I am using hyperref package for adding links.

Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
samsri
  • 123
  • You don't need the quotes: \hyperref[shamir]{http://en.wikipedia.org/wiki/Shamir\%27s_Secret_Sharing}. In fact, the ''s put you into mathematics mode, hence the error about a missing $. –  Apr 23 '15 at 06:28

2 Answers2

5

The underscore characters require math mode, they are used for subscripts there. Thus you need \_ here for a underscore character.

Alternatively \url or \nolinkurl can be used. The latter is \url minus the link property.

An example with some variants:

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\begin{document}

\url{http://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing}

\href{http://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing}{%
  \nolinkurl{http://en.wikipedia.org/wiki/Shamir\%27s_Secret_Sharing}}

\urlstyle{same}
\href{http://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing}{%
  \nolinkurl{http://en.wikipedia.org/wiki/Shamir\%27s_Secret_Sharing}}

\href{http://en.wikipedia.org/wiki/Shamir\%27s_Secret_Sharing}{shamir}

\end{document}

Result

Escaping the comment char via \% is needed, if the URL macros are used inside the argument of another macro.

Heiko Oberdiek
  • 271,626
  • Thank you very much for the solution. I replace \hyperref with \url and it solved my problem – samsri Apr 23 '15 at 06:40
2

The problem is not with % but with the underscore! Use this

\hyperref[shamir]{''http://en.wikipedia.org/wiki/Shamir\%27s\_Secret\_Sharing''}