Your support for our advertisers helps cover the cost of hosting, research, and maintenance of this document
Formatting Information — An introduction to typesetting with LATEX
Chapter 7: Programmability
Section 7.6: Reprogramming LATEX’s internals
In this section…
LATEX’s internal macros can also be reprogrammed or even rewritten entirely, although doing this can require a considerable degree of expertise. Simple changes, however, are easily done. These examples can also be done with the appropriate package, but they are done by hand here as examples of how it works.
7.6.1 Changing numbering levels
Recall that LATEX’s default document structure for the Report document class uses Chapters as the main unit of text, whereas in reality most reports are divided into Sections, not Chapters (see the footnote ‘It is arguable that parts and …’ above). The result of this is that if you start off your report with \section{Introduction}, it will print as
0.1 Introduction
which is not at all what you want. The zero is the (missing) chapter number, because no chapter has been started. But this numbering is controlled by macros, and you can redefine them. In the footnote ‘In fact, any time you define …’ above we said that every counter automatically gets a related command beginning with \the.... In this case what we need to change is that command \thesection because the way the counters are set up makes it reproduce the value of the counter section (see the last para ‘This would make the outermost list …’ in § 4.1 above) plus any higher-level value (eg chapter). It’s redefined afresh in each document class file, using the command \renewcommand (in this case in report.cls):
\renewcommand\thesection{\thechapter.\@arabic\c@section}
You can see it invokes \thechapter (which is defined elsewhere to reproduce the value of the chapter counter), and it then prints a dot, followed by the Arabic value of the counter called section (that \c@ notation is LATEX’s internal way of referring to counters). You can redefine this in your Preamble to simply leave out the reference to chapters:
\renewcommand{\thesection}{\arabic{section}}
I’ve used the more formal modern method of enclosing the command being redefined in curly braces. For largely irrelevant historical reasons these braces are often omitted in LATEX’s internal code (as you may have noticed in the example earlier). And I’ve also used the ‘public’ version of the \arabic command to output the value of section (LATEX’s internals use a ‘private’ set of control sequences containing @-signs, designed to protect them against being changed accidentally).
Now the introduction to your report will start with:
1 Introduction
Never change the installation files
What’s important in making this type of modification is that you DO NOT (ever) alter the original installed document class file report.cls. Instead you copy the command you need to change into your own document Preamble, or a private package file, and modify that instead. It will then override the default because it will get loaded after the document class and replace the original definition.
(XML users may recognise that this is the reverse of the way that Local Subset modifications work with an XML Document Type Description (DTD), where the first declaration always holds, and subsequent redeclarations are ignored.)
7.6.2 Changing list item bullets
As mentioned earlier, here’s how to redefine a bullet for an itemized list, with a slight tweak:
\usepackage{bbding} ... \renewcommand{\labelitemi}{% \raisebox{-.25ex}{\small\PencilRight}}
Here we use the bbding package which has a large selection of ‘dingbats’ or little icons, and we change the label for top-level itemized lists (\labelitemi, find these in any document class file) to make it print a right-pointing pencil (the names for the icons are in the bbding package documentation: see § 3.1.3 above for how to get it).
In this case, we are also using the \raisebox command within the redefinition because it turns out that the symbols in this font are positioned slightly too high for the typeface we’re using. The \raisebox command takes two arguments: the first is a dimension, how much to raise the object by (and a negative value means ‘lower’: there is no need for a separate \lowerbox command); and the second is the text you want to affect. Here, we are shifting the symbol down by ¼ex (see § 1.10.1 above for a list of dimensional units LATEX can use). We also make the icon slightly smaller to go better with the font we are using.
There are label item commands for each level of lists (1–4) which have command names ending in Roman numerals (i–iv) because of the rule that command names can only use letters. Thus to change the icon for the fourth-level list, modify \labelitemiv. There is a vast number of symbols available, not just bbding: see the A comprehensive list of symbols in TEX for a comprehensive list.