Advertisement
Guest User

Untitled

a guest
May 13th, 2020
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 153.95 KB | None | 0 0
  1. %%
  2. %% This is file `nicematrix.sty',
  3. %% generated with the docstrip utility.
  4. %%
  5. %% The original source files were:
  6. %%
  7. %% nicematrix.dtx (with options: `package')
  8. %%
  9. %% Copyright (C) 2017-2019 by F. Pantigny
  10. %%
  11. %% This file may be distributed and/or modified under the
  12. %% conditions of the LaTeX Project Public License, either
  13. %% version 1.3 of this license or (at your option) any later
  14. %% version. The latest version of this license is in:
  15. %%
  16. %% http://www.latex-project.org/lppl.txt
  17. %%
  18. %% and version 1.3 or later is part of all distributions of
  19. %% LaTeX version 2005/12/01 or later.
  20. %%
  21. %% This version has never been released on CTAN
  22. \def\myfileversion{4.0a}
  23. \def\myfiledate{2020/05/13}
  24. \RequirePackage{pgfcore}
  25. \usepgfmodule{shapes}
  26. \RequirePackage{l3keys2e}
  27. \ProvidesExplPackage
  28. {nicematrix}
  29. {\myfiledate}
  30. {\myfileversion}
  31. {Mathematical matrices with PGF/TikZ}
  32. \msg_new:nnn { nicematrix } { expl3~too~old }
  33. {
  34. Your~version~of~LaTeX~(especially~expl3)~is~too~old.~
  35. You~can~go~on~but~you~will~probably~have~other~errors~
  36. if~you~use~the~functionalities~of~nicematrix.
  37. }
  38. \cs_if_exist:NF \l_keys_key_str
  39. { \msg_error:nn { nicematrix } { expl3~too~old } }
  40. \RequirePackage { array }
  41. \RequirePackage { amsmath }
  42. \RequirePackage { xparse }
  43. \cs_new_protected:Npn \__nicematrix_error:n { \msg_error:nn { nicematrix } }
  44. \cs_new_protected:Npn \__nicematrix_error:nn { \msg_error:nnn { nicematrix } }
  45. \cs_new_protected:Npn \__nicematrix_error:nnn { \msg_error:nnnn { nicematrix } }
  46. \cs_new_protected:Npn \__nicematrix_fatal:n { \msg_fatal:nn { nicematrix } }
  47. \cs_new_protected:Npn \__nicematrix_fatal:nn { \msg_fatal:nnn { nicematrix } }
  48. \cs_new_protected:Npn \__nicematrix_msg_new:nn { \msg_new:nnn { nicematrix } }
  49. \cs_new_protected:Npn \__nicematrix_msg_new:nnn { \msg_new:nnnn { nicematrix } }
  50. \cs_new_protected:Npn \__nicematrix_msg_redirect_name:nn
  51. { \msg_redirect_name:nnn { nicematrix } }
  52. \bool_new:N \c__nicematrix_booktabs_loaded_bool
  53. \bool_new:N \c__nicematrix_tikz_loaded_bool
  54. \AtBeginDocument
  55. {
  56. \@ifpackageloaded { booktabs }
  57. { \bool_set_true:N \c__nicematrix_booktabs_loaded_bool }
  58. { }
  59. \@ifpackageloaded { tikz }
  60. {
  61. \bool_set_true:N \c__nicematrix_tikz_loaded_bool
  62. \tl_const:Nn \c__nicematrix_pgfortikzpicture_tl { \exp_not:N \tikzpicture }
  63. \tl_const:Nn \c__nicematrix_endpgfortikzpicture_tl { \exp_not:N \endtikzpicture }
  64. }
  65. {
  66. \tl_const:Nn \c__nicematrix_pgfortikzpicture_tl { \exp_not:N \pgfpicture }
  67. \tl_const:Nn \c__nicematrix_endpgfortikzpicture_tl { \exp_not:N \endpgfpicture }
  68. }
  69. }
  70. \bool_new:N \c__nicematrix_revtex_bool
  71. \@ifclassloaded { revtex4-1 }
  72. { \bool_set_true:N \c__nicematrix_revtex_bool }
  73. { }
  74. \@ifclassloaded { revtex4-2 }
  75. { \bool_set_true:N \c__nicematrix_revtex_bool }
  76. { }
  77. \ProvideDocumentCommand \iddots { }
  78. {
  79. \mathinner
  80. {
  81. \tex_mkern:D 1 mu
  82. \box_move_up:nn { 1 pt } { \hbox:n { . } }
  83. \tex_mkern:D 2 mu
  84. \box_move_up:nn { 4 pt } { \hbox:n { . } }
  85. \tex_mkern:D 2 mu
  86. \box_move_up:nn { 7 pt }
  87. { \vbox:n { \kern 7 pt \hbox:n { . } } }
  88. \tex_mkern:D 1 mu
  89. }
  90. }
  91. \AtBeginDocument
  92. {
  93. \@ifpackageloaded { booktabs }
  94. { \iow_now:Nn \@mainaux \nicematrix@redefine@check@rerun }
  95. { }
  96. }
  97. \cs_set_protected:Npn \nicematrix@redefine@check@rerun
  98. {
  99. \cs_set_eq:NN \__nicematrix_old_pgfutil@check@rerun \pgfutil@check@rerun
  100. \cs_set_protected:Npn \pgfutil@check@rerun ##1 ##2
  101. {
  102. \str_set:Nx \l_tmpa_str { \tl_range:nnn { ##1 } 1 3 }
  103. \str_if_eq:VnF \l_tmpa_str { nm- }
  104. { \__nicematrix_old_pgfutil@check@rerun { ##1 } { ##2 } }
  105. }
  106. }
  107. \bool_new:N \c__nicematrix_colortbl_loaded_bool
  108. \AtBeginDocument
  109. {
  110. \@ifpackageloaded { colortbl }
  111. { \bool_set_true:N \c__nicematrix_colortbl_loaded_bool }
  112. {
  113. \cs_set_protected:Npn \CT@arc@ { }
  114. \cs_set:Npn \arrayrulecolor #1 # { \CT@arc { #1 } }
  115. \cs_set:Npn \CT@arc #1 #2
  116. {
  117. \dim_compare:nNnT \baselineskip = \c_zero_dim \noalign
  118. { \cs_gset:Npn \CT@arc@ { \color #1 { #2 } } }
  119. }
  120. \cs_set:Npn \hline
  121. {
  122. \noalign { \ifnum 0 = `} \fi
  123. \cs_set_eq:NN \hskip \vskip
  124. \cs_set_eq:NN \vrule \hrule
  125. \cs_set_eq:NN \@width \@height
  126. { \CT@arc@ \vline }
  127. \futurelet \reserved@a
  128. \@xhline
  129. }
  130. }
  131. }
  132. \AtBeginDocument
  133. {
  134. \bool_if:NTF \c__nicematrix_standard_cline_bool
  135. {
  136. \cs_set:Npn \__nicematrix_cline #1 { \__nicematrix_cline:w #1 \q_stop }
  137. \cs_set:Npn \__nicematrix_cline:w #1-#2 \q_stop
  138. {
  139. \int_compare:nNnT \l__nicematrix_first_col_int = 0 { \omit & }
  140. \int_compare:nNnTF { #1 } > 1
  141. {
  142. \multispan { \int_eval:n { #1 - 1 } } &
  143. \multispan { \int_eval:n { #2 - #1 + 1 } }
  144. }
  145. { \multispan { \int_eval:n { #2 - #1 + 1 } } }
  146. { \CT@arc@ \leaders \hrule \@height \arrayrulewidth \hfill }
  147. \everycr { }
  148. \cr
  149. \noalign { \skip_vertical:N -\arrayrulewidth }
  150. }
  151. }
  152. {
  153. \cs_set:Npn \__nicematrix_cline
  154. {
  155. \int_compare:nNnT \l__nicematrix_first_col_int = 0 { \omit & }
  156. \__nicematrix_cline_i:nn { 0 }
  157. }
  158. \cs_set:Npn \__nicematrix_cline_i:nn #1 #2 { \__nicematrix_cline_i:w #1-#2 \q_stop }
  159. \cs_set:Npn \__nicematrix_cline_i:w #1-#2-#3 \q_stop
  160. {
  161.  
  162. \int_compare:nNnTF { #2 - #1 - 1 } > 0
  163. {
  164. \multispan { \int_eval:n { #2 - #1 - 2 } } &
  165. \multispan { \int_eval:n { #3 - #2 + 1 } }
  166. }
  167. { \multispan { \int_eval:n { #3 - #2 + 1 } } }
  168. { \CT@arc@ \leaders \hrule \@height \arrayrulewidth \hfill }
  169. \peek_meaning_remove_ignore_spaces:NTF \cline
  170. { & \__nicematrix_cline_i:nn { #3 } }
  171. { \everycr { } \cr }
  172. }
  173. }
  174. }
  175. \cs_new:Npn \__nicematrix_succ:n #1 { \the \numexpr #1 + 1 \relax }
  176. \cs_new:Npn \__nicematrix_pred:n #1 { \the \numexpr #1 - 1 \relax }
  177. \bool_new:N \c__nicematrix_siunitx_loaded_bool
  178. \AtBeginDocument
  179. {
  180. \@ifpackageloaded { siunitx }
  181. { \bool_set_true:N \c__nicematrix_siunitx_loaded_bool }
  182. { }
  183. }
  184. \cs_set_protected:Npn \__nicematrix_adapt_S_column:
  185. {
  186. \bool_if:NT \c__nicematrix_siunitx_loaded_bool
  187. {
  188. \group_begin:
  189. \@temptokena = { }
  190. \cs_set_eq:NN \NC@find \prg_do_nothing:
  191. \NC@rewrite@S { }
  192. \tl_gset:NV \g_tmpa_tl \@temptokena
  193. \group_end:
  194. \tl_new:N \c__nicematrix_table_collect_begin_tl
  195. \tl_set:Nx \l_tmpa_tl { \tl_item:Nn \g_tmpa_tl 2 }
  196. \tl_gset:Nx \c__nicematrix_table_collect_begin_tl { \tl_item:Nn \l_tmpa_tl 1 }
  197. \tl_new:N \c__nicematrix_table_print_tl
  198. \tl_gset:Nx \c__nicematrix_table_print_tl { \tl_item:Nn \g_tmpa_tl { -1 } }
  199. \cs_gset_eq:NN \__nicematrix_adapt_S_column: \prg_do_nothing:
  200. }
  201. }
  202. \cs_new_protected:Npn \__nicematrix_renew_NC@rewrite@S:
  203. {
  204. \renewcommand*{\NC@rewrite@S}[1][]
  205. {
  206. \@temptokena \exp_after:wN
  207. {
  208. \tex_the:D \@temptokena
  209. > { \__nicematrix_Cell: \c__nicematrix_table_collect_begin_tl S {##1} }
  210. c
  211. < { \c__nicematrix_table_print_tl \__nicematrix_end_Cell: }
  212. }
  213. \NC@find
  214. }
  215. }
  216. \int_new:N \g__nicematrix_env_int
  217. \cs_new:Npn \__nicematrix_env: { nm - \int_use:N \g__nicematrix_env_int }
  218. \cs_new_protected:Npn \__nicematrix_qpoint:n #1
  219. { \pgfpointanchor { \__nicematrix_env: - #1 } { center } }
  220. \int_new:N \g__nicematrix_NiceMatrixBlock_int
  221. \dim_new:N \l__nicematrix_columns_width_dim
  222. \seq_new:N \g__nicematrix_names_seq
  223. \bool_new:N \l__nicematrix_in_env_bool
  224. \bool_new:N \l__nicematrix_NiceArray_bool
  225. \bool_new:N \l__nicematrix_NiceTabular_bool
  226. \cs_new_protected:Npn \__nicematrix_test_if_math_mode:
  227. {
  228. \if_mode_math: \else:
  229. \__nicematrix_fatal:n { Outside~math~mode }
  230. \fi:
  231. }
  232. \colorlet { nicematrix-last-col } { . }
  233. \colorlet { nicematrix-last-row } { . }
  234. \str_new:N \g__nicematrix_name_env_str
  235. \str_new:N \g__nicematrix_com_or_env_str
  236. \str_set:Nn \g__nicematrix_com_or_env_str { environment }
  237. \cs_new:Npn \__nicematrix_full_name_env:
  238. {
  239. \str_if_eq:VnTF \g__nicematrix_com_or_env_str { command }
  240. { command \space \c_backslash_str \g__nicematrix_name_env_str }
  241. { environment \space \{ \g__nicematrix_name_env_str \} }
  242. }
  243. \tl_new:N \g__nicematrix_code_after_tl
  244. \tl_new:N \g__nicematrix_internal_code_after_tl
  245. \int_new:N \l__nicematrix_old_iRow_int
  246. \int_new:N \l__nicematrix_old_jCol_int
  247. \bool_new:N \g__nicematrix_row_of_col_done_bool
  248. \bool_new:N \l__nicematrix_code_before_bool
  249. \dim_new:N \l__nicematrix_x_initial_dim
  250. \dim_new:N \l__nicematrix_y_initial_dim
  251. \dim_new:N \l__nicematrix_x_final_dim
  252. \dim_new:N \l__nicematrix_y_final_dim
  253. \dim_zero_new:N \l_tmpc_dim
  254. \dim_zero_new:N \l_tmpd_dim
  255. \bool_new:N \g__nicematrix_empty_cell_bool
  256. \dim_new:N \__nicematrix_old_arraycolsep_dim
  257. \dim_new:N \g__nicematrix_width_last_col_dim
  258. \dim_new:N \g__nicematrix_width_first_col_dim
  259. \int_new:N \l__nicematrix_first_row_int
  260. \int_set:Nn \l__nicematrix_first_row_int 1
  261. \int_new:N \l__nicematrix_first_col_int
  262. \int_set:Nn \l__nicematrix_first_col_int 1
  263. \int_new:N \l__nicematrix_last_row_int
  264. \int_set:Nn \l__nicematrix_last_row_int { -2 }
  265. \bool_new:N \l__nicematrix_last_row_without_value_bool
  266. \bool_new:N \l__nicematrix_last_col_without_value_bool
  267. \int_new:N \l__nicematrix_last_col_int
  268. \int_set:Nn \l__nicematrix_last_col_int { -2 }
  269. \bool_new:N \g__nicematrix_last_col_found_bool
  270. \cs_new_protected:Npn \__nicematrix_pgf_rect_node:nnnnn #1 #2 #3 #4 #5
  271. {
  272. \begin { pgfscope }
  273. \pgfset
  274. {
  275. outer~sep = \c_zero_dim ,
  276. inner~sep = \c_zero_dim ,
  277. minimum~size = \c_zero_dim
  278. }
  279. \pgftransformshift { \pgfpoint { 0.5 * ( #2 + #4 ) } { 0.5 * ( #3 + #5 ) } }
  280. \pgfnode
  281. { rectangle }
  282. { center }
  283. {
  284. \vbox_to_ht:nn
  285. { \dim_abs:n { #5 - #3 } }
  286. {
  287. \vfill
  288. \hbox_to_wd:nn { \dim_abs:n { #4 - #2 } } { }
  289. }
  290. }
  291. { #1 }
  292. { }
  293. \end { pgfscope }
  294. }
  295. \cs_new_protected:Npn \__nicematrix_pgf_rect_node:nnn #1 #2 #3
  296. {
  297. \begin { pgfscope }
  298. \pgfset
  299. {
  300. outer~sep = \c_zero_dim ,
  301. inner~sep = \c_zero_dim ,
  302. minimum~size = \c_zero_dim
  303. }
  304. \pgftransformshift { \pgfpointscale { 0.5 } { \pgfpointadd { #2 } { #3 } } }
  305. \pgfpointdiff { #3 } { #2 }
  306. \pgfgetlastxy \l_tmpa_dim \l_tmpb_dim
  307. \pgfnode
  308. { rectangle }
  309. { center }
  310. {
  311. \vbox_to_ht:nn
  312. { \dim_abs:n \l_tmpb_dim }
  313. { \vfill \hbox_to_wd:nn { \dim_abs:n \l_tmpa_dim } { } }
  314. }
  315. { #1 }
  316. { }
  317. \end { pgfscope }
  318. }
  319. \bool_new:N \c__nicematrix_standard_cline_bool
  320. \bool_set_true:N \c__nicematrix_standard_cline_bool
  321. \dim_new:N \l__nicematrix_cell_space_top_limit_dim
  322. \dim_new:N \l__nicematrix_cell_space_bottom_limit_dim
  323. \dim_new:N \l__nicematrix_inter_dots_dim
  324. \dim_set:Nn \l__nicematrix_inter_dots_dim { 0.45 em }
  325. \dim_new:N \l__nicematrix_xdots_shorten_dim
  326. \dim_set:Nn \l__nicematrix_xdots_shorten_dim { 0.3 em }
  327. \dim_new:N \l__nicematrix_radius_dim
  328. \dim_set:Nn \l__nicematrix_radius_dim { 0.53 pt }
  329. \tl_new:N \l__nicematrix_xdots_line_style_tl
  330. \tl_const:Nn \c__nicematrix_standard_tl { standard }
  331. \tl_set_eq:NN \l__nicematrix_xdots_line_style_tl \c__nicematrix_standard_tl
  332. \bool_new:N \l__nicematrix_light_syntax_bool
  333. \str_new:N \l__nicematrix_baseline_str
  334. \str_set:Nn \l__nicematrix_baseline_str c
  335. \bool_new:N \l__nicematrix_exterior_arraycolsep_bool
  336. \bool_new:N \l__nicematrix_parallelize_diags_bool
  337. \bool_set_true:N \l__nicematrix_parallelize_diags_bool
  338. \bool_new:N \l__nicematrix_hlines_bool
  339. \bool_new:N \l__nicematrix_vlines_bool
  340. \bool_new:N \l__nicematrix_nullify_dots_bool
  341. \bool_new:N \l__nicematrix_auto_columns_width_bool
  342. \str_new:N \l__nicematrix_name_str
  343. \bool_new:N \l__nicematrix_medium_nodes_bool
  344. \bool_new:N \l__nicematrix_large_nodes_bool
  345. \dim_new:N \l__nicematrix_left_margin_dim
  346. \dim_new:N \l__nicematrix_right_margin_dim
  347. \dim_new:N \l__nicematrix_extra_left_margin_dim
  348. \dim_new:N \l__nicematrix_extra_right_margin_dim
  349. \tl_new:N \l__nicematrix_end_of_row_tl
  350. \tl_set:Nn \l__nicematrix_end_of_row_tl { ; }
  351. \tl_new:N \l__nicematrix_xdots_color_tl
  352. \bool_new:N \l__nicematrix_max_delimiter_width_bool
  353. \keys_define:nn { NiceMatrix / xdots }
  354. {
  355. line-style .code:n =
  356. {
  357. \bool_lazy_or:nnTF
  358. { \cs_if_exist_p:N \tikzpicture }
  359. { \str_if_eq_p:nn { #1 } { standard } }
  360. { \tl_set:Nn \l__nicematrix_xdots_line_style_tl { #1 } }
  361. { \__nicematrix_error:n { bad~option~for~line-style } }
  362. } ,
  363. line-style .value_required:n = true ,
  364. color .tl_set:N = \l__nicematrix_xdots_color_tl ,
  365. color .value_required:n = true ,
  366. shorten .dim_set:N = \l__nicematrix_xdots_shorten_dim ,
  367. shorten .value_required:n = true ,
  368. down .tl_set:N = \l__nicematrix_xdots_down_tl ,
  369. up .tl_set:N = \l__nicematrix_xdots_up_tl ,
  370. unknown .code:n = \__nicematrix_error:n { Unknown~option~for~xdots }
  371. }
  372. \keys_define:nn { NiceMatrix / Global }
  373. {
  374. cell-space-top-limit .dim_set:N = \l__nicematrix_cell_space_top_limit_dim ,
  375. cell-space-top-limit .value_required:n = true ,
  376. cell-space-bottom-limit .dim_set:N = \l__nicematrix_cell_space_bottom_limit_dim ,
  377. cell-space-bottom-limit .value_required:n = true ,
  378. xdots .code:n = \keys_set:nn { NiceMatrix / xdots } { #1 } ,
  379. max-delimiter-width .bool_set:N = \l__nicematrix_max_delimiter_width_bool ,
  380. light-syntax .bool_set:N = \l__nicematrix_light_syntax_bool ,
  381. light-syntax .default:n = true ,
  382. end-of-row .tl_set:N = \l__nicematrix_end_of_row_tl ,
  383. end-of-row .value_required:n = true ,
  384. first-col .code:n = \int_zero:N \l__nicematrix_first_col_int ,
  385. first-row .code:n = \int_zero:N \l__nicematrix_first_row_int ,
  386. last-row .int_set:N = \l__nicematrix_last_row_int ,
  387. last-row .default:n = -1 ,
  388. code-for-first-col .tl_set:N = \l__nicematrix_code_for_first_col_tl ,
  389. code-for-first-col .value_required:n = true ,
  390. code-for-last-col .tl_set:N = \l__nicematrix_code_for_last_col_tl ,
  391. code-for-last-col .value_required:n = true ,
  392. code-for-first-row .tl_set:N = \l__nicematrix_code_for_first_row_tl ,
  393. code-for-first-row .value_required:n = true ,
  394. code-for-last-row .tl_set:N = \l__nicematrix_code_for_last_row_tl ,
  395. code-for-last-row .value_required:n = true ,
  396. hlines .bool_set:N = \l__nicematrix_hlines_bool ,
  397. vlines .bool_set:N = \l__nicematrix_vlines_bool ,
  398. hvlines .meta:n = { hlines , vlines } ,
  399. parallelize-diags .bool_set:N = \l__nicematrix_parallelize_diags_bool ,
  400. renew-dots .bool_set:N = \l__nicematrix_renew_dots_bool ,
  401. renew-dots .value_forbidden:n = true ,
  402. nullify-dots .bool_set:N = \l__nicematrix_nullify_dots_bool ,
  403. create-medium-nodes .bool_set:N = \l__nicematrix_medium_nodes_bool ,
  404. create-large-nodes .bool_set:N = \l__nicematrix_large_nodes_bool ,
  405. create-extra-nodes .meta:n =
  406. { create-medium-nodes , create-large-nodes } ,
  407. left-margin .dim_set:N = \l__nicematrix_left_margin_dim ,
  408. left-margin .default:n = \arraycolsep ,
  409. right-margin .dim_set:N = \l__nicematrix_right_margin_dim ,
  410. right-margin .default:n = \arraycolsep ,
  411. margin .meta:n = { left-margin = #1 , right-margin = #1 } ,
  412. margin .default:n = \arraycolsep ,
  413. extra-left-margin .dim_set:N = \l__nicematrix_extra_left_margin_dim ,
  414. extra-right-margin .dim_set:N = \l__nicematrix_extra_right_margin_dim ,
  415. extra-margin .meta:n =
  416. { extra-left-margin = #1 , extra-right-margin = #1 } ,
  417. extra-margin .value_required:n = true
  418. }
  419. \keys_define:nn { NiceMatrix / Env }
  420. {
  421. code-before .code:n =
  422. {
  423. \tl_if_empty:nF { #1 }
  424. {
  425. \tl_set:Nn \l__nicematrix_code_before_tl { #1 }
  426. \bool_set_true:N \l__nicematrix_code_before_bool
  427. }
  428. } ,
  429. c .code:n = \str_set:Nn \l__nicematrix_baseline_str c ,
  430. t .code:n = \str_set:Nn \l__nicematrix_baseline_str t ,
  431. b .code:n = \str_set:Nn \l__nicematrix_baseline_str b ,
  432. baseline .tl_set:N = \l__nicematrix_baseline_str ,
  433. baseline .value_required:n = true ,
  434. columns-width .code:n =
  435. \str_if_eq:nnTF { #1 } { auto }
  436. { \bool_set_true:N \l__nicematrix_auto_columns_width_bool }
  437. { \dim_set:Nn \l__nicematrix_columns_width_dim { #1 } } ,
  438. columns-width .value_required:n = true ,
  439. name .code:n =
  440. \legacy_if:nF { measuring@ }
  441. {
  442. \str_set:Nn \l_tmpa_str { #1 }
  443. \seq_if_in:NVTF \g__nicematrix_names_seq \l_tmpa_str
  444. { \__nicematrix_error:nn { Duplicate~name } { #1 } }
  445. { \seq_gput_left:NV \g__nicematrix_names_seq \l_tmpa_str }
  446. \str_set_eq:NN \l__nicematrix_name_str \l_tmpa_str
  447. } ,
  448. name .value_required:n = true ,
  449. code-after .tl_gset:N = \g__nicematrix_code_after_tl ,
  450. code-after .value_required:n = true ,
  451. }
  452. \keys_define:nn { NiceMatrix }
  453. {
  454. NiceMatrixOptions .inherit:n =
  455. {
  456. NiceMatrix / Global ,
  457. } ,
  458. NiceMatrixOptions / xdots .inherit:n = NiceMatrix / xdots ,
  459. NiceMatrix .inherit:n =
  460. {
  461. NiceMatrix / Global ,
  462. NiceMatrix / Env ,
  463. } ,
  464. NiceMatrix / xdots .inherit:n = NiceMatrix / xdots ,
  465. NiceTabular .inherit:n =
  466. {
  467. NiceMatrix / Global ,
  468. NiceMatrix / Env
  469. } ,
  470. NiceTabular / xdots .inherit:n = NiceMatrix / xdots ,
  471. NiceArray .inherit:n =
  472. {
  473. NiceMatrix / Global ,
  474. NiceMatrix / Env ,
  475. } ,
  476. NiceArray / xdots .inherit:n = NiceMatrix / xdots ,
  477. pNiceArray .inherit:n =
  478. {
  479. NiceMatrix / Global ,
  480. NiceMatrix / Env ,
  481. } ,
  482. pNiceArray / xdots .inherit:n = NiceMatrix / xdots
  483. }
  484. \keys_define:nn { NiceMatrix / NiceMatrixOptions }
  485. {
  486. standard-cline .code:n =
  487. \ifx \@onlypreamble \@notprerr
  488. \__nicematrix_error:n { standard-cline~in~document }
  489. \else
  490. \bool_set_true:N \c__nicematrix_standard_cline_bool
  491. \fi ,
  492. standard-cline .value_forbidden:n = true ,
  493. last-col .code:n = \tl_if_empty:nF { #1 }
  494. { \__nicematrix_error:n { last-col~non~empty~for~NiceMatrixOptions } }
  495. \int_zero:N \l__nicematrix_last_col_int ,
  496. small .bool_set:N = \l__nicematrix_small_bool ,
  497. small .value_forbidden:n = true ,
  498. renew-matrix .code:n = \__nicematrix_renew_matrix: ,
  499. renew-matrix .value_forbidden:n = true ,
  500. transparent .meta:n = { renew-dots , renew-matrix } ,
  501. transparent .value_forbidden:n = true,
  502. exterior-arraycolsep .bool_set:N = \l__nicematrix_exterior_arraycolsep_bool ,
  503. columns-width .code:n =
  504. \str_if_eq:nnTF { #1 } { auto }
  505. { \__nicematrix_error:n { Option~auto~for~columns-width } }
  506. { \dim_set:Nn \l__nicematrix_columns_width_dim { #1 } } ,
  507. allow-duplicate-names .code:n =
  508. \__nicematrix_msg_redirect_name:nn { Duplicate~name } { none } ,
  509. allow-duplicate-names .value_forbidden:n = true ,
  510. letter-for-dotted-lines .code:n =
  511. {
  512. \int_compare:nTF { \tl_count:n { #1 } = 1 }
  513. { \str_set:Nx \l__nicematrix_letter_for_dotted_lines_str { #1 } }
  514. { \__nicematrix_error:n { Bad~value~for~letter~for~dotted~lines } }
  515. } ,
  516. letter-for-dotted-lines .value_required:n = true ,
  517. unknown .code:n = \__nicematrix_error:n { Unknown~key~for~NiceMatrixOptions }
  518. }
  519. \str_new:N \l__nicematrix_letter_for_dotted_lines_str
  520. \str_set_eq:NN \l__nicematrix_letter_for_dotted_lines_str \c_colon_str
  521. \NewDocumentCommand \NiceMatrixOptions { m }
  522. { \keys_set:nn { NiceMatrix / NiceMatrixOptions } { #1 } }
  523. \keys_define:nn { NiceMatrix / NiceMatrix }
  524. {
  525. last-col .code:n = \tl_if_empty:nTF {#1}
  526. {
  527. \bool_set_true:N \l__nicematrix_last_col_without_value_bool
  528. \int_set:Nn \l__nicematrix_last_col_int { -1 }
  529. }
  530. { \int_set:Nn \l__nicematrix_last_col_int { #1 } } ,
  531. l .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl L ,
  532. r .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl R ,
  533. L .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl L ,
  534. R .code:n = \tl_set:Nn \l__nicematrix_type_of_col_tl R ,
  535. S .code:n = \bool_if:NTF \c__nicematrix_siunitx_loaded_bool
  536. { \tl_set:Nn \l__nicematrix_type_of_col_tl S }
  537. { \__nicematrix_error:n { option~S~without~siunitx } } ,
  538. small .bool_set:N = \l__nicematrix_small_bool ,
  539. small .value_forbidden:n = true ,
  540. unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceMatrix }
  541. }
  542. \keys_define:nn { NiceMatrix / NiceArray }
  543. {
  544. small .bool_set:N = \l__nicematrix_small_bool ,
  545. small .value_forbidden:n = true ,
  546. last-col .code:n = \tl_if_empty:nF { #1 }
  547. { \__nicematrix_error:n { last-col~non~empty~for~NiceArray } }
  548. \int_zero:N \l__nicematrix_last_col_int ,
  549. unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceArray }
  550. }
  551. \keys_define:nn { NiceMatrix / pNiceArray }
  552. {
  553. first-col .code:n = \int_zero:N \l__nicematrix_first_col_int ,
  554. last-col .code:n = \tl_if_empty:nF {#1}
  555. { \__nicematrix_error:n { last-col~non~empty~for~NiceArray } }
  556. \int_zero:N \l__nicematrix_last_col_int ,
  557. first-row .code:n = \int_zero:N \l__nicematrix_first_row_int ,
  558. small .bool_set:N = \l__nicematrix_small_bool ,
  559. small .value_forbidden:n = true ,
  560. unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceMatrix }
  561. }
  562. \keys_define:nn { NiceMatrix / NiceTabular }
  563. {
  564. last-col .code:n = \tl_if_empty:nF {#1}
  565. { \__nicematrix_error:n { last-col~non~empty~for~NiceArray } }
  566. \int_zero:N \l__nicematrix_last_col_int ,
  567. unknown .code:n = \__nicematrix_error:n { Unknown~option~for~NiceTabular }
  568. }
  569. \cs_new_protected:Npn \__nicematrix_Cell:
  570. {
  571. \int_gincr:N \c@jCol
  572. \int_compare:nNnT \c@jCol = 1
  573. { \int_compare:nNnT \l__nicematrix_first_col_int = 1 \__nicematrix_begin_of_row: }
  574. \int_gset:Nn \g__nicematrix_col_total_int { \int_max:nn \g__nicematrix_col_total_int \c@jCol }
  575. \hbox_set:Nw \l__nicematrix_cell_box
  576. \bool_if:NF \l__nicematrix_NiceTabular_bool
  577. {
  578. \c_math_toggle_token
  579. \bool_if:NT \l__nicematrix_small_bool \scriptstyle
  580. }
  581. \int_compare:nNnTF \c@iRow = 0
  582. {
  583. \int_compare:nNnT \c@jCol > 0
  584. {
  585. \l__nicematrix_code_for_first_row_tl
  586. \xglobal \colorlet { nicematrix-first-row } { . }
  587. }
  588. }
  589. {
  590. \int_compare:nNnT \c@iRow = \l__nicematrix_last_row_int
  591. {
  592. \l__nicematrix_code_for_last_row_tl
  593. \xglobal \colorlet { nicematrix-last-row } { . }
  594. }
  595. }
  596. }
  597. \cs_new_protected:Npn \__nicematrix_begin_of_row:
  598. {
  599. \int_gincr:N \c@iRow
  600. \dim_gset_eq:NN \g__nicematrix_dp_ante_last_row_dim \g__nicematrix_dp_last_row_dim
  601. \dim_gset:Nn \g__nicematrix_dp_last_row_dim { \box_dp:N \@arstrutbox }
  602. \dim_gset:Nn \g__nicematrix_ht_last_row_dim { \box_ht:N \@arstrutbox }
  603. \pgfpicture
  604. \pgfrememberpicturepositiononpagetrue
  605. \pgfcoordinate
  606. { \__nicematrix_env: - row - \int_use:N \c@iRow - base }
  607. { \pgfpoint \c_zero_dim { 0.5 \arrayrulewidth } }
  608. \str_if_empty:NF \l__nicematrix_name_str
  609. {
  610. \pgfnodealias
  611. { \l__nicematrix_name_str - row - \int_use:N \c@iRow - base }
  612. { \__nicematrix_env: - row - \int_use:N \c@iRow - base }
  613. }
  614. \endpgfpicture
  615. }
  616. \cs_new_protected:Npn \__nicematrix_update_for_first_and_last_row:
  617. {
  618. \int_compare:nNnTF \c@iRow = 0
  619. {
  620. \dim_gset:Nn \g__nicematrix_dp_row_zero_dim
  621. { \dim_max:nn \g__nicematrix_dp_row_zero_dim { \box_dp:N \l__nicematrix_cell_box } }
  622. \dim_gset:Nn \g__nicematrix_ht_row_zero_dim
  623. { \dim_max:nn \g__nicematrix_ht_row_zero_dim { \box_ht:N \l__nicematrix_cell_box } }
  624. }
  625. {
  626. \int_compare:nNnT \c@iRow = 1
  627. {
  628. \dim_gset:Nn \g__nicematrix_ht_row_one_dim
  629. { \dim_max:nn \g__nicematrix_ht_row_one_dim { \box_ht:N \l__nicematrix_cell_box } }
  630. }
  631. }
  632. }
  633. \cs_new_protected:Npn \__nicematrix_end_Cell:
  634. {
  635. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  636. \hbox_set_end:
  637. \box_set_ht:Nn \l__nicematrix_cell_box
  638. { \box_ht:N \l__nicematrix_cell_box + \l__nicematrix_cell_space_top_limit_dim }
  639. \box_set_dp:Nn \l__nicematrix_cell_box
  640. { \box_dp:N \l__nicematrix_cell_box + \l__nicematrix_cell_space_bottom_limit_dim }
  641. \dim_gset:Nn \g__nicematrix_max_cell_width_dim
  642. { \dim_max:nn \g__nicematrix_max_cell_width_dim { \box_wd:N \l__nicematrix_cell_box } }
  643. \__nicematrix_update_for_first_and_last_row:
  644. \bool_if:NTF \g__nicematrix_empty_cell_bool
  645. { \box_use_drop:N \l__nicematrix_cell_box }
  646. {
  647. \dim_compare:nNnTF { \box_wd:N \l__nicematrix_cell_box } > \c_zero_dim
  648. \__nicematrix_node_for_the_cell:
  649. { \box_use_drop:N \l__nicematrix_cell_box }
  650. }
  651. \bool_gset_false:N \g__nicematrix_empty_cell_bool
  652. }
  653. \cs_new_protected:Npn \__nicematrix_node_for_the_cell:
  654. {
  655. \pgfpicture
  656. \pgfsetbaseline \c_zero_dim
  657. \pgfrememberpicturepositiononpagetrue
  658. \pgfset
  659. {
  660. inner~sep = \c_zero_dim ,
  661. minimum~width = \c_zero_dim
  662. }
  663. \pgfnode
  664. { rectangle }
  665. { base }
  666. { \box_use_drop:N \l__nicematrix_cell_box }
  667. { \__nicematrix_env: - \int_use:N \c@iRow - \int_use:N \c@jCol }
  668. { }
  669. \str_if_empty:NF \l__nicematrix_name_str
  670. {
  671. \pgfnodealias
  672. { \l__nicematrix_name_str - \int_use:N \c@iRow - \int_use:N \c@jCol }
  673. { \__nicematrix_env: - \int_use:N \c@iRow - \int_use:N \c@jCol }
  674. }
  675. \endpgfpicture
  676. }
  677. \cs_new_protected:Npn \__nicematrix_instruction_of_type:nn #1 #2
  678. {
  679. \tl_gput_right:cx
  680. { g__nicematrix_ #1 _ lines _ tl }
  681. {
  682. \use:c { __nicematrix _ draw _ #1 : nnn }
  683. { \int_use:N \c@iRow }
  684. { \int_use:N \c@jCol }
  685. { \exp_not:n { #2 } }
  686. }
  687. }
  688. \cs_new_protected:Npn \__nicematrix_array:
  689. {
  690. \bool_if:NTF \c__nicematrix_revtex_bool
  691. {
  692. \cs_set_eq:NN \@acoll \@arrayacol
  693. \cs_set_eq:NN \@acolr \@arrayacol
  694. \cs_set_eq:NN \@acol \@arrayacol
  695. \cs_set:Npn \@halignto { }
  696. \@array@array
  697. }
  698. \array
  699. [ \str_if_eq:VnTF \l__nicematrix_baseline_str c c t ]
  700. }
  701. \cs_set_eq:NN \__nicematrix_old_ialign: \ialign
  702. \cs_new_protected:Npn \__nicematrix_create_row_node:
  703. {
  704. \hbox
  705. {
  706. \bool_if:NT \l__nicematrix_code_before_bool
  707. {
  708. \vtop
  709. {
  710. \skip_vertical:N 0.5\arrayrulewidth
  711. \pgfsys@markposition { \__nicematrix_env: - row - \__nicematrix_succ:n \c@iRow }
  712. \skip_vertical:N -0.5\arrayrulewidth
  713. }
  714. }
  715. \pgfpicture
  716. \pgfrememberpicturepositiononpagetrue
  717. \pgfcoordinate { \__nicematrix_env: - row - \__nicematrix_succ:n \c@iRow }
  718. { \pgfpoint \c_zero_dim { - 0.5 \arrayrulewidth } }
  719. \str_if_empty:NF \l__nicematrix_name_str
  720. {
  721. \pgfnodealias
  722. { \l__nicematrix_name_str - row - \int_use:N \c@iRow }
  723. { \__nicematrix_env: - row - \int_use:N \c@iRow }
  724. }
  725. \endpgfpicture
  726. }
  727. }
  728. \cs_new:Npn \__nicematrix_everycr: { \noalign { \__nicematrix_everycr_i: } }
  729. \cs_new_protected:Npn \__nicematrix_everycr_i:
  730. {
  731. \int_gzero:N \c@jCol
  732. \bool_if:NF \g__nicematrix_row_of_col_done_bool
  733. {
  734. \__nicematrix_create_row_node:
  735. \bool_if:NT \l__nicematrix_hlines_bool
  736. {
  737. \int_compare:nNnT \c@iRow > { -1 }
  738. {
  739. \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int
  740. { { \CT@arc@ \hrule height \arrayrulewidth } }
  741. }
  742. }
  743. }
  744. }
  745. \cs_set_protected:Npn \__nicematrix_newcolumntype #1
  746. {
  747. \cs_if_free:cT { NC @ find @ #1 }
  748. { \NC@list \expandafter { \the \NC@list \NC@do #1 } }
  749. \cs_set:cpn {NC @ find @ #1 } ##1 #1 { \NC@ { ##1 } }
  750. \peek_meaning:NTF [
  751. { \newcol@ #1 }
  752. { \newcol@ #1 [ 0 ] }
  753. }
  754. \cs_new_protected:Npn \__nicematrix_define_columntype:nn #1 #2
  755. {
  756. \__nicematrix_newcolumntype #1 [ 1 ]
  757. {
  758. > {
  759. \__nicematrix_Cell:
  760. \begin { minipage } [ #2 ] { ##1 }
  761. \mode_leave_vertical: \box_use:N \@arstrutbox
  762. }
  763. c
  764. < { \box_use:N \@arstrutbox \end { minipage } \__nicematrix_end_Cell: }
  765. }
  766. }
  767. \cs_new_protected:Npn \__nicematrix_pre_array:
  768. {
  769. \bool_if:NT \c__nicematrix_booktabs_loaded_bool
  770. { \tl_put_left:Nn \@BTnormal \__nicematrix_create_row_node: }
  771. \box_clear_new:N \l__nicematrix_cell_box
  772. \cs_if_exist:NT \theiRow
  773. { \int_set_eq:NN \l__nicematrix_old_iRow_int \c@iRow }
  774. \int_gzero_new:N \c@iRow
  775. \cs_if_exist:NT \thejCol
  776. { \int_set_eq:NN \l__nicematrix_old_jCol_int \c@jCol }
  777. \int_gzero_new:N \c@jCol
  778. \normalbaselines
  779. \bool_if:NT \l__nicematrix_small_bool
  780. {
  781. \cs_set:Npn \arraystretch { 0.47 }
  782. \dim_set:Nn \arraycolsep { 1.45 pt }
  783. }
  784. \cs_set:Npn \ialign
  785. {
  786. \bool_if:NT \l__nicematrix_NiceTabular_bool
  787. { \dim_set_eq:NN \arraycolsep \__nicematrix_old_arraycolsep_dim }
  788. \bool_if:NTF \c__nicematrix_colortbl_loaded_bool
  789. {
  790. \CT@everycr
  791. {
  792. \noalign { \cs_gset_eq:NN \CT@row@color \prg_do_nothing: }
  793. \__nicematrix_everycr:
  794. }
  795. }
  796. { \everycr { \__nicematrix_everycr: } }
  797. \tabskip = \c_zero_skip
  798. \dim_gzero_new:N \g__nicematrix_dp_row_zero_dim
  799. \dim_gset:Nn \g__nicematrix_dp_row_zero_dim { \box_dp:N \@arstrutbox }
  800. \dim_gzero_new:N \g__nicematrix_ht_row_zero_dim
  801. \dim_gset:Nn \g__nicematrix_ht_row_zero_dim { \box_ht:N \@arstrutbox }
  802. \dim_gzero_new:N \g__nicematrix_ht_row_one_dim
  803. \dim_gset:Nn \g__nicematrix_ht_row_one_dim { \box_ht:N \@arstrutbox }
  804. \dim_gzero_new:N \g__nicematrix_dp_ante_last_row_dim
  805. \dim_gzero_new:N \g__nicematrix_ht_last_row_dim
  806. \dim_gset:Nn \g__nicematrix_ht_last_row_dim { \box_ht:N \@arstrutbox }
  807. \dim_gzero_new:N \g__nicematrix_dp_last_row_dim
  808. \dim_gset:Nn \g__nicematrix_dp_last_row_dim { \box_dp:N \@arstrutbox }
  809. \cs_set_eq:NN \ialign \__nicematrix_old_ialign:
  810. \halign
  811. }
  812. \cs_set_eq:NN \__nicematrix_old_ldots \ldots
  813. \cs_set_eq:NN \__nicematrix_old_cdots \cdots
  814. \cs_set_eq:NN \__nicematrix_old_vdots \vdots
  815. \cs_set_eq:NN \__nicematrix_old_ddots \ddots
  816. \cs_set_eq:NN \__nicematrix_old_iddots \iddots
  817. \cs_set_eq:NN \firsthline \hline
  818. \cs_set_eq:NN \lasthline \hline
  819. \cs_set_eq:NN \cline \__nicematrix_cline
  820. \cs_set_eq:NN \Ldots \__nicematrix_Ldots
  821. \cs_set_eq:NN \Cdots \__nicematrix_Cdots
  822. \cs_set_eq:NN \Vdots \__nicematrix_Vdots
  823. \cs_set_eq:NN \Ddots \__nicematrix_Ddots
  824. \cs_set_eq:NN \Iddots \__nicematrix_Iddots
  825. \cs_set_eq:NN \hdottedline \__nicematrix_hdottedline:
  826. \cs_set_eq:NN \Hspace \__nicematrix_Hspace:
  827. \cs_set_eq:NN \Hdotsfor \__nicematrix_Hdotsfor:
  828. \cs_set_eq:NN \Vdotsfor \__nicematrix_Vdotsfor:
  829. \cs_set_eq:NN \multicolumn \__nicematrix_multicolumn:nnn
  830. \cs_set_eq:NN \Block \__nicematrix_Block:
  831. \cs_set_eq:NN \rotate \__nicematrix_rotate:
  832. \cs_set_eq:NN \OnlyMainNiceMatrix \__nicematrix_OnlyMainNiceMatrix:n
  833. \cs_set_eq:NN \dotfill \__nicematrix_dotfill:
  834. \cs_set_eq:NN \CodeAfter \__nicematrix_CodeAfter:n
  835. \cs_set_eq:NN \diagbox \__nicematrix_diagbox:nn
  836. \bool_if:NT \l__nicematrix_renew_dots_bool
  837. {
  838. \cs_set_eq:NN \ldots \__nicematrix_Ldots
  839. \cs_set_eq:NN \cdots \__nicematrix_Cdots
  840. \cs_set_eq:NN \vdots \__nicematrix_Vdots
  841. \cs_set_eq:NN \ddots \__nicematrix_Ddots
  842. \cs_set_eq:NN \iddots \__nicematrix_Iddots
  843. \cs_set_eq:NN \dots \__nicematrix_Ldots
  844. \cs_set_eq:NN \hdotsfor \__nicematrix_Hdotsfor:
  845. }
  846. \seq_gclear_new:N \g__nicematrix_multicolumn_cells_seq
  847. \seq_gclear_new:N \g__nicematrix_multicolumn_sizes_seq
  848. \int_gset:Nn \c@iRow { \l__nicematrix_first_row_int - 1 }
  849. \int_gzero_new:N \g__nicematrix_row_total_int
  850. \int_gzero_new:N \g__nicematrix_col_total_int
  851. \cs_set_eq:NN \@ifnextchar \new@ifnextchar
  852. \__nicematrix_newcolumntype L { > \__nicematrix_Cell: l < \__nicematrix_end_Cell: }
  853. \__nicematrix_newcolumntype C { > \__nicematrix_Cell: c < \__nicematrix_end_Cell: }
  854. \__nicematrix_newcolumntype R { > \__nicematrix_Cell: r < \__nicematrix_end_Cell: }
  855. \__nicematrix_define_columntype:nn p t
  856. \__nicematrix_define_columntype:nn m c
  857. \__nicematrix_define_columntype:nn b b
  858. \__nicematrix_newcolumntype w [ 2 ]
  859. {
  860. > {
  861. \hbox_set:Nw \l__nicematrix_cell_box
  862. \__nicematrix_Cell:
  863. }
  864. c
  865. < {
  866. \__nicematrix_end_Cell:
  867. \hbox_set_end:
  868. \makebox [ ##2 ] [ \str_lowercase:n { ##1 } ]
  869. { \box_use_drop:N \l__nicematrix_cell_box }
  870. }
  871. }
  872. \__nicematrix_newcolumntype W [ 2 ]
  873. {
  874. > {
  875. \hbox_set:Nw \l__nicematrix_cell_box
  876. \__nicematrix_Cell:
  877. }
  878. c
  879. < {
  880. \__nicematrix_end_Cell:
  881. \hbox_set_end:
  882. \cs_set_eq:NN \hss \hfil
  883. \makebox [ ##2 ] [ \str_lowercase:n { ##1 } ]
  884. { \box_use_drop:N \l__nicematrix_cell_box }
  885. }
  886. }
  887. \tl_set_rescan:Nno
  888. \l__nicematrix_letter_for_dotted_lines_str { } \l__nicematrix_letter_for_dotted_lines_str
  889. \exp_args:NV \newcolumntype \l__nicematrix_letter_for_dotted_lines_str
  890. {
  891. !
  892. {
  893. \int_compare:nNnF \c@iRow = 0
  894. {
  895. \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int
  896. { \skip_horizontal:N 2\l__nicematrix_radius_dim }
  897. }
  898. \int_compare:nNnT \c@jCol > \g__nicematrix_last_vdotted_col_int
  899. {
  900. \int_gset_eq:NN \g__nicematrix_last_vdotted_col_int \c@jCol
  901. \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl
  902. { \__nicematrix_vdottedline:n { \int_use:N \c@jCol } }
  903. }
  904. }
  905. }
  906. \int_gzero_new:N \g__nicematrix_last_vdotted_col_int
  907. \bool_if:NT \c__nicematrix_siunitx_loaded_bool \__nicematrix_renew_NC@rewrite@S:
  908. \int_gset:Nn \g__nicematrix_last_vdotted_col_int { -1 }
  909. \bool_gset_false:N \g__nicematrix_last_col_found_bool
  910. \tl_gclear_new:N \g__nicematrix_Cdots_lines_tl
  911. \tl_gclear_new:N \g__nicematrix_Ldots_lines_tl
  912. \tl_gclear_new:N \g__nicematrix_Vdots_lines_tl
  913. \tl_gclear_new:N \g__nicematrix_Ddots_lines_tl
  914. \tl_gclear_new:N \g__nicematrix_Iddots_lines_tl
  915. \tl_gclear_new:N \g__nicematrix_HVdotsfor_lines_tl
  916. }
  917. \NewDocumentEnvironment { NiceArrayWithDelims } { m m O { } m ! O { } }
  918. {
  919. \tl_set:Nn \l__nicematrix_left_delim_tl { #1 }
  920. \tl_set:Nn \l__nicematrix_right_delim_tl { #2 }
  921. \bool_gset_false:N \g__nicematrix_row_of_col_done_bool
  922. \str_if_empty:NT \g__nicematrix_name_env_str
  923. { \str_gset:Nn \g__nicematrix_name_env_str { NiceArrayWithDelims } }
  924. \__nicematrix_adapt_S_column:
  925. \bool_if:NTF \l__nicematrix_NiceTabular_bool
  926. \mode_leave_vertical:
  927. \__nicematrix_test_if_math_mode:
  928. \bool_if:NT \l__nicematrix_in_env_bool { \__nicematrix_fatal:n { Yet~in~env } }
  929. \bool_set_true:N \l__nicematrix_in_env_bool
  930. \bool_if:NF \c__nicematrix_colortbl_loaded_bool
  931. { \cs_set_eq:NN \__nicematrix_old_CT@arc@ \CT@arc@ }
  932. \cs_if_exist:NT \tikz@library@external@loaded
  933. {
  934. \tikzset { external / export = false }
  935. \cs_if_exist:NT \ifstandalone
  936. { \tikzset { external / optimize = false } }
  937. }
  938. \int_gincr:N \g__nicematrix_env_int
  939. \bool_if:NF \l__nicematrix_block_auto_columns_width_bool
  940. { \dim_gzero_new:N \g__nicematrix_max_cell_width_dim }
  941. \cs_set_protected:Npn \@arrayrule { \@addtopreamble \__nicematrix_vline: }
  942. \bool_if:NTF \l__nicematrix_NiceArray_bool
  943. { \keys_set:nn { NiceMatrix / NiceArray } }
  944. { \keys_set:nn { NiceMatrix / pNiceArray } }
  945. { #3 , #5 }
  946. \bool_if:NT \l__nicematrix_code_before_bool
  947. {
  948. \seq_if_exist:cT { __nicematrix_size_ \int_use:N \g__nicematrix_env_int _ seq }
  949. {
  950. \int_zero_new:N \c@iRow
  951. \int_set:Nn \c@iRow
  952. { \seq_item:cn { __nicematrix_size_ \int_use:N \g__nicematrix_env_int _ seq } 2 }
  953. \int_zero_new:N \c@jCol
  954. \int_set:Nn \c@jCol
  955. { \seq_item:cn { __nicematrix_size_ \int_use:N \g__nicematrix_env_int _ seq } 4 }
  956. \int_compare:nNnF \l__nicematrix_last_row_int = { -2 }
  957. { \int_decr:N \c@iRow }
  958. \int_compare:nNnF \l__nicematrix_last_col_int = { -2 }
  959. { \int_decr:N \c@jCol }
  960. \pgfsys@markposition { \__nicematrix_env: - position }
  961. \pgfsys@getposition { \__nicematrix_env: - position } \__nicematrix_picture_position:
  962. \pgfpicture
  963. \int_step_inline:nnn
  964. { \seq_item:cn { __nicematrix_size_ \int_use:N \g__nicematrix_env_int _ seq } 1 }
  965. { \seq_item:cn { __nicematrix_size_ \int_use:N \g__nicematrix_env_int _ seq } 2 + 1 }
  966. {
  967. \pgfsys@getposition { \__nicematrix_env: - row - ##1 } \__nicematrix_node_position:
  968. \pgfcoordinate { \__nicematrix_env: - row - ##1 }
  969. { \pgfpointdiff \__nicematrix_picture_position: \__nicematrix_node_position: }
  970. }
  971. \int_step_inline:nnn
  972. { \seq_item:cn { __nicematrix_size_ \int_use:N \g__nicematrix_env_int _ seq } 3 }
  973. { \seq_item:cn { __nicematrix_size_ \int_use:N \g__nicematrix_env_int _ seq } 4 + 1 }
  974. {
  975. \pgfsys@getposition { \__nicematrix_env: - col - ##1 } \__nicematrix_node_position:
  976. \pgfcoordinate { \__nicematrix_env: - col - ##1 }
  977. { \pgfpointdiff \__nicematrix_picture_position: \__nicematrix_node_position: }
  978. }
  979. \endpgfpicture
  980. \group_begin:
  981. \bool_if:NT \c__nicematrix_tikz_loaded_bool
  982. {
  983. \pgfset
  984. {
  985. every~picture / .style =
  986. { overlay , name~prefix = \__nicematrix_env: - }
  987. }
  988. }
  989. \cs_set_eq:NN \cellcolor \__nicematrix_cellcolor
  990. \cs_set_eq:NN \rectanglecolor \__nicematrix_rectanglecolor
  991. \cs_set_eq:NN \rowcolor \__nicematrix_rowcolor
  992. \cs_set_eq:NN \rowcolors \__nicematrix_rowcolors
  993. \cs_set_eq:NN \columncolor \__nicematrix_columncolor
  994. \cs_set_eq:NN \chessboardcolors \__nicematrix_chessboardcolors
  995. \bool_if:NT \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  996. \l__nicematrix_code_before_tl
  997. \bool_if:NT \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  998. \group_end:
  999. }
  1000. }
  1001. \int_compare:nNnT \l__nicematrix_last_row_int > { -2 }
  1002. {
  1003. \tl_put_right:Nn \__nicematrix_update_for_first_and_last_row:
  1004. {
  1005. \dim_gset:Nn \g__nicematrix_ht_last_row_dim
  1006. { \dim_max:nn \g__nicematrix_ht_last_row_dim { \box_ht:N \l__nicematrix_cell_box } }
  1007. \dim_gset:Nn \g__nicematrix_dp_last_row_dim
  1008. { \dim_max:nn \g__nicematrix_dp_last_row_dim { \box_dp:N \l__nicematrix_cell_box } }
  1009. }
  1010. }
  1011. \int_compare:nNnT \l__nicematrix_last_row_int = { -1 }
  1012. {
  1013. \bool_set_true:N \l__nicematrix_last_row_without_value_bool
  1014. \str_if_empty:NTF \l__nicematrix_name_str
  1015. {
  1016. \cs_if_exist:cT { __nicematrix_last_row_ \int_use:N \g__nicematrix_env_int }
  1017. {
  1018. \int_set:Nn \l__nicematrix_last_row_int
  1019. { \use:c { __nicematrix_last_row_ \int_use:N \g__nicematrix_env_int } }
  1020. }
  1021. }
  1022. {
  1023. \cs_if_exist:cT { __nicematrix_last_row_ \l__nicematrix_name_str }
  1024. {
  1025. \int_set:Nn \l__nicematrix_last_row_int
  1026. { \use:c { __nicematrix_last_row_ \l__nicematrix_name_str } }
  1027. }
  1028. }
  1029. }
  1030. \int_compare:nNnT \l__nicematrix_last_col_int = { -1 }
  1031. {
  1032. \str_if_empty:NTF \l__nicematrix_name_str
  1033. {
  1034. \cs_if_exist:cT { __nicematrix_last_col_ \int_use:N \g__nicematrix_env_int }
  1035. {
  1036. \int_set:Nn \l__nicematrix_last_col_int
  1037. { \use:c { __nicematrix_last_col_ \int_use:N \g__nicematrix_env_int } }
  1038. }
  1039. }
  1040. {
  1041. \cs_if_exist:cT { __nicematrix_last_col_ \l__nicematrix_name_str }
  1042. {
  1043. \int_set:Nn \l__nicematrix_last_col_int
  1044. { \use:c { __nicematrix_last_col_ \l__nicematrix_name_str } }
  1045. }
  1046. }
  1047. }
  1048. \__nicematrix_pre_array:
  1049. \dim_zero_new:N \l__nicematrix_left_delim_dim
  1050. \dim_zero_new:N \l__nicematrix_right_delim_dim
  1051. \bool_if:NTF \l__nicematrix_NiceArray_bool
  1052. {
  1053. \dim_gset:Nn \l__nicematrix_left_delim_dim { 2 \arraycolsep }
  1054. \dim_gset:Nn \l__nicematrix_right_delim_dim { 2 \arraycolsep }
  1055. }
  1056. {
  1057. \hbox_set:Nn \l_tmpa_box { $ \bBigg@ 5 #1 $ }
  1058. \dim_set:Nn \l__nicematrix_left_delim_dim { \box_wd:N \l_tmpa_box }
  1059. \hbox_set:Nn \l_tmpa_box { $\bBigg@ 5 #2 $ }
  1060. \dim_set:Nn \l__nicematrix_right_delim_dim { \box_wd:N \l_tmpa_box }
  1061. }
  1062. \box_clear_new:N \l__nicematrix_the_array_box
  1063. \tl_set:Nn \l_tmpa_tl { #4 }
  1064. \int_compare:nNnTF \l__nicematrix_first_col_int = 0
  1065. { \tl_put_left:NV \l_tmpa_tl \c__nicematrix_preamble_first_col_tl }
  1066. {
  1067. \bool_lazy_all:nT
  1068. {
  1069. \l__nicematrix_NiceArray_bool
  1070. { \bool_not_p:n \l__nicematrix_NiceTabular_bool }
  1071. { \bool_not_p:n \l__nicematrix_vlines_bool }
  1072. { \bool_not_p:n \l__nicematrix_exterior_arraycolsep_bool }
  1073. }
  1074. { \tl_put_left:Nn \l_tmpa_tl { @ { } } }
  1075. }
  1076. \int_compare:nNnTF \l__nicematrix_last_col_int > { -1 }
  1077. { \tl_put_right:NV \l_tmpa_tl \c__nicematrix_preamble_last_col_tl }
  1078. {
  1079. \bool_lazy_all:nT
  1080. {
  1081. \l__nicematrix_NiceArray_bool
  1082. { \bool_not_p:n \l__nicematrix_NiceTabular_bool }
  1083. { \bool_not_p:n \l__nicematrix_vlines_bool }
  1084. { \bool_not_p:n \l__nicematrix_exterior_arraycolsep_bool }
  1085. }
  1086. { \tl_put_right:Nn \l_tmpa_tl { @ { } } }
  1087. }
  1088. \tl_put_right:Nn \l_tmpa_tl { > { \__nicematrix_error_too_much_cols: } L }
  1089. \hbox_set:Nw \l__nicematrix_the_array_box
  1090. \bool_if:NT \l__nicematrix_NiceTabular_bool
  1091. {
  1092. \dim_set_eq:NN \__nicematrix_old_arraycolsep_dim \arraycolsep
  1093. \dim_set_eq:NN \arraycolsep \tabcolsep
  1094. }
  1095. \bool_if:NT \l__nicematrix_vlines_bool
  1096. {
  1097. \dim_add:Nn \arraycolsep { 0.5 \arrayrulewidth }
  1098. \skip_horizontal:N 0.5\arrayrulewidth
  1099. }
  1100. \skip_horizontal:N \l__nicematrix_left_margin_dim
  1101. \skip_horizontal:N \l__nicematrix_extra_left_margin_dim
  1102. \c_math_toggle_token
  1103. \bool_if:NTF \l__nicematrix_light_syntax_bool
  1104. { \use:c { __nicematrix-light-syntax } }
  1105. { \use:c { __nicematrix-normal-syntax } }
  1106. }
  1107. {
  1108. \bool_if:NTF \l__nicematrix_light_syntax_bool
  1109. { \use:c { end __nicematrix-light-syntax } }
  1110. { \use:c { end __nicematrix-normal-syntax } }
  1111. \c_math_toggle_token
  1112. \skip_horizontal:N \l__nicematrix_right_margin_dim
  1113. \skip_horizontal:N \l__nicematrix_extra_right_margin_dim
  1114. \bool_if:NT \l__nicematrix_vlines_bool { \skip_horizontal:N 0.5\arrayrulewidth }
  1115. \hbox_set_end:
  1116. \int_compare:nNnT \l__nicematrix_last_row_int > { -2 }
  1117. {
  1118. \bool_if:NF \l__nicematrix_last_row_without_value_bool
  1119. {
  1120. \int_compare:nNnF \l__nicematrix_last_row_int = \c@iRow
  1121. {
  1122. \__nicematrix_error:n { Wrong~last~row }
  1123. \int_gset_eq:NN \l__nicematrix_last_row_int \c@iRow
  1124. }
  1125. }
  1126. }
  1127. \int_gset_eq:NN \c@jCol \g__nicematrix_col_total_int
  1128. \bool_if:nT \g__nicematrix_last_col_found_bool { \int_gdecr:N \c@jCol }
  1129. \int_gset_eq:NN \g__nicematrix_row_total_int \c@iRow
  1130. \int_compare:nNnT \l__nicematrix_last_row_int > { -1 } { \int_gdecr:N \c@iRow }
  1131. \int_compare:nNnT \l__nicematrix_first_col_int = 0
  1132. {
  1133. \skip_horizontal:N \arraycolsep
  1134. \skip_horizontal:N \g__nicematrix_width_first_col_dim
  1135. }
  1136. \bool_if:NTF \l__nicematrix_NiceArray_bool
  1137. {
  1138. \str_if_eq:VnTF \l__nicematrix_baseline_str { b }
  1139. {
  1140. \pgfpicture
  1141. \__nicematrix_qpoint:n { row - 1 }
  1142. \dim_gset_eq:NN \g_tmpa_dim \pgf@y
  1143. \__nicematrix_qpoint:n { row - \int_use:N \c@iRow - base }
  1144. \dim_gsub:Nn \g_tmpa_dim \pgf@y
  1145. \endpgfpicture
  1146. \int_compare:nNnT \l__nicematrix_first_row_int = 0
  1147. {
  1148. \dim_gadd:Nn \g_tmpa_dim
  1149. { \g__nicematrix_ht_row_zero_dim + \g__nicematrix_dp_row_zero_dim }
  1150. }
  1151. \box_move_up:nn \g_tmpa_dim { \box_use_drop:N \l__nicematrix_the_array_box }
  1152. }
  1153. {
  1154. \str_if_eq:VnTF \l__nicematrix_baseline_str { c }
  1155. { \box_use_drop:N \l__nicematrix_the_array_box }
  1156. {
  1157. \str_if_eq:VnT \l__nicematrix_baseline_str { t }
  1158. { \str_set:Nn \l__nicematrix_baseline_str { 1 } }
  1159. \int_set:Nn \l_tmpa_int \l__nicematrix_baseline_str
  1160. \bool_if:nT
  1161. {
  1162. \int_compare_p:nNn \l_tmpa_int < \l__nicematrix_first_row_int
  1163. || \int_compare_p:nNn \l_tmpa_int > \g__nicematrix_row_total_int
  1164. }
  1165. {
  1166. \__nicematrix_error:n { bad~value~for~baseline }
  1167. \int_set:Nn \l_tmpa_int 1
  1168. }
  1169. \pgfpicture
  1170. \__nicematrix_qpoint:n { row - 1 }
  1171. \dim_gset_eq:NN \g_tmpa_dim \pgf@y
  1172. \__nicematrix_qpoint:n { row - \int_use:N \l_tmpa_int - base }
  1173. \dim_gsub:Nn \g_tmpa_dim \pgf@y
  1174. \endpgfpicture
  1175. \int_compare:nNnT \l__nicematrix_first_row_int = 0
  1176. {
  1177. \dim_gadd:Nn \g_tmpa_dim
  1178. { \g__nicematrix_ht_row_zero_dim + \g__nicematrix_dp_row_zero_dim }
  1179. }
  1180. \box_move_up:nn \g_tmpa_dim
  1181. { \box_use_drop:N \l__nicematrix_the_array_box }
  1182. }
  1183. }
  1184. }
  1185. {
  1186. \int_compare:nNnTF \l__nicematrix_first_row_int = 0
  1187. {
  1188. \dim_set_eq:NN \l_tmpa_dim \g__nicematrix_dp_row_zero_dim
  1189. \dim_add:Nn \l_tmpa_dim \g__nicematrix_ht_row_zero_dim
  1190. }
  1191. { \dim_zero:N \l_tmpa_dim }
  1192. \int_compare:nNnTF \l__nicematrix_last_row_int > { -2 }
  1193. {
  1194. \dim_set_eq:NN \l_tmpb_dim \g__nicematrix_ht_last_row_dim
  1195. \dim_add:Nn \l_tmpb_dim \g__nicematrix_dp_last_row_dim
  1196. }
  1197. { \dim_zero:N \l_tmpb_dim }
  1198. \hbox_set:Nn \l_tmpa_box
  1199. {
  1200. \c_math_toggle_token
  1201. \left #1
  1202. \vcenter
  1203. {
  1204. \skip_vertical:N -\l_tmpa_dim
  1205. \hbox
  1206. {
  1207. \bool_if:NTF \l__nicematrix_NiceTabular_bool
  1208. { \skip_horizontal:N -\tabcolsep }
  1209. { \skip_horizontal:N -\arraycolsep }
  1210. \box_use_drop:N \l__nicematrix_the_array_box
  1211. \bool_if:NTF \l__nicematrix_NiceTabular_bool
  1212. { \skip_horizontal:N -\tabcolsep }
  1213. { \skip_horizontal:N -\arraycolsep }
  1214. }
  1215. \skip_vertical:N -\l_tmpb_dim
  1216. }
  1217. \right #2
  1218. \c_math_toggle_token
  1219. }
  1220. \bool_if:NTF \l__nicematrix_max_delimiter_width_bool
  1221. { \__nicematrix_put_box_in_flow_bis:nn { #1 } { #2 } }
  1222. \__nicematrix_put_box_in_flow:
  1223. }
  1224. \bool_if:NT \g__nicematrix_last_col_found_bool
  1225. {
  1226. \skip_horizontal:N \g__nicematrix_width_last_col_dim
  1227. \skip_horizontal:N \arraycolsep
  1228. }
  1229. \__nicematrix_after_array:
  1230. }
  1231. \cs_new_protected:Npn \__nicematrix_put_box_in_flow:
  1232. {
  1233. \box_set_ht:Nn \l_tmpa_box { \box_ht:N \l_tmpa_box + \l_tmpa_dim }
  1234. \box_set_dp:Nn \l_tmpa_box { \box_dp:N \l_tmpa_box + \l_tmpb_dim }
  1235. \str_if_eq:VnTF \l__nicematrix_baseline_str { c }
  1236. { \box_use_drop:N \l_tmpa_box }
  1237. \__nicematrix_put_box_in_flow_i:
  1238. }
  1239. \cs_new_protected:Npn \__nicematrix_put_box_in_flow_i:
  1240. {
  1241. \str_case:VnF \l__nicematrix_baseline_str
  1242. {
  1243. { t } { \int_set:Nn \l_tmpa_int 1 }
  1244. { b } { \int_set_eq:NN \l_tmpa_int \c@iRow }
  1245. }
  1246. { \int_set:Nn \l_tmpa_int \l__nicematrix_baseline_str }
  1247. \bool_if:nT
  1248. {
  1249. \int_compare_p:nNn \l_tmpa_int < \l__nicematrix_first_row_int
  1250. || \int_compare_p:nNn \l_tmpa_int > \g__nicematrix_row_total_int
  1251. }
  1252. {
  1253. \__nicematrix_error:n { bad~value~for~baseline }
  1254. \int_set:Nn \l_tmpa_int 1
  1255. }
  1256. \pgfpicture
  1257. \__nicematrix_qpoint:n { row - 1 }
  1258. \dim_gset_eq:NN \g_tmpa_dim \pgf@y
  1259. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c@iRow }
  1260. \dim_gadd:Nn \g_tmpa_dim \pgf@y
  1261. \dim_gset:Nn \g_tmpa_dim { 0.5 \g_tmpa_dim }
  1262. \__nicematrix_qpoint:n { row - \int_use:N \l_tmpa_int - base }
  1263. \dim_gsub:Nn \g_tmpa_dim \pgf@y
  1264. \dim_gsub:Nn \g_tmpa_dim { \fontdimen22 \textfont2 }
  1265. \endpgfpicture
  1266. \box_move_up:nn \g_tmpa_dim { \box_use_drop:N \l_tmpa_box }
  1267. \box_use_drop:N \l_tmpa_box
  1268. }
  1269. \cs_new_protected:Npn \__nicematrix_put_box_in_flow_bis:nn #1 #2
  1270. {
  1271. \dim_zero_new:N \l__nicematrix_real_left_delim_dim
  1272. \dim_zero_new:N \l__nicematrix_real_right_delim_dim
  1273. \hbox_set:Nn \l_tmpb_box
  1274. {
  1275. \c_math_toggle_token
  1276. \left #1
  1277. \vcenter
  1278. {
  1279. \vbox_to_ht:nn
  1280. { \box_ht:N \l_tmpa_box + \box_dp:N \l_tmpa_box }
  1281. { }
  1282. }
  1283. \right .
  1284. \c_math_toggle_token
  1285. }
  1286. \dim_set:Nn \l__nicematrix_real_left_delim_dim
  1287. { \box_wd:N \l_tmpb_box - \nulldelimiterspace }
  1288. \hbox_set:Nn \l_tmpb_box
  1289. {
  1290. \c_math_toggle_token
  1291. \left .
  1292. \vbox_to_ht:nn
  1293. { \box_ht:N \l_tmpa_box + \box_dp:N \l_tmpa_box }
  1294. { }
  1295. \right #2
  1296. \c_math_toggle_token
  1297. }
  1298. \dim_set:Nn \l__nicematrix_real_right_delim_dim
  1299. { \box_wd:N \l_tmpb_box - \nulldelimiterspace }
  1300. \skip_horizontal:N \l__nicematrix_left_delim_dim
  1301. \skip_horizontal:N -\l__nicematrix_real_left_delim_dim
  1302. \__nicematrix_put_box_in_flow:
  1303. \skip_horizontal:N \l__nicematrix_right_delim_dim
  1304. \skip_horizontal:N -\l__nicematrix_real_right_delim_dim
  1305. }
  1306. \NewDocumentEnvironment { __nicematrix-normal-syntax } { }
  1307. {
  1308. \peek_meaning_ignore_spaces:NTF \end
  1309. { \__nicematrix_analyze_end:Nn }
  1310. { \exp_args:NV \__nicematrix_array: \l_tmpa_tl }
  1311. }
  1312. {
  1313. \__nicematrix_create_col_nodes:
  1314. \endarray
  1315. }
  1316. \NewDocumentEnvironment { __nicematrix-light-syntax } { b }
  1317. {
  1318. \tl_if_empty:nT { #1 } { \__nicematrix_fatal:n { empty~environment } }
  1319. \tl_map_inline:nn { #1 }
  1320. {
  1321. \tl_if_eq:nnT { ##1 } { & }
  1322. { \__nicematrix_fatal:n { ampersand~in~light-syntax } }
  1323. \tl_if_eq:nnT { ##1 } { \\ }
  1324. { \__nicematrix_fatal:n { double-backslash~in~light-syntax } }
  1325. }
  1326. \__nicematrix_light_syntax_i #1 \CodeAfter \q_stop
  1327. }
  1328. { }
  1329. \cs_new_protected:Npn \__nicematrix_light_syntax_i #1\CodeAfter #2\q_stop
  1330. {
  1331. \tl_gput_right:Nn \g__nicematrix_code_after_tl { #2 }
  1332. \seq_gclear_new:N \g__nicematrix_rows_seq
  1333. \tl_set_rescan:Nno \l__nicematrix_end_of_row_tl { } \l__nicematrix_end_of_row_tl
  1334. \exp_args:NNV \seq_gset_split:Nnn \g__nicematrix_rows_seq \l__nicematrix_end_of_row_tl { #1 }
  1335. \int_compare:nNnT \l__nicematrix_last_row_int = { -1 }
  1336. { \int_set:Nn \l__nicematrix_last_row_int { \seq_count:N \g__nicematrix_rows_seq } }
  1337. \exp_args:NV \__nicematrix_array: \l_tmpa_tl
  1338. \seq_gpop_left:NN \g__nicematrix_rows_seq \l_tmpa_tl
  1339. \exp_args:NV \__nicematrix_line_with_light_syntax_i:n \l_tmpa_tl
  1340. \seq_map_function:NN \g__nicematrix_rows_seq \__nicematrix_line_with_light_syntax:n
  1341. \__nicematrix_create_col_nodes:
  1342. \endarray
  1343. }
  1344. \cs_new_protected:Npn \__nicematrix_line_with_light_syntax:n #1
  1345. { \tl_if_empty:nF { #1 } { \\ \__nicematrix_line_with_light_syntax_i:n { #1 } } }
  1346. \cs_new_protected:Npn \__nicematrix_line_with_light_syntax_i:n #1
  1347. {
  1348. \seq_gclear_new:N \g__nicematrix_cells_seq
  1349. \seq_gset_split:Nnn \g__nicematrix_cells_seq { ~ } { #1 }
  1350. \seq_gpop_left:NN \g__nicematrix_cells_seq \l_tmpa_tl
  1351. \l_tmpa_tl
  1352. \seq_map_inline:Nn \g__nicematrix_cells_seq { & ##1 }
  1353. }
  1354. \cs_new_protected:Npn \__nicematrix_analyze_end:Nn #1 #2
  1355. {
  1356. \str_if_eq:VnT \g__nicematrix_name_env_str { #2 }
  1357. { \__nicematrix_fatal:n { empty~environment } }
  1358. \end { #2 }
  1359. }
  1360. \cs_new:Npn \__nicematrix_create_col_nodes:
  1361. {
  1362. \crcr
  1363. \int_compare:nNnT \c@iRow = 0 { \__nicematrix_fatal:n { Zero~row } }
  1364. \int_compare:nNnT \l__nicematrix_first_col_int = 0
  1365. {
  1366. \omit
  1367. \skip_horizontal:N -2\col@sep
  1368. \bool_if:NT \l__nicematrix_code_before_bool
  1369. { \pgfsys@markposition { \__nicematrix_env: - col - 0 } }
  1370. \pgfpicture
  1371. \pgfrememberpicturepositiononpagetrue
  1372. \pgfcoordinate { \__nicematrix_env: - col - 0 } \pgfpointorigin
  1373. \str_if_empty:NF \l__nicematrix_name_str
  1374. { \pgfnodealias { \l__nicematrix_name_str - col - 0 } { \__nicematrix_env: - col - 0 } }
  1375. \endpgfpicture
  1376. &
  1377. }
  1378. \omit
  1379. \bool_gset_true:N \g__nicematrix_row_of_col_done_bool
  1380. \int_compare:nNnTF \l__nicematrix_first_col_int = 0
  1381. {
  1382. \bool_if:NT \l__nicematrix_code_before_bool
  1383. {
  1384. \hbox
  1385. {
  1386. \skip_horizontal:N -0.5\arrayrulewidth
  1387. \pgfsys@markposition { \__nicematrix_env: - col - 1 }
  1388. \skip_horizontal:N 0.5\arrayrulewidth
  1389. }
  1390. }
  1391. \pgfpicture
  1392. \pgfrememberpicturepositiononpagetrue
  1393. \pgfcoordinate { \__nicematrix_env: - col - 1 }
  1394. { \pgfpoint { - 0.5 \arrayrulewidth } \c_zero_dim }
  1395. \str_if_empty:NF \l__nicematrix_name_str
  1396. { \pgfnodealias { \l__nicematrix_name_str - col - 1 } { \__nicematrix_env: - col - 1 } }
  1397. \endpgfpicture
  1398. }
  1399. {
  1400. \bool_if:NT \l__nicematrix_code_before_bool
  1401. {
  1402. \hbox
  1403. {
  1404. \skip_horizontal:N 0.5 \arrayrulewidth
  1405. \pgfsys@markposition { \__nicematrix_env: - col - 1 }
  1406. \skip_horizontal:N -0.5\arrayrulewidth
  1407. }
  1408. }
  1409. \pgfpicture
  1410. \pgfrememberpicturepositiononpagetrue
  1411. \pgfcoordinate { \__nicematrix_env: - col - 1 }
  1412. { \pgfpoint { 0.5 \arrayrulewidth } \c_zero_dim }
  1413. \str_if_empty:NF \l__nicematrix_name_str
  1414. { \pgfnodealias { \l__nicematrix_name_str - col - 1 } { \__nicematrix_env: - col - 1 } }
  1415. \endpgfpicture
  1416. }
  1417. \skip_gset:Nn \g_tmpa_skip { 0 pt~plus 1 fill }
  1418. \bool_if:NF \l__nicematrix_auto_columns_width_bool
  1419. { \dim_compare:nNnT \l__nicematrix_columns_width_dim > \c_zero_dim }
  1420. {
  1421. \bool_lazy_and:nnTF
  1422. \l__nicematrix_auto_columns_width_bool
  1423. { \bool_not_p:n \l__nicematrix_block_auto_columns_width_bool }
  1424. { \skip_gset_eq:NN \g_tmpa_skip \g__nicematrix_max_cell_width_dim }
  1425. { \skip_gset_eq:NN \g_tmpa_skip \l__nicematrix_columns_width_dim }
  1426. \skip_gadd:Nn \g_tmpa_skip { 2 \col@sep }
  1427. }
  1428. \skip_horizontal:N \g_tmpa_skip
  1429. \hbox
  1430. {
  1431. \bool_if:NT \l__nicematrix_code_before_bool
  1432. {
  1433. \hbox
  1434. {
  1435. \skip_horizontal:N -0.5\arrayrulewidth
  1436. \pgfsys@markposition { \__nicematrix_env: - col - 2 }
  1437. \skip_horizontal:N 0.5\arrayrulewidth
  1438. }
  1439. }
  1440. \pgfpicture
  1441. \pgfrememberpicturepositiononpagetrue
  1442. \pgfcoordinate { \__nicematrix_env: - col - 2 }
  1443. { \pgfpoint { - 0.5 \arrayrulewidth } \c_zero_dim }
  1444. \str_if_empty:NF \l__nicematrix_name_str
  1445. { \pgfnodealias { \l__nicematrix_name_str - col - 2 } { \__nicematrix_env: - col - 2 } }
  1446. \endpgfpicture
  1447. }
  1448. \int_gset:Nn \g_tmpa_int 1
  1449. \bool_if:NTF \g__nicematrix_last_col_found_bool
  1450. { \prg_replicate:nn { \g__nicematrix_col_total_int - 2 } }
  1451. { \prg_replicate:nn { \g__nicematrix_col_total_int - 1 } }
  1452. {
  1453. &
  1454. \omit
  1455. \int_gincr:N \g_tmpa_int
  1456. \skip_horizontal:N \g_tmpa_skip
  1457. \bool_if:NT \l__nicematrix_code_before_bool
  1458. {
  1459. \hbox
  1460. {
  1461. \skip_horizontal:N -0.5\arrayrulewidth
  1462. \pgfsys@markposition { \__nicematrix_env: - col - \__nicematrix_succ:n \g_tmpa_int }
  1463. \skip_horizontal:N 0.5\arrayrulewidth
  1464. }
  1465. }
  1466. \pgfpicture
  1467. \pgfrememberpicturepositiononpagetrue
  1468. \pgfcoordinate { \__nicematrix_env: - col - \__nicematrix_succ:n \g_tmpa_int }
  1469. { \pgfpoint { - 0.5 \arrayrulewidth } \c_zero_dim }
  1470. \str_if_empty:NF \l__nicematrix_name_str
  1471. {
  1472. \pgfnodealias
  1473. { \l__nicematrix_name_str - col - \__nicematrix_succ:n \g_tmpa_int }
  1474. { \__nicematrix_env: - col - \__nicematrix_succ:n \g_tmpa_int }
  1475. }
  1476. \endpgfpicture
  1477. }
  1478. \bool_if:NT \g__nicematrix_last_col_found_bool
  1479. {
  1480. \bool_if:NT \l__nicematrix_code_before_bool
  1481. {
  1482. \pgfsys@markposition { \__nicematrix_env: - col - \__nicematrix_succ:n \g__nicematrix_col_total_int }
  1483. }
  1484. \skip_horizontal:N 2\col@sep
  1485. \pgfpicture
  1486. \pgfrememberpicturepositiononpagetrue
  1487. \pgfcoordinate { \__nicematrix_env: - col - \__nicematrix_succ:n \g__nicematrix_col_total_int }
  1488. \pgfpointorigin
  1489. \str_if_empty:NF \l__nicematrix_name_str
  1490. {
  1491. \pgfnodealias
  1492. { \l__nicematrix_name_str - col - \__nicematrix_succ:n \g__nicematrix_col_total_int }
  1493. { \__nicematrix_env: - col - \__nicematrix_succ:n \g__nicematrix_col_total_int }
  1494. }
  1495. \endpgfpicture
  1496. \skip_horizontal:N -2\col@sep
  1497. }
  1498. \cr
  1499. }
  1500. \tl_const:Nn \c__nicematrix_preamble_first_col_tl
  1501. {
  1502. >
  1503. {
  1504. \__nicematrix_begin_of_row:
  1505. \hbox_set:Nw \l__nicematrix_cell_box
  1506. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  1507. \bool_if:NT \l__nicematrix_small_bool \scriptstyle
  1508. \bool_lazy_and:nnT
  1509. { \int_compare_p:nNn \c@iRow > 0 }
  1510. {
  1511. \bool_lazy_or_p:nn
  1512. { \int_compare_p:nNn \l__nicematrix_last_row_int < 0 }
  1513. { \int_compare_p:nNn \c@iRow < \l__nicematrix_last_row_int }
  1514. }
  1515. {
  1516. \l__nicematrix_code_for_first_col_tl
  1517. \xglobal \colorlet { nicematrix-first-col } { . }
  1518. }
  1519. }
  1520. l
  1521. <
  1522. {
  1523. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  1524. \hbox_set_end:
  1525. \__nicematrix_update_for_first_and_last_row:
  1526. \dim_gset:Nn \g__nicematrix_width_first_col_dim
  1527. { \dim_max:nn \g__nicematrix_width_first_col_dim { \box_wd:N \l__nicematrix_cell_box } }
  1528. \hbox_overlap_left:n
  1529. {
  1530. \dim_compare:nNnTF { \box_wd:N \l__nicematrix_cell_box } > \c_zero_dim
  1531. \__nicematrix_node_for_the_cell:
  1532. { \box_use_drop:N \l__nicematrix_cell_box }
  1533. \skip_horizontal:N \l__nicematrix_left_delim_dim
  1534. \skip_horizontal:N \l__nicematrix_left_margin_dim
  1535. \skip_horizontal:N \l__nicematrix_extra_left_margin_dim
  1536. }
  1537. \skip_horizontal:N -2\col@sep
  1538. }
  1539. }
  1540. \tl_const:Nn \c__nicematrix_preamble_last_col_tl
  1541. {
  1542. >
  1543. {
  1544. \bool_gset_true:N \g__nicematrix_last_col_found_bool
  1545. \int_gincr:N \c@jCol
  1546. \int_gset_eq:NN \g__nicematrix_col_total_int \c@jCol
  1547. \hbox_set:Nw \l__nicematrix_cell_box
  1548. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  1549. \bool_if:NT \l__nicematrix_small_bool \scriptstyle
  1550. \int_compare:nNnT \c@iRow > 0
  1551. {
  1552. \bool_lazy_or:nnT
  1553. { \int_compare_p:nNn \l__nicematrix_last_row_int < 0 }
  1554. { \int_compare_p:nNn \c@iRow < \l__nicematrix_last_row_int }
  1555. {
  1556. \l__nicematrix_code_for_last_col_tl
  1557. \xglobal \colorlet { nicematrix-last-col } { . }
  1558. }
  1559. }
  1560. }
  1561. l
  1562. <
  1563. {
  1564. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  1565. \hbox_set_end:
  1566. \__nicematrix_update_for_first_and_last_row:
  1567. \dim_gset:Nn \g__nicematrix_width_last_col_dim
  1568. { \dim_max:nn \g__nicematrix_width_last_col_dim { \box_wd:N \l__nicematrix_cell_box } }
  1569. \skip_horizontal:N -2\col@sep
  1570. \hbox_overlap_right:n
  1571. {
  1572. \dim_compare:nNnT { \box_wd:N \l__nicematrix_cell_box } > \c_zero_dim
  1573. {
  1574. \skip_horizontal:N \l__nicematrix_right_delim_dim
  1575. \skip_horizontal:N \l__nicematrix_right_margin_dim
  1576. \skip_horizontal:N \l__nicematrix_extra_right_margin_dim
  1577. \__nicematrix_node_for_the_cell:
  1578. }
  1579. }
  1580. }
  1581. }
  1582. \NewDocumentEnvironment { NiceArray } { }
  1583. {
  1584. \bool_set_true:N \l__nicematrix_NiceArray_bool
  1585. \str_if_empty:NT \g__nicematrix_name_env_str
  1586. { \str_gset:Nn \g__nicematrix_name_env_str { NiceArray } }
  1587. \NiceArrayWithDelims . .
  1588. }
  1589. { \endNiceArrayWithDelims }
  1590. \NewDocumentEnvironment { pNiceArray } { }
  1591. {
  1592. \str_if_empty:NT \g__nicematrix_name_env_str
  1593. { \str_gset:Nn \g__nicematrix_name_env_str { pNiceArray } }
  1594. \__nicematrix_test_if_math_mode:
  1595. \NiceArrayWithDelims ( )
  1596. }
  1597. { \endNiceArrayWithDelims }
  1598. \NewDocumentEnvironment { bNiceArray } { }
  1599. {
  1600. \str_if_empty:NT \g__nicematrix_name_env_str
  1601. { \str_gset:Nn \g__nicematrix_name_env_str { bNiceArray } }
  1602. \__nicematrix_test_if_math_mode:
  1603. \NiceArrayWithDelims [ ]
  1604. }
  1605. { \endNiceArrayWithDelims }
  1606. \NewDocumentEnvironment { BNiceArray } { }
  1607. {
  1608. \str_if_empty:NT \g__nicematrix_name_env_str
  1609. { \str_gset:Nn \g__nicematrix_name_env_str { BNiceArray } }
  1610. \__nicematrix_test_if_math_mode:
  1611. \NiceArrayWithDelims \{ \}
  1612. }
  1613. { \endNiceArrayWithDelims }
  1614. \NewDocumentEnvironment { vNiceArray } { }
  1615. {
  1616. \str_if_empty:NT \g__nicematrix_name_env_str
  1617. { \str_gset:Nn \g__nicematrix_name_env_str { vNiceArray } }
  1618. \__nicematrix_test_if_math_mode:
  1619. \NiceArrayWithDelims | |
  1620. }
  1621. { \endNiceArrayWithDelims }
  1622. \NewDocumentEnvironment { VNiceArray } { }
  1623. {
  1624. \str_if_empty:NT \g__nicematrix_name_env_str
  1625. { \str_gset:Nn \g__nicematrix_name_env_str { VNiceArray } }
  1626. \__nicematrix_test_if_math_mode:
  1627. \NiceArrayWithDelims \| \|
  1628. }
  1629. { \endNiceArrayWithDelims }
  1630. \cs_new_protected:Npn \__nicematrix_define_env:n #1
  1631. {
  1632. \NewDocumentEnvironment { #1 NiceMatrix } { ! O { } }
  1633. {
  1634. \str_gset:Nn \g__nicematrix_name_env_str { #1 NiceMatrix }
  1635. \tl_set:Nn \l__nicematrix_type_of_col_tl C
  1636. \keys_set:nn { NiceMatrix / NiceMatrix } { ##1 }
  1637. \exp_args:Nnx \__nicematrix_begin_of_NiceMatrix:nn { #1 } \l__nicematrix_type_of_col_tl
  1638. }
  1639. { \use:c { end #1 NiceArray } }
  1640. }
  1641. \cs_new_protected:Npn \__nicematrix_begin_of_NiceMatrix:nn #1 #2
  1642. {
  1643. \use:c { #1 NiceArray }
  1644. {
  1645. *
  1646. {
  1647. \int_compare:nNnTF \l__nicematrix_last_col_int < 0
  1648. \c@MaxMatrixCols
  1649. { \__nicematrix_pred:n \l__nicematrix_last_col_int }
  1650. }
  1651. #2
  1652. }
  1653. }
  1654. \__nicematrix_define_env:n { }
  1655. \__nicematrix_define_env:n p
  1656. \__nicematrix_define_env:n b
  1657. \__nicematrix_define_env:n B
  1658. \__nicematrix_define_env:n v
  1659. \__nicematrix_define_env:n V
  1660. \NewDocumentEnvironment { NiceTabular } { O { } m ! O { } }
  1661. {
  1662. \keys_set:nn { NiceMatrix / NiceTabular } { #1 , #3 }
  1663. \bool_set_true:N \l__nicematrix_NiceTabular_bool
  1664. \NiceArray { #2 }
  1665. }
  1666. { \endNiceArray }
  1667. \cs_new_protected:Npn \__nicematrix_after_array:
  1668. {
  1669. \group_begin:
  1670. \bool_if:NT \g__nicematrix_last_col_found_bool
  1671. { \int_set_eq:NN \l__nicematrix_last_col_int \g__nicematrix_col_total_int }
  1672. \bool_if:NT \l__nicematrix_last_col_without_value_bool
  1673. {
  1674. \dim_set_eq:NN \l__nicematrix_last_col_int \g__nicematrix_col_total_int
  1675. \iow_shipout:Nn \@mainaux \ExplSyntaxOn
  1676. \iow_shipout:Nx \@mainaux
  1677. {
  1678. \cs_gset:cpn { __nicematrix_last_col_ \int_use:N \g__nicematrix_env_int }
  1679. { \int_use:N \g__nicematrix_col_total_int }
  1680. }
  1681. \str_if_empty:NF \l__nicematrix_name_str
  1682. {
  1683. \iow_shipout:Nx \@mainaux
  1684. {
  1685. \cs_gset:cpn { __nicematrix_last_col_ \l__nicematrix_name_str }
  1686. { \int_use:N \g__nicematrix_col_total_int }
  1687. }
  1688. }
  1689. \iow_shipout:Nn \@mainaux \ExplSyntaxOff
  1690. }
  1691. \bool_if:NT \l__nicematrix_last_row_without_value_bool
  1692. {
  1693. \dim_set_eq:NN \l__nicematrix_last_row_int \g__nicematrix_row_total_int
  1694. \bool_if:NF \l__nicematrix_light_syntax_bool
  1695. {
  1696. \iow_shipout:Nn \@mainaux \ExplSyntaxOn
  1697. \iow_shipout:Nx \@mainaux
  1698. {
  1699. \cs_gset:cpn { __nicematrix_last_row_ \int_use:N \g__nicematrix_env_int }
  1700. { \int_use:N \g__nicematrix_row_total_int }
  1701. }
  1702. \str_if_empty:NF \l__nicematrix_name_str
  1703. {
  1704. \iow_shipout:Nx \@mainaux
  1705. {
  1706. \cs_gset:cpn { __nicematrix_last_row_ \l__nicematrix_name_str }
  1707. { \int_use:N \g__nicematrix_row_total_int }
  1708. }
  1709. }
  1710. \iow_shipout:Nn \@mainaux \ExplSyntaxOff
  1711. }
  1712. }
  1713. \bool_if:NT \l__nicematrix_code_before_bool
  1714. {
  1715. \iow_now:Nn \@mainaux \ExplSyntaxOn
  1716. \iow_now:Nx \@mainaux
  1717. { \seq_clear_new:c { __nicematrix_size _ \int_use:N \g__nicematrix_env_int _ seq } }
  1718. \iow_now:Nx \@mainaux
  1719. {
  1720. \seq_gset_from_clist:cn { __nicematrix_size _ \int_use:N \g__nicematrix_env_int _ seq }
  1721. {
  1722. \int_use:N \l__nicematrix_first_row_int ,
  1723. \int_use:N \g__nicematrix_row_total_int ,
  1724. \int_use:N \l__nicematrix_first_col_int ,
  1725. \bool_lazy_and:nnTF
  1726. { \int_compare_p:nNn \l__nicematrix_last_col_int > { -2 } }
  1727. { \bool_not_p:n \g__nicematrix_last_col_found_bool }
  1728. \__nicematrix_succ:n
  1729. \int_use:N
  1730. \g__nicematrix_col_total_int
  1731. }
  1732. }
  1733. \iow_now:Nn \@mainaux \ExplSyntaxOff
  1734. }
  1735. \bool_if:NT \l__nicematrix_parallelize_diags_bool
  1736. {
  1737. \int_gzero_new:N \g__nicematrix_ddots_int
  1738. \int_gzero_new:N \g__nicematrix_iddots_int
  1739. \dim_gzero_new:N \g__nicematrix_delta_x_one_dim
  1740. \dim_gzero_new:N \g__nicematrix_delta_y_one_dim
  1741. \dim_gzero_new:N \g__nicematrix_delta_x_two_dim
  1742. \dim_gzero_new:N \g__nicematrix_delta_y_two_dim
  1743. }
  1744. \bool_if:nTF \l__nicematrix_medium_nodes_bool
  1745. {
  1746. \bool_if:NTF \l__nicematrix_large_nodes_bool
  1747. \__nicematrix_create_medium_and_large_nodes:
  1748. \__nicematrix_create_medium_nodes:
  1749. }
  1750. { \bool_if:NT \l__nicematrix_large_nodes_bool \__nicematrix_create_large_nodes: }
  1751. \int_zero_new:N \l__nicematrix_initial_i_int
  1752. \int_zero_new:N \l__nicematrix_initial_j_int
  1753. \int_zero_new:N \l__nicematrix_final_i_int
  1754. \int_zero_new:N \l__nicematrix_final_j_int
  1755. \bool_set_false:N \l__nicematrix_initial_open_bool
  1756. \bool_set_false:N \l__nicematrix_final_open_bool
  1757. \bool_if:NT \l__nicematrix_small_bool
  1758. {
  1759. \dim_set:Nn \l__nicematrix_radius_dim { 0.37 pt }
  1760. \dim_set:Nn \l__nicematrix_inter_dots_dim { 0.25 em }
  1761. \dim_set:Nn \l__nicematrix_xdots_shorten_dim { 0.6 \l__nicematrix_xdots_shorten_dim }
  1762. }
  1763. \__nicematrix_draw_dotted_lines:
  1764. \bool_if:NT \l__nicematrix_vlines_bool \__nicematrix_draw_vlines:
  1765. \cs_set_eq:NN \ialign \__nicematrix_old_ialign:
  1766. \g__nicematrix_internal_code_after_tl
  1767. \tl_gclear:N \g__nicematrix_internal_code_after_tl
  1768. \bool_if:NT \c__nicematrix_tikz_loaded_bool
  1769. {
  1770. \tikzset
  1771. {
  1772. every~picture / .style =
  1773. {
  1774. overlay ,
  1775. remember~picture ,
  1776. name~prefix = \__nicematrix_env: -
  1777. }
  1778. }
  1779. }
  1780. \cs_set_eq:NN \line \__nicematrix_line
  1781. \cs_set_eq:NN \CodeAfter \prg_do_nothing:
  1782. \g__nicematrix_code_after_tl
  1783. \tl_gclear:N \g__nicematrix_code_after_tl
  1784. \group_end:
  1785. \str_gclear:N \g__nicematrix_name_env_str
  1786. \__nicematrix_restore_iRow_jCol:
  1787. \bool_if:NF \c__nicematrix_colortbl_loaded_bool
  1788. { \cs_gset_eq:NN \CT@arc@ \__nicematrix_old_CT@arc@ }
  1789. }
  1790. \AtBeginDocument
  1791. {
  1792. \cs_new_protected:Npx \__nicematrix_draw_dotted_lines:
  1793. {
  1794. \c__nicematrix_pgfortikzpicture_tl
  1795. \__nicematrix_draw_dotted_lines_i:
  1796. \c__nicematrix_endpgfortikzpicture_tl
  1797. }
  1798. }
  1799. \cs_new_protected:Npn \__nicematrix_draw_dotted_lines_i:
  1800. {
  1801. \pgfrememberpicturepositiononpagetrue
  1802. \pgf@relevantforpicturesizefalse
  1803. \g__nicematrix_HVdotsfor_lines_tl
  1804. \g__nicematrix_Vdots_lines_tl
  1805. \g__nicematrix_Ddots_lines_tl
  1806. \g__nicematrix_Iddots_lines_tl
  1807. \g__nicematrix_Cdots_lines_tl
  1808. \g__nicematrix_Ldots_lines_tl
  1809. }
  1810. \cs_new_protected:Npn \__nicematrix_restore_iRow_jCol:
  1811. {
  1812. \cs_if_exist:NT \theiRow { \int_gset_eq:NN \c@iRow \l__nicematrix_old_iRow_int }
  1813. \cs_if_exist:NT \thejCol { \int_gset_eq:NN \c@jCol \l__nicematrix_old_jCol_int }
  1814. }
  1815. \cs_new_protected:Npn \__nicematrix_find_extremities_of_line:nnnn #1 #2 #3 #4
  1816. {
  1817. \cs_set:cpn { __nicematrix _ dotted _ #1 - #2 } { }
  1818. \int_set:Nn \l__nicematrix_initial_i_int { #1 }
  1819. \int_set:Nn \l__nicematrix_initial_j_int { #2 }
  1820. \int_set:Nn \l__nicematrix_final_i_int { #1 }
  1821. \int_set:Nn \l__nicematrix_final_j_int { #2 }
  1822. \bool_set_false:N \l__nicematrix_stop_loop_bool
  1823. \bool_do_until:Nn \l__nicematrix_stop_loop_bool
  1824. {
  1825. \int_add:Nn \l__nicematrix_final_i_int { #3 }
  1826. \int_add:Nn \l__nicematrix_final_j_int { #4 }
  1827. \bool_set_false:N \l__nicematrix_final_open_bool
  1828. \int_compare:nNnTF \l__nicematrix_final_i_int > \c@iRow
  1829. {
  1830. \int_compare:nNnTF { #3 } = 1
  1831. { \bool_set_true:N \l__nicematrix_final_open_bool }
  1832. {
  1833. \int_compare:nNnT \l__nicematrix_final_j_int > \c@jCol
  1834. { \bool_set_true:N \l__nicematrix_final_open_bool }
  1835. }
  1836. }
  1837. {
  1838. \int_compare:nNnTF \l__nicematrix_final_j_int < 1
  1839. {
  1840. \int_compare:nNnT { #4 } = { -1 }
  1841. { \bool_set_true:N \l__nicematrix_final_open_bool }
  1842. }
  1843. {
  1844. \int_compare:nNnT \l__nicematrix_final_j_int > \c@jCol
  1845. {
  1846. \int_compare:nNnT { #4 } = 1
  1847. { \bool_set_true:N \l__nicematrix_final_open_bool }
  1848. }
  1849. }
  1850. }
  1851. \bool_if:NTF \l__nicematrix_final_open_bool
  1852. {
  1853. \int_sub:Nn \l__nicematrix_final_i_int { #3 }
  1854. \int_sub:Nn \l__nicematrix_final_j_int { #4 }
  1855. \bool_set_true:N \l__nicematrix_stop_loop_bool
  1856. }
  1857. {
  1858. \cs_if_exist:cTF
  1859. {
  1860. __nicematrix _ dotted _
  1861. \int_use:N \l__nicematrix_final_i_int -
  1862. \int_use:N \l__nicematrix_final_j_int
  1863. }
  1864. {
  1865. \int_sub:Nn \l__nicematrix_final_i_int { #3 }
  1866. \int_sub:Nn \l__nicematrix_final_j_int { #4 }
  1867. \bool_set_true:N \l__nicematrix_final_open_bool
  1868. \bool_set_true:N \l__nicematrix_stop_loop_bool
  1869. }
  1870. {
  1871. \cs_if_exist:cTF
  1872. {
  1873. pgf @ sh @ ns @ \__nicematrix_env:
  1874. - \int_use:N \l__nicematrix_final_i_int
  1875. - \int_use:N \l__nicematrix_final_j_int
  1876. }
  1877. { \bool_set_true:N \l__nicematrix_stop_loop_bool }
  1878. {
  1879. \cs_set:cpn
  1880. {
  1881. __nicematrix _ dotted _
  1882. \int_use:N \l__nicematrix_final_i_int -
  1883. \int_use:N \l__nicematrix_final_j_int
  1884. }
  1885. { }
  1886. }
  1887. }
  1888. }
  1889. }
  1890. \bool_set_false:N \l__nicematrix_stop_loop_bool
  1891. \bool_do_until:Nn \l__nicematrix_stop_loop_bool
  1892. {
  1893. \int_sub:Nn \l__nicematrix_initial_i_int { #3 }
  1894. \int_sub:Nn \l__nicematrix_initial_j_int { #4 }
  1895. \bool_set_false:N \l__nicematrix_initial_open_bool
  1896. \int_compare:nNnTF \l__nicematrix_initial_i_int < 1
  1897. {
  1898. \int_compare:nNnTF { #3 } = 1
  1899. { \bool_set_true:N \l__nicematrix_initial_open_bool }
  1900. {
  1901. \int_compare:nNnT \l__nicematrix_initial_j_int = 0
  1902. { \bool_set_true:N \l__nicematrix_initial_open_bool }
  1903. }
  1904. }
  1905. {
  1906. \int_compare:nNnTF \l__nicematrix_initial_j_int < 1
  1907. {
  1908. \int_compare:nNnT { #4 } = 1
  1909. { \bool_set_true:N \l__nicematrix_initial_open_bool }
  1910. }
  1911. {
  1912. \int_compare:nNnT \l__nicematrix_initial_j_int > \c@jCol
  1913. {
  1914. \int_compare:nNnT { #4 } = { -1 }
  1915. { \bool_set_true:N \l__nicematrix_initial_open_bool }
  1916. }
  1917. }
  1918. }
  1919. \bool_if:NTF \l__nicematrix_initial_open_bool
  1920. {
  1921. \int_add:Nn \l__nicematrix_initial_i_int { #3 }
  1922. \int_add:Nn \l__nicematrix_initial_j_int { #4 }
  1923. \bool_set_true:N \l__nicematrix_stop_loop_bool
  1924. }
  1925. {
  1926. \cs_if_exist:cTF
  1927. {
  1928. __nicematrix _ dotted _
  1929. \int_use:N \l__nicematrix_initial_i_int -
  1930. \int_use:N \l__nicematrix_initial_j_int
  1931. }
  1932. {
  1933. \int_add:Nn \l__nicematrix_initial_i_int { #3 }
  1934. \int_add:Nn \l__nicematrix_initial_j_int { #4 }
  1935. \bool_set_true:N \l__nicematrix_initial_open_bool
  1936. \bool_set_true:N \l__nicematrix_stop_loop_bool
  1937. }
  1938. {
  1939. \cs_if_exist:cTF
  1940. {
  1941. pgf @ sh @ ns @ \__nicematrix_env:
  1942. - \int_use:N \l__nicematrix_initial_i_int
  1943. - \int_use:N \l__nicematrix_initial_j_int
  1944. }
  1945. { \bool_set_true:N \l__nicematrix_stop_loop_bool }
  1946. {
  1947. \cs_set:cpn
  1948. {
  1949. __nicematrix _ dotted _
  1950. \int_use:N \l__nicematrix_initial_i_int -
  1951. \int_use:N \l__nicematrix_initial_j_int
  1952. }
  1953. { }
  1954. }
  1955. }
  1956. }
  1957. }
  1958. }
  1959. \cs_new_protected:Npn \__nicematrix_set_initial_coords:
  1960. {
  1961. \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x
  1962. \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y
  1963. }
  1964. \cs_new_protected:Npn \__nicematrix_set_final_coords:
  1965. {
  1966. \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x
  1967. \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y
  1968. }
  1969. \cs_new_protected:Npn \__nicematrix_set_initial_coords_from_anchor:n #1
  1970. {
  1971. \pgfpointanchor
  1972. {
  1973. \__nicematrix_env:
  1974. - \int_use:N \l__nicematrix_initial_i_int
  1975. - \int_use:N \l__nicematrix_initial_j_int
  1976. }
  1977. { #1 }
  1978. \__nicematrix_set_initial_coords:
  1979. }
  1980. \cs_new_protected:Npn \__nicematrix_set_final_coords_from_anchor:n #1
  1981. {
  1982. \pgfpointanchor
  1983. {
  1984. \__nicematrix_env:
  1985. - \int_use:N \l__nicematrix_final_i_int
  1986. - \int_use:N \l__nicematrix_final_j_int
  1987. }
  1988. { #1 }
  1989. \__nicematrix_set_final_coords:
  1990. }
  1991. \cs_new_protected:Npn \__nicematrix_draw_Ldots:nnn #1 #2 #3
  1992. {
  1993. \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 }
  1994. {
  1995. \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 0 1
  1996. \group_begin:
  1997. \int_compare:nNnTF { #1 } = 0
  1998. { \color { nicematrix-first-row } }
  1999. {
  2000. \int_compare:nNnT { #1 } = \l__nicematrix_last_row_int
  2001. { \color { nicematrix-last-row } }
  2002. }
  2003. \keys_set:nn { NiceMatrix / xdots } { #3 }
  2004. \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } }
  2005. \__nicematrix_actually_draw_Ldots:
  2006. \group_end:
  2007. }
  2008. }
  2009. \cs_new_protected:Npn \__nicematrix_actually_draw_Ldots:
  2010. {
  2011. \bool_if:NTF \l__nicematrix_initial_open_bool
  2012. {
  2013. \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_initial_j_int }
  2014. \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x
  2015. \dim_add:Nn \l__nicematrix_x_initial_dim
  2016. { \bool_if:NTF \l__nicematrix_NiceTabular_bool \tabcolsep \arraycolsep }
  2017. \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int - base }
  2018. \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y
  2019. }
  2020. { \__nicematrix_set_initial_coords_from_anchor:n { base~east } }
  2021. \bool_if:NTF \l__nicematrix_final_open_bool
  2022. {
  2023. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_final_j_int }
  2024. \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x
  2025. \dim_sub:Nn \l__nicematrix_x_final_dim
  2026. { \bool_if:NTF \l__nicematrix_NiceTabular_bool \tabcolsep \arraycolsep }
  2027. \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_final_i_int - base }
  2028. \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y
  2029. }
  2030. { \__nicematrix_set_final_coords_from_anchor:n { base~west } }
  2031. \dim_add:Nn \l__nicematrix_y_initial_dim \l__nicematrix_radius_dim
  2032. \dim_add:Nn \l__nicematrix_y_final_dim \l__nicematrix_radius_dim
  2033. \__nicematrix_draw_line:
  2034. }
  2035. \cs_new_protected:Npn \__nicematrix_draw_Cdots:nnn #1 #2 #3
  2036. {
  2037. \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 }
  2038. {
  2039. \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 0 1
  2040. \group_begin:
  2041. \int_compare:nNnTF { #1 } = 0
  2042. { \color { nicematrix-first-row } }
  2043. {
  2044. \int_compare:nNnT { #1 } = \l__nicematrix_last_row_int
  2045. { \color { nicematrix-last-row } }
  2046. }
  2047. \keys_set:nn { NiceMatrix / xdots } { #3 }
  2048. \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } }
  2049. \__nicematrix_actually_draw_Cdots:
  2050. \group_end:
  2051. }
  2052. }
  2053. \cs_new_protected:Npn \__nicematrix_actually_draw_Cdots:
  2054. {
  2055. \bool_if:NTF \l__nicematrix_initial_open_bool
  2056. {
  2057. \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_initial_j_int }
  2058. \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x
  2059. \dim_add:Nn \l__nicematrix_x_initial_dim
  2060. { \bool_if:NTF \l__nicematrix_NiceTabular_bool \tabcolsep \arraycolsep }
  2061. }
  2062. { \__nicematrix_set_initial_coords_from_anchor:n { mid~east } }
  2063. \bool_if:NTF \l__nicematrix_final_open_bool
  2064. {
  2065. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_final_j_int }
  2066. \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x
  2067. \dim_sub:Nn \l__nicematrix_x_final_dim
  2068. { \bool_if:NTF \l__nicematrix_NiceTabular_bool \tabcolsep \arraycolsep }
  2069. }
  2070. { \__nicematrix_set_final_coords_from_anchor:n { mid~west } }
  2071. \bool_lazy_and:nnTF
  2072. \l__nicematrix_initial_open_bool
  2073. \l__nicematrix_final_open_bool
  2074. {
  2075. \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int }
  2076. \dim_set_eq:NN \l_tmpa_dim \pgf@y
  2077. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l__nicematrix_initial_i_int }
  2078. \dim_set:Nn \l__nicematrix_y_initial_dim { ( \l_tmpa_dim + \pgf@y ) / 2 }
  2079. \dim_set_eq:NN \l__nicematrix_y_final_dim \l__nicematrix_y_initial_dim
  2080. }
  2081. {
  2082. \bool_if:NT \l__nicematrix_initial_open_bool
  2083. { \dim_set_eq:NN \l__nicematrix_y_initial_dim \l__nicematrix_y_final_dim }
  2084. \bool_if:NT \l__nicematrix_final_open_bool
  2085. { \dim_set_eq:NN \l__nicematrix_y_final_dim \l__nicematrix_y_initial_dim }
  2086. }
  2087. \__nicematrix_draw_line:
  2088. }
  2089. \cs_new_protected:Npn \__nicematrix_draw_Vdots:nnn #1 #2 #3
  2090. {
  2091. \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } }
  2092. \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 }
  2093. {
  2094. \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 0
  2095. \group_begin:
  2096. \int_compare:nNnTF { #2 } = 0
  2097. { \color { nicematrix-first-col } }
  2098. {
  2099. \int_compare:nNnT { #2 } = \l__nicematrix_last_col_int
  2100. { \color { nicematrix-last-col } }
  2101. }
  2102. \keys_set:nn { NiceMatrix / xdots } { #3 }
  2103. \__nicematrix_actually_draw_Vdots:
  2104. \group_end:
  2105. }
  2106. }
  2107. \cs_new_protected:Npn \__nicematrix_actually_draw_Vdots:
  2108. {
  2109. \bool_set_false:N \l_tmpa_bool
  2110. \bool_lazy_or:nnF \l__nicematrix_initial_open_bool \l__nicematrix_final_open_bool
  2111. {
  2112. \__nicematrix_set_initial_coords_from_anchor:n { south~west }
  2113. \__nicematrix_set_final_coords_from_anchor:n { north~west }
  2114. \bool_set:Nn \l_tmpa_bool
  2115. { \dim_compare_p:nNn \l__nicematrix_x_initial_dim = \l__nicematrix_x_final_dim }
  2116. }
  2117. \bool_if:NTF \l__nicematrix_initial_open_bool
  2118. {
  2119. \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int }
  2120. \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y
  2121. }
  2122. { \__nicematrix_set_initial_coords_from_anchor:n { south } }
  2123. \bool_if:NTF \l__nicematrix_final_open_bool
  2124. {
  2125. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l__nicematrix_final_i_int }
  2126. \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y
  2127. }
  2128. { \__nicematrix_set_final_coords_from_anchor:n { north } }
  2129. \bool_if:NTF \l__nicematrix_initial_open_bool
  2130. {
  2131. \bool_if:NTF \l__nicematrix_final_open_bool
  2132. {
  2133. \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_initial_j_int }
  2134. \dim_set_eq:NN \l_tmpa_dim \pgf@x
  2135. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_initial_j_int }
  2136. \dim_set:Nn \l__nicematrix_x_initial_dim { ( \pgf@x + \l_tmpa_dim ) / 2 }
  2137. \dim_set_eq:NN \l__nicematrix_x_final_dim \l__nicematrix_x_initial_dim
  2138. \int_compare:nNnT \l__nicematrix_last_col_int > { -2 }
  2139. {
  2140. \int_compare:nNnT \l__nicematrix_initial_j_int = \g__nicematrix_col_total_int
  2141. {
  2142. \dim_set_eq:NN \l_tmpa_dim \l__nicematrix_right_margin_dim
  2143. \dim_add:Nn \l_tmpa_dim \l__nicematrix_extra_right_margin_dim
  2144. \dim_add:Nn \l__nicematrix_x_initial_dim \l_tmpa_dim
  2145. \dim_add:Nn \l__nicematrix_x_final_dim \l_tmpa_dim
  2146. }
  2147. }
  2148. }
  2149. { \dim_set_eq:NN \l__nicematrix_x_initial_dim \l__nicematrix_x_final_dim }
  2150. }
  2151. {
  2152. \bool_if:NTF \l__nicematrix_final_open_bool
  2153. { \dim_set_eq:NN \l__nicematrix_x_final_dim \l__nicematrix_x_initial_dim }
  2154. {
  2155. \dim_compare:nNnF \l__nicematrix_x_initial_dim = \l__nicematrix_x_final_dim
  2156. {
  2157. \dim_set:Nn \l__nicematrix_x_initial_dim
  2158. {
  2159. \bool_if:NTF \l_tmpa_bool \dim_min:nn \dim_max:nn
  2160. \l__nicematrix_x_initial_dim \l__nicematrix_x_final_dim
  2161. }
  2162. \dim_set_eq:NN \l__nicematrix_x_final_dim \l__nicematrix_x_initial_dim
  2163. }
  2164. }
  2165. }
  2166. \__nicematrix_draw_line:
  2167. }
  2168. \cs_new_protected:Npn \__nicematrix_draw_Ddots:nnn #1 #2 #3
  2169. {
  2170. \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 }
  2171. {
  2172. \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 1
  2173. \group_begin:
  2174. \keys_set:nn { NiceMatrix / xdots } { #3 }
  2175. \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } }
  2176. \__nicematrix_actually_draw_Ddots:
  2177. \group_end:
  2178. }
  2179. }
  2180. \cs_new_protected:Npn \__nicematrix_actually_draw_Ddots:
  2181. {
  2182. \bool_if:NTF \l__nicematrix_initial_open_bool
  2183. {
  2184. \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int }
  2185. \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y
  2186. \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_initial_j_int }
  2187. \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x
  2188. }
  2189. { \__nicematrix_set_initial_coords_from_anchor:n { south~east } }
  2190. \bool_if:NTF \l__nicematrix_final_open_bool
  2191. {
  2192. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l__nicematrix_final_i_int }
  2193. \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y
  2194. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_final_j_int }
  2195. \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x
  2196. }
  2197. { \__nicematrix_set_final_coords_from_anchor:n { north~west } }
  2198. \bool_if:NT \l__nicematrix_parallelize_diags_bool
  2199. {
  2200. \int_gincr:N \g__nicematrix_ddots_int
  2201. \int_compare:nNnTF \g__nicematrix_ddots_int = 1
  2202. {
  2203. \dim_gset:Nn \g__nicematrix_delta_x_one_dim
  2204. { \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim }
  2205. \dim_gset:Nn \g__nicematrix_delta_y_one_dim
  2206. { \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim }
  2207. }
  2208. {
  2209. \dim_set:Nn \l__nicematrix_y_final_dim
  2210. {
  2211. \l__nicematrix_y_initial_dim +
  2212. ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) *
  2213. \dim_ratio:nn \g__nicematrix_delta_y_one_dim \g__nicematrix_delta_x_one_dim
  2214. }
  2215. }
  2216. }
  2217. \__nicematrix_draw_line:
  2218. }
  2219. \cs_new_protected:Npn \__nicematrix_draw_Iddots:nnn #1 #2 #3
  2220. {
  2221. \cs_if_free:cT { __nicematrix _ dotted _ #1 - #2 }
  2222. {
  2223. \__nicematrix_find_extremities_of_line:nnnn { #1 } { #2 } 1 { -1 }
  2224. \group_begin:
  2225. \keys_set:nn { NiceMatrix / xdots } { #3 }
  2226. \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } }
  2227. \__nicematrix_actually_draw_Iddots:
  2228. \group_end:
  2229. }
  2230. }
  2231. \cs_new_protected:Npn \__nicematrix_actually_draw_Iddots:
  2232. {
  2233. \bool_if:NTF \l__nicematrix_initial_open_bool
  2234. {
  2235. \__nicematrix_qpoint:n { row - \int_use:N \l__nicematrix_initial_i_int }
  2236. \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y
  2237. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l__nicematrix_initial_j_int }
  2238. \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x
  2239. }
  2240. { \__nicematrix_set_initial_coords_from_anchor:n { south~west } }
  2241. \bool_if:NTF \l__nicematrix_final_open_bool
  2242. {
  2243. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l__nicematrix_final_i_int }
  2244. \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y
  2245. \__nicematrix_qpoint:n { col - \int_use:N \l__nicematrix_final_j_int }
  2246. \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x
  2247. }
  2248. { \__nicematrix_set_final_coords_from_anchor:n { north~east } }
  2249. \bool_if:NT \l__nicematrix_parallelize_diags_bool
  2250. {
  2251. \int_gincr:N \g__nicematrix_iddots_int
  2252. \int_compare:nNnTF \g__nicematrix_iddots_int = 1
  2253. {
  2254. \dim_gset:Nn \g__nicematrix_delta_x_two_dim
  2255. { \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim }
  2256. \dim_gset:Nn \g__nicematrix_delta_y_two_dim
  2257. { \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim }
  2258. }
  2259. {
  2260. \dim_set:Nn \l__nicematrix_y_final_dim
  2261. {
  2262. \l__nicematrix_y_initial_dim +
  2263. ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) *
  2264. \dim_ratio:nn \g__nicematrix_delta_y_two_dim \g__nicematrix_delta_x_two_dim
  2265. }
  2266. }
  2267. }
  2268. \__nicematrix_draw_line:
  2269. }
  2270. \NewExpandableDocumentCommand \NiceMatrixLastEnv { }
  2271. { \int_use:N \g__nicematrix_env_int }
  2272. \cs_new_protected:Npn \__nicematrix_draw_line:
  2273. {
  2274. \pgfrememberpicturepositiononpagetrue
  2275. \pgf@relevantforpicturesizefalse
  2276. \tl_if_eq:NNTF \l__nicematrix_xdots_line_style_tl \c__nicematrix_standard_tl
  2277. \__nicematrix_draw_standard_dotted_line:
  2278. \__nicematrix_draw_non_standard_dotted_line:
  2279. }
  2280. \cs_new_protected:Npn \__nicematrix_draw_non_standard_dotted_line:
  2281. {
  2282. \begin { scope }
  2283. \exp_args:No \__nicematrix_draw_non_standard_dotted_line:n
  2284. { \l__nicematrix_xdots_line_style_tl , \l__nicematrix_xdots_color_tl }
  2285. }
  2286. \cs_new_protected:Npn \__nicematrix_draw_non_standard_dotted_line:n #1
  2287. {
  2288. \draw
  2289. [
  2290. #1 ,
  2291. shorten~> = \l__nicematrix_xdots_shorten_dim ,
  2292. shorten~< = \l__nicematrix_xdots_shorten_dim ,
  2293. ]
  2294. ( \l__nicematrix_x_initial_dim , \l__nicematrix_y_initial_dim )
  2295. -- node [ sloped , above ]
  2296. { \c_math_toggle_token \scriptstyle \l__nicematrix_xdots_up_tl \c_math_toggle_token }
  2297. node [ sloped , below ]
  2298. {
  2299. \c_math_toggle_token
  2300. \scriptstyle \l__nicematrix_xdots_down_tl
  2301. \c_math_toggle_token
  2302. }
  2303. ( \l__nicematrix_x_final_dim , \l__nicematrix_y_final_dim ) ;
  2304. \end { scope }
  2305. }
  2306. \cs_new_protected:Npn \__nicematrix_draw_standard_dotted_line:
  2307. {
  2308. \bool_lazy_and:nnF
  2309. { \tl_if_empty_p:N \l__nicematrix_xdots_up_tl }
  2310. { \tl_if_empty_p:N \l__nicematrix_xdots_down_tl }
  2311. {
  2312. \pgfscope
  2313. \pgftransformshift
  2314. {
  2315. \pgfpointlineattime { 0.5 }
  2316. { \pgfpoint \l__nicematrix_x_initial_dim \l__nicematrix_y_initial_dim }
  2317. { \pgfpoint \l__nicematrix_x_final_dim \l__nicematrix_y_final_dim }
  2318. }
  2319. \pgftransformrotate
  2320. {
  2321. \fp_eval:n
  2322. {
  2323. atand
  2324. (
  2325. \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim ,
  2326. \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim
  2327. )
  2328. }
  2329. }
  2330. \pgfnode
  2331. { rectangle }
  2332. { south }
  2333. {
  2334. \c_math_toggle_token
  2335. \scriptstyle \l__nicematrix_xdots_up_tl
  2336. \c_math_toggle_token
  2337. }
  2338. { }
  2339. { \pgfusepath { } }
  2340. \pgfnode
  2341. { rectangle }
  2342. { north }
  2343. {
  2344. \c_math_toggle_token
  2345. \scriptstyle \l__nicematrix_xdots_down_tl
  2346. \c_math_toggle_token
  2347. }
  2348. { }
  2349. { \pgfusepath { } }
  2350. \endpgfscope
  2351. }
  2352. \pgfrememberpicturepositiononpagetrue
  2353. \pgf@relevantforpicturesizefalse
  2354. \group_begin:
  2355. \dim_zero_new:N \l__nicematrix_l_dim
  2356. \dim_set:Nn \l__nicematrix_l_dim
  2357. {
  2358. \fp_to_dim:n
  2359. {
  2360. sqrt
  2361. (
  2362. ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) ^ 2
  2363. +
  2364. ( \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim ) ^ 2
  2365. )
  2366. }
  2367. }
  2368. \bool_lazy_or:nnF
  2369. { \dim_compare_p:nNn { \dim_abs:n \l__nicematrix_l_dim } > \c__nicematrix_max_l_dim }
  2370. { \dim_compare_p:nNn \l__nicematrix_l_dim = \c_zero_dim }
  2371. \__nicematrix_draw_standard_dotted_line_i:
  2372. \group_end:
  2373. }
  2374. \dim_const:Nn \c__nicematrix_max_l_dim { 50 cm }
  2375. \cs_new_protected:Npn \__nicematrix_draw_standard_dotted_line_i:
  2376. {
  2377. \bool_if:NTF \l__nicematrix_initial_open_bool
  2378. {
  2379. \bool_if:NTF \l__nicematrix_final_open_bool
  2380. {
  2381. \int_set:Nn \l_tmpa_int
  2382. { \dim_ratio:nn \l__nicematrix_l_dim \l__nicematrix_inter_dots_dim }
  2383. }
  2384. {
  2385. \int_set:Nn \l_tmpa_int
  2386. {
  2387. \dim_ratio:nn
  2388. { \l__nicematrix_l_dim - \l__nicematrix_xdots_shorten_dim }
  2389. \l__nicematrix_inter_dots_dim
  2390. }
  2391. }
  2392. }
  2393. {
  2394. \bool_if:NTF \l__nicematrix_final_open_bool
  2395. {
  2396. \int_set:Nn \l_tmpa_int
  2397. {
  2398. \dim_ratio:nn
  2399. { \l__nicematrix_l_dim - \l__nicematrix_xdots_shorten_dim }
  2400. \l__nicematrix_inter_dots_dim
  2401. }
  2402. }
  2403. {
  2404. \int_set:Nn \l_tmpa_int
  2405. {
  2406. \dim_ratio:nn
  2407. { \l__nicematrix_l_dim - 2 \l__nicematrix_xdots_shorten_dim }
  2408. \l__nicematrix_inter_dots_dim
  2409. }
  2410. }
  2411. }
  2412. \dim_set:Nn \l_tmpa_dim
  2413. {
  2414. ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) *
  2415. \dim_ratio:nn \l__nicematrix_inter_dots_dim \l__nicematrix_l_dim
  2416. }
  2417. \dim_set:Nn \l_tmpb_dim
  2418. {
  2419. ( \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim ) *
  2420. \dim_ratio:nn \l__nicematrix_inter_dots_dim \l__nicematrix_l_dim
  2421. }
  2422. \int_set:Nn \l_tmpb_int
  2423. {
  2424. \bool_if:NTF \l__nicematrix_initial_open_bool
  2425. { \bool_if:NTF \l__nicematrix_final_open_bool 1 0 }
  2426. { \bool_if:NTF \l__nicematrix_final_open_bool 2 1 }
  2427. }
  2428. \dim_gadd:Nn \l__nicematrix_x_initial_dim
  2429. {
  2430. ( \l__nicematrix_x_final_dim - \l__nicematrix_x_initial_dim ) *
  2431. \dim_ratio:nn
  2432. { \l__nicematrix_l_dim - \l__nicematrix_inter_dots_dim * \l_tmpa_int }
  2433. { 2 \l__nicematrix_l_dim }
  2434. * \l_tmpb_int
  2435. }
  2436. \dim_gadd:Nn \l__nicematrix_y_initial_dim
  2437. {
  2438. ( \l__nicematrix_y_final_dim - \l__nicematrix_y_initial_dim ) *
  2439. \dim_ratio:nn
  2440. { \l__nicematrix_l_dim - \l__nicematrix_inter_dots_dim * \l_tmpa_int }
  2441. { 2 \l__nicematrix_l_dim }
  2442. * \l_tmpb_int
  2443. }
  2444. \pgf@relevantforpicturesizefalse
  2445. \int_step_inline:nnn 0 \l_tmpa_int
  2446. {
  2447. \pgfpathcircle
  2448. { \pgfpoint \l__nicematrix_x_initial_dim \l__nicematrix_y_initial_dim }
  2449. { \l__nicematrix_radius_dim }
  2450. \dim_add:Nn \l__nicematrix_x_initial_dim \l_tmpa_dim
  2451. \dim_add:Nn \l__nicematrix_y_initial_dim \l_tmpb_dim
  2452. }
  2453. \pgfusepathqfill
  2454. }
  2455. \AtBeginDocument
  2456. {
  2457. \tl_set:Nn \l__nicematrix_argspec_tl { s O { } E { _ ^ } { { } { } } }
  2458. \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl
  2459. \exp_args:NNV \NewDocumentCommand \__nicematrix_Ldots \l__nicematrix_argspec_tl
  2460. {
  2461. \bool_if:nTF { #1 }
  2462. { \__nicematrix_error:n { starred~commands } }
  2463. {
  2464. \int_compare:nNnTF \c@jCol = 0
  2465. { \__nicematrix_error:nn { in~first~col } \Ldots }
  2466. {
  2467. \int_compare:nNnTF \c@jCol = \l__nicematrix_last_col_int
  2468. { \__nicematrix_error:nn { in~last~col } \Ldots }
  2469. {
  2470. \__nicematrix_instruction_of_type:nn { Ldots }
  2471. { #2 , down = #3 , up = #4 }
  2472. }
  2473. }
  2474. }
  2475. \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_ldots }
  2476. \bool_gset_true:N \g__nicematrix_empty_cell_bool
  2477. }
  2478. \exp_args:NNV \NewDocumentCommand \__nicematrix_Cdots \l__nicematrix_argspec_tl
  2479. {
  2480. \bool_if:nTF { #1 }
  2481. { \__nicematrix_error:n { starred~commands } }
  2482. {
  2483. \int_compare:nNnTF \c@jCol = 0
  2484. { \__nicematrix_error:nn { in~first~col } \Cdots }
  2485. {
  2486. \int_compare:nNnTF \c@jCol = \l__nicematrix_last_col_int
  2487. { \__nicematrix_error:nn { in~last~col } \Cdots }
  2488. {
  2489. \__nicematrix_instruction_of_type:nn { Cdots }
  2490. { #2 , down = #3 , up = #4 }
  2491. }
  2492. }
  2493. }
  2494. \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_cdots }
  2495. \bool_gset_true:N \g__nicematrix_empty_cell_bool
  2496. }
  2497. \exp_args:NNV \NewDocumentCommand \__nicematrix_Vdots \l__nicematrix_argspec_tl
  2498. {
  2499. \bool_if:nTF { #1 }
  2500. { \__nicematrix_error:n { starred~commands } }
  2501. \int_compare:nNnTF \c@iRow = 0
  2502. { \__nicematrix_error:nn { in~first~row } \Vdots }
  2503. {
  2504. \int_compare:nNnTF \c@iRow = \l__nicematrix_last_row_int
  2505. { \__nicematrix_error:nn { in~last~row } \Vdots }
  2506. {
  2507. \__nicematrix_instruction_of_type:nn { Vdots }
  2508. { #2 , down = #3 , up = #4 }
  2509. }
  2510. }
  2511. \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_vdots }
  2512. \bool_gset_true:N \g__nicematrix_empty_cell_bool
  2513. }
  2514. \exp_args:NNV \NewDocumentCommand \__nicematrix_Ddots \l__nicematrix_argspec_tl
  2515. {
  2516. \bool_if:nTF { #1 }
  2517. { \__nicematrix_error:n { starred~commands } }
  2518. {
  2519. \int_case:nnF \c@iRow
  2520. {
  2521. 0 { \__nicematrix_error:nn { in~first~row } \Ddots }
  2522. \l__nicematrix_last_row_int { \__nicematrix_error:nn { in~last~row } \Ddots }
  2523. }
  2524. {
  2525. \int_case:nnF \c@jCol
  2526. {
  2527. 0 { \__nicematrix_error:nn { in~first~col } \Ddots }
  2528. \l__nicematrix_last_col_int { \__nicematrix_error:nn { in~last~col } \Ddots }
  2529. }
  2530. {
  2531. \__nicematrix_instruction_of_type:nn { Ddots }
  2532. { #2 , down = #3 , up = #4 }
  2533. }
  2534.  
  2535. }
  2536. }
  2537. \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_ddots }
  2538. \bool_gset_true:N \g__nicematrix_empty_cell_bool
  2539. }
  2540. \exp_args:NNV \NewDocumentCommand \__nicematrix_Iddots \l__nicematrix_argspec_tl
  2541. {
  2542. \bool_if:nTF { #1 }
  2543. { \__nicematrix_error:n { starred~commands } }
  2544. {
  2545. \int_case:nnF \c@iRow
  2546. {
  2547. 0 { \__nicematrix_error:nn { in~first~row } \Iddots }
  2548. \l__nicematrix_last_row_int { \__nicematrix_error:nn { in~last~row } \Iddots }
  2549. }
  2550. {
  2551. \int_case:nnF \c@jCol
  2552. {
  2553. 0 { \__nicematrix_error:nn { in~first~col } \Iddots }
  2554. \l__nicematrix_last_col_int { \__nicematrix_error:nn { in~last~col } \Iddots }
  2555. }
  2556. {
  2557. \__nicematrix_instruction_of_type:nn { Iddots }
  2558. { #2 , down = #3 , up = #4 }
  2559. }
  2560.  
  2561. }
  2562. }
  2563. \bool_if:NF \l__nicematrix_nullify_dots_bool { \phantom \__nicematrix_old_iddots }
  2564. \bool_gset_true:N \g__nicematrix_empty_cell_bool
  2565. }
  2566. }
  2567. \cs_new_protected:Npn \__nicematrix_Hspace:
  2568. {
  2569. \bool_gset_true:N \g__nicematrix_empty_cell_bool
  2570. \hspace
  2571. }
  2572. \cs_set_eq:NN \__nicematrix_old_multicolumn \multicolumn
  2573. \cs_new:Npn \__nicematrix_multicolumn:nnn #1 #2 #3
  2574. {
  2575. \__nicematrix_old_multicolumn { #1 } { #2 } { #3 }
  2576. \peek_remove_spaces:n
  2577. {
  2578. \int_compare:nNnT #1 > 1
  2579. {
  2580. \seq_gput_left:Nx \g__nicematrix_multicolumn_cells_seq
  2581. { \int_use:N \c@iRow - \int_use:N \c@jCol }
  2582. \seq_gput_left:Nn \g__nicematrix_multicolumn_sizes_seq { #1 }
  2583. }
  2584. \int_gadd:Nn \c@jCol { #1 - 1 }
  2585. }
  2586. }
  2587. \cs_new:Npn \__nicematrix_Hdotsfor:
  2588. {
  2589. \multicolumn { 1 } { C } { }
  2590. \__nicematrix_Hdotsfor_i
  2591. }
  2592. \AtBeginDocument
  2593. {
  2594. \tl_set:Nn \l__nicematrix_argspec_tl { O { } m O { } E { _ ^ } { { } { } } }
  2595. \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl
  2596. \exp_args:NNV \NewDocumentCommand \__nicematrix_Hdotsfor_i \l__nicematrix_argspec_tl
  2597. {
  2598. \tl_gput_right:Nx \g__nicematrix_HVdotsfor_lines_tl
  2599. {
  2600. \__nicematrix_Hdotsfor:nnnn
  2601. { \int_use:N \c@iRow }
  2602. { \int_use:N \c@jCol }
  2603. { #2 }
  2604. {
  2605. #1 , #3 ,
  2606. down = \exp_not:n { #4 } , up = \exp_not:n { #5 }
  2607. }
  2608. }
  2609. \prg_replicate:nn { #2 - 1 } { & \multicolumn { 1 } { C } { } }
  2610. }
  2611. }
  2612. \cs_new_protected:Npn \__nicematrix_Hdotsfor:nnnn #1 #2 #3 #4
  2613. {
  2614. \bool_set_false:N \l__nicematrix_initial_open_bool
  2615. \bool_set_false:N \l__nicematrix_final_open_bool
  2616. \int_set:Nn \l__nicematrix_initial_i_int { #1 }
  2617. \int_set_eq:NN \l__nicematrix_final_i_int \l__nicematrix_initial_i_int
  2618. \int_compare:nNnTF #2 = 1
  2619. {
  2620. \int_set:Nn \l__nicematrix_initial_j_int 1
  2621. \bool_set_true:N \l__nicematrix_initial_open_bool
  2622. }
  2623. {
  2624. \cs_if_exist:cTF
  2625. {
  2626. pgf @ sh @ ns @ \__nicematrix_env:
  2627. - \int_use:N \l__nicematrix_initial_i_int
  2628. - \int_eval:n { #2 - 1 }
  2629. }
  2630. { \int_set:Nn \l__nicematrix_initial_j_int { #2 - 1 } }
  2631. {
  2632. \int_set:Nn \l__nicematrix_initial_j_int { #2 }
  2633. \bool_set_true:N \l__nicematrix_initial_open_bool
  2634. }
  2635. }
  2636. \int_compare:nNnTF { #2 + #3 -1 } = \c@jCol
  2637. {
  2638. \int_set:Nn \l__nicematrix_final_j_int { #2 + #3 - 1 }
  2639. \bool_set_true:N \l__nicematrix_final_open_bool
  2640. }
  2641. {
  2642. \cs_if_exist:cTF
  2643. {
  2644. pgf @ sh @ ns @ \__nicematrix_env:
  2645. - \int_use:N \l__nicematrix_final_i_int
  2646. - \int_eval:n { #2 + #3 }
  2647. }
  2648. { \int_set:Nn \l__nicematrix_final_j_int { #2 + #3 } }
  2649. {
  2650. \int_set:Nn \l__nicematrix_final_j_int { #2 + #3 - 1 }
  2651. \bool_set_true:N \l__nicematrix_final_open_bool
  2652. }
  2653. }
  2654. \group_begin:
  2655. \int_compare:nNnTF { #1 } = 0
  2656. { \color { nicematrix-first-row } }
  2657. {
  2658. \int_compare:nNnT { #1 } = \g__nicematrix_row_total_int
  2659. { \color { nicematrix-last-row } }
  2660. }
  2661. \keys_set:nn { NiceMatrix / xdots } { #4 }
  2662. \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } }
  2663. \__nicematrix_actually_draw_Ldots:
  2664. \group_end:
  2665. \int_step_inline:nnn { #2 } { #2 + #3 - 1 }
  2666. { \cs_set:cpn { __nicematrix _ dotted _ #1 - ##1 } { } }
  2667. }
  2668. \AtBeginDocument
  2669. {
  2670. \tl_set:Nn \l__nicematrix_argspec_tl { O { } m O { } E { _ ^ } { { } { } } }
  2671. \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl
  2672. \exp_args:NNV \NewDocumentCommand \__nicematrix_Vdotsfor: \l__nicematrix_argspec_tl
  2673. {
  2674. \tl_gput_right:Nx \g__nicematrix_HVdotsfor_lines_tl
  2675. {
  2676. \__nicematrix_Vdotsfor:nnnn
  2677. { \int_use:N \c@iRow }
  2678. { \int_use:N \c@jCol }
  2679. { #2 }
  2680. {
  2681. #1 , #3 ,
  2682. down = \exp_not:n { #4 } , up = \exp_not:n { #5 }
  2683. }
  2684. }
  2685. }
  2686. }
  2687. \cs_new_protected:Npn \__nicematrix_Vdotsfor:nnnn #1 #2 #3 #4
  2688. {
  2689. \bool_set_false:N \l__nicematrix_initial_open_bool
  2690. \bool_set_false:N \l__nicematrix_final_open_bool
  2691. \int_set:Nn \l__nicematrix_initial_j_int { #2 }
  2692. \int_set_eq:NN \l__nicematrix_final_j_int \l__nicematrix_initial_j_int
  2693. \int_compare:nNnTF #1 = 1
  2694. {
  2695. \int_set:Nn \l__nicematrix_initial_i_int 1
  2696. \bool_set_true:N \l__nicematrix_initial_open_bool
  2697. }
  2698. {
  2699. \cs_if_exist:cTF
  2700. {
  2701. pgf @ sh @ ns @ \__nicematrix_env:
  2702. - \int_eval:n { #1 - 1 }
  2703. - \int_use:N \l__nicematrix_initial_j_int
  2704. }
  2705. { \int_set:Nn \l__nicematrix_initial_i_int { #1 - 1 } }
  2706. {
  2707. \int_set:Nn \l__nicematrix_initial_i_int { #1 }
  2708. \bool_set_true:N \l__nicematrix_initial_open_bool
  2709. }
  2710. }
  2711. \int_compare:nNnTF { #1 + #3 -1 } = \c@iRow
  2712. {
  2713. \int_set:Nn \l__nicematrix_final_i_int { #1 + #3 - 1 }
  2714. \bool_set_true:N \l__nicematrix_final_open_bool
  2715. }
  2716. {
  2717. \cs_if_exist:cTF
  2718. {
  2719. pgf @ sh @ ns @ \__nicematrix_env:
  2720. - \int_eval:n { #1 + #3 }
  2721. - \int_use:N \l__nicematrix_final_j_int
  2722. }
  2723. { \int_set:Nn \l__nicematrix_final_i_int { #1 + #3 } }
  2724. {
  2725. \int_set:Nn \l__nicematrix_final_i_int { #1 + #3 - 1 }
  2726. \bool_set_true:N \l__nicematrix_final_open_bool
  2727. }
  2728. }
  2729. \group_begin:
  2730. \int_compare:nNnTF { #2 } = 0
  2731. { \color { nicematrix-first-col } }
  2732. {
  2733. \int_compare:nNnT { #2 } = \g__nicematrix_col_total_int
  2734. { \color { nicematrix-last-col } }
  2735. }
  2736. \keys_set:nn { NiceMatrix / xdots } { #4 }
  2737. \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } }
  2738. \__nicematrix_actually_draw_Vdots:
  2739. \group_end:
  2740. \int_step_inline:nnn { #1 } { #1 + #3 - 1 }
  2741. { \cs_set:cpn { __nicematrix _ dotted _ ##1 - #2 } { } }
  2742. }
  2743. \cs_new_protected:Npn \__nicematrix_rotate: { \group_insert_after:N \__nicematrix_rotate_i: }
  2744. \cs_new_protected:Npn \__nicematrix_rotate_i: { \group_insert_after:N \__nicematrix_rotate_ii: }
  2745. \cs_new_protected:Npn \__nicematrix_rotate_ii: { \group_insert_after:N \__nicematrix_rotate_iii: }
  2746. \cs_new_protected:Npn \__nicematrix_rotate_iii:
  2747. {
  2748. \box_rotate:Nn \l__nicematrix_cell_box { 90 }
  2749. \int_compare:nNnT \c@iRow = \l__nicematrix_last_row_int
  2750. {
  2751. \vbox_set_top:Nn \l__nicematrix_cell_box
  2752. {
  2753. \vbox_to_zero:n { }
  2754. \skip_vertical:n { - \box_ht:N \@arstrutbox + 0.8 ex }
  2755. \box_use:N \l__nicematrix_cell_box
  2756. }
  2757. }
  2758. }
  2759. \cs_new:Npn \__nicematrix_double_int_eval:n #1-#2 \q_stop
  2760. { \int_eval:n { #1 } - \int_eval:n { #2 } }
  2761. \AtBeginDocument
  2762. {
  2763. \tl_set:Nn \l__nicematrix_argspec_tl { O { } m m ! O { } E { _ ^ } { { } { } } }
  2764. \tl_set_rescan:Nno \l__nicematrix_argspec_tl { } \l__nicematrix_argspec_tl
  2765. \exp_args:NNV \NewDocumentCommand \__nicematrix_line \l__nicematrix_argspec_tl
  2766. {
  2767. \group_begin:
  2768. \keys_set:nn { NiceMatrix / xdots } { #1 , #4 , down = #5 , up = #6 }
  2769. \tl_if_empty:VF \l__nicematrix_xdots_color_tl { \color { \l__nicematrix_xdots_color_tl } }
  2770. \use:x
  2771. {
  2772. \__nicematrix_line_i:nn
  2773. { \__nicematrix_double_int_eval:n #2 \q_stop }
  2774. { \__nicematrix_double_int_eval:n #3 \q_stop }
  2775. }
  2776. \group_end:
  2777. }
  2778. }
  2779. \cs_new_protected:Npn \__nicematrix_line_i:nn #1 #2
  2780. {
  2781. \bool_set_false:N \l__nicematrix_initial_open_bool
  2782. \bool_set_false:N \l__nicematrix_final_open_bool
  2783. \bool_if:nTF
  2784. {
  2785. \cs_if_free_p:c { pgf @ sh @ ns @ \__nicematrix_env: - #1 }
  2786. ||
  2787. \cs_if_free_p:c { pgf @ sh @ ns @ \__nicematrix_env: - #2 }
  2788. }
  2789. {
  2790. \__nicematrix_error:nnn { unknown~cell~for~line~in~code-after } { #1 } { #2 }
  2791. }
  2792. { \__nicematrix_draw_line_ii:nn { #1 } { #2 } }
  2793. }
  2794. \AtBeginDocument
  2795. {
  2796. \cs_new_protected:Npx \__nicematrix_draw_line_ii:nn #1 #2
  2797. {
  2798. \c__nicematrix_pgfortikzpicture_tl
  2799. \__nicematrix_draw_line_iii:nn { #1 } { #2 }
  2800. \c__nicematrix_endpgfortikzpicture_tl
  2801. }
  2802. }
  2803. \cs_new_protected:Npn \__nicematrix_draw_line_iii:nn #1 #2
  2804. {
  2805. \pgfrememberpicturepositiononpagetrue
  2806. \pgfpointshapeborder { \__nicematrix_env: - #1 } { \__nicematrix_qpoint:n { #2 } }
  2807. \dim_set_eq:NN \l__nicematrix_x_initial_dim \pgf@x
  2808. \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y
  2809. \pgfpointshapeborder { \__nicematrix_env: - #2 } { \__nicematrix_qpoint:n { #1 } }
  2810. \dim_set_eq:NN \l__nicematrix_x_final_dim \pgf@x
  2811. \dim_set_eq:NN \l__nicematrix_y_final_dim \pgf@y
  2812. \__nicematrix_draw_line:
  2813. }
  2814. \cs_set_protected:Npn \__nicematrix_cut_on_hyphen:w #1-#2\q_stop
  2815. {
  2816. \tl_set:Nn \l_tmpa_tl { #1 }
  2817. \tl_set:Nn \l_tmpb_tl { #2 }
  2818. }
  2819. \NewDocumentCommand \__nicematrix_rowcolor { O { } m m }
  2820. {
  2821. \tl_if_blank:nF { #2 }
  2822. {
  2823. \pgfpicture
  2824. \pgf@relevantforpicturesizefalse
  2825. \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 }
  2826. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \c@jCol }
  2827. \dim_set:Nn \l_tmpa_dim { \pgf@x + 0.5 \arrayrulewidth }
  2828. \clist_map_inline:nn { #3 }
  2829. {
  2830. \tl_set:Nn \l_tmpa_tl { ##1 }
  2831. \tl_if_in:NnTF \l_tmpa_tl { - }
  2832. { \__nicematrix_cut_on_hyphen:w ##1 \q_stop }
  2833. { \__nicematrix_cut_on_hyphen:w ##1 - ##1 \q_stop }
  2834. \tl_if_empty:NT \l_tmpa_tl { \tl_set:Nn \l_tmpa_tl { 1 } }
  2835. \tl_if_empty:NT \l_tmpb_tl
  2836. { \tl_set:Nx \l_tmpb_tl { \int_use:N \c@iRow } }
  2837. \int_compare:nNnT \l_tmpb_tl > \c@iRow
  2838. { \tl_set:Nx \l_tmpb_tl { \int_use:N \c@iRow } }
  2839. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l_tmpb_tl }
  2840. \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth }
  2841. \__nicematrix_qpoint:n { row - \l_tmpa_tl }
  2842. \dim_set_eq:NN \l_tmpc_dim \pgf@x
  2843. \dim_set:Nn \l_tmpd_dim { \pgf@y + 0.5 \arrayrulewidth }
  2844. \pgfpathrectanglecorners
  2845. { \pgfpoint \l_tmpc_dim \l_tmpd_dim }
  2846. { \pgfpoint \l_tmpa_dim \l_tmpb_dim }
  2847. }
  2848. \pgfusepathqfill
  2849. \endpgfpicture
  2850. }
  2851. }
  2852. \NewDocumentCommand \__nicematrix_columncolor { O { } m m }
  2853. {
  2854. \tl_if_blank:nF { #2 }
  2855. {
  2856. \pgfpicture
  2857. \pgf@relevantforpicturesizefalse
  2858. \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 }
  2859. \__nicematrix_qpoint:n { row - 1 }
  2860. \dim_set:Nn \l_tmpa_dim {\pgf@y + 0.5 \arrayrulewidth }
  2861. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c@iRow }
  2862. \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth }
  2863. \clist_map_inline:nn { #3 }
  2864. {
  2865. \tl_set:Nn \l_tmpa_tl { ##1 }
  2866. \tl_if_in:NnTF \l_tmpa_tl { - }
  2867. { \__nicematrix_cut_on_hyphen:w ##1 \q_stop }
  2868. { \__nicematrix_cut_on_hyphen:w ##1 - ##1 \q_stop }
  2869. \tl_if_empty:NT \l_tmpa_tl { \tl_set:Nn \l_tmpa_tl { 1 } }
  2870. \tl_if_empty:NT \l_tmpb_tl
  2871. { \tl_set:Nx \l_tmpb_tl { \int_use:N \c@jCol } }
  2872. \int_compare:nNnT \l_tmpb_tl > \c@jCol
  2873. { \tl_set:Nx \l_tmpb_tl { \int_use:N \c@jCol } }
  2874. \__nicematrix_qpoint:n { col - \l_tmpa_tl }
  2875. \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth }
  2876. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l_tmpb_tl }
  2877. \dim_set:Nn \l_tmpd_dim { \pgf@x + 0.5 \arrayrulewidth }
  2878. \pgfpathrectanglecorners
  2879. { \pgfpoint \l_tmpc_dim \l_tmpa_dim }
  2880. { \pgfpoint \l_tmpd_dim \l_tmpb_dim }
  2881. }
  2882. \pgfusepathqfill
  2883. \endpgfpicture
  2884. }
  2885. }
  2886. \NewDocumentCommand \__nicematrix_cellcolor { O { } m m }
  2887. {
  2888. \tl_if_blank:nF { #2 }
  2889. {
  2890. \pgfpicture
  2891. \pgf@relevantforpicturesizefalse
  2892. \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 }
  2893. \clist_map_inline:nn { #3 }
  2894. {
  2895. \__nicematrix_cut_on_hyphen:w ##1 \q_stop
  2896. \__nicematrix_qpoint:n { row - \l_tmpa_tl }
  2897. \bool_lazy_and:nnT
  2898. { \int_compare_p:n { \l_tmpa_tl <= \c@iRow } }
  2899. { \int_compare_p:n { \l_tmpb_tl <= \c@jCol } }
  2900. {
  2901. \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth }
  2902. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l_tmpa_tl }
  2903. \dim_set:Nn \l_tmpa_dim { \pgf@y + 0.5 \arrayrulewidth }
  2904. \__nicematrix_qpoint:n { col - \l_tmpb_tl }
  2905. \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth }
  2906. \int_compare:nNnT \l_tmpb_tl = 1
  2907. { \dim_sub:Nn \l_tmpc_dim \arrayrulewidth }
  2908. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l_tmpb_tl }
  2909. \dim_set:Nn \l_tmpd_dim { \pgf@x + 0.5 \arrayrulewidth }
  2910. \pgfpathrectanglecorners
  2911. { \pgfpoint \l_tmpc_dim \l_tmpb_dim }
  2912. { \pgfpoint \l_tmpd_dim \l_tmpa_dim }
  2913. }
  2914. }
  2915. \pgfusepathqfill
  2916. \endpgfpicture
  2917. }
  2918. }
  2919. \NewDocumentCommand \__nicematrix_rectanglecolor { O { } m m m }
  2920. {
  2921. \tl_if_blank:nF { #2 }
  2922. {
  2923. \pgfpicture
  2924. \pgf@relevantforpicturesizefalse
  2925. \tl_if_empty:nTF { #1 } \color { \color [ #1 ] } { #2 }
  2926. \__nicematrix_cut_on_hyphen:w #3 \q_stop
  2927. \bool_lazy_and:nnT
  2928. { \int_compare_p:n { \l_tmpa_tl <= \c@iRow } }
  2929. { \int_compare_p:n { \l_tmpb_tl <= \c@jCol } }
  2930. {
  2931. \__nicematrix_qpoint:n { row - \l_tmpa_tl }
  2932. \dim_set:Nn \l_tmpb_dim { \pgf@y + 0.5 \arrayrulewidth }
  2933. \__nicematrix_qpoint:n { col - \l_tmpb_tl }
  2934. \__nicematrix_cut_on_hyphen:w #4 \q_stop
  2935. \int_compare:nNnT \l_tmpa_tl > \c@iRow
  2936. { \tl_set:Nx \l_tmpa_tl { \int_use:N \c@iRow } }
  2937. \int_compare:nNnT \l_tmpb_tl > \c@jCol
  2938. { \tl_set:Nx \l_tmpb_tl { \int_use:N \c@jCol } }
  2939. \dim_set:Nn \l_tmpc_dim { \pgf@x + 0.5 \arrayrulewidth }
  2940. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \l_tmpa_tl }
  2941. \dim_set:Nn \l_tmpa_dim { \pgf@y + 0.5 \arrayrulewidth }
  2942. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \l_tmpb_tl }
  2943. \dim_set:Nn \l_tmpd_dim { \pgf@x + 0.5 \arrayrulewidth }
  2944. \pgfpathrectanglecorners
  2945. { \pgfpoint \l_tmpc_dim \l_tmpb_dim }
  2946. { \pgfpoint \l_tmpd_dim \l_tmpa_dim }
  2947. \pgfusepathqfill
  2948. }
  2949. \endpgfpicture
  2950. }
  2951. }
  2952. \NewDocumentCommand \__nicematrix_rowcolors { O { } m m m }
  2953. {
  2954. \int_step_inline:nnn { #2 } { \int_use:N \c@iRow }
  2955. {
  2956. \int_if_odd:nTF { ##1 }
  2957. { \__nicematrix_rowcolor [ #1 ] { #3 } }
  2958. { \__nicematrix_rowcolor [ #1 ] { #4 } }
  2959. { ##1 }
  2960. }
  2961. }
  2962. \NewDocumentCommand \__nicematrix_chessboardcolors { O { } m m }
  2963. {
  2964. \int_step_inline:nn { \int_use:N \c@iRow }
  2965. {
  2966. \int_step_inline:nn { \int_use:N \c@jCol }
  2967. {
  2968. \int_if_even:nTF { ####1 + ##1 }
  2969. { \__nicematrix_cellcolor [ #1 ] { #2 } }
  2970. { \__nicematrix_cellcolor [ #1 ] { #3 } }
  2971. { ##1 - ####1 }
  2972. }
  2973. }
  2974. }
  2975. \cs_set_eq:NN \OnlyMainNiceMatrix \use:n
  2976. \cs_new_protected:Npn \__nicematrix_OnlyMainNiceMatrix:n #1
  2977. {
  2978. \int_compare:nNnTF \l__nicematrix_first_col_int = 0
  2979. { \__nicematrix_OnlyMainNiceMatrix_i:n { #1 } }
  2980. {
  2981. \int_compare:nNnTF \c@jCol = 0
  2982. {
  2983. \int_compare:nNnF \c@iRow = { -1 }
  2984. { \int_compare:nNnF \c@iRow = { \l__nicematrix_last_row_int - 1 } { #1 } }
  2985. }
  2986. { \__nicematrix_OnlyMainNiceMatrix_i:n { #1 } }
  2987. }
  2988. }
  2989. \cs_new_protected:Npn \__nicematrix_OnlyMainNiceMatrix_i:n #1
  2990. {
  2991. \int_compare:nNnF \c@iRow = 0
  2992. { \int_compare:nNnF \c@iRow = \l__nicematrix_last_row_int { #1 } }
  2993. }
  2994. \cs_new_protected:Npn \__nicematrix_vline:
  2995. { \__nicematrix_OnlyMainNiceMatrix:n { { \CT@arc@ \vline } } }
  2996. \cs_new_protected:Npn \__nicematrix_draw_vlines:
  2997. {
  2998. \group_begin:
  2999. \CT@arc@
  3000. \pgfpicture
  3001. \pgfrememberpicturepositiononpagetrue
  3002. \pgf@relevantforpicturesizefalse
  3003. \pgfsetlinewidth \arrayrulewidth
  3004. \__nicematrix_qpoint:n { row - 1 }
  3005. \dim_set_eq:NN \l_tmpa_dim \pgf@y
  3006. \pgfusepathqfill
  3007. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c@iRow }
  3008. \dim_sub:Nn \l_tmpa_dim \pgf@y
  3009. \pgfusepathqfill
  3010. \dim_zero:N \l_tmpb_dim
  3011. \int_compare:nNnT \l__nicematrix_last_row_int > { -1 }
  3012. {
  3013. \dim_set_eq:NN \l_tmpb_dim \g__nicematrix_dp_last_row_dim
  3014. \dim_add:Nn \l_tmpb_dim \g__nicematrix_ht_last_row_dim
  3015. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n\c@iRow }
  3016. \dim_add:Nn \l_tmpa_dim \pgf@y
  3017. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \g__nicematrix_row_total_int }
  3018. \dim_sub:Nn \l_tmpa_dim \pgf@y
  3019. \dim_sub:Nn \l_tmpa_dim \l_tmpb_dim
  3020. }
  3021. \dim_add:Nn \l_tmpa_dim \arrayrulewidth
  3022. \int_step_inline:nnn
  3023. { \bool_if:NTF \l__nicematrix_NiceArray_bool 1 2 }
  3024. { \bool_if:NTF \l__nicematrix_NiceArray_bool { \__nicematrix_succ:n \c@jCol } \c@jCol }
  3025. {
  3026. \pgfpathmoveto { \__nicematrix_qpoint:n { col - ##1 } }
  3027. \pgfpathlineto
  3028. {
  3029. \pgfpointadd
  3030. { \__nicematrix_qpoint:n { col - ##1 } }
  3031. { \pgfpoint \c_zero_dim { \l_tmpb_dim + \l_tmpa_dim } }
  3032. }
  3033. }
  3034. \pgfusepathqstroke
  3035. \endpgfpicture
  3036. \group_end:
  3037. }
  3038. \cs_new:Npn \__nicematrix_hdottedline:
  3039. {
  3040. \noalign { \skip_vertical:N 2\l__nicematrix_radius_dim }
  3041. \__nicematrix_hdottedline_i:
  3042. }
  3043. \cs_new_protected:Npn \__nicematrix_hdottedline_i:
  3044. {
  3045. \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl
  3046. { \__nicematrix_hdottedline:n { \int_use:N \c@iRow } }
  3047. }
  3048. \AtBeginDocument
  3049. {
  3050. \cs_new_protected:Npx \__nicematrix_hdottedline:n #1
  3051. {
  3052. \bool_set_true:N \exp_not:N \l__nicematrix_initial_open_bool
  3053. \bool_set_true:N \exp_not:N \l__nicematrix_final_open_bool
  3054. \c__nicematrix_pgfortikzpicture_tl
  3055. \__nicematrix_hdottedline_i:n { #1 }
  3056. \c__nicematrix_endpgfortikzpicture_tl
  3057. }
  3058. }
  3059. \cs_new_protected:Npn \__nicematrix_hdottedline_i:n #1
  3060. {
  3061. \pgfrememberpicturepositiononpagetrue
  3062. \__nicematrix_qpoint:n { row - #1 }
  3063. \dim_set_eq:NN \l__nicematrix_y_initial_dim \pgf@y
  3064. \dim_sub:Nn \l__nicematrix_y_initial_dim \l__nicematrix_radius_dim
  3065. \dim_set_eq:NN \l__nicematrix_y_final_dim \l__nicematrix_y_initial_dim
  3066. \__nicematrix_qpoint:n { col - 1 }
  3067. \dim_set:Nn \l__nicematrix_x_initial_dim
  3068. {
  3069. \pgf@x +
  3070. \bool_if:NTF \l__nicematrix_NiceTabular_bool \tabcolsep \arraycolsep
  3071. - \l__nicematrix_left_margin_dim
  3072. }
  3073. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n \c@jCol }
  3074. \dim_set:Nn \l__nicematrix_x_final_dim
  3075. {
  3076. \pgf@x -
  3077. \bool_if:NTF \l__nicematrix_NiceTabular_bool \tabcolsep \arraycolsep
  3078. + \l__nicematrix_right_margin_dim
  3079. }
  3080. \tl_set:Nn \l_tmpa_tl { ( }
  3081. \tl_if_eq:NNF \l__nicematrix_left_delim_tl \l_tmpa_tl
  3082. { \dim_gadd:Nn \l__nicematrix_x_initial_dim { 0.5 \l__nicematrix_inter_dots_dim } }
  3083. \tl_set:Nn \l_tmpa_tl { ) }
  3084. \tl_if_eq:NNF \l__nicematrix_right_delim_tl \l_tmpa_tl
  3085. { \dim_gsub:Nn \l__nicematrix_x_final_dim { 0.5 \l__nicematrix_inter_dots_dim } }
  3086. \tl_set_eq:NN \l__nicematrix_xdots_line_style_tl \c__nicematrix_standard_tl
  3087. \__nicematrix_draw_line:
  3088. }
  3089. \cs_new_protected:Npn \__nicematrix_vdottedline:n #1
  3090. {
  3091. \bool_set_true:N \l__nicematrix_initial_open_bool
  3092. \bool_set_true:N \l__nicematrix_final_open_bool
  3093. \bool_if:NTF \c__nicematrix_tikz_loaded_bool
  3094. {
  3095. \tikzpicture
  3096. \__nicematrix_vdottedline_i:n { #1 }
  3097. \endtikzpicture
  3098. }
  3099. {
  3100. \pgfpicture
  3101. \__nicematrix_vdottedline_i:n { #1 }
  3102. \endpgfpicture
  3103. }
  3104. }
  3105. \cs_new_protected:Npn \__nicematrix_vdottedline_i:n #1
  3106. {
  3107. \CT@arc@
  3108. \pgfrememberpicturepositiononpagetrue
  3109. \__nicematrix_qpoint:n { col - \int_eval:n { #1 + 1 } }
  3110. \dim_set:Nn \l__nicematrix_x_initial_dim { \pgf@x - \l__nicematrix_radius_dim }
  3111. \dim_set:Nn \l__nicematrix_x_final_dim { \pgf@x - \l__nicematrix_radius_dim }
  3112. \__nicematrix_qpoint:n { row - 1 }
  3113. \dim_set:Nn \l__nicematrix_y_initial_dim { \pgf@y - 0.5 \l__nicematrix_inter_dots_dim }
  3114. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n \c@iRow }
  3115. \dim_set:Nn \l__nicematrix_y_final_dim { \pgf@y + 0.5 \l__nicematrix_inter_dots_dim }
  3116. \tl_set_eq:NN \l__nicematrix_xdots_line_style_tl \c__nicematrix_standard_tl
  3117. \__nicematrix_draw_line:
  3118. }
  3119. \bool_new:N \l__nicematrix_block_auto_columns_width_bool
  3120. \keys_define:nn { NiceMatrix / NiceMatrixBlock }
  3121. {
  3122. auto-columns-width .code:n =
  3123. {
  3124. \bool_set_true:N \l__nicematrix_block_auto_columns_width_bool
  3125. \dim_gzero_new:N \g__nicematrix_max_cell_width_dim
  3126. \bool_set_true:N \l__nicematrix_auto_columns_width_bool
  3127. }
  3128. }
  3129. \NewDocumentEnvironment { NiceMatrixBlock } { ! O { } }
  3130. {
  3131. \int_gincr:N \g__nicematrix_NiceMatrixBlock_int
  3132. \dim_zero:N \l__nicematrix_columns_width_dim
  3133. \keys_set:nn { NiceMatrix / NiceMatrixBlock } { #1 }
  3134. \bool_if:NT \l__nicematrix_block_auto_columns_width_bool
  3135. {
  3136. \cs_if_exist:cT { __nicematrix_max_cell_width_ \int_use:N \g__nicematrix_NiceMatrixBlock_int }
  3137. {
  3138. \exp_args:NNc \dim_set:Nn \l__nicematrix_columns_width_dim
  3139. { __nicematrix_max_cell_width _ \int_use:N \g__nicematrix_NiceMatrixBlock_int }
  3140. }
  3141. }
  3142. }
  3143. {
  3144. \bool_if:NT \l__nicematrix_block_auto_columns_width_bool
  3145. {
  3146. \iow_shipout:Nn \@mainaux \ExplSyntaxOn
  3147. \iow_shipout:Nx \@mainaux
  3148. {
  3149. \cs_gset:cpn
  3150. { __nicematrix _ max _ cell _ width _ \int_use:N \g__nicematrix_NiceMatrixBlock_int }
  3151. { \dim_eval:n { \g__nicematrix_max_cell_width_dim + \arrayrulewidth } }
  3152. }
  3153. \iow_shipout:Nn \@mainaux \ExplSyntaxOff
  3154. }
  3155. }
  3156. \cs_generate_variant:Nn \dim_min:nn { v n }
  3157. \cs_generate_variant:Nn \dim_max:nn { v n }
  3158. \cs_new_protected:Npn \__nicematrix_computations_for_medium_nodes:
  3159. {
  3160. \int_step_variable:nnNn \l__nicematrix_first_row_int \g__nicematrix_row_total_int \__nicematrix_i:
  3161. {
  3162. \dim_zero_new:c { l__nicematrix_row_\__nicematrix_i: _min_dim }
  3163. \dim_set_eq:cN { l__nicematrix_row_\__nicematrix_i: _min_dim } \c_max_dim
  3164. \dim_zero_new:c { l__nicematrix_row_\__nicematrix_i: _max_dim }
  3165. \dim_set:cn { l__nicematrix_row_\__nicematrix_i: _max_dim } { - \c_max_dim }
  3166. }
  3167. \int_step_variable:nnNn \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j:
  3168. {
  3169. \dim_zero_new:c { l__nicematrix_column_\__nicematrix_j: _min_dim }
  3170. \dim_set_eq:cN { l__nicematrix_column_\__nicematrix_j: _min_dim } \c_max_dim
  3171. \dim_zero_new:c { l__nicematrix_column_\__nicematrix_j: _max_dim }
  3172. \dim_set:cn { l__nicematrix_column_\__nicematrix_j: _max_dim } { - \c_max_dim }
  3173. }
  3174. \int_step_variable:nnNn \l__nicematrix_first_row_int \g__nicematrix_row_total_int \__nicematrix_i:
  3175. {
  3176. \int_step_variable:nnNn
  3177. \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j:
  3178. {
  3179. \cs_if_exist:cT
  3180. { pgf @ sh @ ns @ \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: }
  3181. {
  3182. \pgfpointanchor { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: } { south~west }
  3183. \dim_set:cn { l__nicematrix_row_\__nicematrix_i: _min_dim}
  3184. { \dim_min:vn { l__nicematrix_row _ \__nicematrix_i: _min_dim } \pgf@y }
  3185. \seq_if_in:NxF \g__nicematrix_multicolumn_cells_seq { \__nicematrix_i: - \__nicematrix_j: }
  3186. {
  3187. \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _min_dim}
  3188. { \dim_min:vn { l__nicematrix_column _ \__nicematrix_j: _min_dim } \pgf@x }
  3189. }
  3190. \pgfpointanchor { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: } { north~east }
  3191. \dim_set:cn { l__nicematrix_row _ \__nicematrix_i: _ max_dim }
  3192. { \dim_max:vn { l__nicematrix_row _ \__nicematrix_i: _ max_dim } \pgf@y }
  3193. \seq_if_in:NxF \g__nicematrix_multicolumn_cells_seq { \__nicematrix_i: - \__nicematrix_j: }
  3194. {
  3195. \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _ max_dim }
  3196. { \dim_max:vn { l__nicematrix_column _ \__nicematrix_j: _max_dim } \pgf@x }
  3197. }
  3198. }
  3199. }
  3200. }
  3201. \int_step_variable:nnNn \l__nicematrix_first_row_int \g__nicematrix_row_total_int \__nicematrix_i:
  3202. {
  3203. \dim_compare:nNnT
  3204. { \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } } = \c_max_dim
  3205. {
  3206. \__nicematrix_qpoint:n { row - \__nicematrix_i: - base }
  3207. \dim_set:cn { l__nicematrix_row _ \__nicematrix_i: _ max _ dim } \pgf@y
  3208. \dim_set:cn { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } \pgf@y
  3209. }
  3210. }
  3211. \int_step_variable:nnNn \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j:
  3212. {
  3213. \dim_compare:nNnT
  3214. { \dim_use:c { l__nicematrix_column _ \__nicematrix_j: _ min _ dim } } = \c_max_dim
  3215. {
  3216. \__nicematrix_qpoint:n { col - \__nicematrix_j: }
  3217. \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _ max _ dim } \pgf@y
  3218. \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _ min _ dim } \pgf@y
  3219. }
  3220. }
  3221. }
  3222. \cs_new_protected:Npn \__nicematrix_create_medium_nodes:
  3223. {
  3224. \pgfpicture
  3225. \pgfrememberpicturepositiononpagetrue
  3226. \pgf@relevantforpicturesizefalse
  3227. \__nicematrix_computations_for_medium_nodes:
  3228. \tl_set:Nn \l__nicematrix_suffix_tl { -medium }
  3229. \__nicematrix_create_nodes:
  3230. \endpgfpicture
  3231. }
  3232. \cs_new_protected:Npn \__nicematrix_create_large_nodes:
  3233. {
  3234. \pgfpicture
  3235. \pgfrememberpicturepositiononpagetrue
  3236. \pgf@relevantforpicturesizefalse
  3237. \__nicematrix_computations_for_medium_nodes:
  3238. \__nicematrix_computations_for_large_nodes:
  3239. \tl_set:Nn \l__nicematrix_suffix_tl { - large }
  3240. \__nicematrix_create_nodes:
  3241. \endpgfpicture
  3242. }
  3243. \cs_new_protected:Npn \__nicematrix_create_medium_and_large_nodes:
  3244. {
  3245. \pgfpicture
  3246. \pgfrememberpicturepositiononpagetrue
  3247. \pgf@relevantforpicturesizefalse
  3248. \__nicematrix_computations_for_medium_nodes:
  3249. \tl_set:Nn \l__nicematrix_suffix_tl { - medium }
  3250. \__nicematrix_create_nodes:
  3251. \__nicematrix_computations_for_large_nodes:
  3252. \tl_set:Nn \l__nicematrix_suffix_tl { - large }
  3253. \__nicematrix_create_nodes:
  3254. \endpgfpicture
  3255. }
  3256. \cs_new_protected:Npn \__nicematrix_computations_for_large_nodes:
  3257. {
  3258. \int_set:Nn \l__nicematrix_first_row_int 1
  3259. \int_set:Nn \l__nicematrix_first_col_int 1
  3260. \int_step_variable:nNn { \c@iRow - 1 } \__nicematrix_i:
  3261. {
  3262. \dim_set:cn { l__nicematrix_row _ \__nicematrix_i: _ min _ dim }
  3263. {
  3264. (
  3265. \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } +
  3266. \dim_use:c { l__nicematrix_row _ \__nicematrix_succ:n \__nicematrix_i: _ max _ dim }
  3267. )
  3268. / 2
  3269. }
  3270. \dim_set_eq:cc { l__nicematrix_row _ \__nicematrix_succ:n \__nicematrix_i: _ max _ dim }
  3271. { l__nicematrix_row_\__nicematrix_i: _min_dim }
  3272. }
  3273. \int_step_variable:nNn { \c@jCol - 1 } \__nicematrix_j:
  3274. {
  3275. \dim_set:cn { l__nicematrix_column _ \__nicematrix_j: _ max _ dim }
  3276. {
  3277. (
  3278. \dim_use:c { l__nicematrix_column _ \__nicematrix_j: _ max _ dim } +
  3279. \dim_use:c
  3280. { l__nicematrix_column _ \__nicematrix_succ:n \__nicematrix_j: _ min _ dim }
  3281. )
  3282. / 2
  3283. }
  3284. \dim_set_eq:cc { l__nicematrix_column _ \__nicematrix_succ:n \__nicematrix_j: _ min _ dim }
  3285. { l__nicematrix_column _ \__nicematrix_j: _ max _ dim }
  3286. }
  3287. \dim_sub:cn
  3288. { l__nicematrix_column _ 1 _ min _ dim }
  3289. \l__nicematrix_left_margin_dim
  3290. \dim_add:cn
  3291. { l__nicematrix_column _ \int_use:N \c@jCol _ max _ dim }
  3292. \l__nicematrix_right_margin_dim
  3293. }
  3294. \cs_new_protected:Npn \__nicematrix_create_nodes:
  3295. {
  3296. \int_step_variable:nnNn \l__nicematrix_first_row_int \g__nicematrix_row_total_int \__nicematrix_i:
  3297. {
  3298. \int_step_variable:nnNn \l__nicematrix_first_col_int \g__nicematrix_col_total_int \__nicematrix_j:
  3299. {
  3300. \__nicematrix_pgf_rect_node:nnnnn
  3301. { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl }
  3302. { \dim_use:c { l__nicematrix_column_ \__nicematrix_j: _min_dim } }
  3303. { \dim_use:c { l__nicematrix_row_ \__nicematrix_i: _min_dim } }
  3304. { \dim_use:c { l__nicematrix_column_ \__nicematrix_j: _max_dim } }
  3305. { \dim_use:c { l__nicematrix_row_ \__nicematrix_i: _max_dim } }
  3306. \str_if_empty:NF \l__nicematrix_name_str
  3307. {
  3308. \pgfnodealias
  3309. { \l__nicematrix_name_str - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl }
  3310. { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl }
  3311. }
  3312. }
  3313. }
  3314. \seq_mapthread_function:NNN
  3315. \g__nicematrix_multicolumn_cells_seq
  3316. \g__nicematrix_multicolumn_sizes_seq
  3317. \__nicematrix_node_for_multicolumn:nn
  3318. }
  3319. \cs_new_protected:Npn \__nicematrix_extract_coords_values: #1 - #2 \q_stop
  3320. {
  3321. \cs_set:Npn \__nicematrix_i: { #1 }
  3322. \cs_set:Npn \__nicematrix_j: { #2 }
  3323. }
  3324. \cs_new_protected:Npn \__nicematrix_node_for_multicolumn:nn #1 #2
  3325. {
  3326. \__nicematrix_extract_coords_values: #1 \q_stop
  3327. \__nicematrix_pgf_rect_node:nnnnn
  3328. { \__nicematrix_env: - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl }
  3329. { \dim_use:c { l__nicematrix_column _ \__nicematrix_j: _ min _ dim } }
  3330. { \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ min _ dim } }
  3331. { \dim_use:c { l__nicematrix_column _ \int_eval:n { \__nicematrix_j: +#2-1 } _ max _ dim } }
  3332. { \dim_use:c { l__nicematrix_row _ \__nicematrix_i: _ max _ dim } }
  3333. \str_if_empty:NF \l__nicematrix_name_str
  3334. {
  3335. \pgfnodealias
  3336. { \l__nicematrix_name_str - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl }
  3337. { \int_use:N \g__nicematrix_env_int - \__nicematrix_i: - \__nicematrix_j: \l__nicematrix_suffix_tl}
  3338. }
  3339. }
  3340. \NewDocumentCommand \__nicematrix_Block: { O { } m D < > { } m }
  3341. { \__nicematrix_Block_i #2 \q_stop { #1 } { #3 } { #4 } }
  3342. \cs_new:Npn \__nicematrix_Block_i #1-#2 \q_stop { \__nicematrix_Block_ii:nnnnn { #1 } { #2 } }
  3343. \cs_new_protected:Npn \__nicematrix_Block_ii:nnnnn #1 #2 #3 #4 #5
  3344. {
  3345. \tl_gput_left:Nx \g__nicematrix_internal_code_after_tl
  3346. {
  3347. \__nicematrix_Block_iii:nnnnnn
  3348. { \int_use:N \c@iRow }
  3349. { \int_use:N \c@jCol }
  3350. { \int_eval:n { \c@iRow + #1 - 1 } }
  3351. { \int_eval:n { \c@jCol + #2 - 1 } }
  3352. { #3 }
  3353. \exp_not:n
  3354. {
  3355. {
  3356. #4
  3357. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  3358. #5
  3359. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  3360. }
  3361. }
  3362. }
  3363. \cs_set_eq:NN \Block \__nicematrix_Block_error:nn
  3364. }
  3365. \cs_new:Npn \__nicematrix_Block_error:nn #1 #2
  3366. {
  3367. \__nicematrix_error:n { Second~Block }
  3368. \cs_set_eq:NN \Block \use:nn
  3369. }
  3370. \keys_define:nn { NiceMatrix / Block }
  3371. {
  3372. tikz .tl_set:N = \l__nicematrix_tikz_tl ,
  3373. tikz .value_required:n = true ,
  3374. white .bool_set:N = \l__nicematrix_white_bool ,
  3375. white .default:n = true ,
  3376. white .value_forbidden:n = true ,
  3377. }
  3378. \cs_new_protected:Npn \__nicematrix_Block_iii:nnnnnn #1 #2 #3 #4 #5 #6
  3379. {
  3380. \group_begin:
  3381. \keys_set:nn { NiceMatrix / Block } { #5 }
  3382. \bool_lazy_or:nnTF
  3383. { \int_compare_p:nNn { #3 } > \c@iRow }
  3384. { \int_compare_p:nNn { #4 } > \c@jCol }
  3385. { \msg_error:nnnn { nicematrix } { Block~too~large } { #1 } { #2 } }
  3386. {
  3387. \hbox_set:Nn \l__nicematrix_cell_box { #6 }
  3388. \pgfpicture
  3389. \pgfrememberpicturepositiononpagetrue
  3390. \pgf@relevantforpicturesizefalse
  3391. \__nicematrix_qpoint:n { row - #1 }
  3392. \dim_set_eq:NN \l_tmpa_dim \pgf@y
  3393. \__nicematrix_qpoint:n { col - #2 }
  3394. \dim_set_eq:NN \l_tmpb_dim \pgf@x
  3395. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n { #3 } }
  3396. \dim_set_eq:NN \l_tmpc_dim \pgf@y
  3397. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n { #4 } }
  3398. \dim_set_eq:NN \l_tmpd_dim \pgf@x
  3399. \bool_if:NT \l__nicematrix_white_bool
  3400. {
  3401. \begin { pgfscope }
  3402. \pgfsetfillcolor { white }
  3403. \pgfpathrectanglecorners
  3404. {
  3405. \pgfpoint
  3406. { \l_tmpb_dim + 0.5 \arrayrulewidth }
  3407. { \l_tmpa_dim - 0.5 \arrayrulewidth }
  3408. }
  3409. {
  3410. \pgfpoint
  3411. { \l_tmpd_dim - 0.5 \arrayrulewidth }
  3412. { \l_tmpc_dim + 0.5 \arrayrulewidth }
  3413. }
  3414. \pgfusepathqfill
  3415. \end { pgfscope }
  3416. }
  3417. \begin { pgfscope }
  3418. \exp_args:Nx \pgfset { \l__nicematrix_tikz_tl }
  3419. \__nicematrix_pgf_rect_node:nnnnn
  3420. { \__nicematrix_env: - #1 - #2 - block }
  3421. \l_tmpb_dim \l_tmpa_dim \l_tmpd_dim \l_tmpc_dim
  3422. \end { pgfscope }
  3423. \bool_if:NT \l__nicematrix_medium_nodes_bool
  3424. {
  3425. \__nicematrix_pgf_rect_node:nnn
  3426. { \__nicematrix_env: - #1 - #2 - block - medium }
  3427. { \pgfpointanchor { \__nicematrix_env: - #1 - #2 - medium } { north~west } }
  3428. { \pgfpointanchor { \__nicematrix_env: - #3 - #4 - medium } { south~east } }
  3429. }
  3430. \int_compare:nNnTF { #1 } = { #3 }
  3431. {
  3432. \pgfextracty \l_tmpa_dim { \__nicematrix_qpoint:n { row - #1 - base } }
  3433. \__nicematrix_qpoint:n { #1 - #2 - block }
  3434. \pgftransformshift { \pgfpoint \pgf@x \l_tmpa_dim }
  3435. \pgfnode { rectangle } { base }
  3436. { \box_use_drop:N \l__nicematrix_cell_box } { } { }
  3437. }
  3438. {
  3439. \pgftransformshift { \__nicematrix_qpoint:n { #1 - #2 - block } }
  3440. \pgfnode { rectangle } { center }
  3441. { \box_use_drop:N \l__nicematrix_cell_box } { } { }
  3442. }
  3443. \endpgfpicture
  3444. }
  3445. \group_end:
  3446. }
  3447. \cs_set_protected:Npn \__nicematrix_renew_matrix:
  3448. {
  3449. \RenewDocumentEnvironment { pmatrix } { }
  3450. { \pNiceMatrix }
  3451. { \endpNiceMatrix }
  3452. \RenewDocumentEnvironment { vmatrix } { }
  3453. { \vNiceMatrix }
  3454. { \endvNiceMatrix }
  3455. \RenewDocumentEnvironment { Vmatrix } { }
  3456. { \VNiceMatrix }
  3457. { \endVNiceMatrix }
  3458. \RenewDocumentEnvironment { bmatrix } { }
  3459. { \bNiceMatrix }
  3460. { \endbNiceMatrix }
  3461. \RenewDocumentEnvironment { Bmatrix } { }
  3462. { \BNiceMatrix }
  3463. { \endBNiceMatrix }
  3464. }
  3465. \cs_new_protected:Npn \__nicematrix_set_size:n #1-#2 \q_stop
  3466. {
  3467. \int_set:Nn \l__nicematrix_nb_rows_int { #1 }
  3468. \int_set:Nn \l__nicematrix_nb_cols_int { #2 }
  3469. }
  3470. \NewDocumentCommand \AutoNiceMatrixWithDelims { m m O { } m O { } m ! O { } }
  3471. {
  3472. \int_zero_new:N \l__nicematrix_nb_rows_int
  3473. \int_zero_new:N \l__nicematrix_nb_cols_int
  3474. \__nicematrix_set_size:n #4 \q_stop
  3475. \begin { NiceArrayWithDelims } { #1 } { #2 }
  3476. { * { \l__nicematrix_nb_cols_int } { C } } [ #3 , #5 , #7 ]
  3477. \int_compare:nNnT \l__nicematrix_first_row_int = 0
  3478. {
  3479. \int_compare:nNnT \l__nicematrix_first_col_int = 0 { & }
  3480. \prg_replicate:nn { \l__nicematrix_nb_cols_int - 1 } { & }
  3481. \int_compare:nNnT \l__nicematrix_last_col_int > { -1 } { & } \\
  3482. }
  3483. \prg_replicate:nn \l__nicematrix_nb_rows_int
  3484. {
  3485. \int_compare:nNnT \l__nicematrix_first_col_int = 0 { & }
  3486. \prg_replicate:nn { \l__nicematrix_nb_cols_int - 1 } { { } #6 & } #6
  3487. \int_compare:nNnT \l__nicematrix_last_col_int > { -1 } { & } \\
  3488. }
  3489. \int_compare:nNnT \l__nicematrix_last_row_int > { -2 }
  3490. {
  3491. \int_compare:nNnT \l__nicematrix_first_col_int = 0 { & }
  3492. \prg_replicate:nn { \l__nicematrix_nb_cols_int - 1 } { & }
  3493. \int_compare:nNnT \l__nicematrix_last_col_int > { -1 } { & } \\
  3494. }
  3495. \end { NiceArrayWithDelims }
  3496. }
  3497. \cs_set_protected:Npn \__nicematrix_define_com:nnn #1 #2 #3
  3498. {
  3499. \cs_set_protected:cpn { #1 AutoNiceMatrix }
  3500. {
  3501. \str_gset:Nx \g__nicematrix_name_env_str { #1 AutoNiceMatrix }
  3502. \AutoNiceMatrixWithDelims { #2 } { #3 }
  3503. }
  3504. }
  3505. \__nicematrix_define_com:nnn p ( )
  3506. \__nicematrix_define_com:nnn b [ ]
  3507. \__nicematrix_define_com:nnn v | |
  3508. \__nicematrix_define_com:nnn V \| \|
  3509. \__nicematrix_define_com:nnn B \{ \}
  3510. \NewDocumentCommand \AutoNiceMatrix { O { } m O { } m ! O { } }
  3511. {
  3512. \group_begin:
  3513. \bool_set_true:N \l__nicematrix_NiceArray_bool
  3514. \AutoNiceMatrixWithDelims . . { #2 } { #4 } [ #1 , #3 , #5 ]
  3515. \group_end:
  3516. }
  3517. \cs_set_eq:NN \__nicematrix_dotfill \dotfill
  3518. \cs_new_protected:Npn \__nicematrix_dotfill:
  3519. {
  3520. \__nicematrix_dotfill
  3521. \group_insert_after:N \__nicematrix_dotfill_i:
  3522. }
  3523. \cs_new_protected:Npn \__nicematrix_dotfill_i: { \group_insert_after:N \__nicematrix_dotfill_ii: }
  3524. \cs_new_protected:Npn \__nicematrix_dotfill_ii: { \group_insert_after:N \__nicematrix_dotfill_iii: }
  3525. \cs_new_protected:Npn \__nicematrix_dotfill_iii:
  3526. { \dim_compare:nNnT { \box_wd:N \l__nicematrix_cell_box } = \c_zero_dim \__nicematrix_dotfill }
  3527. \cs_new_protected:Npn \__nicematrix_diagbox:nn #1 #2
  3528. {
  3529. \tl_gput_right:Nx \g__nicematrix_internal_code_after_tl
  3530. {
  3531. \__nicematrix_actually_diagbox:nnnn
  3532. { \int_use:N \c@iRow } { \int_use:N \c@jCol } { #1 } { #2 }
  3533. }
  3534. }
  3535. \cs_new_protected:Npn \__nicematrix_actually_diagbox:nnnn #1 #2 #3 #4
  3536. {
  3537. \pgfpicture
  3538. \pgf@relevantforpicturesizefalse
  3539. \pgfrememberpicturepositiononpagetrue
  3540. \__nicematrix_qpoint:n { row - #1 }
  3541. \dim_set_eq:NN \l_tmpa_dim \pgf@y
  3542. \__nicematrix_qpoint:n { col - #2 }
  3543. \dim_set_eq:NN \l_tmpb_dim \pgf@x
  3544. \pgfpathmoveto { \pgfpoint \l_tmpb_dim \l_tmpa_dim }
  3545. \__nicematrix_qpoint:n { row - \__nicematrix_succ:n { #1 } }
  3546. \dim_set_eq:NN \l_tmpc_dim \pgf@y
  3547. \__nicematrix_qpoint:n { col - \__nicematrix_succ:n { #2 } }
  3548. \dim_set_eq:NN \l_tmpd_dim \pgf@x
  3549. \pgfpathlineto { \pgfpoint \l_tmpd_dim \l_tmpc_dim }
  3550. {
  3551. \CT@arc@
  3552. \pgfsetroundcap
  3553. \pgfusepathqstroke
  3554. }
  3555. \pgfset { inner~sep = 1 pt }
  3556. \pgfscope
  3557. \pgftransformshift { \pgfpoint \l_tmpb_dim \l_tmpc_dim }
  3558. \pgfnode { rectangle } { south~west }
  3559. {
  3560. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  3561. #3
  3562. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  3563. }
  3564. { } { }
  3565. \endpgfscope
  3566. \pgftransformshift { \pgfpoint \l_tmpd_dim \l_tmpa_dim }
  3567. \pgfnode { rectangle } { north~east }
  3568. {
  3569. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  3570. #4
  3571. \bool_if:NF \l__nicematrix_NiceTabular_bool \c_math_toggle_token
  3572. }
  3573. { } { }
  3574. \endpgfpicture
  3575. }
  3576. \cs_new_protected:Npn \__nicematrix_CodeAfter:n #1 \end
  3577. {
  3578. \tl_gput_right:Nn \g__nicematrix_code_after_tl { #1 }
  3579. \__nicematrix_CodeAfter_i:n
  3580. }
  3581. \cs_new_protected:Npn \__nicematrix_CodeAfter_i:n #1
  3582. {
  3583. \str_set:NV \l_tmpa_str \@currenvir
  3584. \bool_if:NTF { \str_if_eq_p:Vn \l_tmpa_str { #1 } }
  3585. { \end { #1 } }
  3586. {
  3587. \tl_gput_right:Nn \g__nicematrix_code_after_tl { \end { #1 } }
  3588. \__nicematrix_CodeAfter:n
  3589. }
  3590. }
  3591. \keys_define:nn { NiceMatrix / Package }
  3592. {
  3593. renew-dots .bool_set:N = \l__nicematrix_renew_dots_bool ,
  3594. renew-dots .value_forbidden:n = true ,
  3595. renew-matrix .code:n = \__nicematrix_renew_matrix: ,
  3596. renew-matrix .value_forbidden:n = true ,
  3597. transparent .meta:n = { renew-dots , renew-matrix } ,
  3598. transparent .value_forbidden:n = true,
  3599. starred-commands .code:n =
  3600. \__nicematrix_msg_redirect_name:nn { starred~commands } { none } ,
  3601. starred-commands .value_forbidden:n = true ,
  3602.  
  3603. }
  3604. \ProcessKeysOptions { NiceMatrix / Package }
  3605. \cs_new_protected:Npn \__nicematrix_convert_to_str_seq:N #1
  3606. {
  3607. \seq_clear:N \l_tmpa_seq
  3608. \seq_map_inline:Nn #1
  3609. {
  3610. \seq_put_left:Nx \l_tmpa_seq { \tl_to_str:n { ##1 } }
  3611. }
  3612. \seq_set_eq:NN #1 \l_tmpa_seq
  3613. }
  3614. \cs_new_protected:Npn \__nicematrix_set_seq_of_str_from_clist:Nn #1 #2
  3615. {
  3616. \seq_set_from_clist:Nn #1 { #2 }
  3617. \__nicematrix_convert_to_str_seq:N #1
  3618. }
  3619. \__nicematrix_set_seq_of_str_from_clist:Nn \c__nicematrix_types_of_matrix_seq
  3620. {
  3621. NiceMatrix ,
  3622. pNiceMatrix , bNiceMatrix , vNiceMatrix, BNiceMatrix, VNiceMatrix
  3623. }
  3624. \cs_new_protected:Npn \__nicematrix_error_too_much_cols:
  3625. {
  3626. \seq_if_in:NVTF \c__nicematrix_types_of_matrix_seq \g__nicematrix_name_env_str
  3627. {
  3628. \int_compare:nNnTF \l__nicematrix_last_col_int = { -2 }
  3629. { \__nicematrix_fatal:n { too~much~cols~for~matrix } }
  3630. {
  3631. \bool_if:NF \l__nicematrix_last_col_without_value_bool
  3632. { \__nicematrix_fatal:n { too~much~cols~for~matrix~with~last~col } }
  3633. }
  3634. }
  3635. { \__nicematrix_fatal:n { too~much~cols~for~array } }
  3636. }
  3637. \cs_new:Npn \__nicematrix_message_hdotsfor:
  3638. {
  3639. \tl_if_empty:VF \g__nicematrix_HVdotsfor_lines_tl
  3640. { ~Maybe~your~use~of~\token_to_str:N \Hdotsfor\ is~incorrect.}
  3641. }
  3642. \__nicematrix_msg_new:nn { too~much~cols~for~matrix~with~last~col }
  3643. {
  3644. You~try~to~use~more~columns~than~allowed~by~your~
  3645. \__nicematrix_full_name_env:.\__nicematrix_message_hdotsfor:\ The~maximal~number~of~
  3646. columns~is~\int_eval:n { \l__nicematrix_last_col_int - 1 }~(plus~the~potential~
  3647. exterior~ones).~This~error~is~fatal.
  3648. }
  3649. \__nicematrix_msg_new:nn { too~much~cols~for~matrix }
  3650. {
  3651. You~try~to~use~more~columns~than~allowed~by~your~
  3652. \__nicematrix_full_name_env:.\__nicematrix_message_hdotsfor:\ Recall~that~the~maximal~
  3653. number~of~columns~for~a~matrix~is~fixed~by~the~LaTeX~counter~
  3654. 'MaxMatrixCols'.~Its~actual~value~is~\int_use:N \c@MaxMatrixCols.~
  3655. This~error~is~fatal.
  3656. }
  3657. \__nicematrix_msg_new:nn { too~much~cols~for~array }
  3658. {
  3659. You~try~to~use~more~columns~than~allowed~by~your~
  3660. \__nicematrix_full_name_env:.\__nicematrix_message_hdotsfor:\ The~maximal~number~of~columns~is~
  3661. \int_eval:n { \c@jCol - 1 }~(plus~the~potential~exterior~ones).~
  3662. This~error~is~fatal.
  3663. }
  3664. \__nicematrix_msg_new:nn { in~first~col }
  3665. {
  3666. You~can't~use~the~command~#1 in~the~first~column~(number~0)~of~the~array.\\
  3667. If~you~go~on,~this~command~will~be~ignored.
  3668. }
  3669. \__nicematrix_msg_new:nn { in~last~col }
  3670. {
  3671. You~can't~use~the~command~#1 in~the~last~column~(exterior)~of~the~array.\\
  3672. If~you~go~on,~this~command~will~be~ignored.
  3673. }
  3674. \__nicematrix_msg_new:nn { in~first~row }
  3675. {
  3676. You~can't~use~the~command~#1 in~the~first~row~(number~0)~of~the~array.\\
  3677. If~you~go~on,~this~command~will~be~ignored.
  3678. }
  3679. \__nicematrix_msg_new:nn { in~last~row }
  3680. {
  3681. You~can't~use~the~command~#1 in~the~last~row~(exterior)~of~the~array.\\
  3682. If~you~go~on,~this~command~will~be~ignored.
  3683. }
  3684. \__nicematrix_msg_new:nn { option~S~without~siunitx }
  3685. {
  3686. You~can't~use~the~option~'S'~in~your~environment~\__nicematrix_full_name_env:
  3687. because~you~have~not~loaded~siunitx.\\
  3688. If~you~go~on,~this~option~will~be~ignored.
  3689. }
  3690. \__nicematrix_msg_new:nn { bad~option~for~line-style }
  3691. {
  3692. Since~you~haven't~loaded~Tikz,~the~only~value~you~can~give~to~'line-style'~
  3693. is~'standard'.~If~you~go~on,~this~option~will~be~ignored.
  3694. }
  3695. \__nicematrix_msg_new:nn { Unknown~option~for~xdots }
  3696. {
  3697. As~for~now~there~is~only~three~options~available~here:~'color',~'line-style'~
  3698. and~'shorten'~(and~you~try~to~use~'\l_keys_key_str').~If~you~go~on,~
  3699. this~option~will~be~ignored.
  3700. }
  3701. \__nicematrix_msg_new:nn { ampersand~in~light-syntax }
  3702. {
  3703. You~can't~use~an~ampersand~(\token_to_str &)~to~separate~columns~because
  3704. ~you~have~used~the~option~'light-syntax'.~This~error~is~fatal.
  3705. }
  3706. \__nicematrix_msg_new:nn { double-backslash~in~light-syntax }
  3707. {
  3708. You~can't~use~\token_to_str:N \\~to~separate~rows~because~you~have~used~
  3709. the~option~'light-syntax'.~You~must~use~the~character~'\l__nicematrix_end_of_row_tl'~
  3710. (set~by~the~option~'end-of-row').~This~error~is~fatal.
  3711. }
  3712. \__nicematrix_msg_new:nn { standard-cline~in~document }
  3713. {
  3714. The~key~'standard-cline'~is~available~only~in~the~preamble.\\
  3715. If~you~go~on~this~command~will~be~ignored.
  3716. }
  3717. \__nicematrix_msg_new:nn { starred~commands }
  3718. {
  3719. The~starred~versions~of~\token_to_str:N \Cdots,~\token_to_str:N \Ldots,~
  3720. \token_to_str:N \Vdots,~\token_to_str:N\Ddots\ and~\token_to_str:N\Iddots\
  3721. are~deprecated.~However,~you~can~go~on~for~this~time.~If~you~don't~want~to~
  3722. see~this~error~we~should~load~'nicematrix'~with~the~option~
  3723. 'starred-commands'.
  3724. }
  3725. \__nicematrix_msg_new:nn { bad~value~for~baseline }
  3726. {
  3727. The~value~given~to~'baseline'~(\int_use:N \l_tmpa_int)~is~not~
  3728. valid.~The~value~must~be~between~\int_use:N \l__nicematrix_first_row_int\ and~
  3729. \int_use:N \g__nicematrix_row_total_int\ or~equal~to~'t',~'c'~or~'b'.\\
  3730. If~you~go~on,~a~value~of~1~will~be~used.
  3731. }
  3732. \__nicematrix_msg_new:nn { Second~Block }
  3733. {
  3734. You~can't~use~\token_to_str:N \Block\ twice~in~the~same~cell~of~the~array.\\
  3735. If~you~go~on,~this~command~(and~the~other)~will~be~ignored.
  3736. }
  3737. \__nicematrix_msg_new:nn { empty~environment }
  3738. { Your~\__nicematrix_full_name_env:\ is~empty.~This~error~is~fatal. }
  3739. \__nicematrix_msg_new:nn { unknown~cell~for~line~in~code-after }
  3740. {
  3741. Your~command~\token_to_str:N\line\{#1\}\{#2\}~in~the~'code-after'~
  3742. can't~be~executed~because~a~cell~doesn't~exist.\\
  3743. If~you~go~on~this~command~will~be~ignored.
  3744. }
  3745. \__nicematrix_msg_new:nn { last-col~non~empty~for~NiceArray }
  3746. {
  3747. In~the~\__nicematrix_full_name_env:,~you~must~use~the~option~
  3748. 'last-col'~without~value.\\
  3749. However,~you~can~go~on~for~this~time~
  3750. (the~value~'\l_keys_value_tl'~will~be~ignored).
  3751. }
  3752. \__nicematrix_msg_new:nn { last-col~non~empty~for~NiceMatrixOptions }
  3753. {
  3754. In~\NiceMatrixoptions,~you~must~use~the~option~
  3755. 'last-col'~without~value.\\
  3756. However,~you~can~go~on~for~this~time~
  3757. (the~value~'\l_keys_value_tl'~will~be~ignored).
  3758. }
  3759. \__nicematrix_msg_new:nn { Block~too~large }
  3760. {
  3761. You~try~to~draw~a~block~in~the~cell~#1-#2~of~your~matrix~but~the~matrix~is~
  3762. too~small~for~that~block. \\
  3763. If~you~go~on,~this~command~will~be~ignored.
  3764. }
  3765. \__nicematrix_msg_new:nn { Wrong~last~row }
  3766. {
  3767. You~have~used~'last-row=\int_use:N \l__nicematrix_last_row_int'~but~your~
  3768. \__nicematrix_full_name_env:\ seems~to~have~\int_use:N \c@iRow \ rows.~
  3769. If~you~go~on,~the~value~of~\int_use:N \c@iRow \ will~be~used~for~
  3770. last~row.~You~can~avoid~this~problem~by~using~'last-row'~
  3771. without~value~(more~compilations~might~be~necessary).
  3772. }
  3773. \__nicematrix_msg_new:nn { Yet~in~env }
  3774. {
  3775. Environments~\{NiceArray\}~(or~\{NiceMatrix\},~etc.)~can't~be~nested.\\
  3776. This~error~is~fatal.
  3777. }
  3778. \__nicematrix_msg_new:nn { Outside~math~mode }
  3779. {
  3780. The~\__nicematrix_full_name_env:\ can~be~used~only~in~math~mode~
  3781. (and~not~in~\token_to_str:N \vcenter).\\
  3782. This~error~is~fatal.
  3783. }
  3784. \__nicematrix_msg_new:nn { Bad~value~for~letter~for~dotted~lines }
  3785. {
  3786. The~value~of~key~'\tl_use:N\l_keys_key_str'~must~be~of~length~1.\\
  3787. If~you~go~on,~it~will~be~ignored.
  3788. }
  3789. \__nicematrix_msg_new:nnn { Unknown~key~for~NiceMatrixOptions }
  3790. {
  3791. The~key~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~command~
  3792. \token_to_str:N \NiceMatrixOptions. \\
  3793. If~you~go~on,~it~will~be~ignored. \\
  3794. For~a~list~of~the~*principal*~available~keys,~type~H~<return>.
  3795. }
  3796. {
  3797. The~available~options~are~(in~alphabetic~order):~
  3798. allow-duplicate-names,~
  3799. code-for-first-col,~
  3800. cell-space-bottom-limit,~
  3801. cell-space-top-limit,~
  3802. code-for-first-row,~
  3803. code-for-last-col,~
  3804. code-for-last-row,~
  3805. create-extra-nodes,~
  3806. create-medium-nodes,~
  3807. create-large-nodes,~
  3808. end-of-row,~
  3809. first-col,~
  3810. first-row,~
  3811. hlines,~
  3812. hvlines,~
  3813. last-col,~
  3814. last-row,~
  3815. left-margin,~
  3816. letter-for-dotted-lines,~
  3817. light-syntax,~
  3818. nullify-dots,~
  3819. renew-dots,~
  3820. renew-matrix,~
  3821. right-margin,~
  3822. small,~
  3823. transparent,~
  3824. vlines,~
  3825. xdots/color,~
  3826. xdots/shorten~and~
  3827. xdots/line-style.
  3828. }
  3829. \__nicematrix_msg_new:nnn { Unknown~option~for~NiceArray }
  3830. {
  3831. The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~environment~
  3832. \{NiceArray\}. \\
  3833. If~you~go~on,~it~will~be~ignored. \\
  3834. For~a~list~of~the~*principal*~available~options,~type~H~<return>.
  3835. }
  3836. {
  3837. The~available~options~are~(in~alphabetic~order):~
  3838. b,~
  3839. baseline,~
  3840. c,~
  3841. cell-space-bottom-limit,~
  3842. cell-space-top-limit,~
  3843. code-after,~
  3844. code-for-first-col,~
  3845. code-for-first-row,~
  3846. code-for-last-col,~
  3847. code-for-last-row,~
  3848. columns-width,~
  3849. create-extra-nodes,~
  3850. create-medium-nodes,~
  3851. create-large-nodes,~
  3852. extra-left-margin,~
  3853. extra-right-margin,~
  3854. first-col,~
  3855. first-row,~
  3856. hlines,~
  3857. hvlines,~
  3858. last-col,~
  3859. last-row,~
  3860. left-margin,~
  3861. light-syntax,~
  3862. name,~
  3863. nullify-dots,~
  3864. renew-dots,~
  3865. right-margin,~
  3866. small,~
  3867. t,~
  3868. vlines,~
  3869. xdots/color,~
  3870. xdots/shorten~and~
  3871. xdots/line-style.
  3872. }
  3873. \__nicematrix_msg_new:nnn { Unknown~option~for~NiceMatrix }
  3874. {
  3875. The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~
  3876. \__nicematrix_full_name_env:. \\
  3877. If~you~go~on,~it~will~be~ignored. \\
  3878. For~a~list~of~the~*principal*~available~options,~type~H~<return>.
  3879. }
  3880. {
  3881. The~available~options~are~(in~alphabetic~order):~
  3882. b,~
  3883. baseline,~
  3884. c,~
  3885. cell-space-bottom-limit,~
  3886. cell-space-top-limit,~
  3887. code-after,~
  3888. code-for-first-col,~
  3889. code-for-first-row,~
  3890. code-for-last-col,~
  3891. code-for-last-row,~
  3892. columns-width,~
  3893. create-extra-nodes,~
  3894. create-medium-nodes,~
  3895. create-large-nodes,~
  3896. extra-left-margin,~
  3897. extra-right-margin,~
  3898. first-col,~
  3899. first-row,~
  3900. hlines,~
  3901. hvlines,~
  3902. l~(=L),~
  3903. last-col,~
  3904. last-row,~
  3905. left-margin,~
  3906. light-syntax,~
  3907. name,~
  3908. nullify-dots,~
  3909. r~(=R),~
  3910. renew-dots,~
  3911. right-margin,~
  3912. S,~
  3913. small,~
  3914. t,~
  3915. vlines,~
  3916. xdots/color,~
  3917. xdots/shorten~and~
  3918. xdots/line-style.
  3919. }
  3920. \__nicematrix_msg_new:nnn { Unknown~option~for~NiceTabular }
  3921. {
  3922. The~option~'\tl_use:N\l_keys_key_str'~is~unknown~for~the~environment~
  3923. \{NiceTabular\}. \\
  3924. If~you~go~on,~it~will~be~ignored. \\
  3925. For~a~list~of~the~*principal*~available~options,~type~H~<return>.
  3926. }
  3927. {
  3928. The~available~options~are~(in~alphabetic~order):~
  3929. b,~
  3930. baseline,~
  3931. c,~
  3932. cell-space-bottom-limit,~
  3933. cell-space-top-limit,~
  3934. code-after,~
  3935. code-for-first-col,~
  3936. code-for-first-row,~
  3937. code-for-last-col,~
  3938. code-for-last-row,~
  3939. columns-width,~
  3940. create-extra-nodes,~
  3941. create-medium-nodes,~
  3942. create-large-nodes,~
  3943. extra-left-margin,~
  3944. extra-right-margin,~
  3945. first-col,~
  3946. first-row,~
  3947. hlines,~
  3948. hvlines,~
  3949. last-col,~
  3950. last-row,~
  3951. left-margin,~
  3952. light-syntax,~
  3953. name,~
  3954. nullify-dots,~
  3955. renew-dots,~
  3956. right-margin,~
  3957. t,~
  3958. vlines,~
  3959. xdots/color,~
  3960. xdots/shorten~and~
  3961. xdots/line-style.
  3962. }
  3963. \__nicematrix_msg_new:nnn { Duplicate~name }
  3964. {
  3965. The~name~'\l_keys_value_tl'~is~already~used~and~you~shouldn't~use~
  3966. the~same~environment~name~twice.~You~can~go~on,~but,~
  3967. maybe,~you~will~have~incorrect~results~especially~
  3968. if~you~use~'columns-width=auto'.~If~you~don't~want~to~see~this~
  3969. message~again,~use~the~option~'allow-duplicate-names'.\\
  3970. For~a~list~of~the~names~already~used,~type~H~<return>. \\
  3971. }
  3972. {
  3973. The~names~already~defined~in~this~document~are:~
  3974. \seq_use:Nnnn \g__nicematrix_names_seq { ,~ } { ,~ } { ~and~ }.
  3975. }
  3976. \__nicematrix_msg_new:nn { Option~auto~for~columns-width }
  3977. {
  3978. You~can't~give~the~value~'auto'~to~the~option~'columns-width'~here.~
  3979. If~you~go~on,~the~option~will~be~ignored.
  3980. }
  3981. \__nicematrix_msg_new:nn { Zero~row }
  3982. {
  3983. There~is~a~problem.~Maybe~you~have~used~l,~c~and~r~instead~of~L,~C~
  3984. and~R~in~the~preamble~of~your~environment. \\
  3985. This~error~is~fatal.
  3986. }
  3987.  
  3988. \endinput
  3989. %%
  3990. %% End of file `nicematrix.sty'.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement