LaTeX

bibliography@authorIndex

LaTeX and all its little helpers are your friends … most of the time. However, every once in a while they decide to do some nasty stuff and annoy you.

The Quest for the Lost @

Imagine you’re preparing a citation in BibTeX where the author is an institution called author = {iSleep@Work} (@s seem to be very trendy in names nowadays). Using natbib and the *.bib-file in your document, you run latex/bibtex and everything works.

Later you decide to include an index of authors in your appendix, add all the code to your document (\usepackage{makeidx}\citeindextrue\makeindex in the preamble and \printindex in the appendix), but suddenly latex yells that there’s something wrong …
Looking at the document, you will see that all citations in the body are correct and also the references-section has not changed. The problem lies in the author index section, where the entry for your citation now reads Work – something happened to the iSleep@.

BibTeX vs. MakeIndex

Contrary to BibTeX, MakeIndex uses the @ internally. An index reference called sortByThis@displayThis will only read ‘displayThis’, but will be sorted by sortByThis – so we see that the @ and everything before is skipped. That’s what happened to the iSleep@! The MakeIndex manual suggests that the @ will be displayed if we insert a double quote before it, yet this also shows up in all the BibTeX entries, so it’s not an option.

How to fix it …

The solution is embarrassingly simple: just replace the @ (at least in your author tags that will be used by makeindex) with \char"0040{} in your *.bib-file and everything should work (the example above now is author = {iSleep\char"0040{}Work}).
Explanation: we can avoid the @ sign by inserting it as a unicode character by number, so makeindex does not interpret it as the `sorting’ command and prints the field properly.

Tags: , ,

Friday, June 4th, 2010 LaTeX No Comments

Poor man’s thumb indices in LaTeX

Custom Thumb Indices

Custom Thumb Indices

I’m currently writing my diploma thesis in LaTeX and if you devote yourself (along with a lot of time) to this task, you want it to look good (or at least I do).

One of these days I figured, “I want a thumb index in by thesis”, so I started looking for some easy solution. I found the package thumb that, together with fancyhdr, can be used to generate thumb indices. It worked, but one problem was that my painstakingly adjusted KOMA-Script headers and footers vanished and besides I wanted a more “custom” look than just some bars at the edges of my pages. I also came across a bulk of code for thumb indices (within KOMA) that wouldn’t work for me either.

Some time ago I made a DIN A0 poster in LaTeX. I remembered that I used a background image then, so I dug up some code and re-discovered the package wallpaper.
I admit that this solution is not perfect as it requires manual work and adjustment (i.e. constructing the indices for every chapter), but aesthetically it definitely pays off because you don’t have consider any restrictions in terms of design.

The workflow is basically like this:
(0) Determine how many chapters your report/book will have.
(1) Design the backgrounds for each chapter.
(2) Integrate the designed pages as backgrounds for each chapter.
(3) Marvel at your beautiful custom thumb indices, or start again at (1).

Example: Four Chapters w/appendix
(1) For the example I chose simple black boxes containing chapters’ numbers. If you have some parts in your book that you want to `tie together’ visually, you can also use a larger container in another color for the range of the part (here chapters 2 and 3). One big advantage of this approach is that you are not restricted to LaTeX to design the background, but can use tools like InkScape for example (although I used pstricks here).
Attention: Design your backgrounds a little larger than the final page to avoid annoying gaps at the edges of your page (even a few millimeters will do the trick).

(2) To include the backgrounds, two commands are used right after each chapter:
\ClearWallPaper — deletes any previous background images
\TileWallPaper{width}{height}{image} — includes the image on this and subsequent pages unless \ClearWallPaper is used. Attention! use the width and height of the (larger) background image.

LaTeX-Code

\documentclass[USenglish,fontsize=12pt,
paper=a4,oneside,pdftex,version=last]{scrbook}

\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{xcolor,graphicx,wallpaper}

\begin{document}
\mainmatter
\chapter{This is Chapter One!}
\ClearWallPaper\TileWallPaper{220mm}{297.4mm}{thumb_1.pdf}
Some Text for this first chapter will be\ldots
\newpage
\ldots continued on the next page!

\chapter{Custom made, pt. 1}
\ClearWallPaper\TileWallPaper{220mm}{297.4mm}{thumb_2.pdf}
To indicate the `parts' of your document, you can put the chapter indices into
a larger box. This design shows that chapter 2 and 3 are in the same part.

\chapter{Custom made, pt. 2}
\ClearWallPaper\TileWallPaper{220mm}{297.4mm}{thumb_3.pdf}

\chapter{(Filler)}\ClearWallPaper\TileWallPaper{220mm}{297.4mm}{thumb_4.pdf}

\backmatter
\chapter{Finally, an appendix!}
\ClearWallPaper\TileWallPaper{220mm}{297.4mm}{thumb_A.pdf}

\end{document}

Run pdflatex and that’s it! As you can see, the code can only be used for one-sided documents, but it shouldn’t be too difficult to work out a way to switch between wallpapers on odd and even pages.

The source code along with the thumb index backgrounds can be downloaded here: Custom Thumbs Indices – Source and the compiled version should look like this: Custom Thumb Indices (PDF).

Tags:

Thursday, June 11th, 2009 LaTeX 2 Comments

Quick Tables with LaTeX

Today two friends of mine came for a visit and one of them mentioned LaTeX – he had to prepare a large table the other day and was quite annoyed. Setting tables in LaTeX can – even for seasoned users – be a daunting task. When I started out using LaTeX I had to face this fact early and I was very eager to find something to help me typeset tables quickly.

The Excel2LaTeX Plugin is a very effective utility to convert Excel sheets to LaTeX tables. You can download it from the CTAN (Comprehensive TeX Archive Network) here: http://tug.ctan.org/tex-archive/support/excel2latex/. After you have added it in Excel, an additional button will show up in your toolbar.
Using it is quite intuitive: highlight the cells you need in your table, click on the button (if some error message pops up, close it) and a new window with LaTeX code appears. The converter will also handle multicolumn cells, alignment and escape special characters ($, %, ^, …).

Tags: ,

Friday, February 6th, 2009 LaTeX No Comments

Putting on LaTeX …

As you can see I have switched from the nice but common layout to this darker theme. I also set up some links you might find interesting.

The main topic of this post is about the inclusion of (La)TeX in HTML. To keep the promises I’ve made in my mission statement, nice formulae will play an important role in this blog, so I was looking for a solution to this problem.
I found some code that was supposed to generate images using a server but that didn’t work very well. I’m kind of a DIY-guy, so I set up this minimalistic piece of code that generates a dvi-file and converts it into a png-image.

This is the LaTeX file:

\documentclass{article}
\pagestyle{empty} % clipping won't work with headers/footers
\begin{document}
$f(x|\mu,\sigma^2)=
\frac{1}{\sigma\sqrt{2\pi}}
\exp\left[-\frac{(x-\mu)^2}{2\sigma^2}\right]$
\end{document}

And to compile it type:

latex NameOfYourFile.tex
dvipng NameOfYourFile.dvi -D 100 -T tight

The optional -T tight clips off all borders around the formula (that’s why it is important to set \pagestyle{empty}).
You can adjust the image’s size by altering the resolution (the png below was created using -D 200) if something should be illegible (fractions!).

Normal Distribution (PDF)

The Normal Distribution's probability density function (PDF) rendered in LaTeX

On the right you can see the result of the above code (not really: I manually inverted the colors).

I must admit that this approach isn’t very efficient if you need a lot of formulae, but if you only occasionally want to impress people visiting your site with a little math this might be worth a try.

Tags: ,

Thursday, February 5th, 2009 LaTeX 1 Comment