LaTeX Typesetting

This is my old LaTeX page from the old site that there are still many people linking to. Now here is it again with the same URL but with a new style sheet. Hope you will enjoy it.

Leave comments here!

Here are the short links to my files:

A definition style list

A definition style list is a list that take a word  and then a definition to the word. Very handy when documenting things. Here is one way of doing it if you like.

\newenvironment{mylist}[1]% {
 \renewcommand{\makelabel}[1]{\textbf{\hfill##1}}}}% {\end{list}} 
\begin{mylist}{new Document} 
\item[new Document] 
The inital call to create the object. This will generate the preamble, and a basic title. 
\item[SetTitle] Sets the title to a new value. 
\item[GetTitle] Returns the current title value. 
\item[AddBody] Injects pre-formatted tex data into the document (used in conjunction with 
LongTable and CreateSection). 
\item[CreateSection] This will start a new page, add the section command, and inject in 
the data following the call. 
\item[CreateDoc] This will collate all the settings requested, and return the a string 
containing all the tex data required to generate a \LaTeX\ document.  
This can then be output to a file to be processed by a call to pdflatex. 

Making a protocol counter

If you are taking notes from a meeting you may want to use this little hack to get nice ordered paragraphs with proper counters and paragraph signs:

In the preamble of your document define a new counter:

\newcounter{pc} % Paragraph counter

Then in the body of your document where you want it you will start using the list environment like this:

 \item First we discussed about the bicycle shed. 
 \item Then we decided where the new nuclear reactor should be placed. 
 \item At last we had a nice dinner. 

That’s it. The result is very neat and tidy!

Making proper PDF

The pdflatex command is great for the most part but if you are using EPS pictures in your document it will not work. Then you need to convert all the pictures to PDF files first and then you must change the names of the pictures in your original document.

Also the pdflatex inserts colour codes in your document to visualize links and similar things via the hyperref package when used, while this is great for PDFs intended to be viewed on screen it is not so good for printed PDFs. There does not seem to be a way to turn it off for printed so here is the old way of producing nice PDFs that suits well for printing:

First generate the dvi file as you would with the latex myfile.tex command. When you now have the dvi you can use the command dvips -Ppdf myfile.dvi to generate a post script file from it. Finally then convert the postscript into a PDF by using the ps2pdf command.

The toolchain looks like:

latex mydocument.tex; dvips -Ppdf mydocument.dvi; ps2pdf

Good style for articles and mails

You can download and toy with my private template for making technical documentation. Please if you make any nice changes to it, share it with me. Email me a copy please!

The document needs some non-standard LaTeX things. You need to find and install a copy of ”fancyheadings.sty”. If you are supposed to make use of the hyperlinks in your PDF’s and such I recommend you get epstopdf converter so that you can enjoy your logotypes and pictures in PDF.

I also have a small template for business mails if you are interested in this kind of thing.

Getting rid of orphans and widowed words

Sometimes when you typset something in LaTeX you will find that a single word or a few of them ends by them selves on an otherwise blank page. This is called ”orphans” if it is at the bottom of a page or ”widowed” if they are at the top in typographic lingo and is generally something that TeX handles pretty well (at least better then Word), but in some occasions it still happens.

You can avoid this by setting the following penalty values

\clubpenalty=9999 \widowpenalty=9999

This makes it rather hard for LaTeX to ”break the rule” and typeset orphans or widows. However it is still possible in some situations they will still occur.

It is not recommendet to set this to 10000, bad things can happen then when LaTeX can never break this rule.

Three digit chapter numbers in the TOC

It was for me. I am typesetting a book with roman numbers (I, II, III) as chapter numbers and when there are more then two letters for the chapter there is a problem because the chapter name will then overwrite the last letter.

Like in ”XIV A chapter name”, the A will overwrite the V of the roman number. I found this crude but effective solution to the problem:

copy the book.cls to a your own layout file (like mybook.cls)
edit the \newcommand*\l@chapter[2]{% section :
change ”\setlength\@tempdima{1.5em}%” to ”\setlength\@tempdima{2em}%”
this adds another space to the number
The number {2em} can of course be changed to anything you like in order to make it typset the chapter numbers nicely.

Swedish style of typesetting?

I have written a swedish style ichiswedish.sty to be used with LaTeX to typeset swedish documents. It calls upon babel and does various other things so you do not need to do that yourself. It makes for saving some time when writing a document. You can download it here.

Ideas for this style comes from various sources, among those usenet groups and others.

Footnotes inside tables

This is a little bit tricky, but I have found a solution that works even if it is not a very nice one. It’s a bit crude, but effective.

Inside the table where you want the marker to be, place a \footnotemark there. Then outside of the table place a \footnotetext Now, for each footnote you do this way you need to keep track of the footnotemark/footnotetext pairs yourself. As I said, a bit crude.

In plain TeX you can use \footnote and \vfootnote in the same manner.

Numbering of sections and TOC-depth

LaTeX autonumbering is usually a good thing and works very well. There are however certain instances when this is not what you want and you might like to turn it off. The best way of doing that is to set the counter secnumdepth in the preamble of your document:


This will make section and down numberless. Parts and chapters will still be numbered, to avoid this change the 0 to -1 and so on. Try it out it works all right.

In a similar way you can set tocdepth to the number you want. Standard is 3, you can increase this to get more into the table of contents or lower it to get less.


Adding space between a float and its caption

Sometimes the space is too little when you have done some modifications to a figure or table or something else with a caption. The lengths \belowcaptionskip and \textfloatsep can be used to cure this.


Fancy headings package

The fancy headers package is a great package for changing the headers and footers of your document. There is a lot to say about this, but what you need to do is this:
Place this in the preamble of your document:

\usepackage{fancyheadings} \pagestyle{fancy}

Then set up the pagestyle as you want it by using this template code and filling in whatever you wish here:

%% Setting up pagestyles for ``fancy'' 
\rhead{\sl Page \thepage} 
\lhead{\sl My document} 
\headrulewidth 0.5pt 
\footrulewidth 0.5pt 
 \copyright Me, Myself and I} 
 \rfoot{\tt \scriptsize}

As you can see \thepage gives you a page number. There are similar commands that will give you section numbers, chapters etc. as well. Have a look at the documentation for the fancy headers package if you want to know more about

Barchart Package

Get the file bar.sty from your closest CTAN archive FTP server and install it by copying it to the apropriate directory where your LaTeX installation sists. (You can find a suitable place by searching for other .sty files).

Now you are set to use it. Try this code:

 \caption{Example diagram} 

Writing a letter

Writing letters in LaTeX is rather simple, there are functions that will help you to put things where they should go, and this is the template I usually use myself.

\address{ your name\\ Your address1\\ Your address2\\ your address3\\ } 

\begin{letter}{ Receivers name\\ Receivers address 1\\ Receivers address 2\\ Receivers address 3\\ } 

% letter here 

\closing{Sincerely,\ } 
%% If you have things to enclose, specify here 
%\encl{Encl. 1} 
%\encl{Encl. 2} 
\end{letter} \end{document}

Writing your own environments

To write your own environments is not very hard or hairy at all. Any TeXnician should become familiar with the simple steps you need to learn in order to expand and extend the environments of LaTeX.

It is particularly useful when you are trying to create your own styles for quoted material, writing a protocol or anything like that.

Here is how you define a new environment:

\newenvironment{mycitation} {% This is the begin code 
 \begin{enumerate} } 
{% This is the end code 
\end{quotation} }
As you can see, the \newenvironment command takes three arguments. The first is the name of the new environment, the second is the start of the environment and the last is the closing of the environment.

The above environment will cause a new environment called mycitation to be created. It looks like the ordinary quotation environment but it is numbered. You can use this whenever you want to put a citation in the text. If you do not like the looks of this, then you only need to change your definition in one place of the LaTeX source, not everywhere.

Changing the spacing of paragraphs

Put this early in your document to change how paragraphs are shown. The two lines below will change the environment to show paragraphs the way they are typeset in letters.

\setlength{\parskip}{1ex plus 0.5ex minus 0.2ex}

The parindent length determines how far the paragraphs first line will be indented in print. The second one sets how much vertical space there will be in.

Don’t put this before you have a table of contents or similar autogenerated insertion because it will definitely screw that up. If you still need this, the very least you have to do is to put the parskip back to 0pt again.

Relative Font sizes

From smallest to biggest they go like this:

\tiny \scriptsize \footnotesize \small \normalsize \large \Large \LARGE \huge \Huge


Leave comments here!

Photos and other rants