1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| \documentclass{ctexart} \usepackage{l3draw,expl3,xparse} \ExplSyntaxOn
\coffin_new:N \__label_coffin \coffin_new:N \__content_coffin \dim_zero_new:N \__vsep_dim \dim_zero_new:N \__parsep_dim \dim_zero_new:N \__parindent_dim \dim_set_eq:NN \__parindent_dim \parindent \tl_new:N \__item_tl \cs_generate_variant:Nn \vcoffin_set:Nnn{Nnx} \int_zero_new:N \__item_int \cs_generate_variant:Nn\color_fill:n{x} \cs_generate_variant:Nn\color_select:n{x}
\cs_new:Npn \__item_true_label: { \draw_begin: \draw_baseline:n{0.5ex} \draw_path_rectangle:nn{0,0}{0.4cm,0.4cm} \color_fill:x{\__color_tl} \draw_path_use:n{fill} \draw_scope_begin: \draw_cap_round: \draw_join_round: \color_select:n{white} \draw_path_moveto:n{0.1cm,0.21cm} \draw_path_lineto:n{0.18cm,0.08cm} \draw_path_lineto:n{0.32cm,0.32cm} \draw_linewidth:n{1pt} \draw_path_use:n{stroke} \draw_scope_end: \draw_end: }
\cs_new:Npn \__item_false_label: { \draw_begin: \draw_baseline:n{0.5ex} \draw_linewidth:n{0.8pt} \draw_path_rectangle:nn{0,0}{0.4cm,0.4cm} \color_select:x{\__color_tl} \draw_path_use:n{stroke} \draw_end: }
\cs_new_protected:Npn \__item_label: { \par \int_compare:nF{\__item_int = \c_zero_int} { \__item_content: } \int_incr:N \__item_int \vcoffin_set:Nnx \__label_coffin {1cm}{\__item_tl} \vcoffin_set:Nnw \__content_coffin {\textwidth - \__parsep_dim - 2cm} }
\cs_new_protected:Npn \__item_content: { \vcoffin_set_end: \coffin_join:NnnNnnnn \__label_coffin{T}{r}\__content_coffin{T}{l}{-10pt}{0pt} \coffin_typeset:Nnnnn \__label_coffin{B}{l}{\__parsep_dim}{\__vsep_dim} \par }
\keys_define:nn{test} { colorlist.clist_set:N = \__color_clist, vsep.dim_set:N = \__vsep_dim, vsep.initial:n = 1pt, parsep.dim_set:N = \__parsep_dim, parsep.initial:n = \__parindent_dim, color.str_set:N = \__color_str, color.initial:n = black }
\NewDocumentEnvironment{test}{O{}} { \group_begin: \dim_set:Nn \parindent{0pt} \int_zero:N \__item_int \keys_set:nn{test}{#1} \seq_set_from_clist:NN \__color_seq \__color_clist \clist_if_empty:NTF \__color_clist { \tl_set:Nn\__color_tl {\__color_str} } { \tl_set:Nn\__color_tl {\clist_item:Nn\__color_clist{\__item_int}} } \RenewDocumentCommand{\item}{sO{}} { \IfBooleanTF{##1} { \tl_gset:Nn \__item_tl {\__item_true_label:} } { \tl_gset:Nn \__item_tl { \__item_false_label: } } \__item_label: } } { \__item_content: \group_end: } \ExplSyntaxOff
\begin{document} 我喜欢? \begin{test}[colorlist ={ blue,red,yellow,cyan,black},] \item 抽烟 \item* 喝酒 \item 蹦迪 \item 赌博 \item* 美女 \end{test} \end{document}
|