Working with .cls file in LaTeX

Normally, LaTeX provide predefined class to work like article, report, Book, elsarticle etc. But sometimes we need special features in our document, I can say when we need sudo power on document then we can create our own .cls file. .cls file provide code reusability. It means that whenever  you need similar feature in future projects. Then you just need to put name of your .cls that you have created earlier. Just do following to create and use own .cls file.

Firstly create .cls file and save it with any name for example: Dhiman_article.cls

Dhiman_article.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{Dhiman_article}[2016/05/3 Dhiman custom class]
\LoadClass[a4paper,twocolumn]{article}

%put your code and formatting that you want to reuse.

Note : Must ensure that if you are creating your own .cls file then you don’t have a need to include article or any \documentclass explicitly in .tex file. You just load required main class in your custom .cls file.

Now use your custom .cls in your .tex file

article.tex
\documentclass{Dhiman_article}
\begin{document}

%%%%%% Content here%%%%%
\end{document}

Done.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s