TeX - LaTeX Asked on May 1, 2021
I need to automatically place lettrines on a text I don’t want to edit directly.
So far I have been using
defdrop #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?
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}
defdrop #1#2 {% note the space before {
ifcatnoexpandrelaxnoexpand#1defnext{#1{#2}drop}else
defnext{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}
Correct answer by Steven B. Segletes on May 1, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP