# LaTeX macro for Wikipedia article link

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

% takes an article name and gives me a link called 'Wikipedia'


Then I try calling it like this...

 \urlwhitespacereplace{Charlie Bucket} %expected 'Charlie%20Bucket'



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@ {


Could this have something to do with the the escaped % moving between the macros? Thanks for reading.

-
Welcome to TeX.sx! You didn't provide your code for \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
Related/duplicate: Nested macros and hyperlink problem – Qrrbrbirlbel Nov 29 '12 at 22:20

### Notes:

• Wikipedia escapes spaces with an underscore (_)
• Links with space do work, too.
• Nested macros and hyperlink problem, Martin Scharrer:

The correct syntax is \hyperlink{<name>}{<text>} where <name> must be a valid, expandable label name. It can not contain any non-expandable commands. […] The name must instead expand directly to some text only.

## Code

\documentclass{article}
\usepackage{xstring}
\usepackage{hyperref}

\begin{document}
\urlwhitespacereplace{Charlie Bucket} \par % no output
\wikipedialink{Charlie Bucket} \par % no substituting
\end{document}

-
Oh, just a redirect page … :-) – Speravir Nov 29 '12 at 23:57

My texlinks.sty in the morehype bundle provides macros for links to Wikipedia articles, see Section 8 of texlinks.pdf, e.g., just \Wikiref{⟨lemma⟩} for the "current" language. The documentation proceeds from backbones to smarter macros, which may be difficult to understand quickly, sorry.

\documentclass{minimal}

That's "fwiw", haven't studied details of the question. The texlinks.sty macros work without xstring, even with blanks in lemmas, I do not know exactly why, just seeing this here. Only referring to sections of Wikipedia articles needs "escaping" of blanks, umlauts, commas, ... I guess it's the Wikimedia (MediaWiki) engine that converts spaces into underscores etc.