I'm writing a novel and I defined a set of commands for starting a new chapter:

\newcommand{\AKapitel}[1]{\lettrine[lines=3, lraise=-0.2,findent=-22pt, nindent=14pt, loversize=0.26,slope=9pt]{A}{#1}}

\newcommand{\BKapitel}[1]{\lettrine[lines=3, lraise=-0.2,findent=-9pt, nindent=5pt, loversize=0.26,slope=1pt]{B}{#1}}

\newcommand{\DKapitel}[1]{\lettrine[lines=3, lraise=-0.2,findent=-8pt, nindent=7pt, loversize=0.26,slope=-4pt]{D}{#1}}

This way, I don't have to write out the lettrine parameters all the time. Works pretty well. But when I pick a different format (a4 instead of a5) or a different base font size, it gets messed up. So here is what I want to do: define a constant as factor and multiply all the parameters with it. Something like in this pseudocode:

scalefactor := 0.87
\newcommand{\AKapitel}[1]{\lettrine[lines=3, lraise=-0.2*scalefactor,findent=-22pt*scalefactor, nindent=14pt*scalefactor, loversize=0.26*scalefactor,slope=9pt*scalefactor]{A}{#1}}

How do I do this in actual latex code? Sorry for my limited knowledge about latex, I'm learning by doing.

  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Adam Liter Sep 11 '14 at 19:02
  • I suggest the macros from the calculator package – user31729 Sep 11 '14 at 19:38

It is easier for the keys expecting a <dimen>. For those expecting a decimal, you need something extra, as this is not implemented in core LaTeX. I do it here with package xintexpr. Indeed its macros are expandable.



\newcommand\scalefactor {0.87}

  lraise=\xintRound {4}{\xinttheexpr-0.2*\scalefactor\relax},
  nindent=\scalefactor\dimexpr 14pt\relax,
  loversize=\xintRound {4}{\xinttheexpr 0.26*\scalefactor\relax},
  slope=\scalefactor\dimexpr 9pt\relax]{A}{#1}}


\AKapitel {nd} hier ist ein Beispiel (Scale factor=\scalefactor).


\renewcommand\scalefactor {.5}

\AKapitel {nd} hier ist ein Beispiel (Scale factor=\scalefactor).

\renewcommand\scalefactor {.4176}

\AKapitel {nd} hier ist ein Beispiel (Scale factor=\scalefactor).

\renewcommand\scalefactor {.2}

\AKapitel {nd} hier ist ein Beispiel (Scale factor=\scalefactor).


multiply constant

Rather than xintexpr one may make do here with loading only xintfrac and then like loversize=\xintRound {4}{\xintMul {-0.26}{\scalefactor}} etc..

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.