How can I store a URL in a macro if the URL has a # and/or a % in it? The MWE below works fine for the first two, but not the third one.
Notes:
One solution is to replace the
#with\string#and the%with\%, but wodering if there is an easier way.I realize that this may mess up the syntax highliting, but the
\csdef{}section shown here will be in a separte.deffile that will be be\input{}, so not an issue.
Reference:
Code
\documentclass{article}
\usepackage{etoolbox}
\usepackage{hyperref}
\usepackage{tikz}
\csdef{url Title 1}{The Google}
\csdef{url Link 1}{http://www.google.com}
\csdef{url Title 2}{TeX.SE}
\csdef{url Link 2}{http://tex.stackexchange.com}
%\csdef{url Title 3}{Algebra and Trigonometry:~History of Trigonometry}
%\csdef{url Link 3}{https://books.google.com/books?id=4tFFDwAAQBAJ&pg=PT233&dq=history+of+trigonometry&hl=en&newbks=1&newbks_redir=0&sa=X&ved=2ahUKEwjIzcj0-tnqAhXwFjQIHZ6XDLUQ6AEwAnoECAQQAg#v=onepage&q&f=false}
\def\MaxNUmberOfURLs{5}
\newcommand{\DisplayURLs}{%
\textbf{List of URLs}
\foreach \xCount in {1,...,\MaxNUmberOfURLs} {%
\ifcsdef{url Title \xCount}{%
\par\xCount:
\href{\csuse{url Link \xCount}}{\csuse{url Title \xCount}}
}{}%
}%
}
\begin{document}
\DisplayURLs
\end{document}


\csedef{url Link 3}{\detokenize{https://books.google.com/books?id=4tFFDwAAQBAJ&pg=PT233&dq=history+of+trigonometry&hl=en&newbks=1&newbks_redir=0&sa=X&ved=2ahUKEwjIzcj0-tnqAhXwFjQIHZ6XDLUQ6AEwAnoECAQQAg#v=onepage&q&f=false}}should work. edit Hrmpf: It works in the MWE, but breaks with%. – moewe Jul 19 '20 at 18:49#and/or a%in it?" Isn't this precisely what the\urldefmacro of theurlpackage is supposed to do? E.g.,\urldef{\myURL}\url{https://books.google.com/books?id=4tFFDwAAQBAJ&pg=PT233&dq=history+of+trigonometry&hl=en&newbks=1&newbks_redir=0&sa=X&ved=2ahUKEwjIzcj0-tnqAhXwFjQIHZ6XDLUQ6AEwAnoECAQQAg#v=onepage&q&f=false}– Mico Jul 19 '20 at 19:54\csdefurldefined in moewe's answer works great. – Peter Grill Jul 19 '20 at 20:53