0

I am looking for the TeX source code for the \color function call in the xcolor library which I am importing

\documentclass[12pt]{article}
\usepackage{xcolor}
\begin{document}    

{ \color{blue!60!white} abc }    

\end{document}

I am asking here rather than on tex.stackexchange because I am asking for the programming rather than just the tex commands. In theory, this is working TeX code and I should just move on.

1
  • 2
    You have a strange idea about what is on topic here.
    – cfr
    Nov 20 '16 at 4:25
2

Technically, if you're just interested in what \color does, then you can issue

{\let\protect\show\color}

in your document and check your .log:

> \color =\long macro:
->\@ifnextchar [\@undeclaredcolor \@declaredcolor .

This works because \color is declared to be robust, otherwise issuing \show\color would have worked.

The code shows that \color conditions on whether or not the input stream contains [. That is,

\color[<options>]{<colour>}

would lead to executing \@undeclaredcolor, while calling

\color{<colour>}

would lead to executing \@declaredcolor. In both cases, the {<colour>} argument is gobbled by either \@undeclaredcolor or \@declaredcolor.


If you wish to follow a more detailed path of macro execution and expansion, issuing the tracing command

{\tracingmacros1
\color{blue!60!white} abc }

would allow you to debug quite a bit, revealing a lengthy macro expansion pattern of about 800 lines as one follows deeper down the rabbit hole, starting, of course, with the \@ifnextchar condition mentioned above.

0

Possibly

\long\def\color@b@x#1#2#3%
 {\leavevmode
  \setbox\z@\hbox{\kern\fboxsep{\set@color#3}\kern\fboxsep}%
  \dimen@\ht\z@\advance\dimen@\fboxsep\ht\z@\dimen@
  \dimen@\dp\z@\advance\dimen@\fboxsep\dp\z@\dimen@
  {#1{#2\color@block{\wd\z@}{\ht\z@}{\dp\z@}\box\z@}}}

Not much to look at. Argument #3 seems to be the color. The last line looks most important.

{#1{#2\color@block{\wd\z@}{\ht\z@}{\dp\z@}\box\z@}}

Why do LaTeX internal commands have an @ in them?

1
  • Isn't this for a colour box rather than just a colour switch?
    – cfr
    Nov 20 '16 at 4:24

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.