Using LaTeX Lettrine Package to Create Drop Caps

|

Writing the previous entry reminding me that I never posted the following solution.

While working on my book, The Open Laboratory 2007, I typeset everything in LaTeX. One of the features that I included was a drop cap at the beginning of each entry in the anthology, using the Lettrine package.

However, I could find no way to automate the process in LaTeX, requiring the \lettrine command to be included at the beginning of each entry. This resulted in a few entries missing the drop cap because their omission was not caught in our short development time. I worked on the book a while after it was published, fixing some errata that I found. During this time, I finally developed a way to apply the drop cap automatically to the entries. Here is the solution, simplified a bit.

% Required Packages
\usepackage{ifthen}
\usepackage{lettrine}

% Setup lettrine
\input EileenBl.fd
\newcommand*\initfamily{\usefont{U}{EileenBl}{xl}{n}}
\renewcommand{\LettrineFontHook}{\initfamily}
\setcounter{DefaultLines}{3}

% The Magic: finds first letter and first word in the proceeding text
% and passes them to lettrine
\newcommand*{\ecap}[1]{\begingroup\obeyspaces\etospace{#1}{}}
\newcommand*{\etospace}[3]{\ifthenelse{\equal{#3}{\space}}%
{\endgroup\lettrine{#1}{#2}#3}{\etospace{#1}{#2#3}}}

% Setup environment `entry' to use `entry*' with a drop cap
\newenvironment{entry}{\begin{entry*}\ecap}{\end{entry*}}
% Setup environment `entry*' so that lettrine can be manually specified if needed
\newenvironment{entry*}{}{}

This solution will not always work if the entry begins with something other than text; markup and figures can confuse it. However, for the few instances when I need to specify \lettrine manually, I can fall back to the entry* environment.

About this Entry

This page contains a single entry by Reed A. Cartwright published on February 23, 2009 8:09 PM.

Sumatra PDF and LaTeX was the previous entry in this blog.

Cluster Magic with LSF is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Archives

Powered by Movable Type 4.37