# Using \href with with argument from a list

I would like to define a command that takes an input, passes through a list to generate another variable and then is fed to \href to give a link. As in the following example:

\documentclass[11pt, a4paper]{article}

\usepackage{hyperref}
\usepackage{forarray}

\DefineArrayVar{Names}{@}
{,}{aaa,bbb,ccc}
{,}{Einstein,Newton,Leibnitz}

{\csname Names@#1\endcsname\
}

\begin{document}

Here is a page about \newhref{aaa}.

\end{document}



However the link I obtain is highlighted but doesn't link to anything. What is going wrong? Thank you!

• show a complete example, that makes it much easier to test your code. – Ulrike Fischer Oct 28 '19 at 9:09
• Ok, thanks. I included the \documentclass and end{document} commands. In the exemple above the word Einstein appears linked, but when clicking on it nothing happens. – Francesco Oct 28 '19 at 9:45

The problem is with the \ at the end of the line.

\newcommand{\links}[1]{\csname Names@#1\endcsname}


would solve the issue.

I'd use a friendlier way, though.

\documentclass[11pt, a4paper]{article}

\usepackage{xparse}
\usepackage{hyperref}

\ExplSyntaxOn

% define the array
\NewDocumentCommand{\definearray}{mm}
{% #1 = array name, #2 = items
\prop_new:c { g_francesco_array_#1_prop }
\prop_gset_from_keyval:cn { g_francesco_array_#1_prop } { #2 }
}
% generic command for retrieving a value
\NewExpandableDocumentCommand{\getarrayvalue}{mm}
{% #1 = array name, #2 = array item
\prop_item:cn { g_francesco_array_#1_prop } { #2 }
}

\ExplSyntaxOff

\definearray{Names}{
aaa=Einstein,
bbb=Newton,
ccc=Leibnitz,
}

\newcommand*{\newhref}[1]{%
\href{http://en.wikipedia.org/wiki/\getarrayvalue{Names}{#1}}{\getarrayvalue{Names}{#1}}%
}

\begin{document}

Here is a page about \newhref{aaa}.

\end{document}

• Thank you very much! It solved my problem! – Francesco Oct 28 '19 at 10:33