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?

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}
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.