# Menukeys: typesetting menu sequences, directory path names and keyboard shortcuts in LaTeX

I recently came across the menukeys package and found it very useful for software documentation and description of workflows. The output it creates is quite neat. Therefore, I will briefly introduce the main features and give some examples here.

##### An example at the beginning

\documentclass{article}
\usepackage[T1]{fontenc}

\begin{document}
\noindent For saving a file to the desktop, go to \menu[,]{File, Save As...} and navigate to \directory{Users/Username/Desktop}. Alternatively, use the following keyboard shortcuts: \keys{\cmd+\shift+S} and \keys{\cmd+D}.
\end{document}

##### Getting the package

The package comes with the texlive distribution. Alternatively, you can download it from CTAN or the author’s GitHub repository.

As for any package, menukeys is loaded in the document preamble:

\usepackage{menukeys}

##### Package options

The package implements several options. They handle the differences in keys or key modifiers between different operating systems and are therefore only required when typesetting keyboard shortcuts.

%Windows

%Mac OS X (symbols)

%Mac OS X (text)
\usepackage[os=mac, mackeys=text]{menukeys}

A full list of special keys is given below.

Typesetting menu sequences becomes useful for documenting a software’s graphical user interface or to keep track of a series of actions in a complex analysis workflow. The command is straight forward:

\documentclass{article}

\begin{document}
\menu[,]{Item 1, Item 2, Item 3, ...}
\end{document}

The optional argument [,] changes the default separator to comma (,). Due to a conflict with HTML, I can’t use the package’s default separator, the greater than symbol (>), in the code here on my blog.

##### Directory path names

The default separator for directory path names is the forward slash (/), which is converted to a small arrow-head in the output.

\documentclass{article}

\begin{document}
\directory{Item 1 / Item 2 / Item 3 / ...}
\end{document}

##### Keyboard shortcuts

Keyboard shortcuts describe combinations of keys to be pressed for a certain action. The default separator used between keys is the plus symbol (+).

\documentclass{article}

\begin{document}
\keys{Item 1 + Item 2 + Item 3 + ...}
\end{document}

Below a list of key macros copied from the package documentation.

Here is an example of how to describe the keyboard shortcut to create a custom-size screen grab on Mac OS X using Mac keyboard symbols:

\documentclass{article}
\usepackage[T1]{fontenc} % required for Mac command key rendering

\begin{document}
\keys{\cmd + \shift + 4}
\end{document}

##### Changing the style

The package comes with a set of styles. Some styles change the look only subtly, others more drastically. See chapter 4.2 of the package documentation for a complete list of styles available. To change the style, the package provides the following macro:

\renewmenumacro{list}[separator]{style}

A few examples:

\renewmenumacro{\menu}{roundedmenus} % default: menus
\renewmenumacro{\keys}{shadowedroundedkeys} % default: roundedkeys

##### Changing the default separator

Each command has its specific default separator, as described earlier. Simply use the optional argument to change the default separator. This will not, however, change the way the output looks, only the way a command is typed. E.g. the following command changes the key default separator locally to comma.

\keys[,]{\cmd, \shift, 4}

To change the separator globally (preamble) or from a certain position onwards, use the same macro as for changing the style. Here is an example:

\documentclass{article}
\parindent=0pt

\begin{document}
\directory{Item 1 / Item 2 / Item 3 / ...} % default separator

\directory{Item 1, Item 2, Item 3, ...} % comma as separator
\end{document}

The output is exactly the same.

Final note: Spaces added before or after the separator will be ignored by the package, i.e. a + b, a+ b, and a+b produce exactly the same result.

See the package documentation for a complete list of separators available.

#### 9 Responses to “Menukeys: typesetting menu sequences, directory path names and keyboard shortcuts in LaTeX”

• mbork

Very nice, though I can see that you can only say os=mac or os=win. This means that the two operating systems I use are excluded… Maybe I’ll contact the package auhor about it. I guess that for os=linux not many changes would be required, but os=emacs would definitely need some work;).

• tom

Thanks for your comment! It does’t necessarily mean Linux is not supported. It only means that Linux does’t have any OS-specific buttons like the command key on an Apple or the Windows key on a Windows keyboard.

Tom.

• mbork

Well, my Ubuntu box calls the Windoze key “Super”. And Emacs has its M-x, C-c etc. (basically M (Meta) instead of Alt, C for Control, for Enter etc., and a hyphen instead of a plus sign). I guess it would be easy to implement, and being able to have an option “os=emacs” would be soooo cute;)…

• mbork

Aaargh, your blog engine ate my less than/greater than signs. Of course, Enter is called [RET] in Emacs, with “angle brackets” instead of normal ones.

• tom

I really encourage you to contact the package author to tell him about your ideas. He was extremely friendly and helpful when I got in touch with him while writing the post.