# Create a command for 'menu sequences'

I'm trying to create an extendable command that can take in a single argument (possibly in the following form):

\menuentry{File:New:Class}


And generate something like:

\texttt{File -> New -> Class}


The issue is that the arguments have to be flexible. I should be able to provide any depth of menus. The reason for doing this is that I might want to change the formatting later on and I don't want to have to replace all the texttts manually.

-

The etoolbox package is rich with list processing options. Here's one attempt.

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
}
\makeatother
\begin{document}

\end{document}


\DeclareListParser{<cmd>}{<sep>} declares a list parser command <cmd> that processes a single argument as a list, with list item separator <sep>. The use of this definition is to accommodate an item:item:item:... style list. For regular CSV lists, you could also use \docsvlist which is predefined as \DeclareListParser{\docsvlist}{,} by etoolbox.

The main command \menulist{<menu list>} parses the list and formats each entry using \menuitem{..} but also adds a custom separator \menusep. The last menu item is followed by \menuend. The \menusep is applied with a "single delay" using one of the Cunning LaTeX tricks.

-
All the answers are good but this one seems to be the most robust. So, I'll accept this one. –  recluze Jan 10 '12 at 6:25

A LaTeX3 solution; some input and output parameters are customizable via a key-value syntax. Notice that the default delimiter : must be set after \ExplSyntaxOff. Keys set in the optional argument of \menuentry are local to that command only.

\documentclass{article}
\usepackage{xparse}

\ExplSyntaxOn
{
\group_begin: % to segregate local changes to keys and font
\keys_set:nn { menuentry } { #1 }
\bool_set_false:N \l_tmpa_bool
\group_end:
}
{ \keys_set:nn { menuentry } { #1 } }

{
\bool_if:NTF \l_tmpa_bool
{ \bool_set_true:N \l_tmpa_bool }
\tl_if_empty:nTF { #1 } {EMPTY~ARG!} { #1 }
}
{
}
{
menusep  = ${}\to{}$
}
\ExplSyntaxOff

\begin{document}

\end{document}


-

Here's an example using the xstring package

Have a look at the documentation- there are a lot of other commands that could help you customize this command.

\documentclass{article}
\usepackage{xstring}

\newcommand{\menuentry}[1]{\StrSubstitute{#1}{:}{$\rightarrow$}[\dummy]\texttt{\dummy}}

\begin{document}

\end{document}

-
If you're going to use math mode, isn't it better to write $\rightarrow$ instead of faux-arrows? –  Ryan Reich Jan 10 '12 at 5:38
@RyanReich yes, completely agree :) Looks like Werner did too- thanks! –  cmhughes Jan 10 '12 at 17:13

You can place the menu items in a list and iterate over it. Here is a short MWE as to how to iterate over the list. I have included for a small image uncomment the relevant line to include your own.

\documentclass[justified]{tufte-book}
\usepackage{lipsum}
\begin{document}
\def\spacer{\hspace{3pt}}
\def\test{}
\def\alist{Dashboard, Content, Structure, Hello~yannis, Log Out, \test}
\makeatletter
\noindent\fbox{%
\begin{minipage}{9cm}
\noindent\colorbox{black}{\small
\@for \i:=\alist \do{\color{white}
\texttt\i\spacer
}}
\smallskip
\tiny \lipsum[1-2]
\end{minipage}}
\makeatother
\end{document}

-

Adapting my solution from Micro-graphics inline in text you can use the \foreach from the pgf package to iterate over the list:

\documentclass{article}
\usepackage{tikz}
\usepackage{etoolbox}

\newtoggle{FirstOne}%
\toggletrue{FirstOne}%
\foreach \x in {#1} {%
\iftoggle{FirstOne}{}{${}\rightarrow{}$}%
\texttt{\x}%
\global\togglefalse{FirstOne}%
}%
}%

\begin{document}

As a minor comment, the construct a$\rightarrow$b doesn't look as good as $a \rightarrow b$. Perhaps you could change it to a${}\rightarrow{}$b? –  Marc van Dongen Jan 10 '12 at 8:36