CTeX-org / ctex-kit

Macro Packages and Scripts for Chinese TeX users
985 stars 124 forks source link

jiazhu: 夹注的底线对齐 #535

Closed tanukihee closed 2 years ago

tanukihee commented 4 years ago

在 #508 中,夹注是中线对齐的,但在 clreq 的此份提案中,单行的夹注应该是底线对齐,希望能加一个选项,让用户自己决定是中线对齐还是底线对齐。

tanukihee commented 4 years ago

底线对齐的实现比较简单,夹注的基线下移量为 $s_o (1 - r_o) - s_i (1 - r_i)$,不需要考虑多行的情况,但括号的下移亦需更改。

效果图 image

\cs_new_protected:Npn \__jiazhu_calc_box_offset:
{
  \exp_args:Nxx \__jiazhu_calc_box_offset_aux:nn
  {
    \fp_compare:nNnTF \l__jiazhu_jzideoht_fp = \c_zero_fp
    { \fp_eval:n { 1 -   \l__jiazhu_ideoht_fp } }
    { \fp_eval:n { 1 - \l__jiazhu_jzideoht_fp } }
  }
  { \fp_eval:n { 1 - \l__jiazhu_ideoht_fp } }
}

\cs_new_protected:Npn \__jiazhu_calc_box_offset_aux:nn #1#2
{
  \dim_set:Nn \l__jiazhu_box_offset_dim
  {
    #2 \l__jiazhu_outer_unit_dim - #1 \l__jiazhu_unit_dim
  }
  \dim_set:Nn \l__jiazhu_mark_offset_dim
  {
    #2 \l__jiazhu_outer_unit_dim - \fp_eval:n { #1 * \l__jiazhu_bracket_ratio_fp } \l__jiazhu_unit_dim
  }
}
tanukihee commented 4 years ago

我忘了考虑竖排情况了……竖排时单行夹注是右对齐,对应到横排应该是顶线对齐。此时夹注的基线下移量为 $r_i s_i + (n - 1) b - r_o s_o$,括号下移亦如此。

\cs_new_protected:Npn \__jiazhu_calc_box_offset:
{
  \exp_args:Nxx \__jiazhu_calc_box_offset_aux:nn
  {
    \fp_compare:nNnTF \l__jiazhu_jzideoht_fp = \c_zero_fp
    { \fp_eval:n { \l__jiazhu_ideoht_fp   } }
    { \fp_eval:n { \l__jiazhu_jzideoht_fp } }
  }
  { \fp_eval:n { \l__jiazhu_ideoht_fp } }
}

\cs_new_protected:Npn \__jiazhu_calc_box_offset_aux:nn #1#2
{
  \dim_set:Nn \l__jiazhu_box_offset_dim
  {
    #1 \l__jiazhu_unit_dim + \int_eval:n { \l__jiazhu_lines_int - 1 } \tex_baselineskip:D - #2 \l__jiazhu_outer_unit_dim
  }
  \dim_set:Nn \l__jiazhu_mark_offset_dim
  {
    \fp_eval:n { #1 * \l__jiazhu_bracket_ratio_fp } \l__jiazhu_unit_dim - #2 \l__jiazhu_outer_unit_dim
  }
}

效果图 image

感觉可以让 alignment 接受两个参数,分别控制夹注的两个对其方向(tmb/lcr)