[Tex/LaTex] ! LaTeX Error: Undefined color `BLACK’

colorerrors

i have written all the text in black color, but i get this error several times in the same page:

! LaTeX Error: Undefined color `BLACK'.

i tried to solve it by writting this: \definecolor{black}{gray}{0,0,0} but it didnĀ“t work.

what should i do?

Best Answer

Very likely the color setting is inside a section (or friend) title and the title goes into the header with uppercase letters. \MakeUppercase (or \uppercase) does not know the semantics of arguments, it just converts all letters to uppercase: \textcolor{black}{hello} becomes \textcolor{BLACK}{HELLO}.

Workarounds:

  • Providing a definition for the uppercase color name:

    \documentclass{article}
    \usepackage{xcolor}
    \colorlet{BLACK}{black}
    \pagestyle{headings}
    \begin{document}
    \section{\textcolor{black}{Hello}}
    \end{document}
    
  • Using a command to hide the string "black":

    \documentclass{article}
    \usepackage{color}
    \DeclareRobustCommand{\textblack}{\textcolor{black}}
    \pagestyle{headings}
    \begin{document}
    \section{\textblack{Hello}}
    \end{document}
    

    \DeclareRobustCommand protects \textblack from expanding inside \MakeUppercase to dispose and uppercase "black" in \textcolor{black} again.

BTW: \definecolor{black}{gray}{0,0,0} is not correct, because color model gray only expects one number: \definecolor{black}{gray}{0}.