# How to import additional code into class file

I was inspired by the article "Fancy chapter headings with TikZ" (Stefan Kottwitz many thx) and I have created the whole fancy sectioning. But what I need to do now is to import this whole code for sections and chapter into my REPORT CLASS because I dont want this code to be in my project. For example when I will start my new project and will add the \documentclass[svgnames]{report} and will begin document with \section{bla bla} so the edited sectioning in report class will be automatically applied for the \section{bla bla} command.

I am asking for some help because I have never ever played with the latex files and classes.

-
Would it not be more convenient to put this in your own custom package? Then you could just write: \usepackage{myfancysections}. If you really want it in the class, consider cloning article.cls, but I would not suggest it. It is way less partible then putting this in your own package. – jmc Mar 27 '12 at 13:20

\RequirePackage[utf8]{inputenc}
\RequirePackage[T1]{fontenc}


But you can remove if you want, I added also

 \PassOptionsToPackage{dvipsnames,svgnames}{xcolor}


useful for TikZ

and finally

\RequirePackage{etex}
\RequirePackage{fixltx2e}


But you can also remove these packages. You need to save the next code in a file names myreport.cls.

\NeedsTeXFormat{LaTeX2e}[1995/12/01]% standard latex package works with this format
\ProvidesClass{myreport}% we give the name of the new class (here myreport) and we give
[2012/03/27\space Version:\space 1.0\space myreport documentation class]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
% more complex We create a new class based on an existing class and we want to use the
options of report
\ProcessOptions\relax% this is the way to process the options, Stephan gave the good link
for clsguide.pdf
\LoadClass[]{report}  % add options if necessarry , we can create personal options
\PassOptionsToPackage{dvipsnames,svgnames}{xcolor}
% To avoid clash with xcolor,  \PassOptionsToPackage is the good macro to pass options
% tikz loads xcolor, and if you want some extra colors, you need to use xcolor with
% dvipsnames,svgnames ( see xcolor.pdf ). But you need to make before loading tikz.
\RequirePackage[utf8]{inputenc}
% I recommend to use utf8 but you can prefer latin1. You can adapt this line.
\RequirePackage[T1]{fontenc}
% personally  I don't use this line because I work with fourier font and fourier.sty
\RequirePackage{tikz}
\RequirePackage{kpfonts}
\RequirePackage[explicit]{titlesec}
\RequirePackage{etex}
\RequirePackage{fixltx2e}

% colors
\definecolor{fHlavicky}{RGB}{124,252,0}
\definecolor{fPisma}{RGB}{0,0,0}
\definecolor{fCHaSEK}{RGB}{255,127,0}
\definecolor{fSSaSSS}{RGB}{0,191,255}

\newcommand*\chapterlabel{}
\newcommand*\sectionlabel{}
\newcommand*\subsectionlabel{}
\newcommand*\subsubsectionlabel{}

%CHAPTER
\titleformat{\chapter}
{\gdef\chapterlabel{}
\normalfont\sffamily\Huge\bfseries\scshape}
{\gdef\chapterlabel{\thechapter\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[yshift=-3.2cm] at (current page.north west)
{\begin{tikzpicture}[remember picture, overlay]
\draw[fill=fHlavicky] (0,0) rectangle
(\paperwidth,3cm);
\node[anchor=west,xshift=.7,yshift=.07\paperwidth,rectangle,
rounded corners=20pt,inner sep=11pt,
fill=fCHaSEK]
{\color{fPisma}\chapterlabel#1};
\end{tikzpicture}
};
\end{tikzpicture}
}

%SEKCTION
\titleformat{\section}
{\gdef\sectionlabel{}
\normalfont\sffamily\LARGE\bfseries\slshape}
{\gdef\sectionlabel{\thesection\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=west,xshift=.2\paperwidth,rectangle,
rounded corners=7pt,inner sep=3pt,
fill=fCHaSEK]
{\color{fPisma}\sectionlabel#1};
\end{tikzpicture}
}

%SUBSEC.
\titleformat{\subsection}
{\gdef\subsectionlabel{}
\normalfont\sffamily\large\bfseries\upshape}
{\gdef\subsectionlabel{\thesubsection\ }}{0pt}
{\begin{tikzpicture}[remember picture,overlay]
\node[anchor=west,xshift=.2\paperwidth,rectangle,
rounded corners=5pt,inner sep=2pt,
fill=fSSaSSS]
{\color{fPisma}\subsectionlabel#1};
\end{tikzpicture}
}

%SUBSUBSEC.
\titleformat{\subsubsection}
{\gdef\subsubsectionlabel{}
\normalfont\sffamily\large\bfseries\upshape}
{\gdef\subsubsectionlabel{\thesubsubsection\ }}{0pt}
{\color{fSSaSSS}\subsubsectionlabel#1}

\titlespacing*{\chapter}{0pt}{50pt}{-60pt}
\titlespacing*{\section}{-210pt}{5pt}{10pt}
\titlespacing*{\subsection}{-180pt}{5pt}{10pt}
\titlespacing*{\subsubsection}{-30pt}{5pt}{10pt}
\endinput


Now you use the class :

\documentclass{myreport}
\begin{document}
\section{Introduction}
\section{Suite}
\subsubsection{intro-suite}
\end{document}

-
Wow thank you very much. I had to do some modifications cuz of lots of errors for my example document. But this helped me a lot. But i have few questions because i want to also understand some things for future: Q1: What advantage gives me " \PassOptionsToPackage{dvipsnames,svgnames}{xcolor}" ? Q2:Can you give me some short cooments for the first 5 lines in myreport.cls. ONE MORE TIME :) THANK YOU VERY MUCH – Longobard Mar 30 '12 at 9:32
Yes I will add some comments – Alain Matthes Mar 31 '12 at 6:04

Easiest solution:

1. Make a class file myreport.cls consisting of your code.
2. Add \LoadClass{report} at the beginning.
3. Look at clsguide.pdf for further administrative stuff like \ProvidesClass you should add.
4. Use with \documentclass{myreport}.
-
Thank you Stephan :) – Longobard Mar 30 '12 at 9:32