例如,是否可以从menukeys
包中为菜单中的最后一个项目添加颜色?是否有办法制作一个宏,将菜单中的最后一个项目都加粗?我希望这个宏可以全局使用。
知道如何与菜单和目录中的每个组件直接交互就好了。
手册中的示例menukeys
,2014/03/10 — v1.3 第 9 页:
更高级的命令是 \newmenustyle。它有九个参数:
\newmenustyle⟨* ⟩{⟨name⟩}[⟨pre⟩]{⟨first⟩} [⟨sep⟩]{⟨mid⟩}{⟨last⟩}{⟨single⟩} [⟨post⟩]{⟨theme⟩}
。例子:
\newmenustyle{mystyle}[$\bullet$]{draw,red}[$\ast$]% {draw}{draw,red}{draw,dashed}[$\bullet$]
结果是:
失控参数?./menukeystest.tex:11: 段落在 \tw@declare@sytle@extra@args 完成之前结束。
代码
\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}
模拟输出
答案1
这里有一个解决方案:
- 创建两个副本
roundedmenusA
并roundedmenusB
从中roundedmenus
。 - 修改这两种样式以获得所需的效果。
代码
\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}
输出
\changemenuelement
注意:使用或也可以获得预期的效果\renewmenustyle
,但会出现对齐问题。