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


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.


5 Answers 5


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

enter image description here

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newcommand{\menuitem}{\texttt}% Menu item formatting
\newcommand{\menusep}{\ensuremath{\rightarrow}}% Menu separator
\newcommand{\menuend}{\relax}% Menu end
\newcommand{\menulist}[1]{% \menulist{<menu list>}
  \def\menu@sep{\def\menu@sep{\menusep}}% https://tex.stackexchange.com/a/89187/5764
  \menulistparser{#1}% Process list
\DeclareListParser{\menulistparser}{:}% List separator is ':'

\menulist{File:New:Class}% 3 menu items

\menulist{Tools:Options:Advanced:Properties:Document}% 5 menu items

\menulist{}% 0 menu items/empty list

\menulist{Help}% 1 menu item

\renewcommand{\menusep}{~\rule{1ex}{1ex}~}\renewcommand{\menuend}{!}% Different separator and end


\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, 2012 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.


\NewDocumentCommand{\menuentry}{ O{} m }
   \group_begin: % to segregate local changes to keys and font
   \keys_set:nn { menuentry } { #1 }
   \exp_args:NNx \seq_set_split:Nnn \l_menuentry_seq { \l_menuentry_inputsep_tl } { #2 }
   \tl_use:N \l_menuentry_font_tl
   \bool_set_false:N \l_tmpa_bool
   \seq_map_function:NN \l_menuentry_seq \menuentry_process:n
\NewDocumentCommand{\menuentryset} { m }
  { \keys_set:nn { menuentry } { #1 } }

\tl_new:N \l_menuentry_font_tl
\tl_new:N \l_menuentry_sep_tl
\tl_new:N \l_menuentry_inputsep_tl
\seq_new:N \l_menuentry_seq

\cs_new:Npn \menuentry_process:n #1
   \bool_if:NTF \l_tmpa_bool 
     { \l_menuentry_sep_tl }
     { \bool_set_true:N \l_tmpa_bool }
   \tl_if_empty:nTF { #1 } {EMPTY~ARG!} { #1 }
\keys_define:nn { menuentry }
   menufont .tl_set:N = \l_menuentry_font_tl ,
   menusep  .tl_set:N = \l_menuentry_sep_tl,
   inputsep .tl_set:N = \l_menuentry_inputsep_tl,
\keys_set:nn { menuentry }
   menufont = \sffamily ,
   menusep  = ${}\to{}$


\menuentry{}% 0 menu items/empty list

\menuentry{Help}% 1 menu item

\menuentry{File:New:Class}% 3 menu items

\menuentry{Tools:Options:Advanced:Properties:Document}% 5 menu items

\menuentryset{menufont=\ttfamily,menusep=~>{ },inputsep=/}

\menuentry{Help}% 1 menu item

\menuentry{File/New/Class}% 3 menu items

\menuentry[inputsep=|]{Tools|Options|Advanced|Properties|Document}% 5 menu items


enter image description here


Here's an example using the xstring package

enter image description here

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





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

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

enter image description here


   \foreach \x in {#1} {%

    \Menu{File,New,Class} and then more text.
  • @marc doesn't tikz load pgf? Jan 10, 2012 at 8:32
  • 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?
    – user10274
    Jan 10, 2012 at 8:36
  • @MarcvanDongen: Good suggestion. Have updated the solution. Jan 10, 2012 at 20: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.

enter image description here

\def\alist{Dashboard, Content, Structure, Hello~yannis, Log Out, \test}
\@for \i:=\alist \do{\color{white}
\tiny \lipsum[1-2]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .