0

I' writing a test macro to evaluate the Lettrine arguments for different letters & different sizes (lines). The scenario is this:

  1. The main prog calls a one arg macro to test the Lettrine for a given letter: \TestLettrine{A}
  2. The \TestLettrine macro calls another macro to get the right options passing it the letter & the size (line numbers) to pass it to Lettrine: \LettrineOpts{A}{3}.

When I compile this (I'm using LuaLatex) I get the message:

! Argument of \xs_IfStringCase_ii has an extra }.
<inserted text>
                \par
l.179 \TestLettrine{A}

Ran it on Overleaf got more errors including the one mentioned here.

Here's my MWE:

\documentclass{article}
\usepackage{lettrine}
\usepackage{xstring}
\usepackage{lipsum}

\newcommand{\LettrineOpts}[2]{%
  \IfStrEqCase{#1}{%
    {A}{lines=#2,lraise=0.1,slope=0.6em}%
    {C}{lines=#2,findent=0.1em,nindent=0.18em,slope=-0.5em}
  }%
}%

\newcommand{\TestLettrine}[1]{%
  \providecommand{\opts}{\LettrineOpts{#1}{3}}
  Opts for char #1 and size 3:\\ \opts 
  \lettrine[\opts]{#1}{}3 lines (\opts). One liner.
  \let\opts\relax
  \vspace*{3ex}

  \providecommand{\opts}{\LettrineOpts{#1}{4}}
  Opts for char #1 and size 4:\\ \opts 
  \lettrine[\opts]{#1}{}4 lignes. \\ \lipsum
  \let\opts\relax
  \vspace*{3ex}
}%

\begin{document}

\TestLettrine{A} \par
\TestLettrine{C}
% covering all the letters

\end{document}
2
  • Giving a command as parameter, that is interpreted as by keyval seems to be a problem. Minimal example: \documentclass{article} \usepackage{lettrine} \newcommand{\LettrineOpts}{lines=3} \newcommand{\TestLettrine}[1]{\lettrine[\LettrineOpts]{#1}{}} \begin{document} \TestLettrine{A} \end{document}
    – dexteritas
    Mar 25, 2023 at 11:34
  • Thanks @dexteritas,
    – Reza
    Mar 25, 2023 at 12:40

1 Answer 1

1

Your code generates another error and does not allow me to play the size variation (lines=n).

In the meantime I found another solution which I'm going to adopt. It uses the Lettrine config file where I can define the options for every char I want. I though initially that defining the size will override those definitions. Which is not the case. Lettrine MERGES my options with those already in the config file.

Excellent work of Daniel Flipo!

In case this solution might help someone here is the snippets of the final code.

Config file (options.cfl):

\LettrineOptionsFor{A}{slope=0.1\LettrineWidth, findent=-.5em, nindent=.7em}
\LettrineOptionsFor{À}{slope=0.1\LettrineWidth, findent=-.5em, nindent=0.7em}
\LettrineOptionsFor{V}{slope=-0.1\LettrineWidth, lhang=0.5, nindent=0pt}
\LettrineOptionsFor{C'}{nindent=-0.5em}
\LettrineOptionsFor{Q}{loversize=-0.1, lraise=0.1}

And the macros and their call:

\newcommand{\blah}{\lipsum*[1-2][1-5]}

\newcommand{\TestLettrine}[1]{%
  \lettrine[lines=3]{#1}{} lines: 3 \\ \blah
  \vspace*{3ex}
  \lettrine[lines=4]{#1}{} lines: 4 \\ \blah
  \clearpage
}%

\newcommand{\TestAllLettrines}{%
  \foreach \char in {A, À, C', Q, V }{%
    \TestLettrine{\char} \par%
  }%
}%

\TestAllLettrines

The options are given for the example.

You must log in to answer this question.

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