3

I need to automatically place lettrines on a text I don't want to edit directly.

So far I have been using

\def\drop #1#2 {% note the space before {
  \lettrine{#1}{#2} % a trailing space
}

and

\drop Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sagittis vitae massa nec gravida. Fusce quis porttitor leo. 

The problem is that some paragraphs start with a command, e.g:

\marginnote{Foo} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sagittis vitae massa nec gravida. Fusce quis porttitor leo.

In these cases various errors are returned; I have tried with \expandafter but with no luck.

How can I make Latex use the first "real" word for the lettrine, i.e. ignoring the (eventually) preceding command?

0

1 Answer 1

1

This approach examines the catcode of the token following \drop. If it is a command (catcode 0), it executes the 1st blob of tokens up to the first space and then reissues \drop again. Therefore you can't accidentally leave spaces between arguments of a leading macro, e.g., \rule{1ex} {2ex}, or the inter-space will scrog the argument absorption. Generally, this is not an issue, and won't affect commands taking a single argument.

\documentclass{article}
\usepackage{lettrine,marginnote}
\def\drop #1#2 {% note the space before {
  \ifcat\noexpand\relax\noexpand#1\def\next{#1{#2}\drop}\else
  \def\next{\lettrine{#1}{#2} }\fi% a trailing space
  \next
}
\begin{document}
\drop Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sagittis vitae massa nec gravida. Fusce quis porttitor leo. 

The problem is that some paragraphs start with a command, e.g:

\drop \marginnote{Foo in the margin} Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec sagittis vitae massa nec gravida. Fusce quis porttitor leo.
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .