I have to execute a macro a number of times, and would like to provide a list of the parameters to be executed. So, instead of
\FormatLinks*[Main Search Site]{Google}{http://www.google.com}
\FormatLinks[]{Google}{http://www.google.com}
\FormatLinks{Yahoo}{http://www.yahoo.com}
I would prefer to simply set a list:
\DefineMyFormatLinkParameters{%
*[Main Search Site]{Google}{http://www.google.com},
[]{Google}{http://www.google.com},
{Yahoo}{http://www.yahoo.com},
}
and then execute the \FormatLinks
macro \foreach
each element of this list. I think this is probably some expansion related issue, but I was not able to get it to work. Currently, the output is:
Code:
\documentclass{article}
\usepackage{url}
\usepackage{pgffor}
\usepackage{xparse}
\usepackage{xstring}
\usepackage[colorlinks=true]{hyperref}
\NewDocumentCommand{\FormatLinks}{%
s% #1 =* not used yet
O{}% #2 = optional title
m% #3 = Mandatory title
m% #4 = URL Link
}{%
\par
\IfStrEq{#2}{}{%
\hspace*{1.0cm}\href{#4}{#3}%
}{%
\hspace*{1.0cm}\href{#4}{#3~(#2)}%
}%
}%
\newcommand*{\MyFormatLinkParameters}{}% Initialize
\newcommand*{\DefineMyFormatLinkParameters}[1]{%
\edef\MyFormatLinkParameters{#1}%
}%
\begin{document}
\FormatLinks*[Main Search Site]{Google}{http://www.google.com}
\FormatLinks[]{Google}{http://www.google.com}
\FormatLinks{Yahoo}{http://www.yahoo.com}
% Would prefer to define a list, and later execute the list:
\DefineMyFormatLinkParameters{%
*[Main Search Site]{Google}{http://www.google.com},
[]{Google}{http://www.google.com},
{Yahoo}{http://www.yahoo.com},
}
\bigskip%
Following should produce same results as above:\medskip\par
\foreach \x in \MyFormatLinkParameters {%
\typeout{DEBUG: "\x"}
\FormatLinks{\x}
}
\end{document}