\nicecolorname
请考虑以下代码,尤其是按照模式 ["nice"][shade][hue] 构建颜色名称的命令。在当前名称中,该命令\color
无法获取 的输出\nicecolorname
。
问题:如何修改命令\nicecolorname
以使其输出与兼容\color
?如果不可能,如何修改代码以使其可行?
\documentclass{standalone}
\RequirePackage{xparse}
\RequirePackage{xcolor}
\RequirePackage{xcolor-material}
\definecolor{nicelightblue}{named}{MaterialIndigo50}
\definecolor{nicemidblue}{named}{MaterialIndigo500}
\definecolor{nicedarkblue}{named}{MaterialIndigo900}
\definecolor{nicelightred}{named}{MaterialRed50}
\definecolor{nicemidred}{named}{MaterialRed500}
\definecolor{nicedarkred}{named}{MaterialRed900}
\definecolor{nicelightgreen}{named}{MaterialRed50}
\definecolor{nicemidgreen}{named}{MaterialRed500}
\definecolor{nicedarkgreen}{named}{MaterialRed900}
\newcommand{\nicecolorhue}{green}
\newcommand{\nicecolorshade}{dark}
\newcommand{\nicecolorhueref}{\nicecolorhue}
\newcommand{\nicecolorshaderef}{\nicecolorshade}
\NewDocumentCommand\nicecolorname{O{mid} m}{nice#1#2}
\begin{document}
{\color{blue}$\bullet$} % OK
{\color{nicemidred}$\bullet$} % OK
{\color{\nicecolorname[mid]{red}}$\bullet$} % ERROR
{\color{\nicecolorname[\nicecolorshade]{\nicecolorhue}}$\bullet$} % ERROR
{\color{\nicecolorname[\nicecolorshaderef]{\nicecolorhueref}}$\bullet$} % ERROR
\end{document}
答案1
论点需要扩张变成颜色:
\documentclass{standalone}
% only needed in old latex \RequirePackage{xparse}
\RequirePackage{xcolor}
\RequirePackage{xcolor-material}
\definecolor{nicelightblue}{named}{MaterialIndigo50}
\definecolor{nicemidblue}{named}{MaterialIndigo500}
\definecolor{nicedarkblue}{named}{MaterialIndigo900}
\definecolor{nicelightred}{named}{MaterialRed50}
\definecolor{nicemidred}{named}{MaterialRed500}
\definecolor{nicedarkred}{named}{MaterialRed900}
\definecolor{nicelightgreen}{named}{MaterialRed50}
\definecolor{nicemidgreen}{named}{MaterialRed500}
\definecolor{nicedarkgreen}{named}{MaterialRed900}
\newcommand{\nicecolorhue}{green}
\newcommand{\nicecolorshade}{dark}
\newcommand{\nicecolorhueref}{\nicecolorhue}
\newcommand{\nicecolorshaderef}{\nicecolorshade}
\NewExpandableDocumentCommand\nicecolorname{O{mid} m}{nice#1#2}
\begin{document}
{\color{blue}$\bullet$} % OK
{\color{nicemidred}$\bullet$} % OK
{\color{\nicecolorname[mid]{red}}$\bullet$} % no ERROR
{\color{\nicecolorname[\nicecolorshade]{\nicecolorhue}}$\bullet$} % no ERROR
{\color{\nicecolorname[\nicecolorshaderef]{\nicecolorhueref}}$\bullet$} % no ERROR
\end{document}