我想保存当前文本颜色,然后更改它,然后改回原始颜色。我当时想做这样的事情:
\def\oldcolor{old colour here} % save colour
\color{red} % set colour to new colour
Some text % arbitrary length text, perhaps with more colour changes
\color{\oldcolor} % restore old colour
但我找不到用什么来代替“此处为旧颜色”。我如何读取颜色的当前值,或者在哪里可以找到此信息?
答案1
\documentclass{article}
\usepackage{xcolor}
\begin{document}
\color{green} % set color
\colorlet{oldcolor}{.} % save current colour, internally named as .
\color{red} % set colour to new colour
Some text
\color{oldcolor} % restore old colour
Some text
\end{document}