I'd like to create a LaTeX macro that will auto-create a link to a Wikipedia page for me.
\usepackage{xstring}
\usepackage{hyperref}
% replaces the whitespace with '%20'
\newcommand{\urlwhitespacereplace}[1]{\StrSubstitute{#1}{ }{\%20}}
% takes an article name, replaces the whitespace, and concatenates to form the full URL
\newcommand{\wikipedialink}[1]{http://en.wikipedia.org/wiki/\urlwhitespacereplace{#1}}
% takes an article name and gives me a link called 'Wikipedia'
\newcommand{\anonymouswikipedialink}[1]{\href{\wikipedialink{#1}}{Wikipedia}}
Then I try calling it like this...
\urlwhitespacereplace{Charlie Bucket} %expected 'Charlie%20Bucket'
\wikipedialink{Charlie Bucket} %expected 'http://en.wikipedia.org/wiki/Charlie%20Bucket'
\namedwikipedialink{Charlie Bucket} %expected 'Wikipedia' (hyperlink)
The first two work, returning exactly what you'd expect. However, when I use the third, I get...
! TeX capacity exceeded, sorry [input stack size=5000].
\Hy@href {->\hyper@normalise
\href@ {
l.11 \namedwikipedialink{Charlie Bucket}
Could this have something to do with the the escaped % moving between the macros? Thanks for reading.
\namedwikipedialink, please try to provide it in a minimal working example (MWE) (starting with\documentclass{...}and ending with\end{document}) so we reproduce your situation and find out what the issue is when we see compilable code. – Silke Nov 29 '12 at 22:00