Customising class styles
Tuesday, October 31st, 2006 | LaTeX
The basic premise of TeX is that nearly everything can be changed. So, we could change, for instance, the \maketitle command to output a page of fluffy bunnies with your title, name and other info (like \thanks) in a pink box. This will almost guarantee that your paper looks rather unique in your teacher’s pile of papers to grade—we will leave that up to you to decide whether that is a good thing, though.
Since the character @ lies in a special category (I’ll return to categories some other time—they aren’t strictly relevant to understand for the purpose of this post), it is a good choice to use as internal
variables, since a user doesn’t accidentally use one. Thus, most internal commands are on the form \@myname.
So, when we write something like
\documentclass{article} \author{Henrik Stuart} \title{Brian, the Bunny Slayer} \begin{document} \maketitle \end{document}
We get a fancy first page as seen in this figure:
Not really the thing that’ll catch a child’s fancy (nor most grown-ups for that matter).
Now, what happens when we write \title is that the following command is triggered (the exact details may differ by distribution and version):
\def\title#1{\gdef\@title{#1}}
What this basically does is to globally define the command \@title to contain your argument. In our case, using \@title inside the document would print out Brian, the Bunny Slayer
(sans the quotes, if your browser supports them). Likkewise \author globally defines \@author. The difference between \def and \gdef will also be covered at a later time.
So, using our knowledge, we can generate our title in a… ehm… lovely pink box, like this:
\documentclass{article} \usepackage{tikz,xcolor,pgflibrarysnakes,calc} \author{Henrik Stuart} \title{Brian, the Bunny slayer} \makeatletter \renewcommand{\maketitle}{ \newpage \noindent \begin{tikzpicture} \draw[snake=bumps,fill=pink,color=pink] (0,0) rectangle (\textwidth,6cm); \draw[snake=bumps] (0,0) rectangle (\textwidth,6cm); \draw (.5\textwidth,4cm) node[baseline] {\color{white}\bfseries\Huge\@title}; \draw (.5\textwidth,2cm) node[baseline] {\color{white}\bfseries\itshape\Large\@author}; \end{tikzpicture} } \makeatother \begin{document} \maketitle \end{document}
which results in the following page:
This is probably very appetising for a 5-year old, but I’m not sure who else would want such a title page.
This, however, is not the primary point of this post—albeit it has taken up considerable space. Imagine that you’re working on your LaTeX document in a somewhat diverse group whose members use different distributions on different operating systems. Then \@author could’ve been \@author, or something entirely different, leading to an error when the other group members try to compute the document.
The \maketitle redefinition is a fairly benign command to modify, but imagine if you had to look up the internal commands for altering the layout of the table of contents, list of figure, chapters, sections, etc. Also imagine that the internals can be changed by a new version, rendering all your old documents obsolete. Thus, it is probably for the best to use a popular document class, as it is likely it will quickly be updated to accomodate a new version (or not need to be modified at all), and you can settle with just updating in one place.
The document class of choice isn’t article, report or book that most tutorials use, but rather memoir, which has been written to limit the amount of packages you need, and to provide a great deal of control over the layout and typography of your document. To use memoir, it has a dense and very useful documentation that I would suggest you pursue. It even contains a very good part on typography that is valuable reading. Most of my future posts will be using memoir, so to get ahead of the game, read and enjoy its manuals (also contained at the above link).
No comments yet.
Leave a comment
Categories
Archives
- February 2012
- July 2011
- June 2011
- November 2010
- October 2010
- April 2010
- November 2009
- October 2009
- June 2009
- May 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- December 2006
- November 2006
- October 2006
- September 2006
- June 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- June 2004
- April 2004
- February 2004
- November 2003
- January 2003
- November 2002