自动化 Lettrine

自动化 Lettrine

我知道这个话题在这里和网络上的其他地方已经被提及,但似乎没有人想出好的解决方案。我想要的是将其应用于lettrine一个段落,以便它始终使用相同的模式。例如,选择段落的第一个单词,将第一个字母大写,将单词的其余部分小写,或者如果第一个单词只有一个字母,则将第二个单词的完整字母小写。

\newcommand{\dropcap}[3]{\lettrine{#1}{#2}#3}

那么,LaTeX 是否有某种方法可以解析段落,以便如果第一个单词有超过 1 个字母,则第一个字母将为 #1,单词的其余部分将为 #2,段落的其余部分将为 #3...并且如果第一个单词是 1 个字母,则整个第二个单词为 #2,然后段落中的以下单词为 #3

答案1

你肯定不想将其应用于\lettrine每一个段落。是吗?

\documentclass{article}
\usepackage{lettrine}

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

\begin{document}

\drop It was a dark and stormy night; the rain fell in torrents---except at occasional
intervals, when it was checked by a violent gust of wind which swept up the streets (for it
is in London that our scene lies), rattling along the housetops, and fiercely agitating the
scanty flame of the lamps that struggled against the darkness.

\drop I was born in the Year 1632, in the City of York, of a good Family, tho' not of that
Country, my Father being a Foreigner of Bremen, who settled first at Hull; He got a good
Estate by Merchandise, and leaving off his Trade, lived afterward at York, from whence he
had married my Mother, whose Relations were named Robinson, a very good Family in that
Country, and from whom I was called Robinson Kreutznaer; but by the usual Corruption of
Words in England, we are now called, nay we call our selves, and write our Name Crusoe, and
so my Companions always call'd me.

\drop Whether I shall turn out to be the hero of my own life, or whether that station will
be held by anybody else, these pages must show.


\end{document}

在此处输入图片描述

相关内容