A-  A  A+ RSS Feed

Deep Thoughts by Robert Felty

thoughts on wordpress, latex, cooking et alia

Archive for the 'latex' Category

Monday, September 22nd, 2008

Beamer fragile frames

If you want to include verbatim text, say for some program code, in a frame in beamer, you have to pass the fragile option to the frame, like so:

\begin{frame}[fragile]
\frametitle{a fragile frame}
\begin{verbatim}
some verbatim text here
\end{verbatim}
\end{frame}

Though latex usually doesn’t really care about whitespace at the beginning of a line, in this case it does. If you don’t have your begin and end frame statements at the beginning of a line when you are trying to use the fragile option, your document will not compile. It’s frustrating.

p.s. also note that you can’t use verbatim text with overlays in beamer.

Wednesday, March 19th, 2008

Finally a better LaTeX to html converter

About a year ago I wrote a post about my frustration with the lack of a good LaTeX to html converter. Recently I found one. It is called plasTeX, so named because it is written in python. Finally a converter which works well with most any LaTeX package or macro you write, and produces sane, relatively standards-compliant html. Best of all, it comes with a built-in if \ifplastex, so you can specify that some things should be in the pdf version, while others should be in the html version. It also support some other formats like docbook, but I am not too interested in that, so I haven’t tested it all.

Though I discovered plasTeX a few months ago, I finally decided to play around with it some more this week, when I wasn’t feeling like working too much. So I decided to convert my CV from html to latex, so I can have both pretty pdf and html versions. So now I will update my CV only in latex, which is much nicer to write than html anyways.

To get both a pdf and an html version, this is what I do:

pdflatex cv
plastex -c cv.cfg cv
tidy --show-body-only true -asxhtml -utf8 -wrap 78 -indent cv/index.html > cv/index2.html

It took me awhile to figure out the syntax of the plasTeX config file. It is possible to specify these things on the command line, but I got tired of having too many things on the command line. The trick is that the plasTeX options are divided up into different sections. The sec-num-depth option, which tells plasTeX how many section levels deep to number, is in the document option section, while the split-level option is in the files section. The split-level option tells plasTeX how many different html pages to make. For my CV, I only wanted one. My plastex config file looks like:

[document]
sec-num-depth = 0
[files]
split-level = 0

Though plasTeX is pretty nice, there are 3 complaints I still have. One is that it uses <h1> tags for \section, which I can understand, but there is a long tradition in the web of having only one <h1> tag per page, which usually holds the title of the page. PlasTeX does have the ability to use different themes, so there might be a way to change this with a theme, but I haven’t figured that out yet. For the time being, I simply used \subsection tags instead.

My second complaint about plasTeX is that it doesn’t do any nice formatting of the html like indenting or line-wrapping. That is only a minor complaint though, since I can simply run it through htmltidy (as in the code above).

My third complaint is that plasTeX puts everything inside a <td> or <li> inside a <p>, which seems very strange to me, and creates some ugly formatting, so I used some CSS tricks to basically take away the standard effects of <p> tags inside these:

td > p {margin:0;padding:0;}
li > p {margin:0;padding:0;}

I am not completely finished yet, but you can check out the html and pdf results in: my new CV.

Thursday, February 28th, 2008

Fun with fonts in LaTeX

Today I stumbled across the LaTeX font catalogue, which lists all available fonts for LaTeX. I am really surprised that I had not been aware of it earlier. I was also surprised at the number of fonts there. While some new projects such as XeTeX are making all open-type and true-type fonts available to the TeX typesetting system, I still use regular (pdf)LaTeX most of the time, and every once in awhile I like to play around with fonts. And, I think I have finally figured out the correct way to install new fonts using texlive.

  1. Copy files to the appropriate place under texmf
  2. sudo texhash

    This will tell TeX that there are new files in its path

  3. sudo updmap-sys --enable <newfont>

    This will update the font handling parts of LaTeX

Here is a sample of one font I found pretty cool, and the LaTeX source:

movieola screenshot
screenshot of the movieola font
\documentclass[11pt,letterpaper]{article}
\usepackage{emerald}
\begin{document}
{
\ECFMovieola
\Large
SoMe PrEtTy TeXt HeRe
}
\end{document}
Saturday, November 10th, 2007

numbered footnotes on titlepage

The new lab I work in at Indiana University has an annual progress report, with its own stylesheet. There is a template available for Microsoft Word, but I much prefer LaTeX, so I am trying to write my own class file for that. One of the quirks of the stylesheet is that footnotes from the title are numbered. To clarify what I mean, consider the fact that many journal articles include a footnote or two in the title or author listing which may be an acknowledgment or a clarification of what institutions the authors are working at. These footnotes are usually not numbered, but instead are marked with a symbol such as an asterisk or a dagger, and this is what LaTeX does by default, when one uses the thanks command. Since the reports I will be writing are very similar to articles, I decided to try to just hack the article.cls file into srl.cls. After some experimenting, I found the line in the maketitle declaration which gives the symbols instead of numbers.

\renewcommand\thefootnote{\@fnsymbol\c@footnote}%

I simply commented this line out.

I also commented out the line which sets the footnote numbers to 0 after maketitle is finished typesetting the title

\setcounter{footnote}{0}%

Presto! One part of the stylesheet is done.

Wednesday, October 24th, 2007

advanced typography with pdfLaTeX

I have been using LaTeX for several years now, but only a couple months ago did I start experimenting with pdflatex. Actually, most current LaTeX distributions use pdflatex as the default LaTeX engine, but if you use the latex command, then it will produce a .dvi file, which most people then convert to .ps and probably to .pdf. Using the pdflatex command produces pdf directly, thus skipping two steps. This is always a plus. However, there are many other benefits of using pdflatex, which I would like to talk about here.

Including images

Including images with LaTeX has been possible (and easy) for quite some time, but it has been restricted to .eps files. While .eps is a vectorized (and thus high-quality and scalable) format, fewer and fewer programs will produce .eps (perhaps most notably Microsoft excel, which many unenlightened people use to make plots). In contrast, pdflatex allows inclusion of .png, .pdf, and .tiff files (and maybe a few others I am missing). It does not allow inclusion of .eps files, which at first was a major obstacle for me to switch, since I already had a bunch of .eps files laying around. It turns out that there is a very easy workaround to this though. Simply use the epstopdf package, and when you compile use the shell-escape option like so: pdflatex --shell-escape. Also, make sure that you do not include the file extensions for your graphics. What this does is it allows pdflatex to temporarily stop processing the document if no pdf version of the document is found and convert the eps file to a pdf using ghostscript. Most LaTeX distributions also include ghostscript by default.

\documentclass{minimal}
\usepackage{graphicx}
\usepackage{ifpdf} %check if we are using pdflatex
\ifpdf
  \usepackage{epstopdf} %convert eps to pdf on the fly
\fi
\begin{document}
\includegraphics{foo}
\end{document}

One potential downside of using pdflatex regarding graphics is that pstricks does not work with pdflatex. This makes sense, since pstricks using postscript specials to make graphics, and pdflatex produces pdf directly. There are some supposed work arounds, but they all seem fairly complicated to me, and I have not tried them. I have chosen to use a different graphics package instead — tikz/pgf. This is a a newer package which can produce both .ps and .pdf files, and it has some very nice features. It is not quite as full-featured as pstricks yet, but it is in active development, and is constantly improving. The beamer package for making slides uses pgf for its graphics, which produces incredibly beautiful slides. I have written about pgf elsewhere on the blog, and will be writing about beamer in the near future.

Micro-typesetting features

Another feature of pdflatex is the availability of so-called micro typesetting features. In fact, this is one of the major motivations of writing pdflatex (written by Hàn Thê Thành for his thesis). Accessing these features directly is quite complicated, but fortunately there is the microtype package. There are two main features of the microtype package:

margin kerning
This involves allowing the text to protrude into the margin slightly. You’re probably thinking: “What?! That doesn’t make any sense! LaTeX gives me nicely justified text. Why would I want to ruin that?” Of course you are correct, but it turns out that even though LaTeX lines up text perfectly, it can appear slightly off, because of our human perception. Where this really comes about is in punctuation. Periods, commas, dashes and the like are generally much smaller characters than normal letters, so when such punctuation ends a line, it can seem that the line is slightly indented in the right margin. Microtypes margin kerning feature puts punctuation slightly in the margin, which gives the perception of a straighter line. The microtype package automatically has most standard punctuation defined for this purpose, but it is also possible to customize its behavior.
font expansion
This involves actually making the glyphs slightly wider than normal in order to avoid having to make the interword spacing too large. This is also done on the fly

As always, happy TeXing!