From 15f60291051d3cd3e454d2011fbb0d135c6ed47d Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Sun, 28 Aug 2022 19:54:12 +0000
Subject: exam-zh (28aug22)

git-svn-id: svn://tug.org/texlive/trunk@64219 c570f23f-e606-0410-a88d-b1316a301751
---
 .../tex/latex/exam-zh/exam-zh-choices.sty          | 123 ++++++++++++++++++---
 1 file changed, 109 insertions(+), 14 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/exam-zh/exam-zh-choices.sty')

diff --git a/Master/texmf-dist/tex/latex/exam-zh/exam-zh-choices.sty b/Master/texmf-dist/tex/latex/exam-zh/exam-zh-choices.sty
index ef7c39ba881..05f66871c3a 100644
--- a/Master/texmf-dist/tex/latex/exam-zh/exam-zh-choices.sty
+++ b/Master/texmf-dist/tex/latex/exam-zh/exam-zh-choices.sty
@@ -9,7 +9,7 @@
 \RequirePackage{expl3}
 \RequirePackage{xparse}
 
-\ProvidesExplPackage {exam-zh-choices} {2022-08-15} {v0.1.18}
+\ProvidesExplPackage {exam-zh-choices} {2022-08-28} {v0.1.19}
   {exam-zh choices module}
 
 \dim_new:N \l__examzh_choices_column_sep_dim
@@ -36,7 +36,13 @@
     label-sep   .dim_set:N = \l__examzh_choices_label_sep_dim ,
     label-width .dim_set:N = \l__examzh_choices_label_width_dim ,
     max-columns .int_set:N = \l__examzh_choices_max_columns_int ,
-    index       .int_set:N = \l__examzh_choices_item_index_int
+    index       .int_set:N = \l__examzh_choices_item_index_int,
+    % 环境上方的额外距离
+    top-sep .skip_set:N = \l__examzh_choices_top_sep_skip,
+    % 环境下方的额外距离
+    bottom-sep .skip_set:N = \l__examzh_choices_bottom_sep_skip,
+    % 若不是单行排版，则可以控制行之间的额外间距
+    linesep .skip_set:N = \l__examzh_choices_line_sep_skip
   }
 
 \keys_set:nn { exam-zh / choices }
@@ -45,11 +51,14 @@
     columns     = 0 ,
     label       = \Alph*. ,
     label-pos   = auto ,
-    label-align = right ,
+    label-align = left ,
     label-sep   = .5em ,
     label-width = 0pt ,
     max-columns = 4 ,
     index       = 1,
+    top-sep     = 0pt,
+    bottom-sep  = 0pt,
+    linesep     = 0pt plus .5ex
   }
 
 \NewDocumentCommand \setchoices { m }
@@ -83,17 +92,19 @@
 
 \NewDocumentEnvironment { choices } { O { } +b }
   {
+    \keys_set:nn { exam-zh / choices } {#1}
     \par \nopagebreak
     % 严格禁止孤行和寡行
     \int_set:Nn \clubpenalty { 10000 }
     \int_set:Nn \widowpenalty { 10000 }
     % 尽量避免在选项中间换行
     \int_set:Nn \interlinepenalty { 301 }
+    \vspace* { \l__examzh_choices_top_sep_skip }
     \noindent
-    \dim_set_eq:NN \l__examzh_choices_total_width_dim \linewidth
+    % \dim_set_eq:NN \l__examzh_choices_total_width_dim \linewidth
+    \dim_set:Nn \l__examzh_choices_total_width_dim { \linewidth - \leftskip - \rightskip }
     \int_zero:N \l__examzh_choices_columns_int
     \dim_zero:N \l__examzh_choices_label_width_dim
-    \keys_set:nn { exam-zh / choices } {#1}
   }
   {
     % 用 \item 分割选项
@@ -119,6 +130,7 @@
     \__examzh_print_choices:N \l__examzh_choices_seq
     % 输出正确选项
     \__examzh_print_correctchoice:
+    \vspace* { \l__examzh_choices_bottom_sep_skip }
   }
 
 % 用来存正确选项的序号（entry）
@@ -368,7 +380,9 @@
           { \l__examzh_choices_current_col_int } > { \l__examzh_choices_columns_int }
           {
             % \par \noindent
-            \newline
+            \\[ \l__examzh_choices_line_sep_skip ]
+            % \newline
+            % \skip_vertical:N \l__examzh_choices_line_sep_skip
             \int_set:Nn \l__examzh_choices_current_col_int {1}
           }
         % TODO 为什么 > 1 才加呢？ 这样的话第 1 列和第 2 列之间就没有这个间距？
@@ -386,52 +400,116 @@
 
 \coffin_new:N \l__examzh_choices_item_coffin
 \coffin_new:N \l__examzh_choices_label_coffin
-
+% \box_new:N \l__examzh_choices_item_box
+% \box_new:N \l__examzh_choices_label_box
 \cs_new:Npn \__examzh_print_single_choice:nn #1#2
   {
     % 选项标签
     \__examzh_choices_make_label_coffin:n {#1}
+    % \__examzh_choices_make_label_box:n {#1}
     % 选项内容
     \__examzh_choices_make_item_coffin:n {#2}
+    % \__examzh_choices_make_item_box:n {#2}
     % 合并选项的标签和内容
     \str_case:Vn \l__examzh_choices_label_pos_tl
       {
         { top-left }
           {
             \coffin_join:NnnNnnnn
-              \l__examzh_choices_item_coffin  {l} {H}
               \l__examzh_choices_label_coffin {r} {H}
-              { - \l__examzh_choices_label_sep_dim }
+              \l__examzh_choices_item_coffin  {l} {H}
+              { \l__examzh_choices_label_sep_dim }
               { 0pt }
+            % \hbox_set:Nn \l__examzh_choices_item_box
+            %   {
+            %     \box_use_drop:N \l__examzh_choices_label_box
+            %     \kern \l__examzh_choices_label_sep_dim
+            %     \box_use_drop:N \l__examzh_choices_item_box
+            %   }
           }
         { left }
           {
             \coffin_join:NnnNnnnn
-              \l__examzh_choices_item_coffin  {l} {vc}
               \l__examzh_choices_label_coffin {r} {vc}
-              { - \l__examzh_choices_label_sep_dim }
+              \l__examzh_choices_item_coffin  {l} {vc}
+              { \l__examzh_choices_label_sep_dim }
               { 0pt }
+            % \hbox_set:Nn \l__examzh_choices_item_box
+            %   {
+            %     \box_move_down:nn
+            %       {
+            %         (
+            %           \box_ht:N \l__examzh_choices_label_box -
+            %           \box_dp:N \l__examzh_choices_label_box -
+            %           \box_ht:N \l__examzh_choices_item_box +
+            %           \box_dp:N \l__examzh_choices_item_box
+            %         ) / 2
+            %       }
+            %       { \box_use_drop:N \l__examzh_choices_label_box }
+            %     \kern \l__examzh_choices_label_sep_dim
+            %     \box_use_drop:N \l__examzh_choices_item_box
+            %   }
           }
         { bottom }
           {
             \coffin_join:NnnNnnnn
-              \l__examzh_choices_item_coffin  {hc} {b}
               \l__examzh_choices_label_coffin {hc} {t}
+              \l__examzh_choices_item_coffin  {hc} {b}
               { 0pt }
               % { - \l__examzh_choices_label_sep_dim }
               { 0pt }
+            % \hbox_set:Nn \l__examzh_choices_item_box
+            %   {
+            %     % \vbox_top:n
+            %     %   {
+            %     %     \box_use:N \l__examzh_choices_item_box
+            %     %     \nointerlineskip
+            %     %     % \kern \l__examzh_choices_label_sep_dim 
+            %     %     \box_move_left:nn
+            %     %       {
+            %     %         (
+            %     %           \box_wd:N \l__examzh_choices_label_box -
+            %     %           \box_wd:N \l__examzh_choices_item_box
+            %     %         ) / 2
+            %     %       }
+            %     %       { \box_use_drop:N \l__examzh_choices_label_box }
+            %     %       \box_clear:N \l__examzh_choices_item_box
+            %     %   }
+            %     \hbox_set:Nn \l__examzh_choices_item_box
+            %       {
+            %         \box_use:N \l__examzh_choices_item_box
+            %         \kern \dim_eval:n
+            %           {
+            %             ( - \box_wd:N \l__examzh_choices_label_box
+            %               -  \box_wd:N \l__examzh_choices_item_box ) / 2 
+            %           }
+            %         \box_move_down:nn
+            %           {
+            %             \box_ht:N \l__examzh_choices_label_box +
+            %             \box_dp:N \l__examzh_choices_item_box
+            %             % + \l__examzh_choices_label_sep_dim 
+            %           }
+            %           { \box_use_drop:N \l__examzh_choices_label_box }
+            %         \box_clear:N \l__examzh_choices_item_box
+            %       }
+            %   }
           }
       }
     % 输出合并后
-    \coffin_typeset:Nnnnn \l__examzh_choices_item_coffin {l} {H} {0pt} {0pt}
+    % \coffin_typeset:Nnnnn \l__examzh_choices_item_coffin {l} {H} {0pt} {0pt}
+    \coffin_typeset:Nnnnn \l__examzh_choices_label_coffin {l} {H} {0pt} {0pt}
     \coffin_clear:N \l__examzh_choices_item_coffin
     \coffin_clear:N \l__examzh_choices_label_coffin
+    % \box_use_drop:N \l__examzh_choices_item_box
   }
 
 % 将标签内容存入 coffin
 \cs_new:Npn \__examzh_choices_make_label_coffin:n #1
+% 将标签内容存入 box
+% \cs_new:Npn \__examzh_choices_make_label_box:n #1
   {
     \hcoffin_set:Nn \l__examzh_choices_label_coffin
+    % \hbox_set:Nn \l__examzh_choices_label_box
       {
         \hbox_to_wd:nn { \l__examzh_choices_label_width_dim }
           { \__examzh_choices_make_label:n {#1} \strut }
@@ -452,10 +530,13 @@
 
 % 将选项内容存入 coffin
 \cs_new:Npn \__examzh_choices_make_item_coffin:n #1
+% 将选项内容存入 box
+% \cs_new:Npn \__examzh_choices_make_item_box:n #1
   {
     \hcoffin_set:Nn \l__examzh_choices_item_coffin
+    % \hbox_set:Nn \l__examzh_choices_item_box
       {
-        % 优先尝试使用 hbox，这是因为在 \vcoffin_set 外部能保留原来的 \linewidth 和
+        % 优先尝试使用 hbox，这是因为在 \vbox_set 外部能保留原来的 \linewidth 和
         % \textwidth，方便用户在 \includegraphics 中使用
         \hbox_set:Nn \l_tmpa_box {#1}
         % 若盒子的自然高度大于 2 行，且深度为 0pt，设置为插图模式
@@ -468,9 +549,17 @@
           { \bool_set_true:N \l__examzh_choices_figure_mode_bool }
         \vcoffin_set:Nnn \l_tmpa_coffin
           { \l__examzh_choices_item_width_dim }
+        % \vbox_set:Nn \l_tmpa_box
           {
+            % \dim_set_eq:NN \parskip \c_zero_dim
+            % \dim_set_eq:NN \parindent \listparindent
+            \dim_set_eq:NN \hsize \l__examzh_choices_item_width_dim
+            \dim_set_eq:NN \linewidth \hsize
+            \dim_set_eq:NN \columnwidth \hsize
             \dim_set_eq:NN \parskip \c_zero_dim
             \dim_set_eq:NN \parindent \listparindent
+            \dim_set:Nn \leftskip { 0pt }
+            \dim_set:Nn \rightskip { 0pt }
             \noindent
             % \strut
             % 若标签在底部，将图片居中对齐。
@@ -485,9 +574,15 @@
           }
         \dim_set:Nn \l_tmpa_dim { \coffin_ht:N \l_tmpa_coffin }
         \bool_if:NT \l__examzh_choices_figure_mode_bool
+        % \dim_set:Nn \l_tmpa_dim { \box_ht:N \l_tmpa_box }
+        % \bool_if:NTF \l__examzh_choices_figure_mode_bool
+        %   {
+        %     \box_move_up:nn { \l_tmpa_dim - 0.7 \baselineskip } { \box_use_drop:N \l_tmpa_box }
+        %   }
           {
             \coffin_set_horizontal_pole:Nnn \l_tmpa_coffin {T}
               { \l_tmpa_dim - 0.7 \baselineskip }
+            % \vbox_top:n { \vbox_unpack_drop:N \l_tmpa_box }
           }
         \coffin_typeset:Nnnnn \l_tmpa_coffin {l} {T} {0pt} {0pt}
         \coffin_clear:N \l_tmpa_coffin
-- 
cgit v1.2.3

