5

I would like to have two commands to reduce the code in my document for managing lettrine capitals. The first should work like normal with small caps; but the second should use italic shape. Is there a way to define macros that I can use after the preamble and which will change the font that lettrine uses?

Minimal code example:

\documentclass{scrartcl}

    \usepackage{xltxtra} 
    \usepackage{xcolor} % für farbigen Text

    \setromanfont[SmallCapsFont={Alegreya Sans SC}]{Alegreya Sans}

    \usepackage{lettrine}
    \renewcommand{\LettrineFontHook}{%
        \fontseries{\seriesdefault}
        \fontshape{\shapedefault}
        }
    \renewcommand{\LettrineFontHook}{%
        \fontfamily{\familydefault}
        \fontseries{\seriesdefault}
        \fontshape{\itdefault}
        \selectfont
        }

    \newcommand{\LettrineA}[2]{\lettrine[lines=3,findent=.5em]{\color{olive}#1}{#2}}
    \newcommand{\LettrineB}[2]{\lettrine[lines=3,findent=.5em]{\color{orange}#1}{#2}}
    \begin{document}
    \LettrineA{T}{his text} is written in a normal font. The first 2 words are in small caps. The following words are only here to fill the paper and waste some space, time and hopefully no money. But if it is wasting time it is wasting money aswell if we trust old phrases.
    \LettrineB{T}{his text} is written in a normal font. The first 2 words are in italic shape. The following words are only here to fill the paper and waste some space, time and hopefully no money. But if it is wasting time it is wasting money aswell if we trust old phrases.
    \end{document}
2

Here is a \FlexibleLettrine macro where you can set more parameters than usual for \lettrine. Then you can define \LettrineA and \LettrineB in terms of this.

Note how it's necessary to load Alegreya Sans if you want the small caps font to obey font changing commands.

\documentclass{scrartcl}

\usepackage{fontspec}
\usepackage{xcolor} % für farbigen Text
\usepackage{lettrine}

\setmainfont{Alegreya Sans}[
  UprightFeatures={SmallCapsFont=* SC},
  ItalicFeatures={SmallCapsFont=* SC Italic},
  BoldFeatures={SmallCapsFont=* SC Bold},
  BoldItalicFeatures={SmallCapsFont=* SC Bold Italic},
]

\newcommand{\FlexibleLettrine}[5][]{%
  % #1 = options to \lettrine
  % #2 = font for lettrine
  % #3 = font for the following word parts
  % #4 = lettrine
  % #5 = following word parts
  \begingroup
  \renewcommand{\LettrineFontHook}{\normalfont#2}%
  \lettrine[#1]{#4}{\normalfont#3#5}%
  \endgroup
}
\newcommand{\LettrineA}[2]{%
  \FlexibleLettrine[lines=3,findent=.5em]
    {\normalfont}
    {\scshape}
    {\color{olive}#1}
    {#2}%
}
\newcommand{\LettrineB}[2]{%
  \FlexibleLettrine[lines=3,findent=.5em]
    {}
    {\scshape\itshape}
    {\color{orange}#1}
    {#2}%
}
\newcommand{\LettrineC}[2]{%
  \FlexibleLettrine[lines=3,findent=.5em]
    {\itshape}
    {\itshape}
    {\color{orange}#1}
    {#2}%
}
\newcommand{\LettrineD}[2]{%
  \FlexibleLettrine[lines=3,findent=.5em]
    {}
    {\itshape}
    {\color{orange}#1}
    {#2}%
}

\begin{document}

\LettrineA{T}{his text} is written in a normal font. 
The first 2 words are in small caps. The following 
words are only here to fill the paper and waste some 
space, time and hopefully no money. But if it is wasting 
time it is wasting money aswell if we trust old phrases.

\LettrineB{T}{his text} is written in a normal font. 
The first 2 words are in small caps italic shape. The following 
words are only here to fill the paper and waste some 
space, time and hopefully no money. But if it is wasting 
time it is wasting money aswell if we trust old phrases.

\LettrineC{T}{his text} is written in a normal font. 
The first 2 words are in italic shape. The following 
words are only here to fill the paper and waste some 
space, time and hopefully no money. But if it is wasting 
time it is wasting money aswell if we trust old phrases.

\LettrineD{T}{his text} is written in a normal font. 
The first 2 words are in italic shape. The following 
words are only here to fill the paper and waste some 
space, time and hopefully no money. But if it is wasting 
time it is wasting money aswell if we trust old phrases.

\end{document}

As an aside, loading xltxtra is not recommended nowadays and \setromanfont is deprecated.

enter image description here

  • Thank you, that was incredible helpfully. I just needed to adjust it a bit. – Sam H. Mar 26 '17 at 4:35
  • Can it be, that the lettrine arguments like findent or nindent have no effect after putting it in a group? – Sam H. Mar 26 '17 at 20:34
  • @SamH. That's indeed possible. The alternative to grouping is to save the current value of \LettrineFontHook in place of doing \begingroup and to restore it instead of doing \endgroup. – egreg Mar 26 '17 at 20:37
1

Do you want something like this? So that you can say

\lettrinea

and \lettrine will give an olive, upright lettrine followed by small-caps, or

\lettrineb

and lettrine will give an orange, italic lettrine followed by italics.

\documentclass{scrartcl}
\usepackage{xcolor} % für farbigen Text
\usepackage{fontspec}
\setromanfont[SmallCapsFont={Alegreya Sans SC}]{Alegreya Sans}
\usepackage{lettrine}
\newcommand*\lettrinea{%
  \renewcommand*{\LettrineFontHook}{\normalfont\color{olive}}%
  \renewcommand*\LettrineTextFont{\normalfont\scshape}%
  \setlength\DefaultFindent{.5em}%
  \setcounter{DefaultLines}{3}%
}
\newcommand*\lettrineb{%
  \renewcommand{\LettrineFontHook}{\normalfont\itshape\color{orange}}%
  \renewcommand*\LettrineTextFont{\normalfont\itshape}%
  \setlength\DefaultFindent{.5em}%
  \setcounter{DefaultLines}{3}%
}
\begin{document}
\lettrinea
\lettrine{T}{his text} is written in a normal font. The first 2 words are in small caps. The following words are only here to fill the paper and waste some space, time and hopefully no money. But if it is wasting time it is wasting money aswell if we trust old phrases.
\lettrineb
\lettrine{T}{his text} is written in a normal font. The first 2 words are in italic shape. The following words are only here to fill the paper and waste some space, time and hopefully no money. But if it is wasting time it is wasting money aswell if we trust old phrases.
\end{document}

variable lettrines

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.