4

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

\renewmenumacro{\directory}[/]{paths}
\renewmenumacro{\menu}[>]{roundedmenus} % default: menus
\renewmenumacro{\directory}{pathswithfolder} % default: paths
\renewmenumacro{\keys}{shadowedroundedkeys} % default: roundedkeys
% \newcommand{\button}[1]{{\renewmenumacro{\keys}{roundedkeys}\keys{#1}}}
% better/official:
\newmenumacro{\button}[+]{roundkeys}

\begin{document}

\menu{Macros>AppleScript>Show Files}

\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

enter image description here

8
  • The font is bold, in my point of view
    – user31729
    Oct 15, 2015 at 10:04
  • Untested, but see the menukeys documentation, section 'Declaring styles': last is the style for the last list element.
    – Marijn
    Oct 15, 2015 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} Oct 15, 2015 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, 2015 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. Oct 16, 2015 at 13:45

1 Answer 1

3

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

\copymenustyle{roundedmenusA}{roundedmenus}
\copymenustyle{roundedmenusB}{roundedmenus}

\def\lastcolor{blue!50}

\makeatletter

% modify style roundedmenusA

\tw@declare@style*{roundedmenusA}{%
   \tikz[baseline={($([email protected])+(0,-0.2ex)$)}]{%
      \node(tw@node)[tw@roundedmenus@base,signal to=east]%
      {\strut\CurrentMenuElement};}%
}[\hspace{-0.2em}\hspace{0em plus 0.1em minus 0.05em}]%
{%
   \tikz[baseline={($([email protected])+(0,-0.2ex)$)}]{%
      \node(tw@node)[tw@roundedmenus@base,signal from=west,signal to=east]%
      {\strut\CurrentMenuElement};}%
}{%
   \tikz[baseline={($([email protected])+(0,-0.2ex)$)}]{%
      \node(tw@node)[tw@roundedmenus@base,signal from=west,fill=\lastcolor]%
      {\strut\CurrentMenuElement};}%
}{%
   \tikz[baseline={($([email protected])+(0,-0.2ex)$)}]{%
      \node(tw@node)[tw@roundedmenus@base]{\strut\CurrentMenuElement};}%
}{gray}

% modify style roundedmenusB

\tw@declare@style*{roundedmenusB}{%
   \tikz[baseline={($([email protected])+(0,-0.2ex)$)}]{%
      \node(tw@node)[tw@roundedmenus@base,signal to=east]%
      {\strut\CurrentMenuElement};}%
}[\hspace{-0.2em}\hspace{0em plus 0.1em minus 0.05em}]%
{%
   \tikz[baseline={($([email protected])+(0,-0.2ex)$)}]{%
      \node(tw@node)[tw@roundedmenus@base,signal from=west,signal to=east]%
      {\strut\CurrentMenuElement};}%
}{%
   \tikz[baseline={($([email protected])+(0,-0.2ex)$)}]{%
      \node(tw@node)[tw@roundedmenus@base,signal from=west]%
      {\bfseries\strut\CurrentMenuElement};}%
}{%
   \tikz[baseline={($([email protected])+(0,-0.2ex)$)}]{%
      \node(tw@node)[tw@roundedmenus@base]{\strut\CurrentMenuElement};}%
}{gray}

\makeatother

\renewmenumacro{\directory}[/]{paths}
\renewmenumacro{\menu}[>]{roundedmenus} % default: menus
\renewmenumacro{\directory}{pathswithfolder} % default: paths
\renewmenumacro{\keys}{shadowedroundedkeys} % default: roundedkeys
\newmenumacro{\button}[+]{roundkeys}

\begin{document}

\menu{Macros>AppleScript>Show Files}

\renewmenumacro{\menu}[>]{roundedmenusA}

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

\renewmenumacro{\menu}[>]{roundedmenusB}

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

\directory{/home/user/Desktop}

\keys{SHIFT + H}

\button{Start Process}

\end{document}

Output

enter image description here

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

2
  • Why are there four nodes per style? Could you explain what is going on there? Oct 21, 2015 at 7:38
  • 1
    @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, 2017 at 12:18

You must log in to answer this question.

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