5

My question is a follow-up of my answer to this question Color underline a formula

My answer would have been much better, if I could save the color of the text and then restore it. Is it possible to capture the active color of a group and if yes, how does one do this?

yannisl
  • 117,160

2 Answers2

7

You can save the current color by

\colorlet{currentcolor}{.}

. is just a placeholder for the currently active color. You may choose a name for the color, I just chose currentcolor. Later just use

\color{currentcolor}
Stefan Kottwitz
  • 231,401
0

Usually we don't have to save the color.

You can try \color@begingroup and \color@endgroup, which is used in LaTeX core heavily. In fact, there is no difference between \begingroup and \color@begingroup, and \color@endgroup is defined as \endgraf\endgroup.

After all, @Stefan's solution is still better in many situations.

Leo Liu
  • 77,365