Tabularray – Resolving ‘Undefined Color Azure3’ Error in Tabularray

colortabularray

I found out that all the colors that are used in the examples of tabularray are not defined by xcolor. I can use these colors in the document, but not in the preamble.

What exactly does tabularray do and how can I make these colors available also before the document.

This fails

\documentclass{article}
\usepackage{xcolor}
\usepackage{tabularray}

\colorlet{newcolor}{azure3}

\begin{document}
    \color{azure3} Hello.
\end{document}

with

! Package xcolor Error: Undefined color `azure3'.
                                                
l.5 \colorlet{newcolor}{azure3}

Best Answer

Tabularray checks at the start of the document if the xcolor package is loaded and if yes it will automatically load the ninecolors package, which defines azure3 (amongst others).

According to the tabularray documentation, this is done for proper color contrast.

Here the relevant part of the tabularray source:

\AtBeginDocument{
  \@ifpackageloaded{xcolor}{\RequirePackage{ninecolors}}{}
  \@ifpackageloaded{hyperref}{
    \newenvironment{tblrNoHyper}{\NoHyper}{\endNoHyper}
  }{
    \newenvironment{tblrNoHyper}{}{}
  }
}