[Tex/LaTex] How to globally set the text color in XeLaTeX

colorxetex

With pdfLaTeX I typically used the following code to globally set the text color for all text in the document:

\documentclass{scrreprt}
\usepackage{xcolor}
\begin{document}
\color{red}
\section{A section heading}
some test text
\end{document}

Running the document through pdfLaTeX produces red text. Running this through XeLaTeX produces black text. Using package color instead of xcolor doesn't make a difference.

I'd like to globally set the text color for all text appearing in the document, i.e. the headings, the table of contents, all normal text, in figures, in equations, if possible in TikZ nodes, just everything.

Best Answer

Here's a way to do it which will work whether you use XeLaTeX or not, and whether you use Komascript or not. It works by redefining the default color used by LaTeX.

\documentclass{report}
%\documentclass{scrreprt}

\usepackage{xcolor}

\makeatletter
\newcommand{\globalcolor}[1]{%
  \color{#1}\global\let\default@color\current@color
}
\makeatother

\AtBeginDocument{\globalcolor{red}}

\begin{document}

\section{A section heading}

some test text

\end{document}
Related Question