I'm trying to pass a RGB colour code as an option to my custom-class.cls
, so I can change the colour of a header bar and the colour of my titles in the main-doc.tex
. The default option does work, but when I try to pass a different colour it does not work.
Code
Currently I have the following (based on this):
% main-doc.tex
\documentclass[]{custom-class}
\begin{document}
\header
\section*{Title test}
Test
\end{document}
And the custom-class.cls
:
% custom-class.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{custom-class}[2017/07/25 My custom class]
\LoadClass[a4paper]{article}
% Load required packages
\RequirePackage{titlesec} % To alter the style and spacing of titles
\RequirePackage{xcolor} % Enables the use of colours
\RequirePackage{tikz} % Draw things, needed for the header
\RequirePackage{xkeyval} % Pass options to sutom-class
% \define@key[<prefix>]{<family>}{<key>}[<default>]{<function>}
\define@key{custom-class.cls}{changecolor}[102, 204, 51]{%
\definecolor{maincolor}{RGB}{#1}%
}
\ExecuteOptionsX{changecolor}
\ProcessOptionsX%
% Coloured header
\newcommand{\header}{%
\begin{tikzpicture}[remember picture, overlay]
% Colored bar on top of the page
\node [below right, fill=maincolor, minimum height=4 cm, minimum width=\paperwidth] at (current page.north west) {};
\end{tikzpicture}
\vspace{1 em}
}
% Change format of the section title
\titleformat{\section}{\color{maincolor}\Large}{\thesection}{0em}{}
Result with a default value
Result with a custom value
When I change in main_doc.tex
the following line:
\documentclass[]{custom-class}
into:
\documentclass[changecolor={206, 23, 21}]{custom-class}
I get the following errors:
line 18: Missing \begin{document}.
line 18: You can't use `macro parameter character #' in horizontal mode.
line 18: Paragraph ended before \reserved@a was complete.
line 4: \RequirePackage or \LoadClass in Options Section. \begin{document}
and one warning:
Unused global option(s): [changecolor={206, 23, 21}].
\RequirePackage{kvoptions-patch}
before\RequirePackage{xkeyval}
, see tex.stackexchange.com/a/145454/89417 (possible duplicate). – Marijn Jul 27 '17 at 14:33