我正在编写样式指南文档,并且想使用封面颜色使文档的更新在视觉上更具吸引力。
主要思想是根据文档编写的月份自动更新封面颜色。
封面颜色定义为coverBackground
和coverFont
。
\documentclass[12pt,a4paper]{book}
\usepackage[margin=2cm]{geometry}
\usepackage{xcolor}
\definecolor{grayOne}{rgb}{0.95, 0.95, 0.96}
\definecolor{coverBackground}{rgb}{0.952, 0.929, 0.858}
\definecolor{coverFont}{rgb}{0.223, 0.239, 0.313}
\usepackage[backgroundcolor=grayOne,linecolor=white]{mdframed}
\begin{document}
\begin{titlepage}
\begin{mdframed}[backgroundcolor=coverBackground]
\centering
\vspace*{.25\textheight}
\textcolor{coverFont}{\Huge Page title}\\
\vspace{10pt}\par
\textcolor{coverFont}{\today}\\
\vspace*{.25\textheight}
\end{mdframed}
\end{titlepage}
\end{document}
我还有一个实用程序文件,其中我定义了一大组颜色,使用它们会很棒。
%--------------------------------------------
% Open Color Palette
% https://yeun.github.io/open-color/
%--------------------------------------------
% GRAY
\definecolor{grayZero}{rgb}{0.97, 0.98, 0.98}
\definecolor{grayOne}{rgb}{0.95, 0.95, 0.96}
\definecolor{grayTwo}{rgb}{0.91, 0.93, 0.94}
\definecolor{grayThree}{rgb}{0.87, 0.89, 0.9}
\definecolor{grayFour}{rgb}{0.81, 0.83, 0.85}
\definecolor{grayFive}{rgb}{0.68, 0.71, 0.74}
\definecolor{graySix}{rgb}{0.53, 0.56, 0.59}
\definecolor{graySeven}{rgb}{0.29, 0.31, 0.34}
\definecolor{grayEight}{rgb}{0.2, 0.23, 0.25}
\definecolor{grayNine}{rgb}{0.13, 0.15, 0.16}
% RED
\definecolor{redZero}{rgb}{1.0, 0.96, 0.96}
\definecolor{redOne}{rgb}{1.0, 0.89, 0.89}
\definecolor{redTwo}{rgb}{1.0, 0.79, 0.79}
\definecolor{redThree}{rgb}{1.0, 0.66, 0.66}
\definecolor{redFour}{rgb}{1.0, 0.53, 0.53}
\definecolor{redFive}{rgb}{1.0, 0.42, 0.42}
\definecolor{redSix}{rgb}{0.98, 0.32, 0.32}
\definecolor{redSeven}{rgb}{0.94, 0.24, 0.24}
\definecolor{redEight}{rgb}{0.88, 0.19, 0.19}
\definecolor{redNine}{rgb}{0.79, 0.16, 0.16}
% PINK
\definecolor{pinkZero}{rgb}{1.0, 0.94, 0.96}
\definecolor{pinkOne}{rgb}{1.0, 0.87, 0.92}
\definecolor{pinkTwo}{rgb}{0.99, 0.76, 0.84}
\definecolor{pinkThree}{rgb}{0.98, 0.64, 0.76}
\definecolor{pinkFour}{rgb}{0.97, 0.51, 0.67}
\definecolor{pinkFive}{rgb}{0.94, 0.4, 0.58}
\definecolor{pinkSix}{rgb}{0.9, 0.29, 0.5}
\definecolor{pinkSeven}{rgb}{0.84, 0.2, 0.42}
\definecolor{pinkEight}{rgb}{0.76, 0.15, 0.36}
\definecolor{pinkNine}{rgb}{0.65, 0.12, 0.3}
% GRAPE
\definecolor{grapeZero}{rgb}{0.97, 0.94, 0.99}
\definecolor{grapeOne}{rgb}{0.95, 0.85, 0.98}
\definecolor{grapeTwo}{rgb}{0.93, 0.75, 0.98}
\definecolor{grapeThree}{rgb}{0.9, 0.6, 0.97}
\definecolor{grapeFour}{rgb}{0.85, 0.47, 0.95}
\definecolor{grapeFive}{rgb}{0.8, 0.36, 0.91}
\definecolor{grapeSix}{rgb}{0.75, 0.29, 0.86}
\definecolor{grapeSeven}{rgb}{0.68, 0.24, 0.79}
\definecolor{grapeEight}{rgb}{0.61, 0.21, 0.71}
\definecolor{grapeNine}{rgb}{0.53, 0.18, 0.61}
% VIOLET
\definecolor{violetZero}{rgb}{0.95, 0.94, 1.0}
\definecolor{violetOne}{rgb}{0.9, 0.86, 1.0}
\definecolor{violetTwo}{rgb}{0.82, 0.75, 1.0}
\definecolor{violetThree}{rgb}{0.69, 0.59, 0.99}
\definecolor{violetFour}{rgb}{0.59, 0.46, 0.98}
\definecolor{violetFive}{rgb}{0.52, 0.37, 0.97}
\definecolor{violetSix}{rgb}{0.47, 0.31, 0.95}
\definecolor{violetSeven}{rgb}{0.44, 0.28, 0.91}
\definecolor{violetEight}{rgb}{0.4, 0.25, 0.85}
\definecolor{violetNine}{rgb}{0.37, 0.24, 0.77}
% INDIGO
\definecolor{indigoZero}{rgb}{0.93, 0.95, 1.0}
\definecolor{indigoOne}{rgb}{0.86, 0.89, 1.0}
\definecolor{indigoTwo}{rgb}{0.73, 0.78, 1.0}
\definecolor{indigoThree}{rgb}{0.57, 0.65, 1.0}
\definecolor{indigoFour}{rgb}{0.45, 0.56, 0.99}
\definecolor{indigoFive}{rgb}{0.36, 0.49, 0.98}
\definecolor{indigoSix}{rgb}{0.3, 0.43, 0.96}
\definecolor{indigoSeven}{rgb}{0.26, 0.39, 0.92}
\definecolor{indigoEight}{rgb}{0.23, 0.36, 0.86}
\definecolor{indigoNine}{rgb}{0.21, 0.31, 0.78}
% CYAN
\definecolor{cyanZero}{rgb}{0.89, 0.98, 0.99}
\definecolor{cyanOne}{rgb}{0.77, 0.96, 0.98}
\definecolor{cyanTwo}{rgb}{0.6, 0.91, 0.95}
\definecolor{cyanThree}{rgb}{0.4, 0.85, 0.91}
\definecolor{cyanFour}{rgb}{0.23, 0.79, 0.86}
\definecolor{cyanFive}{rgb}{0.13, 0.72, 0.81}
\definecolor{cyanSix}{rgb}{0.08, 0.67, 0.75}
\definecolor{cyanSeven}{rgb}{0.06, 0.6, 0.68}
\definecolor{cyanEight}{rgb}{0.05, 0.52, 0.6}
\definecolor{cyanNine}{rgb}{0.04, 0.45, 0.52}
% BLUE
\definecolor{blueZero}{rgb}{0.91, 0.96, 1.0}
\definecolor{blueOne}{rgb}{0.82, 0.92, 1.0}
\definecolor{blueTwo}{rgb}{0.65, 0.85, 1.0}
\definecolor{blueThree}{rgb}{0.45, 0.75, 0.99}
\definecolor{blueFour}{rgb}{0.3, 0.67, 0.97}
\definecolor{blueFive}{rgb}{0.2, 0.6, 0.94}
\definecolor{blueSix}{rgb}{0.13, 0.55, 0.9}
\definecolor{blueSeven}{rgb}{0.11, 0.49, 0.84}
\definecolor{blueEight}{rgb}{0.1, 0.44, 0.76}
\definecolor{blueNine}{rgb}{0.09, 0.39, 0.67}
% TEAL
\definecolor{tealZero}{rgb}{0.9, 0.99, 0.96}
\definecolor{tealOne}{rgb}{0.76, 0.98, 0.91}
\definecolor{tealTwo}{rgb}{0.59, 0.95, 0.84}
\definecolor{tealThree}{rgb}{0.39, 0.9, 0.75}
\definecolor{tealFour}{rgb}{0.22, 0.85, 0.66}
\definecolor{tealFive}{rgb}{0.13, 0.79, 0.59}
\definecolor{tealSix}{rgb}{0.07, 0.72, 0.53}
\definecolor{tealSeven}{rgb}{0.05, 0.65, 0.47}
\definecolor{tealEight}{rgb}{0.04, 0.57, 0.41}
\definecolor{tealNine}{rgb}{0.03, 0.5, 0.36}
% GREEN
\definecolor{greenZero}{rgb}{0.92, 0.98, 0.93}
\definecolor{greenOne}{rgb}{0.83, 0.98, 0.85}
\definecolor{greenTwo}{rgb}{0.7, 0.95, 0.73}
\definecolor{greenThree}{rgb}{0.55, 0.91, 0.6}
\definecolor{greenFour}{rgb}{0.41, 0.86, 0.49}
\definecolor{greenFive}{rgb}{0.32, 0.81, 0.4}
\definecolor{greenSix}{rgb}{0.25, 0.75, 0.34}
\definecolor{greenSeven}{rgb}{0.22, 0.7, 0.3}
\definecolor{greenEight}{rgb}{0.18, 0.62, 0.27}
\definecolor{greenNine}{rgb}{0.17, 0.54, 0.24}
% LIME
\definecolor{limeZero}{rgb}{0.96, 0.99, 0.89}
\definecolor{limeOne}{rgb}{0.91, 0.98, 0.78}
\definecolor{limeTwo}{rgb}{0.85, 0.96, 0.64}
\definecolor{limeThree}{rgb}{0.75, 0.92, 0.46}
\definecolor{limeFour}{rgb}{0.66, 0.89, 0.29}
\definecolor{limeFive}{rgb}{0.58, 0.85, 0.18}
\definecolor{limeSix}{rgb}{0.51, 0.79, 0.12}
\definecolor{limeSeven}{rgb}{0.45, 0.72, 0.09}
\definecolor{limeEight}{rgb}{0.4, 0.66, 0.06}
\definecolor{limeNine}{rgb}{0.36, 0.58, 0.05}
% YELLOW
\definecolor{yellowZero}{rgb}{1.0, 0.98, 0.86}
\definecolor{yellowOne}{rgb}{1.0, 0.95, 0.75}
\definecolor{yellowTwo}{rgb}{1.0, 0.93, 0.6}
\definecolor{yellowThree}{rgb}{1.0, 0.88, 0.4}
\definecolor{yellowFour}{rgb}{1.0, 0.83, 0.23}
\definecolor{yellowFive}{rgb}{0.99, 0.77, 0.1}
\definecolor{yellowSix}{rgb}{0.98, 0.69, 0.02}
\definecolor{yellowSeven}{rgb}{0.96, 0.62, 0.0}
\definecolor{yellowEight}{rgb}{0.94, 0.55, 0.0}
\definecolor{yellowNine}{rgb}{0.9, 0.47, 0.0}
% ORANGE
\definecolor{orangeZero}{rgb}{1.0, 0.96, 0.9}
\definecolor{orangeOne}{rgb}{1.0, 0.91, 0.8}
\definecolor{orangeTwo}{rgb}{1.0, 0.85, 0.66}
\definecolor{orangeThree}{rgb}{1.0, 0.75, 0.47}
\definecolor{orangeFour}{rgb}{1.0, 0.66, 0.3}
\definecolor{orangeFive}{rgb}{1.0, 0.57, 0.17}
\definecolor{orangeSix}{rgb}{0.99, 0.49, 0.08}
\definecolor{orangeSeven}{rgb}{0.97, 0.4, 0.03}
\definecolor{orangeEight}{rgb}{0.91, 0.35, 0.05}
\definecolor{orangeNine}{rgb}{0.85, 0.28, 0.06}
答案1
您可以使用命令\ifcase\month
来定义不同的颜色,例如:
\documentclass[12pt,a4paper]{book}
\usepackage[margin=2cm]{geometry}
\usepackage{xcolor}
\definecolor{grayOne}{rgb}{0.95, 0.95, 0.96}
\definecolor{coverBackground}{rgb}{0.952, 0.929, 0.858}
\definecolor{coverFont}{rgb}{0.223, 0.239, 0.313}
\usepackage[backgroundcolor=grayOne,linecolor=white]{mdframed}
\begin{document}
% define coverBackground and coverFont
\ifcase\month\relax
% \ValueWasZero
\or % Jan
\definecolor{coverBackground}{rgb}{0.952, 0.929, 0.858}
\definecolor{coverFont}{rgb}{0.223, 0.239, 0.313}
\or % feb
\colorlet{coverBackground}{gray}
\colorlet{coverFont}{red}
\or % mar
\colorlet{coverBackground}{blue}
\colorlet{coverFont}{yellow}
\or % Apr
\colorlet{coverBackground}{red}
\colorlet{coverFont}{green}
\or % Mai
\colorlet{coverBackground}{pink}
\colorlet{coverFont}{black}
\or % Jun
\colorlet{coverBackground}{red}
\colorlet{coverFont}{green}
\or % Jul
\definecolor{coverBackground}{rgb}{0.952, 0.929, 0.858}
\definecolor{coverFont}{rgb}{0.223, 0.239, 0.313}
\or % aug
\colorlet{coverBackground}{red}
\colorlet{coverFont}{green}
\or % sep
\colorlet{coverBackground}{red}
\colorlet{coverFont}{green}
\or % oct
\colorlet{coverBackground}{red}
\colorlet{coverFont}{green}
\or % nov
\colorlet{coverBackground}{red}
\colorlet{coverFont}{green}
\or % dec
\colorlet{coverBackground}{red}
\colorlet{coverFont}{green}
\else % error
\colorlet{coverBackground}{red}
\colorlet{coverFont}{green}
\fi
\begin{titlepage}
\begin{mdframed}[backgroundcolor=coverBackground]
\centering
\vspace*{.25\textheight}
\textcolor{coverFont}{\Huge Page title}\\
\vspace{10pt}\par
\textcolor{coverFont}{\today}\\
\vspace*{.25\textheight}
\end{mdframed}
\end{titlepage}
\end{document}
我展示了两种方法,直接使用 定义颜色\definecolor{coverFont}
或使用 来使用您的其他预定义颜色\colorlet{coverFont}
。我使用标准颜色来显示主要方式,请将其更改为您需要的颜色。最后一种方法\else
是,如果无法识别月份,则仅进行常规退出(不应该发生,但肯定是肯定的……)。
使用给定的 MWE 您将获得结果:
好吧,抱歉,我知道这个颜色很伤人...但是举个例子...
答案2
为了实现分叉机制,您可以让 LaTeX 评估整数参数\month
。
分叉机制可以基于\ifcase
:
\documentclass{article}
\begin{document}
The date of compilation is: \today
\ifcase\month This should never be done.% <- case month = 0
\or This is done in January.% <- case month = 1
\or This is done in February.% <- case month = 2
\or This is done in March.% <- case month = 3
\or This is done in April.% <- case month = 4
\or This is done in May.% <- case month = 5
\or This is done in June.% <- case month = 6
\or This is done in July.% <- case month = 7
\or This is done in August.% <- case month = 8
\or This is done in September.% <- case month = 9
\or This is done in October.% <- case month = 10
\or This is done in November.% <- case month = 11
\or This is done in December.% <- case month = 12
\fi
\end{document}
您还可以使用类似我的\KeepKthOfLArguments
宏:
\documentclass{article}
\makeatletter
%% Code for \KeepKthOfLArguments:
%%=============================================================================
%% Paraphernalia:
%% \UD@firstoftwo, \UD@secondoftwo, \UD@PassFirstToSecond, \UD@CheckWhetherNull
%%=============================================================================
\newcommand\UD@firstoftwo[2]{#1}%
\newcommand\UD@secondoftwo[2]{#2}%
\newcommand\UD@PassFirstToSecond[2]{#2{#1}}%
%%-----------------------------------------------------------------------------
%% Check whether argument is empty:
%%.............................................................................
%% \UD@CheckWhetherNull{<Argument which is to be checked>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is empty>}%
%% {<Tokens to be delivered in case that argument
%% which is to be checked is not empty>}%
%%
%% The gist of this macro comes from Robert R. Schneck's \ifempty-macro:
%% <https://groups.google.com/forum/#!original/comp.text.tex/kuOEIQIrElc/lUg37FmhA74J>
\newcommand\UD@CheckWhetherNull[1]{%
\romannumeral0\expandafter\UD@secondoftwo\string{\expandafter
\UD@secondoftwo\expandafter{\expandafter{\string#1}\expandafter
\UD@secondoftwo\string}\expandafter\UD@firstoftwo\expandafter{\expandafter
\UD@secondoftwo\string}\expandafter\expandafter\UD@firstoftwo{ }{}%
\UD@secondoftwo}{\expandafter\expandafter\UD@firstoftwo{ }{}\UD@firstoftwo}%
}%
%%=============================================================================
%% Keep only the K-th of L consecutive undelimited arguments.
%% ( IF K < 1 OR K > L just remove L consecutive undelimited arguments. )
%%=============================================================================
%% \KeepKthOfLArguments{<integer number K>}%
%% {<integer number L>}%
%% <sequence of L consecutive undelimited arguments>
%%
%% If L < 1 yields nothing.
%% Else:
%% If K >= 1 and K < L yields:
%% <K-th undelimited argument from <sequence of L consecutive undelimited
%% arguments>>
%% If K < 1 or K > L
%% (-> there is no K-th argument in the
%% <sequence of L consecutive undelimited arguments> )
%% yields nothing but removal of <sequence of L consecutive
%% undelimited arguments>
\newcommand\KeepKthOfLArguments[2]{%
\romannumeral0%
% #1: <integer number K>
% #2: <integer number L>
\expandafter\UD@KeepKthOfLArgumentsKSmallerOneFork
\expandafter{\romannumeral\number\number#1 000\expandafter}%
\expandafter{\romannumeral\number\number#2 000}%
}%
%%-----------------------------------------------------------------------------
\newcommand\UD@KeepKthOfLArgumentsKSmallerOneFork[2]{%
% #1: <K letters m>
% #2: <L letters m >
\UD@CheckWhetherNull{#1}{% K is smaller than one:
\UD@KeepKthOfLArgumentsRemoveNArguments{#2}{ }{}%
}{% K is not smaller than one:
\expandafter\UD@PassFirstToSecond
\expandafter{%
\UD@firstoftwo{}#1%
}{%
\UD@KeepKthOfLArgumentsEvaluateLMinusKDifferenceLoop{#1}{#2}%
}{#2}%
}%
}%
%%-----------------------------------------------------------------------------
\newcommand\UD@KeepKthOfLArgumentsEvaluateLMinusKDifferenceLoop[4]{%
% #1: <K letters m>
% #2: <L letters m>
% (For detecting whether K>L or K<=L, during the loop letters m will
% be removed both from #1 and #2 until at least one of these arguments
% is empty.
% When the loop terminates with 0<K<=L, #1 will be empty and #2
% will hold an amount of letters m corresponding to the the
% difference L-K.
% When the loop terminates with K>L, #1 will not be empty and #2
% will be empty.
% )
% #3: <K-1 letters m>
% #4: <L letters m>
% (#3 and #4 will be left untouched during the loop so they can be
% used for performing appropriate action when loop terminates as
% it is known whether K>L.)
\UD@CheckWhetherNull{#1}{% We have K<=L:
\UD@KeepKthOfLArgumentsRemoveNArguments{%
#3%
}{%
\UD@KeepKthOfLArgumentsRemoveNArguments{#2}{ }%
}{}%
}{%
\UD@CheckWhetherNull{#2}{% We have K>L:
\UD@KeepKthOfLArgumentsRemoveNArguments{#4}{ }{}%
}{% We don't know yet whether K<=L or K>L, thus remove letters m and
% do another iteration:
\expandafter\UD@PassFirstToSecond
\expandafter{%
\UD@firstoftwo{}#2%
}{%
\expandafter\UD@KeepKthOfLArgumentsEvaluateLMinusKDifferenceLoop
\expandafter{%
\UD@firstoftwo{}#1%
}%
}{#3}{#4}%
}%
}%
}%
%%-----------------------------------------------------------------------------
%% \UD@KeepKthOfLArgumentsRemoveNArguments{<N letters m>}%
%% {<argument 1>}%
%% {<argument 2>}%
%% <sequence of consecutive
%% undelimited arguments>
%%.............................................................................
%% Removes the first N undelimited arguments from the <sequence of
%% consecutive undelimited arguments>, then inserts
%% <argument 1><argument 2>
%%
%% On the one hand when providing <argument 2> empty, you can use
%% <argument 1> for nesting calls to \UD@KeepKthOfLArgumentsRemoveNArguments.
%% On the other hand you can provide a <space token> for stopping
%% \romannumeral-expansion as <argument 1> and have the
%% macro grab the <K-th undelimited argument> from the <sequence of L
%% consecutive undelimited arguments> as <argument 2>.
%%
\newcommand\UD@KeepKthOfLArgumentsRemoveNArguments[3]{%
%% #1: <N letters m>
%% #2: <Argument 1>
%% #3: <Argument 2>
\UD@CheckWhetherNull{#1}{#2#3}{%
\UD@firstoftwo{%
\expandafter\UD@KeepKthOfLArgumentsRemoveNArguments
\expandafter{%
\UD@firstoftwo{}#1%
}{#2}{#3}%
}%
}%
}%
%%-----------------------------------------------------------------------------
%% End of code for \KeepKthOfLArguments.
%%-----------------------------------------------------------------------------
\makeatother
\newcommand\Monthfork{%
\KeepKthOfLArguments{\month}{12}%
}%
\begin{document}
The date of compilation is: \today
\Monthfork{%
This is done in January.%
}{%
This is done in February.%
}{%
This is done in March.%
}{%
This is done in April.%
}{%
This is done in May.%
}{%
This is done in June.%
}{%
This is done in July.%
}{%
This is done in August.%
}{%
This is done in September.%
}{%
This is done in October.%
}{%
This is done in November.%
}{%
This is done in December.%
}%
\end{document}