# Using later-defined commands in an own document class

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]
\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)

• If I add \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. May 3 '18 at 9:58
• You know what the more complex things are, I don't. Closing as “too broad”. May 3 '18 at 10:15
• Rule of thumb: if the user has easy access to the class, he will fumble with the class. It doesn't matter how many hooks for customisation you provide. May 3 '18 at 10:40
• I speak from experience, they will modify the class file, if they can reach it easily. Trial and error is easier than common sense. And yes, the users I am talking about are researchers as well. May 3 '18 at 13:29
• One way of having a customizable system: key-value setup. There are some questions on this site showing how to do this. May 3 '18 at 13:39

One solution for defining colors and other commands outside of the class would be a preamble file that can be included into the class:

class file:

...
\RequirePackage{xcolor}
\input{preamble}
\colorlet{examplecolor}{somecolor}
...


preamble file:

\definecolor{somecolor}{rgb}{0,0,1}