1

I have been having trouble with this for some time by now. I want a command \relfontsize{<fontstep>}{<spreadstep>} that works exactly like \fontsize{<fontsize>}{<spreadsize>}, except that it works relatively: It multiplies the font size by 1.20^(<fontstep>) and the line spreading by 1.20^(<fontspread>). So what happens is

fontsize    ---> (1.20)^(<fontstep>)   *   oldfontsize
linespread  ---> (1.20)^(<spreadstep>) *   oldlinespread

(here <fontstep> and <spreadstep> are integers, which may take negative values)

I have <fontstep> more or less working (using this other question of mine), but <spreadstep> causes trouble.

(I do not know if this is going to matter, but I am compiling my document using LuaLaTeX.)

\documentclass[10pt]{memoir}

% Commands that allow me to use powers in \dimexpr expressions:
\usepackage{expl3}
\ExplSyntaxOn
\cs_new_eq:NN \fpeval \fp_eval:n
\cs_new_eq:NN \fptodim \fp_to_dim:n 
\ExplSyntaxOff

\makeatletter
\def\getcurrentfontsize{\f@size pt}
\makeatother

\newcommand*\relfontsize[2]{
\fontsize{\dimexpr\fpeval{1.2^(#1)}\dimexpr \getcurrentfontsize\relax}{%
        %please do some magic for me
   }\selectfont%
}

\begin{document}

First paragraph, normal size.

{

\relfontsize{1}{2} Let's increase the font size by 20 percent and the line spreading 
by 20 percent two times (that is, by 44 percent), BOTH numbers relative to the first paragraph.

\relfontsize{1}{1} Let's increase both further by 20 percent compared to the last paragraph

}

Now we're back at the old size.

\end{document}
Gaussler
  • 12,801
  • The question is perhaps a bit difficult to explain, so if anything at all does not make sense, don't hesitate to comment, and I shall do my best to explain! :-) – Gaussler Jan 22 '15 at 18:23
  • "times" means "multiplication"... why are you using powers? – Werner Jan 22 '15 at 18:26
  • Yes, I feared that sentence would cause confusion. "Increase x by y n times" means (to me) to change x to x y^n. Because I multiply x by y, and I do it n times. – Gaussler Jan 22 '15 at 18:28
  • I know it's confusing, but I cannot think of another formulation. But feel free to suggest one. – Gaussler Jan 22 '15 at 18:30
  • If you had specified luatex in your earlier powers question it would have been easier, lua has exponentiation:-) – David Carlisle Jan 22 '15 at 18:46

1 Answers1

2

Once you set the \fontsize, you need to \selectfont. The following minimal example implements what you're after with the addition of the <baseline> component - stored in \f@baselineskip:

enter image description here

\documentclass[10pt]{memoir}

% Commands that allow me to use powers in \dimexpr expressions:
\usepackage{expl3}
\ExplSyntaxOn
  \cs_new_eq:NN \fpeval \fp_eval:n
\ExplSyntaxOff

\makeatletter
\newcommand{\getcurrentfontsize}{\f@size pt}
\newcommand{\getcurrentbaseline}{\f@baselineskip pt}
\makeatother

\newcommand*\relfontsize[2]{%
  \fontsize
    {\dimexpr\fpeval{1.2^(#1)}\dimexpr\getcurrentfontsize\relax}
    {\dimexpr\fpeval{1.2^(#2)}\dimexpr\getcurrentbaseline\relax}%
  \selectfont%
}

\begin{document}

First paragraph, normal size.

{%
\relfontsize{1}{2} Let's increase the font size by 20 percent and the line spreading 
by 20 percent two times (that is, by 44 percent), BOTH numbers relative to the first paragraph.

\relfontsize{1}{1} Let's increase both further by 20 percent compared to the last paragraph.\par
}

Now we're back at the old size.

\end{document}

Note that it is important to issue a paragraph break (either implicitly via an empty line or explicitly via \par) in order to produce the appropriate baseline skip for the font change. I've used both above.

Werner
  • 603,163