2

MWE:

% !tex=pdflatex
\documentclass[oneside,12pt]{book}
\usepackage{lipsum,lettrine}

\begin{document} % NOTE1: There have text between Chapter and Section, I just want to the first word be dropcaped like below. \chapter{Week1} \lettrine{W}{ith} a drop cap, the initial sits within the margins and runs several lines deep into the paragraph, pushing some normal-sized text off these lines. \section{Day1 of Week1} \lipsum[1]
Chapter one end.

% NOTE2: There have NOT any text between Chapter and Section, but I just want to the first word be drop-caped like below. \chapter{Week2} \section{Day1 of Week2} \lettrine{L}{orem} \lipsum[1]

% NOTE3: How to do this work like above(just let the first word be drop-caped in every chapter) % through the whole book automatically? \chapter{Week3} \lipsum[1]

\end{document}

What I can do are showed as NOTE1 and NOTE2. I just want to find a best solution to do this work automatically(NOTE3).

user26992
  • 93
  • 3
  • 1
    Maybe your question would sound better that way: "Automating lettrine after \chapter command" – Ivan Jan 21 '21 at 19:30
  • How many chapters do you have? This required automation seems like a large investment for minimal reward if you can just edit (say) 10 locations and place a \lettrine there, especially if there's not always a consistent way in which you present what could follow \chapter... just saying. – Werner Jan 21 '21 at 20:22

1 Answers1

2

The solution below, which is actually a half solution and maybe even a brute solution, is inspired by this answer: https://tex.stackexchange.com/a/290567/231952. It requires three conditions. 1) There must not be empty lines after \chapter and 2) the text after \chapter must not start with a \; 3) The standard book class is used:

\documentclass[oneside]{book}
\usepackage{lettrine}
\usepackage{etoolbox}

\def\dolettrine #1#2 { \lettrine{#1}{#2} }
\makeatletter \apptocmd{@chapter}{\dolettrine}{}{} \makeatother

\begin{document} \chapter{Lorem ipsum} Lorem ipsum dolor sit amet

\chapter{Dolor sit} % Dolor sit amet lorem ipsum

\chapter{Dolor magnum} % In this case it does not work correctly \textit{Lorem} ipsum dolor sit amet.

\end{document}

Edit.

The first limitation can be removed with:

\apptocmd\@makechapterhead{\endlinechar=32}{}{}
\apptocmd{\@afterheading}{\endlinechar=13}{}{}

The solution is inspired by https://tex.stackexchange.com/a/16462/231952. The first command appends \endlinechar=32 to \@makechapterhead, so that the end of lines are replaced by a space. The second command restore the default value 13.

For the starred variant of \chapter we need this too:

\apptocmd{\@schapter}{\dolettrine}{}{}
\apptocmd\@makeschapterhead{\endlinechar=32}{}{}
Ivan
  • 4,368
  • Thanks! It works for the situation you mentioned. Maybe have some more perfact method to remove these limitations. – user26992 Jan 22 '21 at 02:02
  • 1
    I edited my answer including a workaround to exclude the first limitation. I added also a third condition: book class is required – Ivan Jan 22 '21 at 12:34
  • Thanks! I try add them but it does not work for the NOTE2 and NOTE3. – user26992 Jan 22 '21 at 13:46
  • It is correct. NOTE2 and NOTE3 start with a \ after \chapter (\section and \lipsum respectively). This violates the second condition. The same job should also be done for the \section command too, but it becomes difficult if there are chapters that start with plain text and others that start with a \section – Ivan Jan 22 '21 at 13:58
  • OK, I see. NOTE2 and NOTE3 make things a little complex. Maybe scoop up paragraphs can do this? I don't know. – user26992 Jan 22 '21 at 14:19
  • Io cannot figure out what you mean by "scoop up paragraphs". Again, the solution I gave requires that there is plain text immediately after \chapter {}. – Ivan Jan 22 '21 at 14:57