Writing LaTeX Using Kile

Last month, I reviewed Kile, a KDE editor for LaTeX. This month, I am going to show the basics of formatting a document in Kile. Once you know the basic structure of LaTeX, writing documents in it is even less complicated than manually coding HTML. Whether you use unmodified Kile’s templates for document structure, write your own code or lightly customize, LaTex turns out to be just another markup language, especially from within Kile. Admittedly, though, it is an usually rich and thorough markup language.

Before writing in Kile, I suggest selecting View | Dynamic WordWrap. This setting will wrap paragraphs so that they are visible in the editing window, instead of being one continuous line that you must scroll to read. In addition, if you are going to use Kile more than once, go to Settings | Configure Kile | General to set some of your options. In particular, set up Document Class Options. For instance, the default settings are A4paper,10pt, but since I have a North American printer and prefer slightly larger text, I have changed the settings to letterpaper,12pt. In addition, you might scroll through other options in the settings to make Kile more compatible with your work-flow. Once you  have adjusted everything to your liking, you are ready to begin.

The Basic Structure

All LaTeX documents have the same basic structure. All LaTeX documents have two main parts: the preamble, or front matter, that defines basic layout, and may give the title and author’s name. Preambles begin with information about the page and font size, followed by the document, and the encoding type, which these days is usually UTF-8:

\documentclass[letterpaper,12pt]{letter}
\usepackage[utf8]{inputenc}

Depending on the document type and your wish to control formatting, other information may be added about formatting such as the margins, and the title and the author’s name.

None of this material is printed until the \begin tag, which marks the start of the content. The content can have sections that override the preamble’s, with tags that begin with a backslash (\) and require end tags.

Both the preamble and the body may also be commented, using lines that being with %. The basic structure will look something like this basic structure for a report:

\documentclass[letterpaper,12pt]{report}
\usepackage[utf8]{inputenc}

% Title Page
\title{}
\author{}

\begin{document}
\maketitle

\begin{abstract}
\end{abstract}

\end{document}    

In between the \begin and \end tags for  the document, there will often be many more tags,  many of them defining sections with different formatting, all of which can be added either by clicking on the tag in the lefthand pane, or else by using tag-completion if you have some idea of the name of the tag that you need.

Working from a Document Type
Even for experienced user, writing in LaTeX is easier when using a document type. A document type will have default layout choices, so you have less to think about.Since there are over a dozen document types, you can often find one that can be modified for whatever you want to write.

A document type will will also have pre-formatted variables that you can use by replacing the name of the variable with your own information. For instance, if you are using a letter document type, you can replace ADDRESS in the tag \address{$$ADDRESS$$} with your own address. If the address is long, for convenience you might want to reformat so it is easier to read. For instance:

\address{$$
Mr. Fitzwilliam Darcy
1111 Pemberley House,
Village of Lambton,
Darbyshire
$$}

Just be sure that you have opening and closing parentheses.

When you have substituted your own values for the variables, enter the text. In the case of a Letter document type, it can go between the \opening and \signature tags. You can divide the paragraphs with an extra line, which will not be visible in the finished document.

Customizing Document Types
On the one hand, you can start with an empty document, adding the preamble and body as needed. However, this approach can be painstaking for beginners, with a single page requiring several hours to write, punctuated by looking up the tags to do what you want. On the positive side, dozens of pages on the Internet explain LaTeX tags, but, on the challenging side, there can be several ways to create the same format, and deciding on which to use only adds the time required to produce a document. On the other hand, one of Kile’s document types may not have the format you need or prefer.

A reasonable compromise is to start with a document type, and customize. You can partially take advantage of a document type’s formatting, and, so long as you do not delete the required tags, variables can be deleted. Although you may still need to look up some tags, you should be able to get away with using only a handful to get results with which you can live.

For example, the default Letter format has no provisions for short lines for addresses, or a right alignment. I customized by using the tag \bgroup\obeylines, which creates a section in which LaTeX to format line length as written in the raw file, until the \egroup tag. In addition, I used \begin{flushright} to give the sender’s address a right alignment. After the sender’s address, I restored the left alignment by creating another group and using \begin{flushleft}:

I also wanted to indent the text body, for which I used the tag \setlength{\parindent}{6ex}. This tag sets the indent for paragraphs to the equivalent of the width of six letter xes. At the end of the letter, I centered the salutation and signature with \begin{center}. The rest of the formatting belongs to the Letter document type, including most of the variables. Yet with only five tags — three of which concern line alignment — I have made the letter my own.

Building
As you are learning Kile and LaTeX, you are likely to make constant mistakes. For this reason, it is a good idea to use Build | QuickFormat and Build | QuickPreview frequently to check what you are doing. Kile will log any errors in your structuring, and generally you should correct the errors, too, making sure that \begin and \end tags match. However, LaTeX can be remarkably tolerant. Many errors will not prevent a successful build although ones like the failure to provide an end tag can cause you endless trouble sometimes. When you finish, you can use Build | Compile to make sure that you have formatted everything correctly.

To avoid repeating the same formatting over and over, save successful documents as templates so that you re-use them without drudgery. However, one way or the other, LaTeX proves far easier to work with than you might expect from its reputation, and using Kile makes LaTeX easier still.

letter

  • jawnhenry

    Good job; thank you.