% \iffalse meta-comment
%
% File: zhlineskip.dtx
% -----------------------------------------------------------------------
%   Copyright (C) 2018-2019 by Ruixi Zhang <ruixizhang42@gmail.com>     *
%   Copyright (C) 2026      by Mingyu Xia  <xiamingyu@westlake.edu.cn>  *
% -----------------------------------------------------------------------
%   This work may be distributed and/or modified under the conditions   *
%   of the LaTeX Project Public License (LPPL), either version 1.3c of  *
%   this license or (at your option) any later version.                 *
%   The latest version of this license is in                            *
%                                                                       *
%       http://www.latex-project.org/lppl.txt                           *
%                                                                       *
%   and version 1.3c or later is part of all distributions of LaTeX     *
%   version 2008 or later.                                              *
%                                                                       *
%   This work has the LPPL maintenance status `maintained'.             *
%                                                                       *
%   The Current Maintainers of this work are Ruixi Zhang and Mingyu Xia.*
% -----------------------------------------------------------------------
%   This work consists of the files zhlineskip.dtx,                     *
%                 the derived files zhlineskip.ins,                     *
%                                   zhlineskip.sty,                     *
%           the documentation files zhlineskip.pdf,                     *
%                                   Latinmetrics.pdf,                   *
%                                   CJKmetrics.pdf,                     *
%                               and README.md.                          *
% -----------------------------------------------------------------------
%                                                                       *
%   Any modification of this file should ensure that the copyright and  *
%   license information is placed in the derived files.                 *
%                                                                       *
% -----------------------------------------------------------------------
%
%<*internal>
\iffalse
%</internal>
%<*readme>
[![CTAN Version](https://img.shields.io/ctan/v/zhlineskip)](https://ctan.org/pkg/zhlineskip)
[![GitHub Release](https://img.shields.io/github/v/release/CTeX-org/ctex-kit)](https://github.com/CTeX-org/ctex-kit/releases/latest)
[![GitHub Last Commit](https://img.shields.io/github/last-commit/CTeX-org/ctex-kit)](https://github.com/CTeX-org/ctex-kit/commits)
[![Actions Status](https://github.com/CTeX-org/ctex-kit/actions/workflows/test.yml/badge.svg?branch=master)](https://github.com/CTeX-org/ctex-kit/actions)
[![GitHub Repo stars](https://img.shields.io/github/stars/CTeX-org/ctex-kit)](https://github.com/CTeX-org/ctex-kit)

The `zhlineskip` Package
========================

`zhlineskip` is a package for typesetting CJK documents. This package allows
users to specify two ratios: One between the leading and the font size of the
body text and the other between those of the footnote text.
For Latin typography, these ratios usually range
[from&nbsp;1.2 to&nbsp;1.45](https://practicaltypography.com/line-spacing.html),
but they should be larger for CJK typography (usually from&nbsp;1.5
to&nbsp;1.67).

Although CJK text requires larger line spacing, maths formulae should follow
the rules of Latin typography, since maths often consists of only Latin-based
letters and symbols. The `zhlineskip` package is capable of restoring the
maths leading to that of the Latin text.

Finally, it is possible to achieve the “Microsoft Word multiple line spacing”
style using `zhlineskip`.

Contributing
------------

This package is a part of the [CTeX-kit](https://github.com/CTeX-org/ctex-kit) project.

Issues and pull requests are welcome.

Copyright and Licence
---------------------

Copyright (C) 2018-2019 by Ruixi Zhang
[`<ruixizhang42@gmail.com>`](mailto:ruixizhang42@gmail.com)

Copyright (C) 2026 by Mingyu Xia
[`<xiamingyu@westlake.edu.cn>`](mailto:xiamingyu@westlake.edu.cn)

This work may be distributed and/or modified under the conditions
of the LaTeX Project Public License (LPPL), either version 1.3c of
this license or (at your option) any later version.
The latest version of this license is in

    http://www.latex-project.org/lppl.txt

and version 1.3c or later is part of all distributions of LaTeX
version 2008 or later.

This work has the LPPL maintenance status `maintained`.

The Current Maintainers of this work are **Ruixi Zhang** and **Mingyu Xia**.
%</readme>
%<*internal>
\fi
\begingroup
  \def\temp{LaTeX2e}
\expandafter\endgroup\ifx\temp\fmtname\else
\csname fi\endcsname
%</internal>
%<*install>

\input ctxdocstrip %
\askforoverwritefalse

\preamble
-----------------------------------------------------------------------
  Copyright (C) 2018-2019 by Ruixi Zhang <ruixizhang42@gmail.com>     *
  Copyright (C) 2026      by Mingyu Xia  <xiamingyu@westlake.edu.cn>  *
-----------------------------------------------------------------------
  This work may be distributed and/or modified under the conditions   *
  of the LaTeX Project Public License (LPPL), either version 1.3c of  *
  this license or (at your option) any later version.                 *
  The latest version of this license is in                            *
                                                                      *
      http://www.latex-project.org/lppl.txt                           *
                                                                      *
  and version 1.3c or later is part of all distributions of LaTeX     *
  version 2008 or later.                                              *
                                                                      *
  This work has the LPPL maintenance status `maintained'.             *
                                                                      *
  The Current Maintainers of this work are Ruixi Zhang and Mingyu Xia.*
-----------------------------------------------------------------------
\endpreamble
\postamble
-----------------------------------------------------------------------
  This work consists of the files zhlineskip.dtx,                     *
                the derived files zhlineskip.ins,                     *
                                  zhlineskip.sty,                     *
          the documentation files zhlineskip.pdf,                     *
                                  Latinmetrics.pdf,                   *
                                  CJKmetrics.pdf,                     *
                              and README.md.                          *
-----------------------------------------------------------------------
\endpostamble

\keepsilent

\generate{
  \usedir{tex/latex/zhlineskip}
    \file{zhlineskip.sty}                {\from{\jobname.dtx}{package}}
  \usedir{doc/latex/zhlineskip}
%</install>
%<*internal>
    \usedir{source/latex/zhlineskip}
    \file{\jobname.ins}                  {\from{\jobname.dtx}{install}}
%</internal>
%<*install>
  \nopreamble\nopostamble
    \file{README.md}                     {\from{\jobname.dtx}{readme} }
}

\endbatchfile
%</install>
%<*internal>
\fi
%</internal>
%<package>\NeedsTeXFormat{LaTeX2e}[2026/06/01]
%<package>\RequirePackage{expl3}
%<*package>
%<+!driver>\GetIdInfo $Id: zhlineskip.dtx v1.0f 2026-06-28 Mingyu Xia<myhsia@outlook.com>$
%<package>  {Line spacing for CJK documents}
%<package>\ProvidesExplPackage {\ExplFileName}
%<!driver>  {\ExplFileDate} {\ExplFileVersion} {\ExplFileDescription}
%<package>\edef \ZhLSFileDate        {\ExplFileDate}
%<package>\edef \ZhLSFileVersion     {\ExplFileVersion}
%<package>\edef \ZhLSFileDescription {\ExplFileDescription}
% ^^A \ExplFileDate 是 "YYYY/MM/DD" 格式, 手册标题格式需斜杠换 hyphen.
% ^^A 用全局 (g) 版本是因为 \ZhLSFileDate 由上方 \edef 在包加载期定义,
% ^^A 此时无分组嵌套, g/l 等价, 用 g 跟 \edef 的全局可见性匹配.
%<package>\tl_greplace_all:Nnn \ZhLSFileDate { / } { - }
%</package>
%<*driver>
% `ctxdoc` 已经加载了 unicode-math, zhlineskip 在 `restoremathleading = true`
% (默认) 时会加载 mathtools, 而 unicode-math 必须在 mathtools 之后加载, 否则
% mathtools 的 `\colon` 之类 会被 unicode-math 后续重定义覆盖.
% 顺序固定: ctxdoc -> unicode-math.
\RequirePackage{mathtools}
\documentclass[cs-break, zihao = 5, a4paper, fontset = none]{ctxdoc}
\unimathsetup{
  math-style   = ISO,
  warnings-off = {mathtools-colon, mathtools-overbracket}
}
\setmathfont{texgyrepagella-math.otf}[
  Scale             = 1.059248554913295
]
\setmainfont{texgyrepagella}[
  Extension         = .otf,
  UprightFont       = *-regular,
  ItalicFont        = *-italic,
  BoldFont          = *-bold,
  BoldItalicFont    = *-bolditalic,
  Scale             = 1.059248554913295,
  SmallCapsFeatures = {LetterSpace = 5}
]
\setsansfont{texgyreheros}[
  Extension         = .otf,
  UprightFont       = *-regular,
  ItalicFont        = *-italic,
  BoldFont          = *-bold,
  BoldItalicFont    = *-bolditalic,
  Scale             = 1.006858710562414
]
\setmonofont{Inconsolatazi4}[
  Extension         = .otf,
  UprightFont       = *-Regular,
  BoldFont          = *-Bold,
  Scale             = 1.001185648174325,
  AutoFakeSlant     = .111
]
\setCJKmainfont{Noto Serif CJK SC}[
  UprightFont       = * Medium,
  ItalicFont        = * Black,
  BoldFont          = * Bold
]
% Sans/Mono 不显式 UprightFont. fontspec 默认让 fontconfig 模糊匹配
% Regular weight (Noto OTC 集合里没有单独 "Regular" 暴露名). 显式
% `* Regular` 反而让 fontconfig 查不到. xeCJK 也是直接 `Noto Sans CJK SC`.
\setCJKsansfont{Noto Sans CJK SC}[
  BoldFont          = * Bold
]
\setCJKmonofont{Noto Sans CJK SC}[
  BoldFont          = * Bold
]
\frenchspacing
\usepackage{zhlineskip}
\newenvironment{english}{\addvspace\medskipamount}
                        {\par\addvspace\medskipamount}
\SetTextEnvironmentSinglespace{1.112}
\SetMathEnvironmentSinglespace{1.112}
\makeatletter
\newenvironment{originalpmatrix}
  {\mathopen{}\mathclose\bgroup\left(\env@matrix}
  {\endmatrix\aftergroup\egroup\right)}
\newenvironment{originalcases}{\env@cases}{\endarray\right.}
\makeatother
\usepackage{caption, docext, xurl, booktabs, hyperref}
\captionsetup{format = hang, font = small}
\hypersetup{
  pdfstartview = FitH, pdftitle  = zhlineskip,
  unicode      = true, pdfauthor = Ruixi Zhang and Mingyu Xia
}
\newcommand \mail[1] {\href{mailto:#1}{\ttfamily #1}}
\begin{document}
  \DocInput{\jobname.dtx}
  \IndexLayout
  \PrintChanges
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \changes{v1.0a}{2018/08/03}
%   {去掉了对 \pkg{setspace} 与 \pkg{caption} 宏包的依赖。}
% \changes{v1.0a}{2018/08/03}
%   {去掉了键值选项 \opt{captionleadingratio}。}
% \changes{v1.0a}{2018/08/03}{重命名键值选项
%   \opt{MicrosoftWordLineSpacingMultiple} 为\opt{MSLineSpacingMultiple}}
% \changes{v1.0a}{2018/08/03}{对外提供两个新的宏：
%   \tn{SetTextEnvironmentSinglespace} 与 \tn{SetMathEnvironmentSinglespace}，
%   分别用于微调西文环境与数学环境的行距。}
% \changes{v1.0a}{2018/08/03}{其余优化与改动只涉及到含 \texttt{@} 的内部宏，
%   例如：宏命名更加规范、利用 \texttt{sp} 长度做计算。}
%
% \begin{documentation}
%
% \GetFileId{zhlineskip.sty}
% \title{\bfseries
%   \pkg{zhlineskip} 宏包\thanks{^^A
%     \url{https://ctan.org/pkg/zhlineskip},\
%     \url{https://github.com/CTeX-org/ctex-kit}^^A
%   }^^A
% }
% \author{^^A
%   张瑞熹\thanks{\mail{ruixizhang42@gmail.com}},^^A
%   \texorpdfstring{\quad}{ }
%   夏明宇\thanks{\mail{xiamingyu@westlake.edu.cn}}^^A
% }
% \date{Released \ZhLSFileDate\quad \texttt{\ZhLSFileVersion}}
% \maketitle
% \tableofcontents
%
% \section{简介}
%
% \pkg{zhlineskip} 宏包允许用户指定正文行距相比于正文字号的倍数
% （通常建议设置在 $1.5$至 $1.67$ 之间），以及脚注行距相比于脚注字号的倍数。
% 另一方面，由于数学公式主要是由西文字符构成的，
% \pkg{zhlineskip} 还能将数学公式的行距“恢复”成西文较为紧凑的行距
% （通常为西文字号的 $1.2$~倍），使得全文的视觉密度较为均匀。
% 最后，本宏包还支持按照 Microsoft Word 进行“多倍行距”排版。
%
% \subsection{宏包依赖}
%
% 本宏包是针对中日韩文的横排文档设计出来的，它依赖于下面这些宏包：
%
% \begin{itemize}
%   \item \makebox[9ex][l]{\pkg{etoolbox}} 宏包：
%   处理脚注行距与数学行距时需要打补丁。
%   \item \makebox[9ex][l]{\pkg{mathtools}} 宏包：
%   只有在恢复数学行距为西文行距时，才会载入这个宏包。
% \end{itemize}
% 请确保你的 \TeX\ 发行版里已经安装好了以上这些宏包的最新版本。
%
% \subsection{中西有别}
%
% 在西文排版里，相邻两行\emph{基线}（|baseline|）之间的距离称为\emph{行距}
% （leading，发音为 led-ding）。这个词的词根是 lead，即\emph{铅}。
% 早在铅字时代，每当工匠填满一行铅字之后要开始填下一行，都会在两行之间插入铅条，
% 从而适当地扩大行距。因为西文的每个字母四周与其\emph{字框}
% （em-box，见图~\ref{fig:eng-font-size}）之间有较大的空隙，所以不需要插入很高的铅条。
% 一般来说，西文的行距为\emph{字号}（|fontsize|）的 $1.2$ 至 $1.45$~倍\footnote{^^A
% 参见~\url{https://practicaltypography.com/line-spacing.html}。}。
%
% \begin{figure}[htbp]
%   \centering
%   \includegraphics[width = .8\linewidth]{Latinmetrics}
%   \caption[西文字体]{西文字体。绿色方框即为 |em-box|，它在纸上的实际边长就是西文字号。}
%   \label{fig:eng-font-size}
% \end{figure}
%
% 中文排版虽然没有基线的概念，但有非常相似的概念：\emph{底线}（ideographic baseline，
% 见图~\ref{fig:chi-font-size}）。中文里相邻两行底线之间的距离，
% 与西文里行距的概念是一致的。另一概念是上一行底线和下一行\emph{顶线}之间的距离，
% 即\emph{行间距}（|linegap|），这与西文里插入铅条的高度是一致的。
% 由于汉字四周与其字框间的空隙较小，所以需要使用比西文更大的行间距。根据场合不同，
% 行间距从字号的 $1/4$ 至 $1$~倍不等：以中文书刊为例，
% 行间距一般为字号的 $1/2$ 至 $2/3$~倍\footnote{^^A
% 参见张胜涛、王忆波著《方正飞腾4.0实用培训教程》，第~6.1.1~节。}，
% 即行距约为字号的 $1.5$ 至 $1.67$~倍。
%
% \begin{figure}[htbp]
%   \centering
%   \includegraphics[width = .8\linewidth]{CJKmetrics}
%   \caption[中文字体]{中文字体。汉字字面几乎占满整个字框，字框的边长即为中文字号。}
%   \label{fig:chi-font-size}
% \end{figure}
%
% 在一般情况下，\CTeX\ 会默认用 \opt{linespread = 1.3}
% 这个文档类选项将中文的行距设置为字号的 $1.56$~倍
% （基础行距是字号的 $1.2$~倍，而 $1.2 \times 1.3 = 1.56$）。
% 通过这种方法扩大全文的行距，自然会影响到文章里数学公式的行距。
% 而数学公式主要是由西文字符构成的，把它们按照中文的行距进行排版，就会显得有些松散。
% 图~\ref{fig:math-leading}  左边是 \CTeX\ 默认排版效果，文本、数学看似一紧、一松；
% 右边是配合用 \pkg{zhlineskip} 的效果，视觉密度比较均匀。
% \pkg{zhlineskip} 宏包还允许用户调整数学行距的大小。
%
% \begin{figure}[htbp]
% \long \def \0{^^A
%   设 $\symbf I_2 =
%     \begin{psmallmatrix}
%       1 & 0 \\
%       0 & 1
%     \end{psmallmatrix}$.
%   又设 $\symbf A = (a_{ij})_{m \times n}$ 为一个 $m$~行
%   $n$~列的实值矩阵, 即
%   \[
%     \symbf A =
%     \begin{originalpmatrix}
%       a_{11} & a_{12} & \dotsc & a_{1n} \\
%       a_{21} & a_{22} & \dotsc & a_{2n} \\
%       \vdots & \vdots &        & \vdots \\
%       a_{m1} & a_{m2} & \dotsc & a_{mn}
%     \end{originalpmatrix},
%   \]
%   其中 $a_{ij} \in \symbb R$, $i = 1$, $\dotsc\,$,~$m$,
%   $j = 1$, $\dotsc\,$,~$n$. 又因为
%   \[
%     \sum_{\substack{i=1\\i\neq j}}^m a_{ij} =
%     \begin{originalcases}
%       0, & j = 1,\\
%       1, & j > 1,
%     \end{originalcases}
%   \]
%   我们得到……
% }
% \long \def \1{^^A
%   设 $\symbf I_2 =
%     \begin{psmallmatrix}
%       1 & 0 \\
%       0 & 1
%     \end{psmallmatrix}$.
%   又设 $\symbf A = (a_{ij})_{m \times n}$ 为一个 $m$~行
%   $n$~列的实值矩阵, 即
%   \[
%     \symbf A =
%     \begin{pmatrix}
%       a_{11} & a_{12} & \dotsc & a_{1n} \\
%       a_{21} & a_{22} & \dotsc & a_{2n} \\
%       \vdots & \vdots &        & \vdots \\
%       a_{m1} & a_{m2} & \dotsc & a_{mn}
%     \end{pmatrix},
%   \]
%   其中 $a_{ij} \in \symbb R$, $i = 1$, $\dotsc\,$,~$m$,
%   $j = 1$, $\dotsc\,$,~$n$. 又因为
%   \[
%     \sum_{\substack{i=1\\i\neq j}}^m a_{ij} =
%     \begin{cases}
%       0, & j = 1,\\
%       1, & j > 1,
%     \end{cases}
%   \]
%   我们得到……
% }
% \sbox0{^^A
%   \parbox[t]{.45\linewidth}{\fontsize{9}{10.8}\linespread{1.3}\selectfont\0}}
%   \centering
%   \fbox{\parbox[t][\dimexpr\dp0+\ht0+6pt]{.45\linewidth}^^A
%     {\fontsize{9}{10.8}\linespread{1.3}\selectfont\par\vskip\fboxsep\0}}^^A
%   \kern-.4pt^^A
%   \fbox{\parbox[t][\dimexpr\dp0+\ht0+6pt]{.45\linewidth}^^A
%     {\fontsize{9}{10.8}\linespread{1.3}\selectfont\par\vskip\fboxsep\1}}
% \caption[数学行距对比]{数学行距对比。在左图中，大矩阵 \env{pmatrix} 与
%   分类 \env{cases} 两个环境受到影响，行距都被扩大了；但第一行文本里的小矩阵与末尾
%   公式里求和号的下角标却没有受到影响，行距仍然较为紧凑。在右图中，数学公式的行距
%   都是西文的行距，密度比较均匀，行间公式里的大括弧、大括号也不会特别突兀。}
% \label{fig:math-leading}
% \end{figure}
%
% 综上所述，在进行中西文混排时，最好能够区分中文与西文的行距。在使用 \pkg{zhlineskip}
% 时，就可以分开处理中文文本与数学公式的行距。用户甚至还能分别指定正文行距与脚注
% 行距，实现灵活的排版。同时，\pkg{zhlineskip} 宏包能恢复各种“多行”数学环境
% （包括矩阵、分类、多行公式推导等等）的行距，使数学公式的行距符合西文行距的规范。
%
% 最后，\pkg{zhlineskip} 宏包还支持用户在一定范围内按 Microsoft Word 的
% “多倍行距”进行排版\footnote{本宏包默认假定“被要求”用的字体是中易系列字体，
% 这包括 Microsoft Word 里的“宋体”、“黑体”、“楷体”与“仿宋”。若改用其他字体，
% 可能需要调整 \opt{MSWordSinglespaceRatio} 的值。
% 参见第~\ref{sec:key-value}~节与第~\ref{sec:MS-Word}~节。}。
% 用户可以指定“多倍行距”的“倍数”，但是这只保证用 \TeX\ 排出来的文本行距与用
% Microsoft Word 排的行距相同。硬要用 \TeX\ 模仿 Microsoft Word 是没有
% 太大意义的。
%
% \section{功能介绍}
%
% 首先，请避免使用“多倍行距”这个概念：Microsoft Word 中“单倍行距”的值严重依赖于字体
% （参见第~\ref{sec:MS-Word}~节）。
% 在严格排版的时候，一般都会给定具体的字号与行距，例如字号 $12$~磅、行距 $22$~磅。
% 对于一般的用户，指定目标行距相比字号的倍数即可 ---
% \pkg{zhlineskip} 宏包可以自动提取基础行距（即 \TeX\ 中的单倍行距）
% 相比字号的倍数（详见表~\ref{tab:default-leading-ratio}），
% 再通过用户指定的倍数来计算所需的行伸展因子。
% 因此，不论是中日韩文还是西文的横排文档，都是可以使用本宏包的。
% 本宏包的缺省设置更适合中日韩文文档。
% \begin{table}[htbp]
%   \newcommand*\defaultleadingratio[3]{\opt{#1} & $#2$ & $#3$}
%   \centering
%   \caption[基础行距倍数]{\cls{ctexart} 与~\cls{article} 各个文档类选项
%     设置的基础行距倍数。}
%   \label{tab:default-leading-ratio}
%   \begin{tabular}{p{.2\linewidth}p{.2\linewidth}p{.2\linewidth}}
%     \toprule
%     文档类选项 & 正文基础行距 & 脚注基础行距 \\
%     \midrule
%     \defaultleadingratio{zihao=5}{1.2}{1.2} \\
%     \defaultleadingratio{zihao=-4}{1.2}{1.2} \\
%     \defaultleadingratio{10pt}{12/10}{9.5/8} \\
%     \defaultleadingratio{11pt}{13.6/10.95}{11/9} \\
%     \defaultleadingratio{12pt}{14.5/12}{12/10} \\
%     \bottomrule
%   \end{tabular}
% \end{table}
%
% \subsection{载入宏包时的键值选项}\label{sec:key-value}
%
% 载入\CJKecglue\pkg{zhlineskip} 宏包时可以设定六个基本的键值选项，它们分别是：
% \begin{keyval}
%   \item [\keys{bodytextleadingratio}]\val{real}：
%   指定正文目标行距相比于正文字号的倍数\hfill
%   (初始值：|1.5|，$1/2$~的行间距)\\
%   以书刊为例，建议设置在~$1.5$ 至~$1.67$ 之间。
%   \item [\keys{footnoteleadingratio}]\val{real}：
%   指定脚注目标行距相比于脚注字号的倍数\hfill
%   (初始值：|1.48|，正文倍数的~$98.67\%$)\\
%   它可以比正文的倍数稍小一些，建议设置在正文倍数的 $98\%$ 至 $100\%$ 之间。
%   \item [\keys{restoremathleading}]\val{\TTF}：
%   指定是否将数学公式行距恢复成西文基础行距。\hfill
%   (初始值：|true|，默认值：|true|)\\
%   该选项为真时，会自动载入 \pkg{mathtools} 宏包，此时还能利用
%   \begin{quote}
%     \tn{SetMathEnvironmentSinglespace} \marg{real}
%   \end{quote}
%   命令\emph{微调}数学公式的基础行距。
%   \item [\keys{MSWordLineSpacingMultiple}]\val{\TTF, real}：
%   设置 MS Word“多倍行距”的“倍数”\hfill
%   (初始值：|false|，默认值：|1.15|)\\
%   在排版论文时，如果被要求按照 Microsoft Word 来设置“多倍行距”，那么用户可以
%   将该选项设置为~\opt{true}，亦或直接通过该选项指定“倍数”，
%   这会忽略用户之前指定的正文行距与脚注行距倍数，但是与数学行距的设置独立。
%   在不修改 \opt{MSWordSinglespaceRatio} 时，
%   相当于设置了目标行距为字号的 $1.49140625$~倍，适用于中易字体
%   （参见第~\ref{sec:MS-Word}~节）。
%   \item [\keys{MSWordSinglespaceRatio}]\val{real}：
%   设置 Microsoft Word 的“单倍行距”相比字号的倍数\hfill
%   (初始值：|1.296875|)\\
%   仅在 \opt{MSWordLineSpacingMultiple} 为真时生效。
%   适用于中易字体（参见第~\ref{sec:MS-Word}~节）。
%   若改用其他字体，则需调整该选项的值。
% \end{keyval}
%
% \subsection{载入宏包后的用户命令}
%
% \subsubsection{调整数学公式的行距}
%
% 当键值选项 \opt{restoremathleading}为~\opt{true} 时，
% 数学公式的行距被恢复成字号的 $1.2$~倍。
% 对于某些字面较大的数学字体（例如类似 Palatino 的字体），
% 这个基础行距会显得过小。此时，用户可以通过如下命令微调数学行距：
% \begin{function}[added   = 2018-08-03,
%                  updated = 2018-10-29]{\SetMathEnvironmentSinglespace}
%   \begin{syntax}
%     \tn{SetMathEnvironmentSinglespace} \marg{real}
%   \end{syntax}
% 如果数学字体来自 \pkg{newpxmath} 或是 TeX Gyre Pagella Math，
% 那么数学行距在字号 $1.2$~倍的基础上再扩大 $1.05$~倍更加合适。
% 此时，只需指定 |\SetMathEnvironmentSinglespace{1.05}| 即可。
% \end{function}
% 本宏包恢复的多行数学环境包括：
% \begin{description}
%   \raggedright
%   \item[\LaTeX\ 环境]
%   \env{array}；
%   \item[\pkg{amsmath} 宏包各环境]
%   \ExplSyntaxOn
%   \seq_set_from_clist:Nn \l_tmpa_seq
%     {
%       (p|b|B|v|V)matrix,       cases,
%       aligned,     alignedat,  gathered,    gather(*),
%       align(*),    flalign(*), alignat(*),
%       xalignat(*), xxalignat,  multline(*), split,
%     }
%     \seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq
%       { \env{#1} }
%     \seq_use:Nn \l_tmpb_seq {,~}.
%   \ExplSyntaxOff
%   \item[\pkg{mathtools} 宏包各环境]
%   \ExplSyntaxOn
%   \seq_set_from_clist:Nn \l_tmpa_seq
%     {
%       (p|b|B|v|V)matrix*, cases*,        (d|r|dr)cases(*),
%       multlined         , (l|r)gathered,
%     }
%     \seq_set_map:NNn \l_tmpb_seq \l_tmpa_seq
%       { \env{#1} }
%     \seq_use:Nn \l_tmpb_seq {,~}.
%   \ExplSyntaxOff
% \end{description}
% 超出上述列表范围、用户自定义的\emph{数学}环境，可用如下命令恢复其行距：
% \begin{function}[added   = 2018-07-14,
%                  updated = 2019-05-16]{\RestoreMathEnvironmentLeading}
%   \begin{syntax}
%     \tn{RestoreMathEnvironmentLeading} \marg{env name}
%   \end{syntax}
% 例如本宏包恢复 \LaTeX\ 数学环境 \env{array} 的行距，是通过
%   \begin{quote}
%     |\RestoreMathEnvironmentLeading {array}|
%   \end{quote}
% 实现的。
% \meta{env name} 可以是由若干环境名构成的逗号列表。
% \begin{texnote}
%   在 |restoremathleading = false| 时，
%   命令 \tn{SetMathEnvironmentSinglespace} 与\linebreak
%   \tn{RestoreMathEnvironmentLeading} 无效。
% \end{texnote}
% \end{function}
%
% \subsubsection{调整西文文本的行距}
%
% 与数学行距命令对应，本宏包还提供两个调整\emph{西文文本}行距的命令，用法类似。
%
% \begin{function}[added   = 2018-08-03,
%                  updated = 2018-10-16]{\SetTextEnvironmentSinglespace}
%   \begin{syntax}
%     \tn{SetTextEnvironmentSinglespace} \marg{env name}
%   \end{syntax}
%   如果西文字体来自 \pkg{newpxtext} 或是 TeX Gyre Pagella，
%   那么可以指定
%   \begin{quote}
%     |\SetTextEnvironmentSinglespace {1.05}|
%   \end{quote}
% \end{function}
%
% \begin{function}[added   = 2018-07-14,
%                  updated = 2019-05-16]{\RestoreTextEnvironmentLeading}
%   \begin{syntax}
%     \tn{RestoreTextEnvironmentLeading} \marg{env name}
%   \end{syntax}
%   使用范例：假设文中的表格仅含西文、数字，此时如果想要文本环境 \env{tabular}
%   的行距与西文行距一致，可通过
%   \begin{quote}
%     |\RestoreTextEnvironmentLeading {tabular}|
%   \end{quote}
%   实现。亦可参见\ref{example:english-block}
%   \meta{env name} 可以是由若干环境名构成的逗号列表。
% \end{function}
% 如果作者没有顾及到某些\emph{基本环境}（数学或文本），鼓励用户向 \pkg{zhlineskip}
% 的 \href{https://github.com/CTeX-org/ctex-kit/issues}{GitHub 维护页}
% 提供相关信息。
%
% \subsection{使用范例}
%
% 下面以 \CTeX\ 提供的 \cls{ctexart} 文档类为例，
% 展示 \pkg{zhlineskip} 的使用方法。
%
% \begingroup
% \renewcommand *\thesubsubsection{例\arabic{subsubsection}.}
% \subsubsection{直接载入}
%
% \begin{verbatim}
%   \documentclass{ctexart}
%   \usepackage{zhlineskip}
%   \begin{document}
%     正文测试。
%   \end{document}
% \end{verbatim}
%
% \subsubsection{导言区设置正文行距为字号的 1.6 倍}
%
% \begin{verbatim}
%   \usepackage[
%     bodytextleadingratio = 1.6,             % 设置正文行距倍数为 1.6
%     footnoteleadingratio = 1.57             % 设置脚注行距倍数为 1.57
%   ]{zhlineskip}                             % 初始数学行距倍数为 1.2
% \end{verbatim}
%
% \subsubsection{导言区按照 Microsoft Word 设置“1.62 倍行距”}
%
% \begin{verbatim}
%   \usepackage[
%     restoremathleading            = false,  % 可选
%     MSWordLineSpacingMultiple     = 1.62
%   ]{zhlineskip}
% \end{verbatim}
%
% \subsubsection{中文正文里需要插入成段的西文}\label{example:english-block}
%
% 如果需要插入成段的西文，最好的方法是先定义一个西文专用的环境。
% 比如说可以在导言区定义如下这个环境：
% \begin{verbatim}
%   \newenvironment{english}                  % 新建“英文”段落环境
%     {\addvspace\medskipamount}              % 段前间距，上文段落需结束
%     {\par\addvspace\medskipamount}          % 段后间距
% \end{verbatim}
% 注意要先用空行结束上文段落。这时，可以通过 \pkg{zhlineskip} 声明
% \begin{verbatim}
%   \RestoreTextEnvironmentLeading{english}   % 恢复“英文”使用紧凑行距
% \end{verbatim}
% 将“英文”段落的行距恢复成西文较为紧凑的行距。
% 这样一来，正文（也许是中英交替的译文）就会有比较均匀的视觉密度，
% 而不至于“中文很挤、英文很散”。
%
% \iffalse
%<*example>
% \fi
\begingroup
\ExplSyntaxOn
\patchcmd \__codedoc_codemo_end:Nn
  { \parbox [ c ] [ \l__codedoc_codemo_int \baselineskip + .48ex ] }
  { \parbox [ c ] [ 16 \baselineskip + .48ex ] [ t ] }
  { } { }
\patchcmd \__codedoc_codemo_end:Nn
  { \parbox [ c ] [ \l__codedoc_codemo_int \baselineskip + .48ex ] }
  { \parbox [ c ] [ 16 \baselineskip + .48ex ] [ t ] }
  { } { }
\setlength \ttwd {0pt}
\ExplSyntaxOff
\docextset{ratio = .5}
\linespread{1.25}\selectfont
\begin{codemo}
\setlength \parindent {2\ccwd}
\RestoreTextEnvironmentLeading{english}
人人生而自由，在尊严和权利上一律平等。他们
赋有理性和良心，并应以兄弟关系的精神相对待。
\begin{english}
All human beings are born free and equal in
dignity and rights. They are endowed with
reason and conscience and should act towards
one another in a spirit of brotherhood.
\end{english}
人人有资格享有本宣言所载的一切权利和自由，
不分种族、肤色、性别、语言……
\begin{english}
Everyone is entitled to all the rights and
freedoms set forth in this Declaration,
without distinction of any kind, such as
race, colour, sex, language\dots
\end{english}
\end{codemo}
\endgroup
% \iffalse
%</example>
% \fi
%
% \endgroup
%
% \subsection{MS Word 中的“单倍行距”}
% \label{sec:MS-Word}
%
% Microsoft Word 中“单倍行距”的设置，其行距值相比字号的倍数严重依赖于字体，
% 甚至还可能因为操作系统的不同而迥然不同。
% 表~\ref{tab:word-line-height} 列出
% 几种常见字体对应的单倍行距倍数。正是因为“单倍行距”本身随字体、操作系统而变化，
% 所以请尽量避免使用“多倍行距”的概念！
% \begin{table}[htbp]
%   \centering
%   \caption[单倍行距倍数]{在 Microsoft Word 中设置“单倍行距”后，实际的行距
%   依赖于字体。}
%   \label{tab:word-line-height}
%   \def \fontandsinglespaceratio #1#2#3^^A
%     {#1 & $\makebox[4ex][r]{#2}/\makebox[4ex][l]{#3} = \fpeval{#2/#3}$}
% \begin{tabular}{p{.4\linewidth}p{.4\linewidth}}
% \toprule
% 字体名称 & “单倍行距”除以字号的倍数                             \\
% \midrule
% \fontandsinglespaceratio{Arial}{2355}{2048}                     \\
% \fontandsinglespaceratio{Times New Roman}{2355}{2048}           \\
% \fontandsinglespaceratio{中易系列字体}{332}{256}                \\
% \fontandsinglespaceratio{华文中宋（Windows）}{1479}{1000}       \\
% \fontandsinglespaceratio{微软雅黑 Light（Windows）}{3400}{2048} \\
% \fontandsinglespaceratio{微软雅黑 Regular/Bold}{3513}{2048}     \\
% \fontandsinglespaceratio{华文中宋（macOS）}{1723}{1000}         \\
% \fontandsinglespaceratio{微软雅黑 Light（macOS）}{3542}{2048}   \\
% \fontandsinglespaceratio{苹方（macOS）}{1820}{1000}             \\
% \fontandsinglespaceratio{思源宋体~1.001}{1869}{1000}            \\
% \fontandsinglespaceratio{思源黑体~2.000}{1882}{1000}            \\
% \fontandsinglespaceratio{思源黑体~1.004}{1924}{1000}            \\
% \bottomrule
% \end{tabular}
% \end{table}
%
% \begin{thebibliography}{9}
%   \bibitem{butterick2018linespacing}
%   \textsc{Butterick, Matthew}.
%   \newblock \textit{Butterick's Practical Typography\textup:
%     Line spacing}.
%   \newblock \url{https://practicaltypography.com/line-spacing.html},
%     访问日期: 2018/10/28.
%
%   \bibitem{knuth1986tex}
%   \textsc{Knuth, Donald Ervin}.
%   \newblock \textit{The \TeX book}.
%   \newblock Addison--Wesley, 1986.
%
%   \bibitem{lunde2008cjkv}
%   \textsc{Lunde, Ken}.
%   \newblock \textit{CJKV Information Processing\textup:
%     Chinese\textup, Japanese\textup, Korean \textup\&
%     Vietnamese Computing} (2~ed.).
%   \newblock O'Reilly Media, Inc., 2008.
%
%   \bibitem{zhang2005fang}
%   张胜涛 \& 王忆波.
%   \newblock \textbf{方正飞腾 4.0 实用培训教程}.
%   \newblock 清华大学出版社, 2005.
% \end{thebibliography}
%
% \end{documentation}
%
% \StopEventually{\PrintIndex}
% \clearpage \appendix
%
% \begin{implementation}
%
% \section{代码实现}
%
% \changes{v1.0f}{2026/06/26}
%   {使用 \LaTeX3 重构，删除对 \pkg{kvoptions} 与 \pkg{xintexpr} 的依赖。}
%
% 用 |ZhLS| 作为命名空间.
%    \begin{macrocode}
%<@@=ZhLS>
%    \end{macrocode}
% 为 \pkg{ctxdocstrip} 开始选项列表 |package|.
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
% \begin{macro}
%   {
%     \@@_msg_new:nn,
%     \@@_msg_error:nn,
%     \@@_msg_error:ne,
%     \@@_msg_warning:nn,
%     \@@_msg_warning:ne,
%     \@@_msg_info:nn,
%     \@@_msg_info:ne,
%     \@@_msg_new:nnn,
%     \@@_msg_error:nnn,
%     \@@_msg_error:nne,
%     \@@_msg_warning:nnn,
%     \@@_msg_warning:nne
%   }
% 消息管理: 私有函数用来创建新消息并作为 error, warning, 或 info 进行广播.
%    \begin{macrocode}
\cs_new_protected:Npn \@@_msg_new:nn  { \msg_new:nnn  { ZhLS } }
\cs_new_protected:Npn \@@_msg_new:nnn { \msg_new:nnnn { ZhLS } }
\clist_map_inline:nn { error, warning }
  {
    \cs_new_protected:cpn { @@_msg_#1:nn  }
      { \use:c { msg_#1:nnn  } { ZhLS } }
    \cs_new_protected:cpn { @@_msg_#1:ne  }
      { \use:c { msg_#1:nne  } { ZhLS } }
    \cs_new_protected:cpn { @@_msg_#1:nnn }
      { \use:c { msg_#1:nnnn } { ZhLS } }
    \cs_new_protected:cpn { @@_msg_#1:nee }
      { \use:c { msg_#1:nnee } { ZhLS } }
  }
%    \end{macrocode}
% \end{macro}
% 创建新消息: |Unknown Option|, 将在 \opt{ZhLS / pkgopt} 中使用.
%    \begin{macrocode}
\@@_msg_new:nn { Unknown ~ Option }
  {
    Unknown ~ Option ~ `#1'.                                \iow_newline:
    Available ~ options ~ are:                              \iow_newline:
    \space\space`bodytextleadingratio',                     \iow_newline:
    \space\space`footnoteleadingratio',                     \iow_newline:
    \space\space`restoremathleading',                       \iow_newline:
    \space\space`MSWordLineSpacingMultiple', ~ and          \iow_newline:
    \space\space`MSWordSinglespaceRatio'.
  }
%    \end{macrocode}
% 创建新消息: |MSWord ~ Multiple ~ Line ~ Spacing|.
%    \begin{macrocode}
\@@_msg_new:nn { MSWord ~ Multiple ~ Line ~ Spacing }
  {
    Use ~ Microsoft ~ Word ~ multiple ~ line ~ spacing:     \iow_newline:
    Singlespace ~ to ~ fontsize ~ ratio ~ = ~ `#1'.         \iow_newline:
    Multiple ~ = ~ `#2'.
  }
%    \end{macrocode}
% 创建新消息: |Ineffective ~ Option|.
%    \begin{macrocode}
\@@_msg_new:nn { Ineffective ~ Option }
  {
    The ~ `#1' ~ option ~ is ~ ineffective.                 \iow_newline:
    It ~ only ~ takes ~ effect ~ when ~ #2.
  }
%    \end{macrocode}
% 创建新消息: |Not ~ Loaded ~ Package|.
%    \begin{macrocode}
\@@_msg_new:nn { Not ~ Loaded ~ Package }
  {
    Package #1 ~ is ~ NOT ~ loaded ~ by ~ zhlineskip.       \iow_newline:
    Some ~ of ~ its ~ features ~ may ~ not ~ be ~ available.\iow_newline:
    #2.
  }
%    \end{macrocode}
% 创建新消息: |Illegal ~ Usage|.
%    \begin{macrocode}
\@@_msg_new:nn { Illegal ~ Usage }
  {
    Cannot ~ use ~ \string#1\space here.                    \iow_newline:
    Try ~ loading ~ zhlineskip ~ with ~ option:             \iow_newline:
    `restoremathleading ~ = ~ true'.
  }
%    \end{macrocode}
% 加载依赖 \pkg{etoolbox} 宏包.
%    \begin{macrocode}
\RequirePackage{etoolbox}
%    \end{macrocode}
%
% \changes{v1.0c}{2018/10/29}{对未知的键值选项与无效的用户命令报错。}
% \changes{v1.0f}{2026/06/27}{移除布尔选项 \texttt{UseMSWordMultipleLineSpacing}，
%   将其并入选项 \texttt{MSWordLineSpacingMultiple} 中。}
%
% \begin{variable}
%   {
%     \g_@@_MSWordLineSpacingMultiple_bool,
%     \g_@@_bodytextleadingratio_fp,
%     \g_@@_footnoteleadingratio_fp,
%     \g_@@_restoremathleading_bool,
%     \g_@@_MSWordLineSpacingMultiple_fp,
%     \g_@@_MSWordSinglespaceRatio_fp
%   }
% 声明宏包选项.
%    \begin{macrocode}
\bool_new:N \g_@@_MSWordLineSpacingMultiple_bool
\fp_new:N   \g_@@_MSWordLineSpacingMultiple_fp
\keys_define:nn { ZhLS / pkgopt }
  {
    bodytextleadingratio                .fp_set:N   =
      \g_@@_bodytextleadingratio_fp,
      bodytextleadingratio              .initial:n  = { 1.5   },
    footnoteleadingratio                .fp_set:N   =
      \g_@@_footnoteleadingratio_fp,
      footnoteleadingratio              .initial:n  = { 1.48  },
    restoremathleading                  .bool_set:N =
      \g_@@_restoremathleading_bool,
      restoremathleading                .initial:n  = { true  },
      restoremathleading                .default:n  = { true  },
    MSWordLineSpacingMultiple           .choice:,
    MSWordLineSpacingMultiple           .default:n  = { true  },
    MSWordLineSpacingMultiple / true    .code:n     =
      {
        \bool_gset_true:N \g_@@_MSWordLineSpacingMultiple_bool
        \fp_gset:Nn \g_@@_MSWordLineSpacingMultiple_fp { 1.15 }
      },
    MSWordLineSpacingMultiple / false   .code:n     =
      { \bool_gset_false:N \g_@@_MSWordLineSpacingMultiple_bool },
    MSWordLineSpacingMultiple / unknown .code:n     =
      {
        \bool_gset_true:N \g_@@_MSWordLineSpacingMultiple_bool
        \fp_gset:Nn \g_@@_MSWordLineSpacingMultiple_fp {#1}
      },
    MSWordSinglespaceRatio              .fp_set:N   =
      \g_@@_MSWordSinglespaceRatio_fp,
    MSWordSinglespaceRatio              .initial:n  = { 1.296875 },
    unknown                             .code:n     =
      \@@_msg_error:ne { Unknown ~ Option } { \l_keys_key_str }
  }
\ProcessKeyOptions [ ZhLS / pkgopt ]
%    \end{macrocode}
% 在用户更改 \opt{MSWordSinglespaceRatio} 但未将 \opt{MSWordLineSpacingMultiple}
% 设置为 \opt{true} 时产生警告.
%    \begin{macrocode}
\AtEndOfPackage
  {
    \bool_lazy_or:nnF
      { \g_@@_MSWordLineSpacingMultiple_bool                                 }
      { \fp_compare_p:nNn { \g_@@_MSWordSinglespaceRatio_fp } = { 1.296875 } }
      {
        \@@_msg_warning:nnn { Ineffective ~ Option } { MSWordSinglespaceRatio }
          { MSWordLineSpacingMultiple ~ = ~ true }
      }
  }
%    \end{macrocode}
% \end{variable}
%
% \changes{v1.0a}{2018/07/07}{自动计算基础行距对字号的倍数。
%   正文、脚注的基础行距与其字号的比值现在通过 \tn{f@baselineskip} 与 \tn{f@size}
%   计算得到。用户手册还更新了 \pkg{mtpro2} 正确的放大方法。}
% \changes{v1.0b}{2018/10/16}{新增选项 \opt{MSWordSinglespaceRatio}。}
% \changes{v1.0d}{2018/12/01}{增加警告描述。}
%
% \begin{variable}{\g_@@_targetbodyleading_fp,  \g_@@_targetfootleading_fp}
% \begin{variable}{\g_@@_bodylinespread_fp,     \g_@@_footlinespread_fp}
% \begin{variable}{\g_@@_defaultbodyleading_fp, \g_@@_defaultfootleading_fp}
% \begin{variable}{\l_@@_tmpa_fp}
% \begin{variable}{\l_@@_tmpa_dim,              \l_@@_tmpb_dim}
% 临时浮点数与 |dim| 变量, 用于在 \opt{MSWordLineSpacingMultiple}
% 的 TF 分支下计算正文和页脚的 |linespread|.
% 两部分计算中分别采用 \tn{f@size} 和 \tn{f@baselineskip} 在 \tn{normalsize} 和
% \tn{footnotesize} 下的值, 计算原理相同.
%
% 作用域说明: 这些 |fp| 变量用全局 (|g|) 命名空间, 因为计算结果 (|linespread| 等)
% 要在用户文档全周期生效, 不受分组限制.
% 后面 \tn{SetTextEnvironmentSinglespace} / \tn{SetMathEnvironmentSinglespace}
% 写的 |tl| 变量则用局部 (|l|), 它们只在当前作用域内影响 \tn{linespread},
% 是用户文档级临时调整.
%    \begin{macrocode}
\fp_new:N  \g_@@_targetbodyleading_fp
\fp_new:N  \g_@@_targetfootleading_fp
\fp_new:N  \g_@@_bodylinespread_fp
\fp_new:N  \g_@@_footlinespread_fp
\fp_new:N  \g_@@_defaultbodyleading_fp
\fp_new:N  \g_@@_defaultfootleading_fp
\fp_new:N  \l_@@_tmpa_fp
\dim_new:N \l_@@_tmpa_dim
\dim_new:N \l_@@_tmpb_dim
\group_begin:
  \normalsize
  \dim_set:Nn    \l_@@_tmpa_dim { \f@size\p@ }
  \dim_set_eq:NN \l_@@_tmpb_dim \f@baselineskip
  \fp_set:Nn \l_@@_tmpa_fp { \dim_to_decimal_in_sp:n { \l_@@_tmpa_dim } }
  \bool_if:NTF \g_@@_MSWordLineSpacingMultiple_bool
    {
      \@@_msg_warning:nee { MSWord ~ Multiple ~ Line ~ Spacing }
        { \fp_use:N \g_@@_MSWordSinglespaceRatio_fp    }
        { \fp_use:N \g_@@_MSWordLineSpacingMultiple_fp }
      \fp_gset:Nn \g_@@_targetbodyleading_fp
        {
          \l_@@_tmpa_fp * \g_@@_MSWordSinglespaceRatio_fp
                        * \g_@@_MSWordLineSpacingMultiple_fp
        }
    }
    {
      \fp_gset:Nn \g_@@_targetbodyleading_fp
        { \l_@@_tmpa_fp * \g_@@_bodytextleadingratio_fp }
    }
  \fp_gset:Nn \g_@@_defaultbodyleading_fp
    { \dim_to_decimal_in_sp:n { \l_@@_tmpb_dim } }
\group_end:
\group_begin:
  \footnotesize
  \dim_set:Nn    \l_@@_tmpa_dim { \f@size\p@ }
  \dim_set_eq:NN \l_@@_tmpb_dim \f@baselineskip
  \fp_set:Nn \l_@@_tmpa_fp { \dim_to_decimal_in_sp:n { \l_@@_tmpa_dim } }
  \bool_if:NTF \g_@@_MSWordLineSpacingMultiple_bool
    {
      \fp_gset:Nn \g_@@_targetfootleading_fp
        {
          \l_@@_tmpa_fp * \g_@@_MSWordSinglespaceRatio_fp
                        * \g_@@_MSWordLineSpacingMultiple_fp
        }
    }
    {
      \fp_gset:Nn \g_@@_targetfootleading_fp
        { \l_@@_tmpa_fp * \g_@@_footnoteleadingratio_fp }
    }
  \fp_gset:Nn \g_@@_defaultfootleading_fp
    { \dim_to_decimal_in_sp:n { \l_@@_tmpb_dim } }
\group_end:
%    \end{macrocode}
% \end{variable}
% \end{variable}
% \end{variable}
% \end{variable}
% \end{variable}
% \begin{variable}{\g_@@_bodylinespread_fp, \g_@@_footlinespread_fp}
% 计算正文和页脚的 |linespread|.
%    \begin{macrocode}
\fp_set:Nn \g_@@_bodylinespread_fp
  { \g_@@_targetbodyleading_fp / \g_@@_defaultbodyleading_fp }
\fp_set:Nn \g_@@_footlinespread_fp
  { \g_@@_targetfootleading_fp / \g_@@_defaultfootleading_fp }
%    \end{macrocode}
% \end{variable}
%
% \changes{v1.0e}{2019/05/16}{延迟正文行距调整。}
%
% 使用计算结果 \cs{g_@@_bodylinespread_fp} 在文档开始时设置 \tn{linespread}.\\
% 使用计算结果 \cs{g_@@_footlinespread_fp} 为 \tn{@footnotetext} 和
% \tn{@mpfootnotetext} 打补丁.
%    \begin{macrocode}
\hook_gput_code:nnn { begindocument } { . }
  { \linespread { \fp_use:N \g_@@_bodylinespread_fp } \selectfont }
\patchcmd \@footnotetext { \reset@font }
  { \def \baselinestretch { \fp_use:N \g_@@_footlinespread_fp } \reset@font }
  {}{}
\patchcmd\@mpfootnotetext { \reset@font }
  { \def \baselinestretch { \fp_use:N \g_@@_footlinespread_fp } \reset@font }
  {}{}
%    \end{macrocode}
% \begin{macro}{\@@_resetfootnotesep:n}
% 使用计算结果 \cs{g_@@_footlinespread_fp} 重制 \tn{footnotesep}.
%    \begin{macrocode}
\cs_new:Npn \@@_resetfootnotesep:n #1
  {
    \group_begin:
      \footnotesize
      \linespread { \fp_use:N #1 } \selectfont
      \dim_gset:Nn \footnotesep { \box_ht:N \strutbox }
    \group_end:
  }
\@@_resetfootnotesep:n { \g_@@_footlinespread_fp }
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\SetTextEnvironmentSinglespace}
% \LaTeXe\ 用户接口, 设置 \tn{ZhLS@textlinespread} 的默认值为 |1|.
% \end{macro}
%    \begin{macrocode}
\newcommand*\SetTextEnvironmentSinglespace[1]
  { \tl_set:Nn \l_@@_textlinespread_tl {#1} }
\tl_set:Nn \l_@@_textlinespread_tl { 1 }
%    \end{macrocode}
%
% \changes{v1.0a}{2018/06/13}{Add \tn{textlinespre@d}。
%   如果 scale 了西文字体或数学字体，可以通过 \tn{textlinespre@d} 或
%   \tn{m@thlinespre@d} 微调行距。}
%
% \begin{macro}{\RestoreTextEnvironmentLeading}
% \LaTeXe\ 用户接口.
% \begin{macro}{\@@_restoretextenvironmentleading:n}
% \tn{RestoreTextEnvironmentLeading} 的辅助命令.
%    \begin{macrocode}
\newcommand*\RestoreTextEnvironmentLeading[1]
  { \forcsvlist \@@_restoretextenvironmentleading:n {#1} }
\cs_new:Npn \@@_restoretextenvironmentleading:n #1
  {
    \hook_gput_code:nnn { env / #1 / begin } { . }
      { \linespread { \l_@@_textlinespread_tl } \selectfont \ignorespaces }
  }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \changes{v1.0f}{2026/05/25}
%   {修复 \env{split} 环境行距恢复泄漏导致的 \texttt{display} 间距异常。}
%
% 布尔选项 \opt{restoremathleading}: 是否要将数学公式的行距恢复成西文基础行距.
% \begin{macro}{\SetMathEnvironmentSinglespace, \RestoreMathEnvironmentLeading}
% 在布尔值 \cs{g_@@_restoremathleading_bool} 的 TF 分支下分别定义 \LaTeXe\ 用户接口
% \linebreak
% \tn{SetMathEnvironmentSinglespace} 与 \tn{RestoreMathEnvironmentLeading}.
%    \begin{macrocode}
\bool_if:NTF \g_@@_restoremathleading_bool
  {
    \RequirePackage { mathtools }
    \newcommand*\SetMathEnvironmentSinglespace[1]
      { \tl_set:Nn \l_@@_mathlinespread_tl {#1} }
    \SetMathEnvironmentSinglespace{1}
    \newcommand*\RestoreMathEnvironmentLeading[1]
      { \forcsvlist \@@_restoremathenvironmentleading:n {#1} }
    \cs_new:Npn \@@_restoremathenvironmentleading:n #1
      {
        \hook_gput_code:nnn { env / #1 / begin } { . }
          { \linespread { \l_@@_mathlinespread_tl } \selectfont \ignorespaces }
      }
    \patchcmd \start@gather { \collect@body }
      { \linespread { \l_@@_mathlinespread_tl } \selectfont \collect@body }
      {} {}
    \patchcmd \start@align { \collect@body }
      { \linespread { \l_@@_mathlinespread_tl } \selectfont \collect@body }
      {} {}
    \patchcmd \start@multline { \collect@body }
      { \linespread { \l_@@_mathlinespread_tl } \selectfont \collect@body }
      {} {}
    \patchcmd \gather@split { \spread@equation\vcenter\bgroup }
      {
        \vcenter\bgroup
        \linespread { \l_@@_mathlinespread_tl } \selectfont \spread@equation
      } {} {}
    \clist_map_inline:nn
      {
        array,
        matrix,
        pmatrix,
        bmatrix,
        Bmatrix,
        vmatrix,
        Vmatrix,
        cases,
        aligned,
        alignedat,
        gathered,
        matrix*,
        pmatrix*,
        bmatrix*,
        Bmatrix*,
        vmatrix*,
        Vmatrix*,
        cases*,
        dcases,
        dcases*,
        rcases,
        rcases*,
        drcases,
        drcases*,
        multlined,
        lgathered,
        rgathered,
      } { \RestoreMathEnvironmentLeading {#1} }
  }
  {
    \@@_msg_warning:nnn { Not ~ Loaded ~ Package } { mathtools }
      { Leading ~ in ~ multi-line ~ math ~ will ~ be ~ stretched }
    \newcommand*\SetMathEnvironmentSinglespace[1]
      {
        \@@_msg_error:nn { Illegal ~ Usage }
          { \SetMathEnvironmentSinglespace }
      }
    \newcommand*\RestoreMathEnvironmentLeading[1]
      {
        \@@_msg_error:nn { Illegal ~ Usage }
          { \RestoreMathEnvironmentLeading }
      }
  }
%    \end{macrocode}
% \end{macro}
% 为 \pkg{ctxdocstrip} 结束选项列表 |package|.
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% 恢复命名空间.
%    \begin{macrocode}
%<@@=>
%    \end{macrocode}
% \iffalse
%<package>\file_input_stop:
% \fi
% \end{implementation}
