How can I define a macro to expand to a textual representation of the current color as this color was at an arbitrary point of my choosing in the LaTeX manuscript? The colors can be assumed to be managed by the xcolor package.

The purpose of this textual representation is to be printed out to the log file so I can inspect it with my eyes and figure out the color as well as compare the current color at different times to see if they were equal.


Adapted from Define a no-op color name which is always the current color:


    \typeout{Current color: \csname\string\color@.\endcsname}%

{\color{mycolor} This text is orange\showcurrentcolor} and this text is not

Which prints in the terminal and in the log file:

Current color: 1 0.31374 0 rg 1 0.31374 0 RG

i.e., the rgb values scaled from 0 to 1.

  • 1
    Thanks. The following version would be even more versatile: \def\curcol{\csname\string\color@.\endcsname}. – Evan Aad Aug 5 '17 at 8:12
  • However, without the \typeout the color name would be typeset in the document (and not in the log), presumably this is not what you want? – Marijn Aug 5 '17 at 8:15
  • This is why I said it would be more versatile: it can be printed out to the document, to the output (e.g. \typeout\curcol) or even used in an if block. – Evan Aad Aug 5 '17 at 8:16
  • 1
    That is true - "a truth like a cow" as we would say in Dutch :D – Marijn Aug 5 '17 at 8:19

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.