Wednesday, 2 November 2011

Using Sweave with Beamer: A note on fonts

Recently, I've been preparing a poster using the LaTeX packages Beamer and beamerposter. The poster discusses a bunch of R stuff that I've been doing lately, so I successfully used Sweave to incorporate R code into the poster. However, I had some trouble with package names that I wanted to typeset as small caps. The package names looked the same as the rest of the text. A bit of sleuthing around revealed Sweave as the culprit. In the Sweave.sty package, on line 20, it calls the deprecated LaTeX package "ae", which for some reason doesn't recognise small caps. Changing the package to "lmodern" made small caps turn up correctly within the text.

Unfortunately, my problems had not yet been solved completely. I had mentioned the package names in the titles which were set in bold. I thus had created a fairly commonly encountered bugbear with LaTeX—the non-compatibility of bold and small caps in computer modern font. While there are workarounds for this (see this Stack Exchange and TeX FAQ for more details), unfortunately these solutions did not work with Beamer.

So, I set about finding a font that both looked alright, and would accomodate bold and small caps. I found that using helvetica would be fine, but had to be loaded after Sweave to work. As my Sweave block kept placing the \usepackage{Sweave} immedediately before \begin{document}, I resorted to calling helvetica in the Sweave file itself.

The relevant lines in of the Sweave.sty (lines 18-21) file. Before:
\ifthenelse{\boolean{Sweave@ae}}{%
\RequirePackage[T1]{fontenc}
\RequirePackage{ae}
}{}%
After:
\ifthenelse{\boolean{Sweave@ae}}{%
\RequirePackage[T1]{fontenc}
\RequirePackage[scaled]{helvet}
}{}%

3 comments:

Unknown said...
This comment has been removed by the author.
Marc Schwartz said...

If you review ?RweaveLatex, you will note that Sweave.sty supports the 'noae' option. So try using:

\usepackage[noae]{Sweave}

in your preamble and see if that helps.

Jeromy Anglim said...

Any chance that you'd share the source code for the finished product (e.g., on something like github)? It's interesting to see working examples of reproducible research.