命令增加字体大小并分步扩展

命令增加字体大小并分步扩展

我已经为此烦恼了一段时间了。我想要一个与\relfontsize{<fontstep>}{<spreadstep>}完全相同的命令\fontsize{<fontsize>}{<spreadsize>},只不过它能正常工作相对地:它将字体大小乘以1.20^(<fontstep>),线条扩展乘以1.20^(<fontspread>)。因此,结果如下

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

(这里<fontstep><spreadstep>是整数,可能取负值

<fontstep>或多或少都有工作(使用我的另一个问题),但却<spreadstep>带来了麻烦。

(我不知道这是否重要,但是我正在使用 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}

答案1

设置后\fontsize,您需要\selectfont。以下最小示例通过添加<baseline>存储在中的组件来实现您想要的功能\f@baselineskip

在此处输入图片描述

\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}

请注意,发出段落中断(通过空行隐式中断或通过 显式中断\par)非常重要,以便为字体更改产生适当的基线跳过。我在上面两种方法都用过。

相关内容