Site icon texblog

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}
\usepackage[os=mac, mackeys=symbols]{menukeys}

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

 

Loading the package

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
\usepackage[os=win]{menukeys}

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

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

A full list of special keys is given below.

 

Menu sequences

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}
\usepackage{menukeys}

\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}
\usepackage{menukeys}

\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}
\usepackage{menukeys}

\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
\usepackage[os=mac, mackeys=symbols]{menukeys}

\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{\directory}{pathswithfolder} % default: paths
\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
\usepackage{menukeys}

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

\renewmenumacro{\directory}[,]{paths}
\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.

Exit mobile version