[Tex/LaTex] Command with variable number of arguments to format menu sequences

macros

I would like to define a command that accepts a variable number of arguments:

\menu{foo}
% would result in \emph{foo}

\menu{foo}{bar}
% would result in \emph{foo} $\to$ \emph{bar}

\menu{foo}{bar}{baz}
% would result in \emph{foo} $\to$ \emph{bar} $\to$ \emph{baz}

and so on. Is this possible, and if it is, how can I do this?

Best Answer

Use menukeys … I guess it’s what your looking for ;-)

\documentclass{article}

\usepackage{menukeys}

% create a new simple style to add arrwos between the items
\newmenustylesimple*{arrows}{\CurrentMenuElement}[ $\to$ ]{blacknwhite}

\begin{document}
\menu{foo > bar > baz}

\bigskip

% apply the new style to the old macro. The optional arguments
% defines the separator, the default is a comma
\renewmenumacro{\menu}[>]{arrows}
\menu{foo > bar > baz}
\end{document}

menukeys

The first line shows the default style of \menu, but it’s possible to change it in many ways. The example shows a very simple style. More predefined styles can be found in the manual …

Related Question