| 1 |
%% |
| 2 |
%% This is file `xeCJK-listings.sty', |
| 3 |
%% generated with the docstrip utility. |
| 4 |
%% |
| 5 |
%% The original source files were: |
| 6 |
%% |
| 7 |
%% xeCJK.dtx (with options: `listings') |
| 8 |
%% |
| 9 |
%% Copyright (C) 2007--2010 by Wenchang Sun <[email protected]> |
| 10 |
%% Copyright (C) 2009--2022 by Leo Liu <[email protected]> |
| 11 |
%% Copyright (C) 2012--2022 by Qing Lee <[email protected]> |
| 12 |
%% ---------------------------------------------------------------------- |
| 13 |
%% |
| 14 |
%% This work may be distributed and/or modified under the |
| 15 |
%% conditions of the LaTeX Project Public License, either |
| 16 |
%% version 1.3c of this license or (at your option) any later |
| 17 |
%% version. This version of this license is in |
| 18 |
%% http://www.latex-project.org/lppl/lppl-1-3c.txt |
| 19 |
%% and the latest version of this license is in |
| 20 |
%% http://www.latex-project.org/lppl.txt |
| 21 |
%% and version 1.3 or later is part of all distributions of |
| 22 |
%% LaTeX version 2005/12/01 or later. |
| 23 |
%% |
| 24 |
%% This work has the LPPL maintenance status "maintained". |
| 25 |
%% |
| 26 |
%% The Current Maintainers of this work are Leo Liu and Qing Lee. |
| 27 |
%% |
| 28 |
%% ---------------------------------------------------------------------- |
| 29 |
%% |
| 30 |
\NeedsTeXFormat{LaTeX2e} |
| 31 |
\RequirePackage{expl3} |
| 32 |
\GetIdInfo$Id: xeCJK.dtx c4ccfae 2022-08-05 21:02:32 +0800 Qing Lee <[email protected]> $ |
| 33 |
{xeCJK patch file for listings} |
| 34 |
\ProvidesExplPackage{xeCJK-listings} |
| 35 |
{\ExplFileDate}{3.9.1}{\ExplFileDescription} |
| 36 |
\DeclareOption* { \PassOptionsToPackage { \CurrentOption } { xeCJK } } |
| 37 |
\ProcessOptions \scan_stop: |
| 38 |
\RequirePackage { xeCJK } |
| 39 |
\RequirePackage { listings } |
| 40 |
\lst@AddToHook { Init } { \__xeCJK_listings_initial_hook: } |
| 41 |
\lst@AddToHook { SelectCharTable } { \__xeCJK_listings_toks_hook: } |
| 42 |
\lst@AddToHook { OutputBox } |
| 43 |
{ |
| 44 |
\tl_set_eq:NN \l_xeCJK_punct_style_tl \c__xeCJK_punct_style_plain_tl |
| 45 |
\l__xeCJK_restore_listings_toks_tl |
| 46 |
\__xeCJK_listings_output_CM: |
| 47 |
} |
| 48 |
\lst@AddToHook { PreSet } { \bool_set_true:N \l__xeCJK_listings_env_bool } |
| 49 |
\cs_new_protected:Npn \__xeCJK_listings_initial_hook: |
| 50 |
{ |
| 51 |
\tex_noindent:D |
| 52 |
\bool_gset_false:N \g__xeCJK_listings_CM_bool |
| 53 |
\tl_put_left:Nn \lst@numberstyle { \l__xeCJK_restore_listings_toks_tl } |
| 54 |
\xeCJK_add_to_shipout:n { \l__xeCJK_restore_listings_toks_tl } |
| 55 |
\lst@ifbreaklines |
| 56 |
\cs_set_eq:NN \__xeCJK_listings_CJK_toks_hook: \__xeCJK_listings_breaklines_toks: |
| 57 |
\tl_if_empty:NF \lst@prebreak |
| 58 |
{ \tl_put_left:Nn \lst@prebreak { \l__xeCJK_restore_listings_toks_tl } } |
| 59 |
\tl_if_empty:NF \lst@postbreak |
| 60 |
{ \tl_put_left:Nn \lst@postbreak { \l__xeCJK_restore_listings_toks_tl } } |
| 61 |
\fi: |
| 62 |
\int_set:Nn \l__xeCJK_listings_max_char_int |
| 63 |
{ \lst@ifec 255 \else: 127 \fi: } |
| 64 |
} |
| 65 |
\int_new:N \l__xeCJK_listings_max_char_int |
| 66 |
\cs_new_protected:Npn \__xeCJK_listings_toks_hook: |
| 67 |
{ |
| 68 |
\tl_clear:N \l__xeCJK_restore_listings_toks_tl |
| 69 |
\seq_map_function:NN |
| 70 |
\g__xeCJK_class_seq \__xeCJK_backup_inter_class_toks:n |
| 71 |
\seq_map_inline:Nn \g__xeCJK_non_CJK_class_seq |
| 72 |
{ |
| 73 |
\str_if_eq:nnF { ##1 } { Boundary } |
| 74 |
{ |
| 75 |
\xeCJK_inter_class_toks:nnn { Boundary } { ##1 } |
| 76 |
{ \__xeCJK_listings_process_Default:nN { ##1 } } |
| 77 |
} |
| 78 |
} |
| 79 |
\xeCJK_inter_class_toks:nnn { Boundary } { CM } |
| 80 |
{ \__xeCJK_listings_process_CM:nN { 0 } } |
| 81 |
\__xeCJK_listings_CJK_toks_hook: |
| 82 |
} |
| 83 |
\cs_new_protected:Npn \__xeCJK_backup_inter_class_toks:n #1 |
| 84 |
{ |
| 85 |
\tl_set:Nx \l__xeCJK_tmp_tl |
| 86 |
{ \xeCJK_get_inter_class_toks:nn { Boundary } {#1} } |
| 87 |
\tl_put_right:Nx \l__xeCJK_restore_listings_toks_tl |
| 88 |
{ |
| 89 |
\xeCJK_inter_class_toks:nnn { Boundary } {#1} |
| 90 |
{ |
| 91 |
\tl_if_empty:NTF \l__xeCJK_tmp_tl |
| 92 |
{ \exp_not:N \prg_do_nothing: } |
| 93 |
{ \exp_not:o \l__xeCJK_tmp_tl } |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
\tl_new:N \l__xeCJK_restore_listings_toks_tl |
| 98 |
\cs_new_protected:Npn \__xeCJK_listings_CJK_toks_hook: |
| 99 |
{ |
| 100 |
\xeCJK_inter_class_toks:nnn { Boundary } { CJK } |
| 101 |
{ \__xeCJK_listings_process_CJK:nN { 2 } } |
| 102 |
\xeCJK_inter_class_toks:nnn { Boundary } { FullLeft } |
| 103 |
{ \__xeCJK_listings_process_CJK:nN { 2 } } |
| 104 |
\xeCJK_inter_class_toks:nnn { Boundary } { FullRight } |
| 105 |
{ \__xeCJK_listings_process_CJK:nN { 2 } } |
| 106 |
\xeCJK_inter_class_toks:nnn { Boundary } { HangulJamo } |
| 107 |
{ \__xeCJK_listings_process_CJK:nN { 2 } } |
| 108 |
\seq_map_inline:Nn \g__xeCJK_CJK_sub_class_seq |
| 109 |
{ |
| 110 |
\xeCJK_inter_class_toks:nnn { Boundary } { CJK/##1 } |
| 111 |
{ \__xeCJK_listings_process_CJK:nN { 2 } } |
| 112 |
} |
| 113 |
} |
| 114 |
\cs_new_protected:Npn \__xeCJK_listings_breaklines_toks: |
| 115 |
{ |
| 116 |
\xeCJK_inter_class_toks:nnn { Boundary } { CJK } |
| 117 |
{ \__xeCJK_listings_process_breaklines_CJK:nN { 2 } } |
| 118 |
\xeCJK_inter_class_toks:nnn { Boundary } { HangulJamo } |
| 119 |
{ \__xeCJK_listings_process_breaklines_CJK:nN { 2 } } |
| 120 |
\xeCJK_inter_class_toks:nnn { Boundary } { FullLeft } |
| 121 |
{ \__xeCJK_listings_process_FullLeft:nN { 2 } } |
| 122 |
\xeCJK_inter_class_toks:nnn { Boundary } { FullRight } |
| 123 |
{ \__xeCJK_listings_process_FullRight:nN { 2 } } |
| 124 |
\seq_map_inline:Nn \g__xeCJK_CJK_sub_class_seq |
| 125 |
{ |
| 126 |
\xeCJK_inter_class_toks:nnn { Boundary } { CJK/##1 } |
| 127 |
{ \__xeCJK_listings_process_breaklines_CJK:nN { 2 } } |
| 128 |
} |
| 129 |
} |
| 130 |
\cs_new_protected:Npn \__xeCJK_listings_process_Default:nN #1#2 |
| 131 |
{ |
| 132 |
\int_compare:nNnTF |
| 133 |
{ \xeCJK_token_value_charcode:N #2 } > \l__xeCJK_listings_max_char_int |
| 134 |
{ |
| 135 |
\token_if_letter:NTF #2 |
| 136 |
{ \lst@ProcessLetter #2 } |
| 137 |
{ \lst@ProcessOther #2 } |
| 138 |
} |
| 139 |
{ \__xeCJK_listings_output_Default:nN {#1} #2 } |
| 140 |
} |
| 141 |
\cs_new_protected:Npn \__xeCJK_listings_output_Default:nN #1#2 |
| 142 |
{ |
| 143 |
\group_begin: |
| 144 |
\xeCJK_clear_inter_class_toks:nn { Boundary } {#1} |
| 145 |
\xeCJK_inter_class_toks:nnn {#1} { Boundary } { \group_end: } |
| 146 |
#2 |
| 147 |
\scan_stop: |
| 148 |
} |
| 149 |
\cs_new_protected:Npn \__xeCJK_listings_process_CJK:nN #1#2 |
| 150 |
{ |
| 151 |
\token_if_letter:NTF #2 |
| 152 |
{ \__xeCJK_listings_process_letter:nN {#1} #2 } |
| 153 |
{ \__xeCJK_listings_process_other:nN {#1} #2 } |
| 154 |
} |
| 155 |
\cs_new_protected:Npn \__xeCJK_listings_append:nN #1#2 |
| 156 |
{ |
| 157 |
\int_add:Nn \lst@length { #1 - 1 } |
| 158 |
\lst@Append #2 |
| 159 |
} |
| 160 |
\cs_new_protected:Npn \__xeCJK_listings_process_letter:nN |
| 161 |
{ |
| 162 |
\lst@whitespacefalse |
| 163 |
\bool_if:NTF \l__xeCJK_listings_letter_bool |
| 164 |
{ \lst@lettertrue } |
| 165 |
{ |
| 166 |
\lst@ifletter \lst@Output \else: \lst@OutputOther \lst@lettertrue \fi: |
| 167 |
\bool_set_true:N \l__xeCJK_listings_letter_bool |
| 168 |
} |
| 169 |
\__xeCJK_listings_append:nN |
| 170 |
} |
| 171 |
\bool_new:N \l__xeCJK_listings_letter_bool |
| 172 |
\cs_new_protected:Npn \__xeCJK_listings_process_other:nN #1#2 |
| 173 |
{ |
| 174 |
\lst@whitespacefalse |
| 175 |
\bool_if:NTF \l__xeCJK_listings_letter_bool |
| 176 |
{ |
| 177 |
\lst@Output \lst@letterfalse |
| 178 |
\bool_set_false:N \l__xeCJK_listings_letter_bool |
| 179 |
} |
| 180 |
{ \lst@ifletter \lst@Output \lst@letterfalse \fi: } |
| 181 |
\cs_set_eq:NN \lst@lastother #2 |
| 182 |
\__xeCJK_listings_append:nN {#1} #2 |
| 183 |
} |
| 184 |
\cs_new_protected:Npn \__xeCJK_listings_process_breaklines_CJK:nN |
| 185 |
{ |
| 186 |
\lst@whitespacefalse |
| 187 |
\bool_if:NTF \l__xeCJK_listings_letter_bool |
| 188 |
{ |
| 189 |
\int_compare:nNnF \l__xeCJK_listings_flag_int = 2 { \lst@Output } |
| 190 |
\lst@lettertrue |
| 191 |
} |
| 192 |
{ |
| 193 |
\lst@ifletter \lst@Output \else: \lst@OutputOther \lst@lettertrue \fi: |
| 194 |
\bool_set_true:N \l__xeCJK_listings_letter_bool |
| 195 |
} |
| 196 |
\int_set_eq:NN \l__xeCJK_listings_flag_int \c_one_int |
| 197 |
\__xeCJK_listings_append:nN |
| 198 |
} |
| 199 |
\cs_new_protected:Npn \__xeCJK_listings_process_FullLeft:nN #1#2 |
| 200 |
{ |
| 201 |
\lst@whitespacefalse |
| 202 |
\bool_if:NTF \l__xeCJK_listings_letter_bool |
| 203 |
{ |
| 204 |
\int_compare:nNnF \l__xeCJK_listings_flag_int = 2 |
| 205 |
{ |
| 206 |
\int_compare:nNnTF \l__xeCJK_listings_flag_int = 3 |
| 207 |
{ \bool_if:NT \l__xeCJK_punct_breakable_bool { \lst@Output } } |
| 208 |
{ \lst@Output } |
| 209 |
} |
| 210 |
\lst@lettertrue |
| 211 |
} |
| 212 |
{ |
| 213 |
\lst@ifletter \lst@Output \else: \lst@OutputOther \lst@lettertrue \fi: |
| 214 |
\bool_set_true:N \l__xeCJK_listings_letter_bool |
| 215 |
} |
| 216 |
\int_set:Nn \l__xeCJK_listings_flag_int { 2 } |
| 217 |
\__xeCJK_listings_append:nN {#1} #2 |
| 218 |
} |
| 219 |
\cs_new_protected:Npn \__xeCJK_listings_process_FullRight:nN #1#2 |
| 220 |
{ |
| 221 |
\lst@whitespacefalse |
| 222 |
\bool_if:NTF \l__xeCJK_listings_letter_bool |
| 223 |
{ |
| 224 |
\int_compare:nNnT \l__xeCJK_listings_flag_int < 2 |
| 225 |
{ \__xeCJK_punct_if_long:NT #2 { \lst@Output } } |
| 226 |
\lst@lettertrue |
| 227 |
} |
| 228 |
{ |
| 229 |
\lst@ifletter \lst@Output \else: \lst@OutputOther \lst@lettertrue \fi: |
| 230 |
\bool_set_true:N \l__xeCJK_listings_letter_bool |
| 231 |
} |
| 232 |
\int_set:Nn \l__xeCJK_listings_flag_int { 3 } |
| 233 |
\__xeCJK_listings_append:nN {#1} #2 |
| 234 |
} |
| 235 |
\int_new:N \l__xeCJK_listings_flag_int |
| 236 |
\cs_set_protected:Npn \lst@AppendLetter |
| 237 |
{ |
| 238 |
\bool_if:NTF \l__xeCJK_listings_letter_bool |
| 239 |
{ |
| 240 |
\lst@Output \lst@lettertrue |
| 241 |
\bool_set_false:N \l__xeCJK_listings_letter_bool |
| 242 |
} |
| 243 |
{ \reverse_if:N \lst@ifletter \lst@OutputOther \lst@lettertrue \fi: } |
| 244 |
\lst@ifbreaklines \int_zero:N \l__xeCJK_listings_flag_int \fi: |
| 245 |
\lst@Append |
| 246 |
} |
| 247 |
\cs_set_protected:Npn \lst@AppendOther |
| 248 |
{ |
| 249 |
\bool_if:NTF \l__xeCJK_listings_letter_bool |
| 250 |
{ |
| 251 |
\lst@Output \lst@letterfalse |
| 252 |
\bool_set_false:N \l__xeCJK_listings_letter_bool |
| 253 |
} |
| 254 |
{ \lst@ifletter \lst@Output \lst@letterfalse \fi: } |
| 255 |
\lst@ifbreaklines \int_zero:N \l__xeCJK_listings_flag_int \fi: |
| 256 |
\tex_futurelet:D \lst@lastother \lst@Append |
| 257 |
} |
| 258 |
\cs_new_protected:Npn \__xeCJK_listings_process_CM:nN |
| 259 |
{ |
| 260 |
\reverse_if:N \lst@ifflexible |
| 261 |
\bool_gset_true:N \g__xeCJK_listings_CM_bool |
| 262 |
\fi: |
| 263 |
\__xeCJK_listings_process_letter:nN |
| 264 |
} |
| 265 |
\cs_new_protected:Npn \__xeCJK_listings_output_CM: |
| 266 |
{ |
| 267 |
\reverse_if:N \lst@ifflexible |
| 268 |
\bool_if:NT \g__xeCJK_listings_CM_bool |
| 269 |
{ |
| 270 |
\bool_gset_false:N \g__xeCJK_listings_CM_bool |
| 271 |
\xeCJK_cs_clear:N \lst@FillOutputBox |
| 272 |
\cs_set_eq:NN \CJKglue \tex_hss:D |
| 273 |
} |
| 274 |
\fi: |
| 275 |
} |
| 276 |
\bool_new:N \g__xeCJK_listings_CM_bool |
| 277 |
\cs_new_protected:Npn \__xeCJK_listings_peek_active_loop:TF #1#2#3 |
| 278 |
{ |
| 279 |
\token_if_active:NTF #3 |
| 280 |
{ #1#3 } |
| 281 |
{ |
| 282 |
\token_if_cs:NTF #3 |
| 283 |
{ #2#3 } |
| 284 |
{ |
| 285 |
\int_compare:nNnTF { `#3 } > { \l__xeCJK_listings_max_char_int } |
| 286 |
{ \__xeCJK_listings_peek_active_loop:TF { #1#3 } { #2#3 } } |
| 287 |
{ #2#3 } |
| 288 |
} |
| 289 |
} |
| 290 |
} |
| 291 |
\cs_set_eq:NN \lst@IfNextCharActive \__xeCJK_listings_peek_active_loop:TF |
| 292 |
\cs_new_protected:Npn \__xeCJK_listings_rescan:Nn #1#2 |
| 293 |
{ |
| 294 |
\__xeCJK_listings_set_escape: |
| 295 |
\tl_set:Nn \l__xeCJK_tmp_tl {#2} |
| 296 |
\__xeCJK_listings_escape_backslash: |
| 297 |
\tl_set_rescan:Nno #1 { } { \l__xeCJK_tmp_tl } |
| 298 |
} |
| 299 |
\cs_new_protected:Npn \__xeCJK_listings_inside_convert:nw #1 ~ \@empty |
| 300 |
{ |
| 301 |
\__xeCJK_listings_rescan:Nn \l__xeCJK_tmp_tl {#1} |
| 302 |
\tl_put_right:No \lst@arg { \l__xeCJK_tmp_tl } |
| 303 |
} |
| 304 |
\cs_set_eq:NN \lst@InsideConvert@ \__xeCJK_listings_inside_convert:nw |
| 305 |
\cs_new_protected:Npn \__xeCJK_listings_inline_group:w |
| 306 |
{ |
| 307 |
\exp_after:wN \__xeCJK_listings_inline_group:n |
| 308 |
\exp_after:wN { \if_int_compare:w `} = \c_zero_int \fi: |
| 309 |
} |
| 310 |
\cs_set_eq:NN \lst@InlineGJ \__xeCJK_listings_inline_group:w |
| 311 |
\cs_new_protected:Npn \__xeCJK_listings_inline_group:n #1 |
| 312 |
{ |
| 313 |
\__xeCJK_listings_rescan:Nn \lst@arg {#1} |
| 314 |
\lst@InlineGJEnd |
| 315 |
} |
| 316 |
\group_begin: |
| 317 |
\cs_set:Npn \__xeCJK_tmp:w #1 |
| 318 |
{ |
| 319 |
\group_end: |
| 320 |
\cs_new_protected:Npn \__xeCJK_listings_set_escape: |
| 321 |
{ \xeCJK_swap_cs:NN #1 \__xeCJK_listings_escape:N } |
| 322 |
\cs_new_protected:Npn \__xeCJK_listings_escape:N ##1 |
| 323 |
{ \cs_if_eq:NNTF #1 ##1 { \__xeCJK_listings_escape:N } {##1} } |
| 324 |
} |
| 325 |
\use:n |
| 326 |
{ |
| 327 |
\char_set_catcode_active:N \\ |
| 328 |
\__xeCJK_tmp:w |
| 329 |
} |
| 330 |
{ \ } |
| 331 |
\cs_new_protected:Npx \__xeCJK_listings_escape_backslash: |
| 332 |
{ |
| 333 |
\tl_replace_all:Nnn \exp_not:N \l__xeCJK_tmp_tl |
| 334 |
{ \c_backslash_str } |
| 335 |
{ \c_backslash_str \c_backslash_str } |
| 336 |
} |
| 337 |
%% |
| 338 |
%% This package consists of the files xeCJK.dtx, |
| 339 |
%% full-stop.map, |
| 340 |
%% fullwidth-stop.map, |
| 341 |
%% han-simp.map, |
| 342 |
%% han-trad.map, |
| 343 |
%% and the derived files xeCJK.pdf, |
| 344 |
%% xeCJK.sty, |
| 345 |
%% xeCJK.cfg, |
| 346 |
%% xeCJK.ins, |
| 347 |
%% xeCJKfntef.sty, |
| 348 |
%% xeCJK-listings.sty, |
| 349 |
%% xunicode-addon.sty, |
| 350 |
%% xunicode-extra.def, |
| 351 |
%% xeCJK-example-autofake.tex, |
| 352 |
%% xeCJK-example-fallback.tex, |
| 353 |
%% xeCJK-example-subCJKblock.tex, |
| 354 |
%% xeCJK-example-CJKecglue.tex, |
| 355 |
%% xeCJK-example-checksingle.tex, |
| 356 |
%% xeCJK-example-CJKfntef.tex, |
| 357 |
%% xeCJK-example-punctstyle.tex, |
| 358 |
%% xeCJK-example-verbatim.tex, |
| 359 |
%% xeCJK-example-CM.tex, |
| 360 |
%% xeCJK-example-listings.tex, |
| 361 |
%% xeCJK-example-mathblock.tex, |
| 362 |
%% xunicode-symbols.tex, |
| 363 |
%% xunicode-commands.tex, |
| 364 |
%% xunicode-combine-marks.tex, |
| 365 |
%% xunicode-symbols.pdf, |
| 366 |
%% full-stop.tec, |
| 367 |
%% fullwidth-stop.tec, |
| 368 |
%% han-simp.tec, |
| 369 |
%% han-trad.tec, and |
| 370 |
%% README.md. |
| 371 |
%% |
| 372 |
%% End of file `xeCJK-listings.sty'. |