Archive for LaTeX for non-masochists

A hurdle in the instalation of Ubuntu Hardy Heron

I decided to give a try to Ubuntu Hardy Heron, and installed the [[amd64]] version of it in my laptop.

My gripe is caused by a really annoying issue with the installation in a multiboot system. I have a laptop with four root partitions (Windows, Debian, Fedora and Ubuntu), and obviously [[GRUB]] generates the menu that allows me to choose at boot time. The file that GRUB reads is /root/grub/menu.lst, at /dev/sda5 (the Fedora partition, which was the last one).

The annoying issue I mention is that the installation is absolutely smooth but a [[bootloader]] is not installer. What this means is that when I reboot the computer after installation, I always get the old GRUB menu, and the new OS does not appear in the list.

The only solution I found is to do the following:

  1. Do a normal install of Ubuntu, but do not reboot
  2. Open a console (after installation Ubuntu lauches a GNOME live session)
  3. Locate the kernel and initrd images I need. They are, respectively: /target/boot/vmlinuz-2.6.24-16-generic and /target/boot/initrd-img-2.6.24-16-generic.bak
  4. Mount /dev/sda5 into /mnt/root3
  5. Edit /mnt/root3/boot/grub/menu.lst (the old GRUB menu), and add the lines:
  6. title --------- Ubuntu 8.04 TLS Hardy Heron - sda6 ----------
    root

    title Ubuntu Hardy Heron - kernel 2.6.24
    root (hd0,5)
    kernel /boot/vmlinuz-2.6.24-16-generic root=/dev/sda6 ro quiet splash
    initrd /boot/initrd.img-2.6.24-16-generic.bak
    boot

  7. Reboot

After that, the new Ubuntu appears in the GRUB list.

The procedure is not incredibly difficult, but for a beginner it would be a major showstopper. And, in any case, it is a really sad error.

Comments (3)

Interesting TeX tricks

Simply a page with some interesting TeX tricks: volkerschatz.com.

Comments

LaTeX programming: how to implement conditionals

I have recently come across a problem while creating a LaTeX style (for making A0-size posters). Maybe it could be avoided or solved more elegantly, but I wanted to solve it with conditionals.

Basically, what I wanted to do was define a command (actually, an environment) that accepted one argument, and make it return different output, depending on the argument:

if (argument equals something) then
  do something
else
  do somethingelse
end if

It gave me some headaches to get it, but I also learned some interesting things on the way. There are at least two ways of playing with conditionals: defining boolean variables or directly using logical comparisons.

Defining logical valiables

We can define a logical variable logvar as follows:

\newif\iflogvar

By default, it is set to false. We can set it to true by:

\logvartrue

and back to false by:

\logvarfalse

The variable can be used in a conditional as follows:

\iflogvar
  aaaa
\else
  bbbb
\fi

You can think of the above code as a single object, the output value of which will be “aaaa” if logvar is true, and “bbbb” if false. Basically, the following code will, thus, output “Today is great“:

Today

\newif\ifismonday

\ismondayfalse

\ifismonday
  sucks!
\else
  is \textbf{great}
\fi

Direct logic comparison

The example I provide works for numbers, but check this page for more info. Recall that LaTeX works with integers (counters) and text strings. As far as I know, floating point operations are impossible in LaTeX (nothing is actually impossible in LaTeX, just veeery difficult).

For example, defining the following command in the preamble:

\newcommand{\isitthree}[1]
{
  \ifnum#1=3
    number #1 is 3
  \else
    number #1 is not 3
  \fi
}

allows us to call it in the document, so the following outputs “We know that number 33 is not 3”:

We know that \isitthree{33}

Nesting

Obviously the conditionals can be nested (put one inside another), when more than one condition needs to be tested. For example:

Today

\newif\ifismonday
\newif\ifistuesday

\ismondayfalse
\istuesdaytrue

\ifismonday
  sucks!
\else
  \ifistuesday
    almost sucks.
  \else
    is \textbf{great}
  \fi
\fi

Comments (7)

PowerDot screen size error in Debian Lenny

I use the PowerDot class to make presentations (such as the one in a previous post), and I have come across a nasty problem in the current testing branch of Debian (Lenny). Obviously it is bound to affect any other distro relying on Debian, such as Ubuntu.

The problem is discussed in this thread in freelists.org, and a solution is given by Hendri Adriaens in the tug.org bug page.

In short, when selecting paper=screen paper size in a PowerDot .tex file, the current dvips (version 5.96.1, provided by the package texlive-bin version 2007-12) generates a PostScript file with a wrong paper size. To fix it, you can get the following file:

% wget http://tug.org/svn/texlive/trunk/Master/texmf/dvips/config/config.ps

and put it where the following command tells you:

% kpsewhich --format='dvips config' config.ps

after backing up the old (buggy) one, just in case. For example:

% mv /etc/texmf/dvips/config/config.ps /etc/texmf/dvips/config/config.ps.backup
% mv config.ps /etc/texmf/dvips/config/

This fixes the problem for me.

Comments

LaTeX: the textpos package

I have recently discovered a marvelous LaTeX package, namely textpos (PDF manual). My problem was that I wanted to place pieces of text arbitrarily in a page. I had tried tabular environments, a liberal use of \vspace and \hspace, the minipage environment, and even the picture environment. None would do.

However textpos is just what I wanted. The package is loaded with the usual:

\usepackage[options]{textpos}

The options I have used are:

  • absolute – the placing is made with respect to the whole page (stuff me if I understand this)
  • showboxes – draws boxes around the text, so you exactly see what you do (for debugging, of course)

Some variables have to (can) be set, namely the width and height units, for example:

\setlength{\TPHorizModule}{\paperwidth}\setlength{\TPVertModule}{\paperheight}

After that, all the placing specifications can be referred to \TPHorizModule and TPVertModule. A typical use of textpos would be:

\begin{textblock}{width}[xt,yt](X,Y)  the-text-goes-here  \end{textblock}

where width is the desired width of the text box (the height will be enough to place all the text specified), X and Y are the (x,y) placement of the text box, and xt and yt are the point inside the text box which will be placed at (X,Y). All the units refer to \TPHorizModule and TPVertModule. For example:

\begin{textblock}{0.6}[0.5,0.5](0.3,0.4)  hello world\end{textblock}

will print the text “hello world” in a box of width 60% of \TPHorizModule (in my example, this is 60% of the total page width). The center (0.5,0.5) of that box will be placed at a point 30% to the right of the left margin, and 40% below the top margin (in TPxxxModule units).

Comments (1)

Word processors are easy to use

Frustrating. Very frustrating.

I am teaching my father how to use OpenOffice.org, as a replacement/reinforcement of a MS Word course he took recently.

My present rant comes from the ubiquitous problem of where some feature of a text piece starts/ends, which is not always obvious. More precisely, I’ll refer to itemized/numbered lists and nested lists, like:

* Item 1
  - Subitem 1.1
* Item 2
  - Subitem 2.1
  - Subitem 2.2

After years using LaTeX almost exclusively for document writing, I found it annoying to no end the way in which OpenOffice.org (or any other word processor) handles this kind of things. When I make a list of items, I want the list to be perfectly separated from the surrounding (regular) text, so that I know exactly when I am introducing items in the list, or text before or after the list. I also want to have a logical tree of items and subitems, so I know in every moment at what nesting level I am, and what comes after, or at a lower level than, what.

With LaTeX, this is trivial, as can be seen in the following example:

text before list

\begin{enumerate}

  \item Item 1

  \begin{enumerate}    \item Subitem 2  \end{enumerate}

\end{enumerate}

text after list

I have absolute control about what belongs where. No more fuss about terminating the lists, or about inserting them somewhere, or anything.

On the other hand, word processors provide neither clear separation from the surrounding nor logic for lists. My poor father was struggling to teach the damned program what nest level each entry he wanted it in, how to eliminate the damned dangling “last item”, how to add text after a list, but telling the program that it is already out of the list… a nightmare. Yes, some of his problems were probably trivial, but I am the first to admit that I have come across all of them at least once. And some, I never figured out.

Comments (4)

TeX capacity exceeded error

I am definitely dumb. Well, LaTeX has its part in it, too.

It turns out that all of a sudden, I started having this error when compiling a .tex file:

! TeX capacity exceeded, sorry [input stack size=1500].

After googling for an answer, I found out that the “stack size” limit is defined in the following file:

/usr/share/texmf/web2c/texmf.cnf

However, changing the value made no good: any limit, no matter how large, would be “exceeded”. The reason (after a little more hitting my head against the wall) is that there was an infinite loop in the input .tex (maybe \input{file.tex} inside file.tex, or somesuch). 10 hours (well, 5 minutes, actually) of head-banging later, when I was pretty sure no freaking infinite loop was there, I found the answer:

I had deleted the \end{document} tag!!

Now, yes, how stupid am I? And… how stupid is LaTeX to give that silly error, instead of:

TeX warning: You are too dumb, and forgot an \end{document}

Comments (43)

Custom style in PowerDot

Rembember I mentioned PowerDot for LaTeX? PowerDot is a LaTeX class to produce PowerPoint-like presentations. It creates PDFs that can be read fullscreen with any PDF reader, and turn out to be very nice looking presentations.

I am now fiddling with it, and wanted to do a custom style. I have read the PowerDot Manual[PDF], and it says all you have to do is to copy and rename an existing style, then modify it:

% cd /usr/share/texmf-texlive/tex/latex/powerdot/
% cp powerdot-default.sty powerdot-isilanes.sty
% vi powerdot-isilanes.sty

Then, put style=isilanes in your .tex, et voilà!. Well, it fails misserably, saying (among the usual garbage):

! Class powerdot Error: unknown style `isilanes'.

But the .sty is there!

OK, the problem is that LaTeX “doesn’t know” you added the style. To remind it, in my Debian Etch box:

% dpkg-reconfigure tetex-base

or, much better (thanks to a comment by bjacquem):

% texhash

This seems to “refresh” the internal LaTeX database, and now it works.

Comments

LaTeX: PowerDot

Tired of hearing that GNU/Linux is good for “technical things”, but not for visually appealing matters, such as presentations? Tired of hearing that LaTeX is good for 200-page books full of cross-references, tables and bibliograpy, but not for “other” documents?

Well, next time you can point your ignorant fellow to some LaTeX solutions for making fancy presentations.

You can find some overviews here:

Among the different programs and methods, I’d like to mention the Seminar and Prosper packages for LaTeX. Prosper was written by Timothy van Zandt, and is available as a package for Debian. However, the Prosper package had its capabilities extended by Hendri Adriaens, to create the HA-prosper LaTeX package. Later on, HA-prosper was dropped, and Adriaens and Christopher Ellison commited themselves to the development of PowerDot, a LaTeX class that would supercede both Prosper and HA-Prosper. The PowerDot class (and many others) can be found in the Debian package texlive-latex-recommended.

What Prosper, HA-Prosper and PowerDot do is (since you are using LaTeX) create a DVI, PS or PDF. Usually, your aim will be to create a PDF, since it even allows for fancy slide transitions (an infamous hability of you know who).

Examples of PowerDot presentations (taken from Adriaens’ site), can be accessed here: Example 1, Example 2, Example 3.

Actually, I am considering to use PowerDot to make the presentation of my PhD defense… I hope I don’t give up and end up using the GUI (and, thus, evil) programs KPresenter or (God forbid) OpenOffice.org.

Comments

LaTeX: footnotes in tables

Although an apparently widely known LaTeX issue, I came across it just today. Fact is if you use \footnote inside a \tabular environment, the footnote will be “trapped” inside the table, and actually never get displayed at all in the output.

You can find some possible solutions for that at the UK TeX FAQ on the Web.

The trick I’ll comment here is to use \tabularx, which is covered in the link above, and also at J.L. Diaz’s LaTeX blog[es].

The “problem” is that \tabularx requires a fixed table width value to be input by the user, so the following will fail misserably:

\usepackage{tabularx} % required in the preamble
\begin{tabularx}{100mm}{|c|c|} \hline
A & B \\ \hline
C & D \\ \hline
\end{tabularx}

Why? Because the {c} especification (to center the text inside the cell) makes the affected column as wide as necessary, not more (so will {r} or {l}). The output can be seen below:

The effect of the whole table being actually wider than the sum of the integrating colums could be partially “concealed” if the \hlines were eliminated, but the table would still be actually incorrectly wide, which would make things like aligning the whole table “fail” (to the eye).

Fortunately, the tabularx package provides a way to tell LaTeX that a column must be of the necessary width, so that the sum of colum widths equals the total column width. This is the {X} keyword (notice the capitalization of the “X”). E.g.:

\begin{tabularx}{100mm}{|c|X|} \hline
A & B \\ \hline
C & D \\ \hline
\end{tabularx}

This makes the first column just as wide as needed, not more (the {c}), and then, the second column will be as wide as needed to reach the 100mm. The output:

If multiple columns are given the {X} keyword, they will all have the same width, precisely the one required to meet the total table width.

Comments (3)

« Previous entries Next Page » Next Page »