如果这个问题比较模糊,我很抱歉。
我正在写一些东西(我暂时还不能分享),里面涉及很多复杂的想法,我正在尝试在整个 LaTeX 文档中使用彩色文本和方程式来帮助解释事情。我发现随着时间的推移,保持一致变得越来越困难。
我想要的是一种告诉 LaTeX 的方法,比如说,在文档中使用颜色时,使用彩虹的(适当可见的)色调。这需要以一种方式,让我能够以相对不受编辑影响的方式一致地重复使用以前的颜色。
我希望这是有道理的。
我不知道该如何去做这件事。
请帮忙 :)
这是来自评论:
想象一下 LaTaX 中数学试卷的命令,你只需在事物前面放置某些内容
\begin{document}
,然后使用类似\RainbowColour[x]{X}
为文本/方程式 X 着色的内容,并使用可选标签“x”表示该颜色,以便 LaTeX 会相应地分配颜色,并且可以重复使用标签为“x”的颜色(如果需要)。
假设我有这个:
使用
\documentclass[a4paper, fleqn]{amsart}
\usepackage{color}
\begin{document}
\textcolor[rgb]{1,0,0}{Far far away,} behind the word mountains, far from the countries \textcolor[rgb]{1,0.41,0.13}{Vokalia and Consonantia,} there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean.
A small river named Duden flows by their place and supplies it with the \textcolor[rgb]{1,1,0}{necessary regelialia}. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.
Even the \textcolor[rgb]{0,1,0}{all-powerful Pointing} has no control about the blind texts it is an almost \textcolor[rgb]{0,0,1}{unorthographic life} One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar.
The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little \textcolor[rgb]{0.5,0,0.5}{Blind Text} didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way.
\end{document}
假设在此之后,我想为“关于盲文”着色,并以同样的方式突出显示“语法世界”。那么我必须通过操纵数字来更改当前存在的所有颜色,例如\textcolor[rgb]{1,0.41,0.13}{Vokalia and Consonantia,}
使彩虹更平滑。一段时间后,这会变得非常耗费人力,尤其是对于大型复杂的文档。假设我这样做了:
使用
\documentclass[a4paper, fleqn]{amsart}
\usepackage{color}
\begin{document}
\textcolor[rgb]{1,0,0}{Far far away,} behind the word mountains, far from the countries \textcolor[rgb]{1,0.41,0.13}{Vokalia and Consonantia,} there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean.
A small river named Duden flows by their place and supplies it with the \textcolor[rgb]{1,1,0}{necessary regelialia}. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.
Even the \textcolor[rgb]{0,1,0}{all-powerful Pointing} has no control \textcolor[rgb]{0,0.58,0}{about the blind texts} it is an almost \textcolor[rgb]{0,0,1}{unorthographic life} One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far \textcolor[rgb]{0,0.58,0}{World of Grammar}.
The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little \textcolor[rgb]{0.5,0,0.5}{Blind Text} didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way.
\end{document}
可是等等!这是不该强调的事情! 该死的!现在我必须再次改变一切!
等等 。 。 。
答案1
我将“编辑证明”解释为“这样,如果我们添加更多标签,颜色就会以一致的方式自动调整”。
在这里我将定义一个宏\colorize{label}{text}
,为每个不同的标签分配不同的颜色并使用该颜色进行排版。如果您需要全局设置颜色或在方程式中设置颜色等,text
它可以轻松适应使用。\color
\textcolor
它不需要预先知道标签,也不需要知道标签的总数。它可以适应从任何特定的渐变生成颜色。
\documentclass{article}
\usepackage{xcolor}
\makeatletter
\newcount\colorlabels
\colorlabels=0\relax
\newcount\colorize@curr
\AtEndDocument{\write\@auxout{\protect\total@colors{\the\colorlabels}}}
\def\total@colors#1{\global\def\totalcolors{#1}}
\total@colors{1}
\newcommand{\colorize}[2]{%
\@ifundefined{\string\color@colorize#1}{%
\colorize@curr=\colorlabels\relax%
\multiply\colorize@curr by 451%
\divide\colorize@curr by \totalcolors\relax%
\advance\colorize@curr by 363%
\definecolor{colorize#1}{wave}{\the\colorize@curr}%
\advance\colorlabels by 1\relax%
}{}%
\textcolor{colorize#1}{#2}%
}
\makeatother
\begin{document}
\colorize{fst}{Far far away,} behind the word mountains, far from the countries \colorize{other}{Vokalia and Consonantia,} there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean.
A small river named Duden flows by their place and supplies it with the \colorize{lbl3}{necessary regelialia}. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.
Even the \colorize{lbl4}{all-powerful Pointing} has no control \colorize{important}{about the blind texts} it is an almost \colorize{lbl5}{unorthographic life} One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far \colorize{important}{World of Grammar}.
The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little \colorize{lbl6}{Blind Text} didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way.
\end{document}
请注意,标有标签的两个部分important
都使用相同的颜色。此外,渐变均匀分布在标签上,因此如果您添加新标签,所有颜色都会略微偏移,为新标签留出空间。
怎么运行的
这个想法是将每个标签与可见光谱中的唯一颜色相关联(通过使用的wave
颜色模型xcolor
);这可以推广到不同的渐变。要决定使用哪种颜色,我们只需将存储在中的增量数字\colorlabels
与每个标签关联起来,LBL
然后计算颜色(\colorlabels*451/tot)+362
(请参阅的波模型文档以xcolor
理解这种表达式);此颜色以名称保存colorizeLBL
,这是用于为标有标签的文本着色的颜色名称LBL
。要计算标签的总数,我们需要将最后\colorlabels
生成的值保存到文件中aux
,以便在第二次运行 latex 时我们可以得到中的值\totalcolors
。
一个限制是模型中一个颜色只有 451 个有效值wave
,因此如果您拥有的标签多于这个数字,则需要重新定义颜色的生成方式。