diff --git a/choices.sty b/choices.sty index e4eddec..54480be 100644 --- a/choices.sty +++ b/choices.sty @@ -1,6 +1,6 @@ \NeedsTeXFormat{LaTeX2e}[2020/10/01] \RequirePackage{expl3} -\ProvidesExplPackage {choices} {2021-12-25} {3.0.0} +\ProvidesExplPackage {choices} {2021-12-26} {3.0.1} { A package for flexibly LaTeXing choice items based on hlist and LaTeX3. Kangwei Xia @@ -57,41 +57,43 @@ % \makeatother % 剩下的工作就是设置key-value将quan选项也能纳入进去 -\dim_new:N \l__quan_height_of_number_dim % quan: 储存数字的高度 -\dim_new:N \l__quan_radius_of_circle_dim % quan: 圆的半径 +\dim_new:N \l__quan_height_of_number_dim % quan: 储存数字的高度 +\dim_new:N \l__quan_radius_of_circle_dim % quan: 圆的半径 \dim_new:N \l__choices_max_width_dim % choice: 选项的最大宽度 -\dim_new:N \l__line_width_dim % 储存当时行宽 +\dim_new:N \l__line_width_dim % 储存当时行宽 -\fp_new:N \l__quan_xscale_of_number_fp % quan: 数字的水平压缩比例 -\fp_new:N \l__quan_yscale_of_number_fp % quan: 数字的垂直压缩比例 +\fp_new:N \l__quan_xscale_of_number_fp % quan: 数字的水平压缩比例 +\fp_new:N \l__quan_yscale_of_number_fp % quan: 数字的垂直压缩比例 \seq_new:N \l__choices_items_seq % choice: 储存选项 \tl_new:N \l__choices_check_tl % choice: 将输入进行初步过滤:去掉尾部的&(若有的话) -\tl_new:N \l__hlistchoice_label_style_tl % hlistchoice: 用于设置选项的label-style -\tl_new:N \l__coffinchoice_label_style_tl % coffinchoice: 用于设置选项的label-style +\tl_new:N \l__hlistchoice_label_style_tl % hlistchoice: 用于设置选项的label-style +\tl_new:N \l__coffinchoice_label_style_tl % coffinchoice: 用于设置选项的label-style \tl_new:N \l__choices_prelabel_tl % choice: label的前面的设置 \tl_new:N \l__choices_poslabel_tl % choice: label的后面的设置 -\tl_new:N \l__hlistchoice_show_label_tl % hlistchoice: 控制是否显示label +\tl_new:N \l__hlistchoice_show_label_tl % hlistchoice: 控制是否显示label \str_new:N \l__choices_check_last_item_str % choice: 用于储存\l__choices_check_tl中最后一个字符 \int_new:N \l__choices_item_number_int % choice: 储存一共有多少个选项 -\int_new:N \l__choices_items_per_line_int % choice: 每行排多少个 +\int_new:N \l__choices_items_per_line_int % choice: 每行排多少个 +\int_new:N \l__choices_line_number_int % choice: 一共有几行 + +\bool_new:N \l__choices_items_shuffle_bool % choice: 是否打乱顺序 -\bool_new:N \l__choices_items_shuffle_bool % choice: 是否打乱顺序 -% \bool_set_true:N \l__choices_items_shuffle_bool \cs_set_eq:NN \my_settoheight:Nn \settoheight % 获取高度 % 产生变体 \prg_generate_conditional_variant:Nnn \dim_compare:nNn {nNv} {F} -\cs_generate_variant:Nn \dim_set:Nn { Nv } +\prg_generate_conditional_variant:Nnn \dim_compare:nNn {vNv} {F} +\cs_generate_variant:Nn \dim_set:Nn { Nv, cv} \cs_generate_variant:Nn \dim_max:nn { nv } \cs_generate_variant:Nn \coffin_join:NnnNnnnn {cVVcVVnn,NVVNVVnn} +\cs_generate_variant:Nn \coffin_attach:NnnNnnnn {cVVcVVnn,NVVNVVnn} \cs_generate_variant:Nn \coffin_typeset:Nnnnn {cVVnn} \cs_generate_variant:Nn \seq_set_split:Nnn {NnV} \cs_generate_variant:Nn \str_case:nn {Vn} - % 检查最后一行是否用&&结尾,是的话就去掉,否则choice命令会多出一项 \cs_new:Npn \__choices_check:n #1 { @@ -135,6 +137,15 @@ % 检测内容中是否有插图命令,默认将anchor改变 \bool_new:N \l__coffinchoice_check_graphics_bool \str_new:N \l__coffinchoice_check_graphics_anchor_str +% 控制对应anchor的bool来控制anchor不同的其它操作比如content的升降 +\clist_map_inline:nn + { + north, south, west, east, + northwest, northeast, southwest, southeast + } + { + \bool_new:c { g__coffinchoice_anchor_#1_bool} + } % 对齐方式 \tl_new:N \l__coffinchoice_align_tl % labelcoffin的水平基准点 @@ -172,6 +183,13 @@ % 行间距 \dim_new:N \l__coffinchoice_row_sep_dim \dim_new:N \l__coffinchoice_row_sep_add_dim +% 计算coffin的深度+高度(源自hanzibox.sty) +\cs_new_nopar:Npn \__coffinchoice_ht_plus_dp:N #1 + { + \coffin_ht:N #1 + \coffin_dp:N #1 + } + +\cs_generate_variant:Nn \__coffinchoice_ht_plus_dp:N {c} \@ifclassloaded { exam } @@ -196,6 +214,15 @@ anchor .choice:, anchor / north.code:n = { + \bool_gset_true:N \g__coffinchoice_anchor_north_bool + \clist_map_inline:nn + { + south, west, east, + northwest, northeast, southwest, southeast + } + { + \bool_gset_false:c { g__coffinchoice_anchor_#1_bool } + } \tl_set:Nn \l__labelcoffin_horizontal_position_tl { hc } \tl_set:Nn \l__labelcoffin_vertical_position_tl { H } \tl_set:Nn \l__contentcoffin_horizontal_position_tl { hc } @@ -206,16 +233,39 @@ { -6pt } \tl_set:Nn \l__typeset_horizontal_position_tl { hc } \tl_set:Nn \l__typeset_vertical_position_tl { t } - \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } - \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } - \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_row_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 1em } - \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 6em } + \bool_if:NTF \l__coffinchoice_check_graphics_bool + { + % 图片版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { -0.5em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 1.5em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 1.2em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } + { + % 文字版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } }, anchor / south.code:n = { + \bool_gset_true:N \g__coffinchoice_anchor_south_bool + \clist_map_inline:nn + { + north, west, east, + northwest, northeast, southwest, southeast + } + { + \bool_gset_false:c { g__coffinchoice_anchor_#1_bool } + } \tl_set:Nn \l__labelcoffin_horizontal_position_tl { hc } \tl_set:Nn \l__labelcoffin_vertical_position_tl { t } \tl_set:Nn \l__contentcoffin_horizontal_position_tl { hc } @@ -226,16 +276,39 @@ { 8pt } \tl_set:Nn \l__typeset_horizontal_position_tl { hc } \tl_set:Nn \l__typeset_vertical_position_tl { b } - \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } - \dim_set:Nn \l__typeset_vertical_yshift_dim { -1em } - \dim_set:Nn \l__coffinchoice_top_sep_dim { 0.5em } - \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_row_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 1em } - \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 6em } + \bool_if:NTF \l__coffinchoice_check_graphics_bool + { + % 图片版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { -1em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 3em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.3em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 1.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } + { + % 文字版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { -1em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.3em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.7em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } }, anchor / east.code:n = { + \bool_gset_true:N \g__coffinchoice_anchor_east_bool + \clist_map_inline:nn + { + north, south, west, + northwest, northeast, southwest, southeast + } + { + \bool_gset_false:c { g__coffinchoice_anchor_#1_bool } + } \tl_set:Nn \l__labelcoffin_horizontal_position_tl { l } \tl_set:Nn \l__labelcoffin_vertical_position_tl { vc } \tl_set:Nn \l__contentcoffin_horizontal_position_tl { r } @@ -243,19 +316,42 @@ \dim_set:Nn \l__labelcontentcoffin_join_horizontal_xshift_dim { -8pt } \dim_set:Nn \l__labelcontentcoffin_join_vertical_yshift_dim - { 0pt } + { -1pt } \tl_set:Nn \l__typeset_horizontal_position_tl { r } \tl_set:Nn \l__typeset_vertical_position_tl { vc } - \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } - \dim_set:Nn \l__typeset_vertical_yshift_dim { -1em } - \dim_set:Nn \l__coffinchoice_top_sep_dim { 0.5em } - \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 5em } - \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 12em } + \bool_if:NTF \l__coffinchoice_check_graphics_bool + { + % 图片版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 0.6em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 8.5em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8.5em } + } + { + % 文字版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 0.6em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.3em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.3em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 5em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8.5em } + } }, anchor / west.code:n = { + \bool_gset_true:N \g__coffinchoice_anchor_west_bool + \clist_map_inline:nn + { + north, south, east, + northwest, northeast, southwest, southeast + } + { + \bool_gset_false:c { g__coffinchoice_anchor_#1_bool } + } \tl_set:Nn \l__labelcoffin_horizontal_position_tl { r } \tl_set:Nn \l__labelcoffin_vertical_position_tl { vc } \tl_set:Nn \l__contentcoffin_horizontal_position_tl { l } @@ -263,19 +359,42 @@ \dim_set:Nn \l__labelcontentcoffin_join_horizontal_xshift_dim { 8pt } \dim_set:Nn \l__labelcontentcoffin_join_vertical_yshift_dim - { 0pt } + { -1pt } \tl_set:Nn \l__typeset_horizontal_position_tl { l } \tl_set:Nn \l__typeset_vertical_position_tl { vc } - \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } - \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } - \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 0.3em } - \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 1.5em } + \bool_if:NTF \l__coffinchoice_check_graphics_bool + { + % 图片版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { -4em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } + { + % 文字版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.2em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.2em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { -4em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } }, anchor / northeast.code:n = { + \bool_gset_true:N \g__coffinchoice_anchor_northeast_bool + \clist_map_inline:nn + { + north, south, west, east, + northwest, southwest, southeast + } + { + \bool_gset_false:c { g__coffinchoice_anchor_#1_bool } + } \tl_set:Nn \l__labelcoffin_horizontal_position_tl { l } \tl_set:Nn \l__labelcoffin_vertical_position_tl { H } \tl_set:Nn \l__contentcoffin_horizontal_position_tl { r } @@ -286,16 +405,39 @@ { -4pt } \tl_set:Nn \l__typeset_horizontal_position_tl { r } \tl_set:Nn \l__typeset_vertical_position_tl { t } - \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } - \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } - \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.5em } - \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 5em } - \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 10em } + \bool_if:NTF \l__coffinchoice_check_graphics_bool + { + % 图片版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 1.5em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 1.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 10em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 9em } + } + { + % 文字版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 6em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 9em } + } }, anchor / northwest.code:n = { + \bool_gset_true:N \g__coffinchoice_anchor_northwest_bool + \clist_map_inline:nn + { + north, south, west, east, + northeast, southwest, southeast + } + { + \bool_gset_false:c { g__coffinchoice_anchor_#1_bool } + } \tl_set:Nn \l__labelcoffin_horizontal_position_tl { r } \tl_set:Nn \l__labelcoffin_vertical_position_tl { H } \tl_set:Nn \l__contentcoffin_horizontal_position_tl { l } @@ -306,16 +448,39 @@ { -4pt } \tl_set:Nn \l__typeset_horizontal_position_tl { l } \tl_set:Nn \l__typeset_vertical_position_tl { t } - \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } - \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } - \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.5em } - \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 4em } + \bool_if:NTF \l__coffinchoice_check_graphics_bool + { + % 图片版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 1.5em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 1.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } + { + % 文字版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { -2em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } }, anchor / southeast.code:n = { + \bool_gset_true:N \g__coffinchoice_anchor_southeast_bool + \clist_map_inline:nn + { + north, south, west, east, + northwest, northeast, southwest + } + { + \bool_gset_false:c { g__coffinchoice_anchor_#1_bool } + } \tl_set:Nn \l__labelcoffin_horizontal_position_tl { l } \tl_set:Nn \l__labelcoffin_vertical_position_tl { t } \tl_set:Nn \l__contentcoffin_horizontal_position_tl { r } @@ -326,16 +491,39 @@ { 0pt } \tl_set:Nn \l__typeset_horizontal_position_tl { r } \tl_set:Nn \l__typeset_vertical_position_tl { H } - \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } - \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } - \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 5em } - \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 10em } + \bool_if:NTF \l__coffinchoice_check_graphics_bool + { + % 图片版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 2.5em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.2em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 1.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 3em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } + { + % 文字版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 1.5em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.2em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { 7em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 9em } + } }, anchor / southwest.code:n = { + \bool_gset_true:N \g__coffinchoice_anchor_southwest_bool + \clist_map_inline:nn + { + north, south, west, east, + northwest, northeast, southeast + } + { + \bool_gset_false:c { g__coffinchoice_anchor_#1_bool } + } \tl_set:Nn \l__labelcoffin_horizontal_position_tl { r } \tl_set:Nn \l__labelcoffin_vertical_position_tl { t } \tl_set:Nn \l__contentcoffin_horizontal_position_tl { l } @@ -343,16 +531,30 @@ \dim_set:Nn \l__labelcontentcoffin_join_horizontal_xshift_dim { 6pt } \dim_set:Nn \l__labelcontentcoffin_join_vertical_yshift_dim - { 20pt } + { -2pt } \tl_set:Nn \l__typeset_horizontal_position_tl { l } \tl_set:Nn \l__typeset_vertical_position_tl { H } - \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } - \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } - \dim_set:Nn \l__coffinchoice_top_sep_dim { 0em } - \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.2em } - \dim_set:Nn \l__coffinchoice_first_column_sep_dim { -2.5em } - \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 1em } + \bool_if:NTF \l__coffinchoice_check_graphics_bool + { + % 图片版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 2em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.2em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 1.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { -5em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } + { + % 文字版本 + \dim_set:Nn \l__typeset_horizontal_xshift_dim { 0em } + \dim_set:Nn \l__typeset_vertical_yshift_dim { 0em } + \dim_set:Nn \l__coffinchoice_top_sep_dim { 1em } + \dim_set:Nn \l__coffinchoice_bottom_sep_dim { 0.2em } + \dim_set:Nn \l__coffinchoice_row_sep_dim { 0.5em } + \dim_set:Nn \l__coffinchoice_first_column_sep_dim { -2em } + \dim_set:Nn \l__coffinchoice_greater_than_first_column_sep_dim { 8em } + } }, anchor .initial:n = west, items .int_set:N = \l__choices_items_per_line_int, @@ -558,13 +760,6 @@ { \group_begin: \dim_set_eq:NN \l__line_width_dim \linewidth % 储存行宽 - % \seq_set_split:Nnn \l__choices_items_seq {&&} {#2} - % \tl_set:Nn \l__choices_check_tl {#2} - % \str_set:Nx \l__choices_check_last_item_str { \tl_item:Nn \l__choices_check_tl {-1} } - % \str_if_eq:VnT { \l__choices_check_last_item_str } { & } - % { - % \seq_pop_right:NN \l__choices_items_seq \l_tmpa_seq - % } \__choices_check:n {#2} \__choices_items_shuffle:n { \l__choices_items_seq } \bool_if:NT \l__coffinchoice_check_graphics_bool @@ -649,13 +844,17 @@ { \dim_new:c { l__coffinchoice_measure_width_ \int_to_roman:n { ##1 } _dim } } - % 把每个选项存到对应的盒子里面 - \hcoffin_set:cn { l__content_ \int_to_roman:n { ##1 } _coffin } - { + \hcoffin_set:cw { l__content_ \int_to_roman:n { ##1 } _coffin } + % { + % \fbox{ + % \raisebox{1em}{ \begin{varwidth}{\hsize} \seq_item:Nn \l__choices_items_seq { ##1 } \end{varwidth} - } + % } + % } + % } + \hcoffin_set_end: % \hcoffin_set:cn { l__label_ \int_to_roman:n { ##1 } _coffin } % { % \l__choices_prelabel_tl @@ -685,7 +884,158 @@ { \int_set:Nn \l__choices_items_per_line_int {4} } } \keys_set:nn { choice / coffinchoice } { label-style = Alph, #1 } - % \__choices_items_shuffle:n { \l__choices_items_seq } + + % 储存总行数 + \int_set:Nn \l__choices_line_number_int + { + \int_compare:nNnTF + { + \int_mod:nn { \l__choices_item_number_int } { \l__choices_items_per_line_int } + } = { 0 } + { + \int_div_truncate:nn + { \l__choices_item_number_int } + { \l__choices_items_per_line_int } + } + { + \int_div_truncate:nn + { \l__choices_item_number_int } + { \l__choices_items_per_line_int } +1 + } + } + % 创建行高度最大值变量 + % 注意要用##1, 因为是在coffinchoice命令中定义 + \int_step_inline:nn { \l__choices_line_number_int } + { + \dim_if_exist:cTF { l__coffinchoice_max_height_ \int_to_roman:n {##1}_dim } + {} + { + \dim_new:c { l__coffinchoice_max_height_ \int_to_roman:n {##1}_dim } + } + } + \int_step_inline:nn { \l__choices_item_number_int } + { + \hcoffin_set:cw { l__content_ \int_to_roman:n { ##1 } _coffin } + \begin{varwidth}{\hsize} + \seq_item:Nn \l__choices_items_seq { ##1 } + \end{varwidth} + \hcoffin_set_end: + % \coffin_scale:cnn { l__content_ \int_to_roman:n { ##1 } _coffin } + % {1} {0.6} + } + % 先把每行第一个的总高度存到max_行里面 + \int_step_inline:nn { \l__choices_item_number_int } + { + \int_compare:nNnTF { \int_mod:nn {##1} { \l__choices_items_per_line_int } } = {1} + { + \dim_set:cn { l__coffinchoice_max_height_ \int_to_roman:n { \int_div_truncate:nn {##1} { \l__choices_items_per_line_int } +1}_dim } + { + \__coffinchoice_ht_plus_dp:c { l__content_ \int_to_roman:n { ##1 } _coffin } + } + } + {} + } + \int_step_inline:nn { \l__choices_item_number_int } + { + % 新建每项的高度变量 + \dim_if_exist:cTF { l__coffinchoice_height_ \int_to_roman:n {##1}_dim } + {} + { + \dim_new:c { l__coffinchoice_height_ \int_to_roman:n {##1}_dim } + } + \dim_set:cn { l__coffinchoice_height_ \int_to_roman:n {##1}_dim } + { + \__coffinchoice_ht_plus_dp:c { l__content_ \int_to_roman:n { ##1 } _coffin } + % \coffin_ht:c { l__content_ \int_to_roman:n { ##1 } _coffin } + } + % 每项的高度改变量 + \dim_if_exist:cTF { l__coffinchoice_height_change_ \int_to_roman:n {##1}_dim } + {} + { + \dim_new:c { l__coffinchoice_height_change_ \int_to_roman:n {##1}_dim } + } + % \dim_use:c { l__coffinchoice_height_ \int_to_roman:n {##1}_dim } + } + % 下面将获取每行的高度最大值并储存到max_行里面 + \int_step_inline:nn { \l__choices_line_number_int } + { + \int_step_inline:nn { \l__choices_item_number_int } + { + \int_compare:nNnTF + { \l__choices_items_per_line_int * (##1 -1) } < { ####1 } + { + \int_compare:nNnTF + { ####1 } < { \l__choices_items_per_line_int * ##1 +1 } + { + \dim_compare:vNvF { l__coffinchoice_max_height_ \int_to_roman:n {##1}_dim } > { l__coffinchoice_height_ \int_to_roman:n {####1}_dim } + % 把大的储存到max里面 + { + \dim_set:cv + { l__coffinchoice_max_height_ \int_to_roman:n {##1}_dim } + { l__coffinchoice_height_ \int_to_roman:n {####1}_dim } + } + } + {} + } + {} + } + } + % 搞不懂为什么bool为什么没有用 + % \clist_map_inline:nn + % { + % north, south, west, east, + % northwest, northeast, southwest, southeast + % } + % { + % \bool_if:cTF { g__coffinchoice_anchor_##1_bool } + % { ##1 true \par } + % { ##1 false \par } + % } + \int_step_inline:nn { \l__choices_line_number_int } + { + \int_step_inline:nn { \l__choices_item_number_int } + { + \dim_set:cn { l__coffinchoice_height_change_ \int_to_roman:n {##1}_dim } + { + \dim_eval:n + { + \use:c + { l__coffinchoice_max_height_ \int_to_roman:n {##1}_dim }/2 + - + \cs:w l__coffinchoice_height_ \int_to_roman:n {####1}_dim \cs_end:/15 + } + } + \hcoffin_set:cw { l__content_ \int_to_roman:n { ####1 } _coffin } + \raisebox + { + 1em + % \dim_use:c { l__coffinchoice_height_change_ \int_to_roman:n {##1}_dim } + % \bool_if:NTF \g__coffinchoice_anchor_south_bool + % { + % \cs:w l__coffinchoice_max_height_ \int_to_roman:n {##1}_dim \cs_end: /2 + % - + % \cs:w l__coffinchoice_height_ \int_to_roman:n {####1}_dim \cs_end: /15 + % } + % {2em} + % \bool_if:NT \g__coffinchoice_anchor_north_bool + % { + % \use:c + % { l__coffinchoice_max_height_ \int_to_roman:n {##1}_dim } + % - + % \cs:w l__coffinchoice_height_ \int_to_roman:n {####1}_dim \cs_end:/2 + % } + % {0em} + } + { + \begin{varwidth}{\hsize} + \seq_item:Nn \l__choices_items_seq { ####1 } + \end{varwidth} + } + % } + % } + \hcoffin_set_end: + } + } \int_step_inline:nn { \l__choices_item_number_int } { \hcoffin_set:cn { l__label_ \int_to_roman:n { ##1 } _coffin } @@ -707,7 +1057,8 @@ \vspace* { \dim_eval:n { \l__coffinchoice_top_sep_dim + \l__coffinchoice_top_sep_add_dim} } % topsep \int_step_inline:nn { \l__choices_item_number_int } { - \coffin_join:cVVcVVnn + % 把join改成attach就解决了对齐问题 + \coffin_attach:cVVcVVnn { l__label_ \int_to_roman:n { ##1 } _coffin } % { l__content_ \int_to_roman:n { ##1 } _coffin } \l__labelcoffin_horizontal_position_tl