Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
2  
Try placing \color{red} right after \begin{document}. –  Gonzalo Medina Aug 25 '11 at 20:40
    
@Gonzalo Unfortunately, that doesn't work with Komascript. I've changed the example document accordingly. –  kongo09 Aug 25 '11 at 20:45
add comment

4 Answers

up vote 6 down vote accepted

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}
share|improve this answer
    
This seems to be the only way working around a XeTeX bug that creates a problem with white text as illustrated here: tex.stackexchange.com/questions/28305/… So thanks a lot! –  kongo09 Sep 13 '11 at 21:23
    
BTW, this will also set the default drawing color for figures created using TikZ – which may or may not be desirable :-) –  ilpssun Aug 10 '12 at 11:52
    
@ilpssun: you can get around this by using \usepackage{etoolbox} and then doing \makeatletter\preto{\tikzpicture}{\color{black}\let\default@color\current@color‌​}\makeatother –  Philippe Goutet Aug 10 '12 at 15:59
    
Only LaTeX could be a document processing language where something as simple as setting foreground and background color requires importing packages and defining custom commands... –  picomancer Sep 27 '13 at 18:54
add comment

Since you say you're using XeLaTeX, you can also define a colour in the font definition:

In order to change colours if you do this, you need to use fontspec's \addfontfeature instead of the regular \color or \textcolor commands. Alternatively, you can define a new font family for the other colour(s).

\documentclass{scrreprt}
\usepackage{xcolor}
\usepackage{fontspec}
\setmainfont[Color=red]{Linux Libertine O}
\setsansfont[Color=red]{Linux Biolinum O}
\setmonofont[Color=red]{Inconsolata}
% If you will be changing colours a lot, it's best to define a new font family
% for each colour that you will use; if you're just changing a few times, then
% \addfontfeature is fine
\newfontfamily\blueroman[Color=blue]{Linux Libertine O} 

\begin{document}
\chapter{A chapter}
\section{A section}
\texttt{Some mono text}

Some regular text.

{\addfontfeature{Color=blue} Some blue text without defining a new font family.}

{\blueroman Some blue text with a new font family command.}
\end{document}
share|improve this answer
    
then \textcolor{blue}{blue} won't work –  Herbert Aug 26 '11 at 15:45
    
@Herbert True. You need to use \addfontfeature to do this, or make a new fontfamily. I'll add this to my answer. –  Alan Munn Aug 26 '11 at 17:11
    
@Alan: I would only use the Color font feature if I really wanted all the colors specified in the document to be overwritten (e.g. to convert a document to black and white, pictures non-withstanding). Otherwise, redefining LaTeX's \default@color is much more natural, doesn't interfere with \color or \textcolor and works whatever the engine or the document class. –  Philippe Goutet Aug 26 '11 at 18:38
    
@Philippe Thanks for your comment and answer. Indeed, the above solution does not work for the text colour of white as illustrated by my other question: tex.stackexchange.com/questions/28305/… –  kongo09 Sep 13 '11 at 21:21
add comment
\documentclass{scrreprt}
    
\usepackage{xcolor}
    
\AtBeginDocument{\color{red}}
    
\addtokomafont{sectioning}{\color{red}}
    
\begin{document}
    
\section{A section heading}

    some test text
    
\end{document}
share|improve this answer
    
Sorry, that doesn't work with Komascript. Section headings stay black. I've changed the minimum example accordingly. –  kongo09 Aug 25 '11 at 20:50
    
sure, it does ;-) –  Herbert Aug 25 '11 at 20:51
    
Thanks a lot, Herbert! And please ignore my comment above, adding \addtokomafont fixes the problem, now it is working. I found that I can also get it working by putting one \color just before and one \color just after the \begin{document} (thanks to @Gonzalo) –  kongo09 Aug 25 '11 at 20:53
    
While easy and elegant, it doesn't work for all the Komascript elements unless listed individually with \addtokomafont –  kongo09 Sep 13 '11 at 21:20
add comment

As Alan Munn suggested, since you're using XeLaTeX, you could use fontspec's capabilities to set the color of the font. If you want all the text to be a given color, you can even set that in the default font features:

\documentclass{scrreprt}
\usepackage{xcolor}
\usepackage{fontspec}
\defaultfontfeatures{Ligatures=TeX,Color=red}
\setmainfont{Linux Libertine O}
\setsansfont{Linux Biolinum O}
\setmonofont{Inconsolata}

\begin{document}
\chapter{A chapter}
\section{A section}
\texttt{Some mono text}
Some regular text.
\end{document}
share|improve this answer
    
same here: color changes are not possible with color commands, onyl with another \addfontfeatures{Color=blue} –  Herbert Aug 26 '11 at 15:58
    
Also, this doesn't work with white –  kongo09 Sep 13 '11 at 21:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.