LaTeX error "Undefined color `darkgreen'": cause and fix
A color command got a name that is not defined. Without options, xcolor knows 19 names: red, green, blue, cyan, magenta, yellow, black, gray, white, darkgray, lightgray, brown, lime, olive, orange, pink, purple, teal and violet.
Why it happens
- The name is not among the predefined ones, for example
darkgreen,lightblueornavy. - The name belongs to a set that has to be switched on with an option.
ForestGreenneeds\usepackage[dvipsnames]{xcolor},DarkGreenneeds the optionsvgnames. - The spelling differs. Color names are case-sensitive, so
Redis notred, and the gray tone is spelledgray, notgrey. - A hex code is written where a name is expected, as in
\textcolor{#00FF00}{...}. - Only the package
coloris loaded. It knows 8 names and reports "LaTeX Error: Undefined color" fororange.
How to fix it
- Define the color in the preamble:
\definecolor{darkgreen}{RGB}{0,120,60}or\definecolor{darkgreen}{HTML}{00783C}. - Mix it from known colors:
green!60!blackis 60 % green and 40 % black. - For a hex code, name the color model in the optional argument:
\textcolor[HTML]{00FF00}{...}. - Load a larger set of names with
\usepackage[dvipsnames]{xcolor}or\usepackage[svgnames]{xcolor}.
A document that produces the message
\documentclass{article}
\usepackage{xcolor}
\begin{document}
\textcolor{darkgreen}{This text is green.}
\end{document}The corrected document
\documentclass{article}
\usepackage{xcolor}
\definecolor{darkgreen}{RGB}{0,120,60}
\begin{document}
\textcolor{darkgreen}{This text is green.}
\end{document}Both documents were compiled with pdfLaTeX from TeX Live 2023. The first produces the message, the second compiles without an error.
Finding the line in the editor
The editor lists every error and warning of a compile run with file and line. Select an entry and the cursor jumps to that line. See Error list with jump to the line.
Related pages
- Package
xcolor - How-to Colored text in LaTeX
- How-to Highlight text in LaTeX
- How-to Color table rows, columns and cells in LaTeX