/ Markus Amersdorfer:home / university / about:me /
\ Say NO to Software-Patents! \

# TeX & Co

## LaTeX

LaTeX is a document preparation system for high-quality typesetting. The idea is get rid of thinking about the appearance of what you write and concentrate on the content. Besides many other great features, LaTeX offers perfect typesetting of mathematical formulae. Furthermore, it is easily possible to use different output formats such as Postscript, PDF or HTML.

### Overfull HBOXes

One of the few "problems" in LaTeX that I know of are the "Overfull HBOXes" -- and they aren't a 'bug' but a 'feature', actually. :)
An "overfull hbox" occurs if LaTeX can not insert a newline or use hyphenation properly. With LaTeX, by default, not being allowed to stretch a line above a certain limit, it rather writes beyond the right edge of the line instead of putting the (whole or part of the) word into the next line. LaTeX views a line as a "horizontal box", and in case it has too much data to put into this box, it is "overfull".

In many cases, an overfull hbox can be ignored, as the human eye won't see the "error" being too small to be recognised. However, in other cases, the output simply looks ugly (at least).

#### Finding Overfull HBOXes

Inserting `\overfullrule=5pt` in the preamble results in black rectangulars at the right hand side of the lines where an overfull hbox occurs. This way, you can easily track them down.

## LyX

LyX is the first WYSIWYM (= what you see is what you mean) document processor. Using LaTeX in the background, LyX inherits all of LaTeX's advantages. While LaTeX is IMHO somewhat hard to learn, LyX smoothes these rough edges and makes creation of both small and large documents a breeze - it's a really easy to use graphical frontend for the creation of terrific output!

### Installing LyX

With the QT libraries compiled and installed under `/usr/local/qt/`, I compile and install LyX with the QT interface as follows:

```Compile and install LyX:
./configure --prefix=/opt/lyx --with-frontend=qt --with-qt-includes=/usr/local/qt/include/
make
make install
```

If the configuration process does not find the correct QT libraries, you might have to run the following first (which is only necessary when QT has been compiled manually, usually):

```Possibly necessary beforehand:
QTDIR=/usr/local/qt
PATH=\$QTDIR/bin:\$PATH
MANPATH=\$QTDIR/doc/man:\$MANPATH
LD_LIBRARY_PATH=\$QTDIR/lib:\$LD_LIBRARY_PATH
export QTDIR PATH MANPATH LD_LIBRARY_PATH
```

### Localisations

Though being from Austria, I like to have my programs "talk English" (while, of course, they shall still be able to process European stuff such as German umlauts etc.) - see my Debian documentation for general details on this topic.
With the current GDM2 version in Sarge, I couldn't figure out how to get the desired behaviour, so I'm using XDM at the moment (with this setup using the settings in `/etc/environment`).

Despite of this, I still had problems with LyX not only talking English but also understanding English in the way that I want to use the English keyboard shortcuts: `"ALT+p, i"` for "Itemize" (instead of the German `"ALT+a, i"`, with "p" probably meaning "paragraph" and "a" meaning "Absatz").
In order for this to be fixed, I use the following mini-script to start LyX:

```/usr/local/bin/lyx:
#!/bin/bash
export LANG=C
/opt/lyx/bin/lyx \$@
```

### Document Settings (based on my thesis document)

I wrote my thesis document in LyX. Here are the custom settings:

• Layout
• `Document class: report` -- offers "abstract" and "chapters", among others.
• `Page style: fancy` -- offers fully configurable headers and footers (see below).
• `Font & size: newcent - default`.
• `Line spacing: OneHalf`.
• Paper
• `Paper size: A4`.
• `Two-sided document`.
Note that the inner part of the page is smaller than the outer one, as when your document is bound as a book, each outer margin should have the same width as the two inner margins together: `|------|<text>|---||---|<text>|------|`
• Margins
• `Margins: Small margins` -- the default margins are too large on A4 paper, IMHO.
• `Preamble:`
```% Fancy Headers - see http://www.ctan.org/tex-archive/info/german/fancyhdr/
\fancyfoot{}
\fancyfoot[CO,CE]{\thepage}% page number in footer, always centered

% To be able to use xfig figures with inline LaTeX commands
% (also see xfig figures in LyX below)
\usepackage{color}
\usepackage{graphicx}

% BibTeX
\usepackage{url}

% Roman page numbering for the TOC
% http://wiki.lyx.org/pmwiki.php/Examples/RomanPageNumbering
% (warning: with this activated, exporting to HTML loses every layout information!)
\pagenumbering{roman}
\let\myTOC\tableofcontents
\renewcommand\tableofcontents{%
\myTOC
\clearpage
\pagenumbering{arabic}
}

% Show black rectangles where overfull hboxes occur - used for "debugging":
%\overfullrule=5pt

% Prevents overfull hboxes by allowing
% the text to be stretched more than usual:
%\emergencystretch=11pt

%%%% PDFs with hyperrefs
%%%% see tex2pdf below instead of the following:
%% I could not get both hyperref and A4 sized output to work
%% at the same time when using pdflatex through LyX or manually.
%%http://wiki.lyx.org/pmwiki.php/FAQ/PDF
%%http://www.tug.org/pipermail/pdftex/2001-December/002048.html
%\usepackage{hyperref}
%\usepackage[plainpages=false,pdfpagelabels,hypertexnames=false]{hyperref}
%
% Make pdflatex use A4 (and not letter)
% though we use package "graphicx":
%\pdfpagewidth=210truemm
%\pdfpageheight=297truemm
%\pdfcompresslevel=9
```

### LyX Keyboard Shortcuts

Besides many others, there are the following ones I use most:

 `ALT+p, i` Itemize `ALT+p, d` Description `ALT+p, e` Enumerate `ALT+p, s` Standard `ALT+p, [123456]` chapter, section, subsection, [...], subparagraph `CTRL+SHIFT+p` Switch between `typewriter` and standard font `CTRL+e` Switch between emphasised and standard font face `CTRL+b` Switch between bold and standard font face `CTRL+m` Math mode `CTRL+ALT+[123]` Save Bookmark [123] `CTRL+[123]` Go to Bookmark [123] `CTRL+t` View (as) Postscript `CTRL+g` Go to Error (useful if the latex-process returns errors, which show up in LyX) `SHIFT+ALT+Right` Increase environment depth (of e.g. itemizations) `SHIFT+ALT+Left` Decrease environment depth (of e.g. itemizations)

### xfig: xfig figures in LyX

Though being a somewhat elder program already and having a user interface one has to get used to, `xfig` has many features that make it great to be used: With the use of the keyboard-shortcuts, work can be performed quite quickly, etc. But most importantly, xfig figures can be perfectly integrated into LyX / LaTeX, with features such as some text of the figures (e.g. mathematical formulae) being rendered by LaTeX, using the same font as for the rest of the document.
"The LyX User's Guide" (LyX: Help -- User's Guide) explains, how this can be done correctly (simply search for "xfig" in the document). Anyway, here's how I did it ...

#### xfig: Create the figures correctly in the first place

While the graphical part of the figure is best exported as Postscript (which offers both perfect quality and lots of fine-tuning such as thickness of lines, etc.), the text itself is exported as LaTeX code. This makes it possible for LaTeX to render the text, including formulae etc.

The text to be rendered by LaTeX must have the special flag set: In the "EDIT" dialog of a text, set "Special Flag" to "Special" (instead of "Normal"). The possibly better way is to start xfig with the command `"xfig -specialtext"`, to have any text entered default to the special flag being set.

#### xfig: Export the figures correctly next

Next, export your figure as "Combined PS/LaTeX (both parts)". This will create two files: A `.pstex` part that holds the Postscript graphics and a `.pstex_t` part with the LaTeX commands. (The latter will be included by your document.)
In the "pstex_t" file you will find an `\includegraphics{x-y-z.pstex}` line in order for the Postscript part to be included too, eventually. Whether the path to the "pstex" file is absolute or relative here, depends on how you created and exported the figure. If you have your `.lyx` in (say) `~/MyDocs/` and if you use a separate directory for your figures (such as `~/MyDocs/figures/`), you should check this path to be either absolute (`/home/\$USER/MyDocs/figures/x-y-z.pstex`), or even better be relative to your LyX-documents-directory (`figures/x-y-z.pstex`) - with the latter making you somewhat more independent if you refactored your directory structure some day. (If the path was not correct, running LaTeX will throw some errors (which are always "strange" ones in LaTeX, IMHO ;) ...)

#### xfig: Include the `pstex_t` file in LyX

The figure is (IMHO) best included in LyX as "Insert -- Floats -- Figure"; give it a name, a label and then include the file in this float: "Insert -- Include File", point to `x-y-z.pstex_t` and set "Include Type: Input".

For your file to be compiled correctly by LaTeX, you need to have the preamble include two packages:
`\usepackage{color}`
`\usepackage{graphicx}`
(You might be able to get rid of the `color`-dependency, see lyx-users mailing-list posting if you'd like to.)

## tex2pdf

The PDF file format offers links inside the document. With the LaTeX package hyperref and the command `pdflatex`, such files can be created from your LyX/LaTeX documents.
As you can see in my preamble listing above, I'd tried to get them working using the hyperref package, but I did not succeed as either I had hyperref's in the document but `pdflatex` produced a letter-sized paper, or I had an A4 paper with no hyperref's.

tex2pdf is a Perl-script that manages everything quite perfectly when creating PDF files from your documents.
My best experiences were with the development version 3.2a on an up-to-date (as of February 2004) Debian Sarge machine.

Run `"tex2pdf -c"` to configure the script according to your wishes. (It is e.g. easily possible to set the color of the hyperref-links this way ...)
To produce a PDF file, simply run `"tex2pdf your-doc.lyx"` or `"tex2pdf your-doc.tex"`.
(The script manages the conversion of the possibly PS-based figures to PDF-files, which is necessary for "pdflatex", etc...)

### Known bugs

As has just been mentioned, "pdflatex" can not process PS-files directly, so they have to be converted to PDF first. Unfortunately, that's a step of the overall process that might mess up your graphics by rotating them by 90°, or something like that. However, this only happened on a rather old Debian Sarge installation (date Aug. 2003 with tetex-1 packages, etc.). The problems disappeared on an up-to-date machine (as of February 2004 with tetex-2.0.2 packages, etc.) and the 3.2a version of "tex2pdf".
(Note: Different conversion programs PS -> PDF have different qualities of output. The "tex2pdf"'s default produces best quality, but sometimes suffers from the rotation bug. You might check out other conversion options (introduced in the current CVS-version of the "tex2pdf" script).)

back to index