I am writing a LaTeX class that provides general layout and design features. Elements like the color scheme should be user-defined in the main document. However, the class is loaded before their definition in the main document.
How to pass latex commands like color definitions to the documentclass?
MWE Class file:
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{K}[2018/05/03 Example]
\LoadClass{book}
\RequirePackage{xcolor}
\definecolor{somecolor}{rgb}{1,0.3,0.1}
% How to define this color in the main document?
\colorlet{examplecolor}{somecolor} % this is necessary
\renewcommand\thechapter{\textcolor{examplecolor}{\arabic{chapter}}}
MWE main document:
\documentclass{K}
% Ideally user-specific color definitions should go here!
% But they are already required by class K before,
% so \definecolor{somecolor}{rgb}{1,0.3,0.1} here does not work
\begin{document}
\chapter{Example chapter}
Example text
\newpage
Example text
\end{document}
Key-value approaches probably don't work, because neither is a command a simple value, nor can I use \definecolor in the first line of the latex document before including the xcolor package. Are there alternatives to late-definitions? (Using later defined macro values)
\definecolor{examplecolor}{rgb}{0,0,1}in the document preamble, I get the chapter number colored blue. On the other hand, it's not recommended to add formatting instructions to\thechapter. – egreg May 03 '18 at 09:58somecolor) in the class by\colorlet. Also, formatting\thechapteris only a simple example to illustrate my problem, I don't do it in the real code. There are other, more complex things going on in my template, which are beyond an MWE, so it'll be great to focus on the general problem rather than the content of the MWE. – Martin May 03 '18 at 10:07\thechapter, otherwise that would appear in the chapter title, all references as well as the running heads. – Werner May 03 '18 at 17:45