Writing your own class
4 stars based on
Sometimes the best option to customize a document is to write a new class from scratch. This article explains the main structure and commands needed in a new class. The first thing to do before coding a new class is to determine whether you really need a new class or not. Another important thing to have in mind is the difference between packages and classes. Making the wrong choice can affect the flexibility of the final product. In the next subsections a more detailed description of the structure and a working example, latex letter document class options.
Additionally, a date can be added within brackets to specify the minimal release date required. Open an example of how to write a class in ShareLaTeX. Most of the classes extend and customize existing ones, and also need some external packages to work.
Below, some more code is added to the sample class latex letter document class options. The commands in this part either initialize some parameters that latter will be used to manage the options, or import external files. Therefore all the commands in the standard article class will be automatically available in the example class, except that the document will be printed in a two-column format. To allow some flexibility in the classes a few additional options are very useful.
The next part in the file "exampleclass. It takes two parameters, the first one is the name of the option and the second one is the latex letter document class options to execute if the option is passed. In this case the document is set to two-column and if the user tries to change it to one column that won't work, the option will be ignored.
It takes only one parameter, the code to execute when an unknown option is passed. In this case it will run the next command:. Passes the latex letter document class options inside the first pair of latex letter document class options to the document class set inside the second pair of braces.
In the latex letter document class options, all unknown options will be passed to the article document class. There's a starred version of this command that will execute the options in the exact order specified by the calling commands. In the example, if the options red or green are passed to the document the font used for the headline and the sections will be set to the corresponding colour. The colour called "slcolor" was defined in the preliminary declarations after importing the xcolor package.
In this part most of the commands will appear. Below you can see the full class file. To understand the rest of the commands see the reference guide and the links in the further reading section.
When it comes to develop new classes it's important to handle possible errors to let know the user that something went wrong. There are four main commands to report errors in the compiler. Open an example of how to write a class ShareLaTeX.
Writing your own class. Contents 1 Introduction 2 General structure 2.