How can I apply formatting to specific menu items or keys or directories in menukeys?

For example, is it possible to color the last item in a menu from the menukeys package? Is there a way to make a macro out of making every last item in menu bold? I would like this macro to work globally.

It would be nice to know how to interact directly with each component in menus and directories.

The example from the menukeys Manual, 2014/03/10 — v1.3 page 9:

The more advanced command is \newmenustyle. It has nine arguments: \newmenustyle⟨* ⟩{⟨name⟩}[⟨pre⟩]{⟨first⟩} [⟨sep⟩]{⟨mid⟩}{⟨last⟩}{⟨single⟩} [⟨post⟩]{⟨theme⟩}.

Example: \newmenustyle{mystyle}[$\bullet$]{draw,red}[$\ast$]% {draw}{draw,red}{draw,dashed}[$\bullet$]

results in:

Runaway argument? ./menukeystest.tex:11: Paragraph ended before \tw@declare@sytle@extra@args was complete.

Code

\documentclass{article}

\usepackage{fontspec}
\usepackage{xcolor}

\renewmenumacro{\directory}{pathswithfolder} % default: paths
% better/official:

\begin{document}

\menu{Macros>AppleScript>Show Files} <-- Color last item

\menu{Macros>AppleScript>\textbf{Show Files}} <-- Make last item bold

\directory{/home/user/Desktop}

\keys{SHIFT + H}

\button{Start Process}

\end{document}


Simulated Output

• The font is bold, in my point of view – user31729 Oct 15 '15 at 10:04
• Untested, but see the menukeys documentation, section 'Declaring styles': last is the style for the last list element. – Marijn Oct 15 '15 at 10:17
• @Marijn I think there is a problem with the documentation, because the example does not work. It does not demonstrate how to implement mystyle. I defined it using the example and implemented like this: \renewmenumacro{\menu}[>]{roundedmenus,mystyle} – Jonathan Komar Oct 15 '15 at 11:05
• @macmadness86 you are right about the example in the manual, it has eight arguments while there should be nine - adding, e.g., {grey} at the end resolves the error. I've edited your post (for future reference) to try to focus the question on the actual issue which is nicely illustrated by your MWE and desired output. – Marijn Oct 16 '15 at 9:22
• @Marijn Thanks. Edits are mostly fine. Although, I am not sure that the removal of the last key is helpful for future reference. Afterall, it is essential in formatting the last constituent in \menu. – Jonathan Komar Oct 16 '15 at 13:45

Here a solution:

1. create two copy roundedmenusA and roundedmenusB from roundedmenus.
2. modify those two styles to get the desired effects.

Code

\documentclass{article}

\usepackage{fontspec}
\usepackage{xcolor}

\def\lastcolor{blue!50}

\makeatletter

% modify style roundedmenusA

\tikz[baseline={($(tw@node.base)+(0,-0.2ex)$)}]{%
}[\hspace{-0.2em}\hspace{0em plus 0.1em minus 0.05em}]%
{%
\tikz[baseline={($(tw@node.base)+(0,-0.2ex)$)}]{%
}{%
\tikz[baseline={($(tw@node.base)+(0,-0.2ex)$)}]{%
}{%
\tikz[baseline={($(tw@node.base)+(0,-0.2ex)$)}]{%
}{gray}

% modify style roundedmenusB

\tikz[baseline={($(tw@node.base)+(0,-0.2ex)$)}]{%
}[\hspace{-0.2em}\hspace{0em plus 0.1em minus 0.05em}]%
{%
\tikz[baseline={($(tw@node.base)+(0,-0.2ex)$)}]{%
}{%
\tikz[baseline={($(tw@node.base)+(0,-0.2ex)$)}]{%
}{%
\tikz[baseline={($(tw@node.base)+(0,-0.2ex)$)}]{%
}{gray}

\makeatother

\renewmenumacro{\directory}{pathswithfolder} % default: paths

\begin{document}

\menu{Macros>AppleScript>Show Files} <-- Color last item

\menu{Macros>AppleScript>Show Files} <-- Make last item bold

\directory{/home/user/Desktop}

\keys{SHIFT + H}

\button{Start Process}

\end{document}


Output

Note: you can also obtain the desired effects with \changemenuelement or \renewmenustyle, but problems of alignment appear.

• Why are there four nodes per style? Could you explain what is going on there? – Jonathan Komar Oct 21 '15 at 7:38
• @macmadness86: The four nodes are: single element, first of multiple elements, last of multiple elements and others in multiple elements (arguments not in this order). – Tobi Jan 24 '17 at 12:18