summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/diagbox
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-03-01 03:01:38 +0000
committerNorbert Preining <norbert@preining.info>2020-03-01 03:01:38 +0000
commitad1928316d819ffb337fc4a926dbef47607dfb95 (patch)
treeccca9edbbeacc0e88602998f86c75b2c24c02af6 /macros/latex/contrib/diagbox
parent4736ac744a8c914e0d5ced1d157e017a385bbf43 (diff)
CTAN sync 202003010301
Diffstat (limited to 'macros/latex/contrib/diagbox')
-rw-r--r--macros/latex/contrib/diagbox/diagbox.dtx337
-rw-r--r--macros/latex/contrib/diagbox/diagbox.ins2
-rw-r--r--macros/latex/contrib/diagbox/diagbox.pdfbin233171 -> 244804 bytes
3 files changed, 255 insertions, 84 deletions
diff --git a/macros/latex/contrib/diagbox/diagbox.dtx b/macros/latex/contrib/diagbox/diagbox.dtx
index 0fa92deec6..341a3cdccf 100644
--- a/macros/latex/contrib/diagbox/diagbox.dtx
+++ b/macros/latex/contrib/diagbox/diagbox.dtx
@@ -58,6 +58,7 @@
\makeatother
\usepackage[numbered]{hypdoc}
\hypersetup{pdfstartview=FitH}
+\fvset{gobble=1} %% 删除例子代码开头的 %
\EnableCrossrefs
\CodelineIndex
\RecordChanges
@@ -69,7 +70,7 @@
%</driver>
% \fi
%
-% \CheckSum{661}
+% \CheckSum{901}
%
% \CharacterTable
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
@@ -97,7 +98,8 @@
% \newbox, \newdimen, \p@, \PackageError, \pkg, \put, \relax, \RequirePackage,
% \setbox, \setkeys, \setlength, \strip@pt, \unexpanded, \unitlength,
% \vcenter, \wd, \xdef, \z@, \@ifnextchar, \bgroup, \FPadd, \FPmul, \FPneg,
-% \FPsub, \FPupn, \let, \unless, \hspace}
+% \FPsub, \FPupn, \let, \unless, \hspace, \@tempskipa, \newif, \detokenize,
+% \@@, \\, \c, \l, \cs, \fp, \dim, \msg, \scan}
%
% \providecommand*{\pkg}{\textsf}
% \GetFileInfo{diagbox.dtx}
@@ -629,13 +631,8 @@
% \begin{macrocode}
\RequirePackage{pict2e}
% \end{macrocode}
-% 计算依赖 \pkg{fp} 宏包。
% \changes{v2.2}{2016/12/28}{避免 \pkg{fp} 包的 \texttt{nomessages} 选项在使用
% \pkg{catoptions} 包时冲突}
-% \begin{macrocode}
-\RequirePackage{fp}
-\FPmessagesfalse
-% \end{macrocode}
% 长度计算 \pkg{calc} 宏包。
% \changes{v2.2}{2016/12/28}{使用 \pkg{calc} 包计算选项参数,以支持
% \cs{widthof} 等命令。}
@@ -1004,6 +1001,88 @@
% \changes{v2.3}{2020/02/09}{检测二次方程无解、异常解的情形}
% 分成三部分的盒子。四个参数,分别为 key-value 格式的可选项、左半边内容、中间
% 内容、右半边内容。
+% \begin{macrocode}
+\def\diagbox@triple#1#2#3#4{%
+ \begingroup
+ \diagbox@clear
+ \def\diagbox@part{triple}%
+ \setkeys{diagbox}{dir=NW,#1}%
+ \@nameuse{diagbox@triple@setbox@\diagbox@dir}{#2}{#3}{#4}%
+% \end{macrocode}
+% 在宏包最后定义,需要返回 "\x", "\xm", "\xxm", "\y", "\ym" 和 "\yym"。
+% \begin{macrocode}
+ \diagbox@solve@equations
+ $\vcenter{\hbox{\diagbox@pict}}$%
+ \endgroup}
+% \end{macrocode}
+% \end{macro}
+%
+% \subsection{用户命令}
+%
+% \begin{macro}{\diagbox}
+% \changes{v2.0}{2011/11/22}{判断参数个数,选择两部分或三部分盒子。}
+% 主要的用户命令。判断使用两部分还是三部分的盒子。
+% \begin{macrocode}
+\newcommand\diagbox[3][]{%
+ \@ifnextchar\bgroup
+ {\diagbox@triple{#1}{#2}{#3}}{\diagbox@double{#1}{#2}{#3}}}
+% \end{macrocode}
+% \end{macro}
+%
+% 以下代码用来模拟 \pkg{slashbox} 宏包的功能。
+%
+% 禁止读入 \pkg{slashbox}。
+% \begin{macrocode}
+\expandafter\xdef\csname ver@slashbox.\@pkgextension\endcsname{9999/99/99}
+% \end{macrocode}
+%
+%
+% \begin{macro}{\slashbox}
+% 模拟 "\slashbox"。
+% \begin{macrocode}
+\def\slashbox{%
+ \def\diagbox@slashbox@options{dir=SW,}%
+ \slashbox@}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\backslashbox}
+% 模拟 "\backslashbox"。
+% \begin{macrocode}
+\def\backslashbox{%
+ \def\diagbox@slashbox@options{dir=NW,}%
+ \slashbox@}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\slashbox@}
+% \begin{macrocode}
+\newcommand\slashbox@[1][]{%
+ \ifx\relax#1\relax\else
+ \edef\diagbox@slashbox@options{%
+ \unexpanded\expandafter{\diagbox@slashbox@options}%
+ \unexpanded{width=#1,}}%
+ \fi
+ \slashbox@@}
+% \end{macrocode}
+% \end{macro}
+%
+%
+% \begin{macro}{\slashbox@@}
+% \begin{macrocode}
+\newcommand\slashbox@@[3][]{%
+ \edef\diagbox@slashbox@options{%
+ \unexpanded\expandafter{\diagbox@slashbox@options}%
+ \unexpanded{trim=#1,}}%
+ \expandafter\diagbox\expandafter[\diagbox@slashbox@options]{#2}{#3}}
+% \end{macrocode}
+% \end{macro}
+%
+% \changes{v2.4}{2020/02/28}{利用 \pkg{l3fp} 解方程组。}
+%
+% \subsection{解方程组}
%
% 这里计算双斜线盒子宽、高的算法是简单而直观的。如下图所示,将 A、M、B 三个子盒
% 子分别放在斜线盒的三个角后,斜线正好使 M 盒、A 或 B 盒、斜线盒的一角三点共
@@ -1023,6 +1102,16 @@
% \frac{y}{y_b} &= \frac{x - x_m}{x - x_m - x_b}.
% \end{align*}
% 该方程组通常可化简为一个一元二次方程求解,两组共轭根中可以只需要较大的一组。
+% 通过 Mathematica 软件,容易得到方程组的解为:
+% \begin{align*}
+% x & = \frac{u + v \pm \sqrt{\Delta}} {2(t - y_b)}, \\
+% y & = \frac{u - v \mp \sqrt{\Delta}} {2(x_a - s)}, \\
+% \Delta & := (u + v)^2 + 4 x_a (t - y_b) \bigl(x_m (y_b - y_m) - x_b y_m\bigr), \\
+% u & := x_a y_m - x_m y_b, \\
+% v & := st - x_a y_b, \\
+% s & := x_b + x_m, \\
+% t & := y_a + y_m.
+% \end{align*}
% 但须注意上面的方程组并非总有正的实根,经过简单的代数分析可知,要给出几何直观
% 的可行解(正实根),需要同时满足以下条件:
% \begin{align*}
@@ -1030,13 +1119,164 @@
% y_b &< y_m + y_a.
% \end{align*}
% 该条件需要在计算中予以检查。
+%
+% \begin{macro}{\diagbox@solve@equations}
+% 如果 \pkg{expl3} 环境可用,就使用 \pkg{l3fp} 计算,否则使用 \pkg{fp} 包。
% \begin{macrocode}
-\def\diagbox@triple#1#2#3#4{%
- \begingroup
- \diagbox@clear
- \def\diagbox@part{triple}%
- \setkeys{diagbox}{dir=NW,#1}%
- \@nameuse{diagbox@triple@setbox@\diagbox@dir}{#2}{#3}{#4}%
+\ifcsname\detokenize{fp_eval:n}\endcsname
+\csname fi\endcsname
+\ExplSyntaxOn
+%<@@=diagbox>
+\cs_new_protected:Npn \@@_solve_equations:
+ {
+% \end{macrocode}
+% 取长宽。
+% \begin{macrocode}
+ \fp_set:Nn \l_@@_xa_fp
+ { \dim_to_fp:n { \wd \diagbox@boxa } }
+ \fp_set:Nn \l_@@_ya_fp
+ { \dim_to_fp:n { \ht \diagbox@boxa + \dp \diagbox@boxa } }
+ \fp_set:Nn \l_@@_xb_fp
+ { \dim_to_fp:n { \wd \diagbox@boxb } }
+ \fp_set:Nn \l_@@_yb_fp
+ { \dim_to_fp:n { \ht \diagbox@boxb + \dp \diagbox@boxb } }
+ \fp_set:Nn \l_@@_xm_fp
+ { \dim_to_fp:n { \wd \diagbox@boxm } }
+ \fp_set:Nn \l_@@_ym_fp
+ { \dim_to_fp:n { \ht \diagbox@boxm + \dp \diagbox@boxm } }
+ \fp_set:Nn \l_@@_s_fp { \l_@@_xb_fp + \l_@@_xm_fp }
+ \fp_set:Nn \l_@@_t_fp { \l_@@_ya_fp + \l_@@_ym_fp }
+% \end{macrocode}
+% 如果宽度和长度都被指定了,就不需要列方程组求解。
+% \begin{macrocode}
+ \fp_set_eq:NN \l_@@_delta_fp \c_nan_fp
+ \dim_compare:nNnTF \diagbox@wd = \c_zero_dim
+ { \@@_calculate_width: }
+ { \fp_set:Nn \l_@@_x_fp { \dim_to_fp:n { \diagbox@wd } } }
+ \dim_compare:nNnTF \diagbox@ht = \c_zero_dim
+ { \@@_calculate_height: }
+ { \fp_set:Nn \l_@@_y_fp { \dim_to_fp:n { \diagbox@ht } } }
+ \edef \x { \fp_use:N \l_@@_x_fp }
+ \edef \y { \fp_use:N \l_@@_y_fp }
+ \edef \xm { \fp_use:N \l_@@_xm_fp }
+ \edef \ym { \fp_use:N \l_@@_ym_fp }
+ \edef \xxm { \fp_eval:n { \l_@@_x_fp - \l_@@_xm_fp } }
+ \edef \yym { \fp_eval:n { \l_@@_y_fp - \l_@@_ym_fp } }
+ }
+% \end{macrocode}
+% 检查可行解条件,解二次方程。这里对于无正实根的情形,会给出一个宽松的值作为斜
+% 线盒子的宽高:
+% \begin{align*}
+% x &= 2 \max(x_a + x_m, x_b + x_m),\\
+% y &= 2 \max(y_a + y_m, y_b + y_m).
+% \end{align*}
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_calculate_width:
+ {
+ \fp_zero:N \l_@@_x_fp
+ \fp_compare:nNnT \l_@@_yb_fp < \l_@@_t_fp
+ {
+ \@@_calculate_coefficient:
+ \fp_if_nan:nF { \l_@@_sqrt_fp }
+ {
+ \fp_set:Nn \l_@@_x_fp
+ {
+ ( \l_@@_u_fp + \l_@@_v_fp + \l_@@_sqrt_fp ) /
+ ( 2 ( \l_@@_t_fp - \l_@@_yb_fp ) )
+ }
+ }
+ }
+ \fp_compare:nNnF \l_@@_x_fp > \c_zero_fp
+ {
+ \fp_set:Nn \l_@@_x_fp
+ { 2 ( max( \l_@@_xa_fp , \l_@@_xb_fp ) + \l_@@_xm_fp ) }
+ \msg_warning:nnxx { diagbox } { calculate-error }
+ { width } { \fp_use:N \l_@@_x_fp }
+ }
+ \diagbox@wd = \fp_to_dim:N \l_@@_x_fp \scan_stop:
+ }
+\cs_new_protected:Npn \@@_calculate_height:
+ {
+ \fp_zero:N \l_@@_y_fp
+ \fp_compare:nNnT \l_@@_xa_fp < \l_@@_s_fp
+ {
+ \@@_calculate_coefficient:
+ \fp_if_nan:nF { \l_@@_sqrt_fp }
+ {
+ \fp_set:Nn \l_@@_y_fp
+ {
+ ( \l_@@_u_fp - \l_@@_v_fp - \l_@@_sqrt_fp ) /
+ ( 2 ( \l_@@_xa_fp - \l_@@_s_fp ) )
+ }
+ }
+ }
+ \fp_compare:nNnF \l_@@_y_fp > \c_zero_fp
+ {
+ \fp_set:Nn \l_@@_y_fp
+ { 2 ( max( \l_@@_ya_fp , \l_@@_yb_fp ) + \l_@@_ym_fp ) }
+ \msg_warning:nnxx { diagbox } { calculate-error }
+ { height } { \fp_use:N \l_@@_y_fp }
+ }
+ \diagbox@ht = \fp_to_dim:N \l_@@_y_fp \scan_stop:
+ }
+\cs_new_protected:Npn \@@_calculate_coefficient:
+ {
+ \fp_if_nan:nT { \l_@@_delta_fp }
+ { \@@_calculate_coefficient_aux: }
+ }
+\cs_new_protected:Npn \@@_calculate_coefficient_aux:
+ {
+ \fp_set:Nn \l_@@_u_fp
+ {
+ \l_@@_xa_fp * \l_@@_ym_fp -
+ \l_@@_xm_fp * \l_@@_yb_fp
+ }
+ \fp_set:Nn \l_@@_v_fp
+ {
+ \l_@@_s_fp * \l_@@_t_fp -
+ \l_@@_xa_fp * \l_@@_yb_fp
+ }
+ \fp_set:Nn \l_@@_delta_fp
+ {
+ ( \l_@@_u_fp + \l_@@_v_fp )^2 +
+ 4 * \l_@@_xa_fp * ( \l_@@_t_fp - \l_@@_yb_fp ) *
+ ( \l_@@_xm_fp * ( \l_@@_yb_fp - \l_@@_ym_fp ) -
+ \l_@@_xb_fp * \l_@@_ym_fp )
+ }
+ \fp_compare:nNnTF \l_@@_delta_fp < \c_zero_fp
+ { \fp_set_eq:NN \l_@@_sqrt_fp \c_nan_fp }
+ { \fp_set:Nn \l_@@_sqrt_fp { sqrt(\l_@@_delta_fp) } }
+ }
+\cs_new_eq:NN \diagbox@solve@equations \@@_solve_equations:
+\fp_new:N \l_@@_xa_fp
+\fp_new:N \l_@@_ya_fp
+\fp_new:N \l_@@_xb_fp
+\fp_new:N \l_@@_yb_fp
+\fp_new:N \l_@@_xm_fp
+\fp_new:N \l_@@_ym_fp
+\fp_new:N \l_@@_x_fp
+\fp_new:N \l_@@_y_fp
+\fp_new:N \l_@@_s_fp
+\fp_new:N \l_@@_t_fp
+\fp_new:N \l_@@_u_fp
+\fp_new:N \l_@@_v_fp
+\fp_new:N \l_@@_sqrt_fp
+\fp_new:N \l_@@_delta_fp
+\msg_new:nnn { diagbox } { calculate-error }
+ {
+ Cannot~calculate~proper~#1~of~triple~diagbox~
+ \msg_line_context:. \\
+ Use~#2pt~instead.
+ }
+\file_input_stop:
+% \end{macrocode}
+%
+% 若 \pkg{l3fp} 不可用,则引入 \pkg{fp} 包计算。
+% \begin{macrocode}
+\fi
+\RequirePackage{fp}
+\FPmessagesfalse
+\def\diagbox@solve@equations{%
% \end{macrocode}
% 取长宽
% \begin{macrocode}
@@ -1096,81 +1336,12 @@
\else
\edef\y{\strip@pt\diagbox@ht}%
\fi
-% \end{macrocode}
-% 画盒子
-% \begin{macrocode}
\FPsub\xxm\x\xm
\FPsub\yym\y\ym
- $\vcenter{\hbox{\diagbox@pict}}$%
- \endgroup}
-% \end{macrocode}
-% \end{macro}
-%
-% \subsection{用户命令}
-%
-% \begin{macro}{\diagbox}
-% \changes{v2.0}{2011/11/22}{判断参数个数,选择两部分或三部分盒子。}
-% 主要的用户命令。判断使用两部分还是三部分的盒子。
-% \begin{macrocode}
-\newcommand\diagbox[3][]{%
- \@ifnextchar\bgroup
- {\diagbox@triple{#1}{#2}{#3}}{\diagbox@double{#1}{#2}{#3}}}
-% \end{macrocode}
-% \end{macro}
-%
-% 以下代码用来模拟 \pkg{slashbox} 宏包的功能。
-%
-% 禁止读入 \pkg{slashbox}。
-% \begin{macrocode}
-\expandafter\xdef\csname ver@slashbox.\@pkgextension\endcsname{9999/99/99}
-% \end{macrocode}
-%
-%
-% \begin{macro}{\slashbox}
-% 模拟 "\slashbox"。
-% \begin{macrocode}
-\def\slashbox{%
- \def\diagbox@slashbox@options{dir=SW,}%
- \slashbox@}
-% \end{macrocode}
-% \end{macro}
-%
-%
-% \begin{macro}{\backslashbox}
-% 模拟 "\backslashbox"。
-% \begin{macrocode}
-\def\backslashbox{%
- \def\diagbox@slashbox@options{dir=NW,}%
- \slashbox@}
-% \end{macrocode}
-% \end{macro}
-%
-%
-% \begin{macro}{\slashbox@}
-% \begin{macrocode}
-\newcommand\slashbox@[1][]{%
- \ifx\relax#1\relax\else
- \edef\diagbox@slashbox@options{%
- \unexpanded\expandafter{\diagbox@slashbox@options}%
- \unexpanded{width=#1,}}%
- \fi
- \slashbox@@}
-% \end{macrocode}
-% \end{macro}
-%
-%
-% \begin{macro}{\slashbox@@}
-% \begin{macrocode}
-\newcommand\slashbox@@[3][]{%
- \edef\diagbox@slashbox@options{%
- \unexpanded\expandafter{\diagbox@slashbox@options}%
- \unexpanded{trim=#1,}}%
- \expandafter\diagbox\expandafter[\diagbox@slashbox@options]{#2}{#3}}
-\endinput
+}
% \end{macrocode}
% \end{macro}
%
-%
% \iffalse
%</package>
% \fi
diff --git a/macros/latex/contrib/diagbox/diagbox.ins b/macros/latex/contrib/diagbox/diagbox.ins
index 196e5eb08b..2011c3321c 100644
--- a/macros/latex/contrib/diagbox/diagbox.ins
+++ b/macros/latex/contrib/diagbox/diagbox.ins
@@ -16,7 +16,7 @@
%% and the derived filebase diagbox.sty.
%%
-\input docstrip.tex
+\input l3docstrip.tex
\keepsilent
\usedir{tex/latex/diagbox}
diff --git a/macros/latex/contrib/diagbox/diagbox.pdf b/macros/latex/contrib/diagbox/diagbox.pdf
index b891b8926a..51592660f8 100644
--- a/macros/latex/contrib/diagbox/diagbox.pdf
+++ b/macros/latex/contrib/diagbox/diagbox.pdf
Binary files differ