7

Consider the code (which I compile with lualatex)

\documentclass[12pt]{book}
\textwidth=4.5in
\usepackage{lettrine}

\renewcommand{\LettrineFontHook}{\bfseries{}} % for the initial argument.
\renewcommand{\LettrineTextFont}{\scshape} % for the second argument

\begin{document}
\thispagestyle{empty}

\lettrine[lines=1,loversize=.65,findent=-.08em,nindent=2.5pt]{O}{, how} one may automatically make a comma bold when it begins the second argument of a lettrine?
\end{document}

which produces

enter image description here

QUESTION: I would like the comma following the drop cap to be bold. I know I can simply replace it by \textbf{,} and that will work. However, I would like to know if there is a way for LaTeX to recognize when a comma begins the second argument of a lettrine; and if so, can it then automatically render the comma (that is, the comma only) in bold---leaving in this case, the word "how" as is in regular small caps?

Thank you.

2
  • 1
    Adapting the answer of @egreg at tex.stackexchange.com/a/609553 may give a more pleasing result than bold.
    – Thérèse
    Commented Jun 10 at 21:22
  • Thank you @Thérèse for providing this helpful link.
    – DDS
    Commented Jun 10 at 21:54

2 Answers 2

7

With \peek_charcode_remove:NT , { <code> } we can check whether the next token is a comma and, in this case, it is removed and <code> is executed. Otherwise, nothing is done.

\documentclass[12pt]{book}
\usepackage{fontspec}
\usepackage{lettrine}

\renewcommand{\LettrineFontHook}{\bfseries} % for the initial argument.
\renewcommand{\LettrineTextFont}{\scshape} % for the second argument

\newcommand{\ddslettrine}[2]{%
  \lettrine[lines=1,loversize=.65,findent=-.08em,nindent=2.5pt]{#1}{\checkcomma#2}%
}
\ExplSyntaxOn
\NewDocumentCommand{\checkcomma}{}
 {
  \peek_charcode_remove:NT , { \textnormal{\textbf{,}} }
 }
\ExplSyntaxOff

\textwidth=4.5in

\begin{document}
\thispagestyle{empty}

\ddslettrine{O}{, how} one may automatically make a comma bold
when it begins the second argument of a lettrine?

\ddslettrine{O}{ how} one may automatically make a comma bold
when it begins the second argument of a lettrine?

\end{document}

enter image description here

You may want to try

\ExplSyntaxOn
\NewDocumentCommand{\checkcomma}{}
 {
  \peek_charcode_remove:NT , { \textnormal{\textbf{\large,}} }
 }
\ExplSyntaxOff

enter image description here

0
5

If it is a oneoff, I would simply go the manual way (but not with \textbfbut rather

\lettrine[lines=1,loversize=.65,findent=-.08em,nindent=2.5pt]{O\large\!,}{ how}

If automation is desired then @egreg's solution is great but I would again add some negative space because otherwise the sidebearing of the initial is likely to be too large. looks like \!works reasonably well for that (maybe something slightly smally would be better), though it would need to be verified with other initials

enter image description here

1
  • Thank you for adding this answer.
    – DDS
    Commented Jun 12 at 14:51

You must log in to answer this question.

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