You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MRTtab.sty 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. \newcommand*\MRTtab@version{0.0.3}
  2. \newcommand*\MRTtab@date{2018-10-02}
  3. \NeedsTeXFormat{LaTeX2e}
  4. \RequirePackage{expl3,xparse,setspace,array,etoolbox}
  5. \PassOptionsToPackage{table}{xcolor}
  6. \RequirePackage{xcolor}
  7. \ProvidesExplPackage
  8. {MRTtab} {\MRTtab@date}
  9. {\MRTtab@version} {tables matching the style in MRT scripts}
  10. %% check whether the table option got used for xcolor >>>
  11. \cs_if_exist:NF \rowcolors
  12. {
  13. \msg_new:nnn { MRTtab } { rowcolors~unavailable }
  14. {
  15. Macro~\exp_not:N \rowcolors is~not~available.~`MRTtab`~tries~to~load~
  16. package~`xcolor`~with~the~`table`~option,~this~however~can~fail~if~
  17. `xcolor`~got~loaded~earlier~without~this~option.~To~solve~this~issue~
  18. place~the~following~code~before~\exp_not:N \documentclass:\\
  19. \ \ \exp_not:n { \PassOptionsToPackage{table}{xcolor} }
  20. }
  21. \msg_error:nn { MRTtab } { rowcolors~unavailable }
  22. }
  23. %<<<
  24. %% package variables >>>
  25. %%=============================================================================
  26. \newcolumntype{\MRTtabRepeatCols}{!{\d@llarend&\span\@gobbletwo}}
  27. \definecolor{tablegray}{gray}{0.85}
  28. \tl_new:N \l_MRTtab_tmpa_tl
  29. \int_new:N \l_MRTtab_tmpa_int
  30. \int_new:N \l_MRTtab_tmpb_int
  31. \int_new:N \g__MRTtab_current_row_int
  32. \int_new:N \g__MRTtab_color_upto_int
  33. \int_gset:Nn \g__MRTtab_color_upto_int { -\c_max_int }
  34. \bool_new:N \l_MRTtab_longtable_bool
  35. \bool_new:N \l_MRTtab_bare_bool
  36. \bool_new:N \g__MRTtab_komaoptions_defined_bool% >>>
  37. \bool_gset:Nn \g__MRTtab_komaoptions_defined_bool
  38. { \cs_if_exist_p:N \KOMAoptions }% <<<
  39. \bool_new:N \l_MRTtab_caption_above_bool
  40. \bool_new:N \g__MRTtab_head_bool
  41. \skip_new:N \l_MRTtab_in_text_sep_skip
  42. \tl_new:N \l_MRTtab_table_lable_tl
  43. \tl_new:N \g__MRTtab_bol_hook_private_tl
  44. \tl_new:N \g__MRTtab_eol_hook_private_tl
  45. \tl_new:N \l__MRTtab_bol_hook_public_tl
  46. \tl_new:N \l__MRTtab_eol_hook_public_tl
  47. \tl_new:N \l__MRTtab_table_pre_hook_tl
  48. \tl_new:N \l__MRTtab_table_post_hook_tl
  49. \tl_new:N \l__MRTtab_env_begin_tl
  50. \tl_new:N \l__MRTtab_env_end_tl
  51. % messages >>>
  52. \msg_new:nnn { MRTtab } { patch~failed } { Patching~of~\string#1~failed. }
  53. \msg_new:nnn { MRTtab } { KOMA~not~loaded }
  54. { It~seems~like~KOMA~is~not~loaded.#1 }
  55. \msg_new:nnn { MRTtab } { deprecated~syntax }
  56. {
  57. The~used~syntax~for~`#1`~\tl_if_empty:nF { #2 } { to~#2~ } is~deprecated~
  58. (but~should~still~work).~Please~take~a~look~into~`MRTtab`s~documentation.
  59. }
  60. \bool_if:NF \l_MRTtab_longtable_bool
  61. {
  62. \msg_new:nnn { MRTtab } { option~longtable~not~used }
  63. {
  64. You~have~not~used~the~option~longtable~during~package~load~time,~
  65. therefore~the~key~#1~is~not~defined.
  66. }
  67. }
  68. % <<<
  69. %%==========================================================================<<<
  70. \DeclareOption { longtable } { \bool_set_true:N \l_MRTtab_longtable_bool }
  71. \ProcessOptions\relax
  72. \bool_if:NT \l_MRTtab_longtable_bool { \RequirePackage{longtable} }
  73. %% options >>>
  74. %%=============================================================================
  75. \cs_new:Nn \__MRTtab_caption_above:% >>>
  76. {
  77. \bool_if:NT \g__MRTtab_komaoptions_defined_bool
  78. { \KOMAoptions{captions=tableheading} }
  79. \bool_set_true:N \l_MRTtab_caption_above_bool
  80. }% <<<
  81. \cs_new:Nn \__MRTtab_caption_below:% >>>
  82. {
  83. \bool_if:NT \g__MRTtab_komaoptions_defined_bool
  84. { \KOMAoptions{captions=tablesignature} }
  85. \bool_set_false:N \l_MRTtab_caption_above_bool
  86. }% <<<
  87. \cs_new:Nn \__MRTtab_stretch_caption:n% >>>
  88. {
  89. \__MRTtab_setkomafont:nn { caption } { \setstretch { #1 } \normalfont }
  90. \__MRTtab_setkomafont:nn { captionlabel } { \setstretch { #1 } \normalfont }
  91. }% <<<
  92. \cs_new:Nn \__MRTtab_setkomafont:nn% >>>
  93. {
  94. \bool_if:NTF \g__MRTtab_komaoptions_defined_bool
  95. { \setkomafont { #1 } { #2 } }
  96. {
  97. \msg_warning:nnn { MRTtab } { KOMA~not~loaded }
  98. { ~Therefore~\setkomafont~is~not~available. }
  99. }
  100. }% <<<
  101. \cs_new:Nn \__MRTtab_table_stripe_invert:% >>>
  102. {
  103. \tl_set_eq:NN \l_MRTtab_tmpa_tl \l_MRTtab_table_scolor_one_tl
  104. \tl_set_eq:NN \l_MRTtab_table_scolor_one_tl \l_MRTtab_table_scolor_two_tl
  105. \tl_set_eq:NN \l_MRTtab_table_scolor_two_tl \l_MRTtab_tmpa_tl
  106. }% <<<
  107. \cs_new_protected:Nn \__MRTtab_table_label_key:n% >>>
  108. {
  109. \tl_if_blank:nTF { #1 }
  110. { \tl_clear:N \l_MRTtab_table_lable_tl }
  111. { \tl_set:Nn \l_MRTtab_table_lable_tl { \label{#1} } }
  112. }% <<<
  113. \keys_define:nn { MRTtab }% >>>
  114. {
  115. ,caption~above .code:n = { \__MRTtab_caption_above: }
  116. ,caption~above .value_forbidden:n = true
  117. ,above .meta:n = { caption~above }
  118. ,above .value_forbidden:n = true
  119. ,bare .bool_set:N = \l_MRTtab_bare_bool
  120. ,BoL .code:n = { \MRTtabAddtoBoLHook { #1 } }
  121. ,caption~below .code:n = { \__MRTtab_caption_below: }
  122. ,caption~below .value_forbidden:n = true
  123. ,below .meta:n = { caption~below }
  124. ,below .value_forbidden:n = true
  125. ,EoL .code:n = { \MRTtabAddtoEoLHook { #1 } }
  126. ,stretch~tabular .tl_set:N = \l_MRTtab_stretch_tl
  127. ,stretch~tabular .initial:n = { 1 }
  128. ,stretch~tab .meta:n = { stretch~tabular = { #1 } }
  129. ,stretch .meta:n = { stretch~tabular = { #1 } }
  130. ,stretch~caption .code:n = \__MRTtab_stretch_caption:n { #1 }
  131. ,stretch~cap .meta:n = { stretch~caption = { #1 } }
  132. ,cstretch .meta:n = { stretch~caption = { #1 } }
  133. % for MRTtable
  134. ,caption .tl_set:N = \l_MRTtab_table_cap_tl
  135. ,cap .meta:n = { caption = { #1 } }
  136. ,columns .tl_set:N = \l_MRTtab_table_col_tl
  137. ,columns .initial:n = { l\MRTtabRepeatCols c }
  138. ,col .meta:n = { columns = { #1 } }
  139. ,env~begin .tl_set:N = \l__MRTtab_env_begin_tl
  140. ,env~end .tl_set:N = \l__MRTtab_env_end_tl
  141. ,env .code:n =
  142. {
  143. \tl_if_empty:nTF { #1 }
  144. {
  145. \keys_set:nn { MRTtab }
  146. {
  147. env~begin = {},
  148. env~end = {},
  149. }
  150. }
  151. {
  152. \keys_set:nn { MRTtab }
  153. {
  154. env~begin = { \begin{#1} },
  155. env~end = { \end{#1} }
  156. }
  157. }
  158. }
  159. ,env .initial:n = MRTtabular
  160. ,float .bool_set:N = \l_MRTtab_table_float_bool
  161. ,float .default:n = { true }
  162. ,float .initial:n = { true }
  163. ,head~rows .int_set:N = \g__MRTtab_color_upto_int
  164. ,head~rows .initial:n = { -\c_max_int }
  165. ,head .meta:n = { head~rows = { #1 } }
  166. ,in~text~sep .skip_set:N = \l_MRTtab_in_text_sep_skip
  167. ,in~text~sep .initial:n = \intextsep
  168. ,label .code:n = { \__MRTtab_table_label_key:n { #1 }}
  169. ,no~float .bool_set_inverse:N = \l_MRTtab_table_float_bool
  170. ,no~float .default:n = { true }
  171. ,no~inner~env .meta:n = { env~begin = {}, env~end = {} }
  172. ,no~inner~env .value_forbidden:n = true
  173. ,pos .tl_set:N = \l_MRTtab_table_pos_tl
  174. ,pos .initial:n = { tbp }
  175. ,post~tab .code:n = { \MRTtabAddtoPostHook { #1 } }
  176. ,post .meta:n = { pre~tab = { #1 } }
  177. ,pre~tab .code:n = { \MRTtabAddtoPreHook { #1 } }
  178. ,pre .meta:n = { pre~tab = { #1 } }
  179. ,short caption .tl_set:N = \l_MRTtab_table_scap_tl
  180. ,short cap .meta:n = { short caption = { #1 } }
  181. ,scap .meta:n = { short caption = { #1 } }
  182. ,striped .bool_set:N = \l_MRTtab_table_striped_bool
  183. ,stripe~color~1 .tl_set:N = \l_MRTtab_table_scolor_one_tl
  184. ,stripe~color~1 .initial:n = { tablegray!50 }
  185. ,stripe~1 .meta:n = { stripe~color~1 = { #1 } }
  186. ,scolor~1 .meta:n = { stripe~color~1 = { #1 } }
  187. ,scolor1 .meta:n = { stripe~color~1 = { #1 } }
  188. ,stripe~color~2 .tl_set:N = \l_MRTtab_table_scolor_two_tl
  189. ,stripe~color~2 .initial:n = { white }
  190. ,stripe~2 .meta:n = { stripe~color~2 = { #1 } }
  191. ,scolor~2 .meta:n = { stripe~color~2 = { #1 } }
  192. ,scolor2 .meta:n = { stripe~color~2 = { #1 } }
  193. ,stripe~invert .code:n = \__MRTtab_table_stripe_invert:
  194. ,stripe~invert .value_forbidden:n = true
  195. ,sinvert .meta:n = { stripe~invert }
  196. ,sinvert .value_forbidden:n = true
  197. ,stripe~start .tl_set:N = \l_MRTtab_table_stripe_start_tl
  198. ,stripe~start .initial:n = { 2 }
  199. ,sstart .meta:n = { stripe~start = { #1 } }
  200. }% <<<
  201. \bool_if:NTF \l_MRTtab_longtable_bool% >>>
  202. {
  203. \keys_define:nn { MRTtab }% >>>
  204. {
  205. ,long .bool_set:N = \l_MRTtab_table_long_bool
  206. ,long .default:n = { true }
  207. ,continue~caption .tl_set:N = \l_MRTtab_contcap_tl
  208. ,cont~cap .meta:n = { continue~caption }
  209. ,continue~with~caption .bool_set:N = \l_MRTtab_contwcap_bool
  210. ,continue~with~caption .default:n = { true }
  211. ,cont~with~cap .meta:n = { continue~with~caption = { #1 } }
  212. ,cont~with~cap .default:n = { true }
  213. ,cont~w~cap .meta:n = { continue~with~caption = { #1 } }
  214. ,cont~w~cap .default:n = { true }
  215. }% <<<
  216. }
  217. {
  218. \bool_new:N \l_MRTtab_table_long_bool
  219. \clist_map_inline:nn% >>>
  220. {
  221. long, continue~caption, cont~cap, continue~with~caption, cont~with~cap,
  222. cont~w~cap
  223. }
  224. {
  225. \keys_define:nn { MRTtab }
  226. {
  227. #1.code:n =
  228. { \msg_error:nnn { MRTtab } { option~longtable~not~used } { #1 } }
  229. }
  230. }% <<<
  231. }% <<<
  232. %%==========================================================================<<<
  233. %% package macros >>>
  234. %%=============================================================================
  235. \NewDocumentCommand \MRTtabSetup { +m }% >>>
  236. {
  237. \keys_set:nn { MRTtab } { #1 }
  238. }% <<<
  239. %%==========================================================================<<<
  240. %% MRTtabular >>>
  241. %%=============================================================================
  242. \cs_new:Npn \MRTtab@BoLHook% >>>
  243. {
  244. \g__MRTtab_bol_hook_private_tl
  245. \l__MRTtab_bol_hook_public_tl
  246. }% <<<
  247. \cs_new:Npn \MRTtab@EoLHook% >>>
  248. {
  249. \g__MRTtab_eol_hook_private_tl
  250. \l__MRTtab_eol_hook_public_tl
  251. }% <<<
  252. \cs_new_protected:Npn \MRTtab@@arraystarthook% >>>
  253. {
  254. \int_gset:Nn \g__MRTtab_current_row_int { \c_zero }
  255. }% <<<
  256. \cs_new_protected:Nn \MRTtab_step_row:% >>>
  257. {
  258. \int_gincr:N \g__MRTtab_current_row_int
  259. }% <<<
  260. \cs_new_protected:Nn \MRTtab_addto_private_bol_hook:n% >>>
  261. {
  262. \tl_gput_right:Nn \g__MRTtab_bol_hook_private_tl { #1 }
  263. }% <<<
  264. \cs_new_protected:Nn \MRTtab_addto_private_eol_hook:n% >>>
  265. {
  266. \tl_gput_right:Nn \g__MRTtab_eol_hook_private_tl { #1 }
  267. }% <<<
  268. \cs_new_protected:Nn \MRTtab_clear_private_bol_hook:% >>>
  269. {
  270. \tl_gclear:N \g__MRTtab_bol_hook_private_tl
  271. }% <<<
  272. \cs_new_protected:Nn \MRTtab_clear_private_eol_hook:% >>>
  273. {
  274. \tl_gclear:N \g__MRTtab_eol_hook_private_tl
  275. }% <<<
  276. \cs_new_protected:Nn \MRTtab_addto_public_bol_hook:n% >>>
  277. {
  278. \tl_put_right:Nn \l__MRTtab_bol_hook_public_tl { #1 }
  279. }% <<<
  280. \cs_new_protected:Nn \MRTtab_addto_public_eol_hook:n% >>>
  281. {
  282. \tl_put_right:Nn \l__MRTtab_eol_hook_public_tl { #1 }
  283. }% <<<
  284. \cs_new_protected:Nn \MRTtab_clear_public_bol_hook:% >>>
  285. {
  286. \tl_clear:N \l__MRTtab_bol_hook_public_tl
  287. }% <<<
  288. \cs_new_protected:Nn \MRTtab_clear_public_eol_hook:% >>>
  289. {
  290. \tl_clear:N \l__MRTtab_eol_hook_public_tl
  291. }% <<<
  292. \cs_new_protected:Nn \MRTtab_patchcmd:Nnn% >>>
  293. {
  294. \patchcmd #1 { #2 } { #3 } {}
  295. { \msg_error:nnn { MRTtab } { patch~failed} { #1 } }
  296. }% <<<
  297. \cs_new_protected:Nn \MRTtab_pretocmd:Nn% >>>
  298. {
  299. \pretocmd #1 { #2 } {} { \msg_error:nnn { MRTtab } { patch~failed } { #1 } }
  300. }% <<<
  301. \cs_new_protected:Nn \MRTtab_apptocmd:Nn% >>>
  302. {
  303. \apptocmd #1 { #2 } {} { \msg_error:nnn { MRTtab } { patch~failed } { #1 } }
  304. }% <<<
  305. \cs_new_protected:Npn \MRTtab@unpatcharray% >>>
  306. {
  307. \cs_set_eq:NN \@@array \@@array_original
  308. \cs_set_eq:NN \@arraycr \@arraycr_original
  309. \cs_set_eq:NN \@xarraycr \@xarraycr_original
  310. \cs_set_eq:NN \@xargarraycr \@xargarraycr_original
  311. \cs_set_eq:NN \@yargarraycr \@yargarraycr_original
  312. \cs_set_eq:NN \tabular \tabular_original
  313. \cs_set_eq:NN \endtabular \endtabular_original
  314. \cs_set_eq:NN \array \array_original
  315. \cs_set_eq:NN \endarray \endarray_original
  316. }% <<<
  317. \cs_new_protected:Nn \MRTtab_patch_array:% >>>
  318. {
  319. \cs_set_eq:NN \@@array_original \@@array
  320. \cs_set_eq:NN \@arraycr_original \@arraycr
  321. \cs_set_eq:NN \@xarraycr_original \@xarraycr
  322. \cs_set_eq:NN \@xargarraycr_original \@xargarraycr
  323. \cs_set_eq:NN \@yargarraycr_original \@yargarraycr
  324. \cs_set_eq:NN \tabular_original \tabular
  325. \cs_set_eq:NN \endtabular_original \endtabular
  326. \cs_set_eq:NN \array_original \array
  327. \cs_set_eq:NN \endarray_original \endarray
  328. \MRTtab_pretocmd:Nn \tabular { \MRTtab@unpatcharray }
  329. \MRTtab_pretocmd:Nn \array { \MRTtab@unpatcharray }
  330. \MRTtab_pretocmd:Nn \@@array { \MRTtab@@arraystarthook }
  331. \MRTtab_pretocmd:Nn \@arraycr { \MRTtab@EoLHook }
  332. \MRTtab_apptocmd:Nn \@yargarraycr { \MRTtab@BoLHook }
  333. \MRTtab_patchcmd:Nnn \@xarraycr { \cr } { \cr \MRTtab@BoLHook }
  334. \MRTtab_patchcmd:Nnn \@xargarraycr { \cr } { \cr \MRTtab@BoLHook }
  335. \MRTtab_patchcmd:Nnn \@@array { \cr } { \cr \noexpand \MRTtab@BoLHook }
  336. }% <<<
  337. \cs_new:Nn \MRTtab_head_start_inner:% >>>
  338. {
  339. \int_compare:nNnF \g__MRTtab_current_row_int = \c_one
  340. { \MRTtab_surround_lines: }
  341. \headR
  342. }% <<<
  343. \cs_new:Nn \MRTtab_declare_head_macro:% >>>
  344. {
  345. \DeclareExpandableDocumentCommand \head { m }
  346. {
  347. \headS
  348. \noalign
  349. {
  350. \int_gset:Nn \g__MRTtab_color_upto_int
  351. { \g__MRTtab_current_row_int + ##1 - \c_one }
  352. }
  353. }
  354. \MRTtab_declare_head_macrosSRE:
  355. }% <<<
  356. \cs_new:Nn \MRTtab_declare_head_macrosSRE:% >>>
  357. {
  358. \DeclareExpandableDocumentCommand \headS { }
  359. {
  360. \noalign { \bool_gset_true:N \g__MRTtab_head_bool }
  361. \MRTtab_head_start_inner:
  362. }
  363. \DeclareExpandableDocumentCommand \headR { }
  364. {
  365. \rowcolor { tablegray }
  366. }
  367. \DeclareExpandableDocumentCommand \headE { }
  368. {
  369. \noalign { \bool_gset_false:N \g__MRTtab_head_bool }
  370. \MRTtab_surround_lines:
  371. }
  372. }% <<<
  373. \cs_new:Nn \MRTtab_surround_lines:% >>>
  374. {
  375. \int_compare:nNnF
  376. { \g__MRTtab_color_upto_int + 1 } = { \g__MRTtab_current_row_int }
  377. { \crcr \hline }
  378. }% <<<
  379. \cs_new:Nn \MRTtab_head_hook:% >>>
  380. {
  381. \int_compare:nNnTF \g__MRTtab_current_row_int > \g__MRTtab_color_upto_int
  382. {
  383. \int_compare:nNnT
  384. { \g__MRTtab_color_upto_int + \c_one } = \g__MRTtab_current_row_int
  385. { \headE\hline }
  386. }
  387. {
  388. \headR
  389. }
  390. }% <<<
  391. \MRTtab_addto_private_bol_hook:n { \noalign { \MRTtab_step_row: } }
  392. \MRTtab_addto_private_bol_hook:n { \MRTtab_head_hook: }
  393. \NewDocumentEnvironment { MRTtabular } { O{} o +m o }% >>>
  394. {% begin >>>
  395. \MRTtab_patch_array:
  396. \MRTtab_declare_head_macro:
  397. \bool_gset_false:N \g__MRTtab_head_bool
  398. \IfValueT { #2 }
  399. {
  400. \int_gset:Nn \g__MRTtab_color_upto_int { #2 }
  401. \msg_warning:nnnn { MRTtab } { deprecated~syntax } { MRTtabular }
  402. { set~the~number~of~head~rows }
  403. }
  404. \IfValueT { #4 } { \int_gset:Nn \g__MRTtab_color_upto_int { #4 } }
  405. \setstretch { \l_MRTtab_stretch_tl }
  406. \begin{tabular_original}[#1]{#3}
  407. \MRTtab_surround_lines:
  408. }% <<<
  409. {% end >>>
  410. \MRTtab_surround_lines:
  411. %\crcr\hline
  412. \end{tabular_original}
  413. \int_gset:Nn \g__MRTtab_color_upto_int { -\c_max_int }
  414. }% <<<
  415. % <<<
  416. \NewDocumentCommand \MRTtabAddtoBoLHook { +m }% >>>
  417. {
  418. \MRTtab_addto_public_bol_hook:n { #1 }
  419. }% <<<
  420. \NewDocumentCommand \MRTtabAddtoEoLHook { +m }% >>>
  421. {
  422. \MRTtab_addto_public_eol_hook:n { #1 }
  423. }% <<<
  424. \NewDocumentCommand \MRTtabClearBoLHook {}% >>>
  425. {
  426. \MRTtab_clear_public_bol_hook:
  427. }% <<<
  428. \NewDocumentCommand \MRTtabClearEoLHook {}% >>>
  429. {
  430. \MRTtab_clear_public_eol_hook:
  431. }% <<<
  432. \NewExpandableDocumentCommand \MRTtabCurrentRow {}% >>>
  433. {
  434. \int_use:N \g__MRTtab_current_row_int
  435. }% <<<
  436. \NewDocumentCommand \MRTtabDeclareHeadMacros {}% >>>
  437. {
  438. \MRTtab_declare_head_macrosSRE:
  439. }% <<<
  440. %%==========================================================================<<<
  441. %% MRTcline >>>
  442. %%=============================================================================
  443. \tl_new:N \l__MRTtab_cline_output_tl
  444. \cs_new:Nn \MRTtab_cline_output_single:nNnnnn% >>>
  445. {
  446. % #1 fill color
  447. % #2 if star
  448. % #3 left skip
  449. % #4 right skip
  450. % #5 start column
  451. % #6 end column
  452. \tl_put_right:Nn \l__MRTtab_cline_output_tl
  453. {
  454. \@multicnt#5
  455. \advance\@multispan\m@ne
  456. \ifnum\@multicnt=\@ne
  457. \@firstofone{&\omit}
  458. \fi
  459. \@multicnt#6
  460. \advance\@multicnt -#5
  461. \advance\@multispan\@ne
  462. \group_begin:
  463. \color{#1}\rule{#3}\arrayrulewidth
  464. \group_end:
  465. \group_begin:
  466. \bool_if:NTF #2 { \color { #1 } } { \CT@arc@ }
  467. \leaders\hrule\@height\arrayrulewidth\hfill
  468. \group_end:
  469. \group_begin:
  470. \color{#1}\rule{#4}\arrayrulewidth
  471. \group_end:
  472. \cr
  473. \noalign{\vskip-\arrayrulewidth}
  474. }
  475. }% <<<
  476. \cs_generate_variant:Nn \MRTtab_cline_output_single:nNnnnn { xNxxxx }
  477. \cs_new:Nn \MRTtab_cline_output_strip:nNnnnn% >>>
  478. {
  479. % #1 fill color
  480. % #2 if star
  481. % #3 left skip
  482. % #4 right skip
  483. % #5 start column
  484. % #6 end column
  485. \MRTtab_cline_output_single:xNxxxx
  486. { \tl_trim_spaces:n { #1 } }
  487. #2
  488. { \tl_trim_spaces:n { #3 } }
  489. { \tl_trim_spaces:n { #4 } }
  490. { \tl_trim_spaces:n { #5 } }
  491. { \tl_trim_spaces:n { #6 } }
  492. }% <<<
  493. \cs_new:Npn \MRTtab_cline_split_columns:nNnnw #1 #2 #3 #4 #5 - #6 \q_stop% >>>
  494. {
  495. % #1 fill color
  496. % #2 if star
  497. % #3 left skip
  498. % #4 right skip
  499. % #5 start column
  500. % #6 end column
  501. \MRTtab_cline_output_strip:nNnnnn { #1 } #2 { #3 } { #4 } { #5 } { #6 }
  502. }% <<<
  503. \cs_new:Npn \MRTtab_cline_get_columns:nNnnw #1 #2 #3 #4 #5 \q_stop% >>>
  504. {
  505. % #1 fill color
  506. % #2 if star
  507. % #3 left skip
  508. % #4 right skip
  509. % #5 columns
  510. %\tl_analysis_show:n { #5 }
  511. \tl_if_in:nnTF { #5 } { , }
  512. { \MRTtab_cline_column_group:nNnnn { #1 } #2 { #3 } { #4 } { #5 } }
  513. {
  514. \tl_if_in:nnTF { #5 } { - }
  515. {
  516. \MRTtab_cline_split_columns:nNnnw { #1 } #2 { #3 } { #4 } #5 \q_stop
  517. }
  518. {
  519. \MRTtab_cline_output_strip:nNnnnn { #1 } #2 { #3 } { #4 } { #5 }
  520. { #5 }
  521. }
  522. }
  523. }% <<<
  524. \cs_new:Nn \MRTtab_cline_column_group:nNnnn% >>>
  525. {
  526. % #1 fill color
  527. % #2 if star
  528. % #3 left skip
  529. % #4 right skip
  530. % #5 column group
  531. %\tl_analysis_show:n { #5 }
  532. %\tl_analysis_show:n { #6 }
  533. \int_set:Nn \l_MRTtab_tmpb_int { \clist_count:n { #5 } }
  534. \clist_map_inline:nn { #5 }
  535. {
  536. \int_decr:N \l_MRTtab_tmpb_int
  537. \MRTtab_cline_get_columns:nNnnw { #1 } #2 { #3 } { #4 } ##1 \q_stop
  538. \int_compare:nNnT \l_MRTtab_tmpb_int > 0
  539. { \tl_put_right:Nn \l__MRTtab_cline_output_tl { \omit } }
  540. }
  541. }% <<<
  542. \cs_new:Nn \MRTtab_cline_peek_column_group:nNnn% >>>
  543. {
  544. % #1 fill color
  545. % #2 if star
  546. % #3 left skip
  547. % #4 right skip
  548. \peek_meaning_ignore_spaces:NTF \c_group_begin_token
  549. { \MRTtab_cline_column_group:nNnnw { #1 } #2 { #3 } { #4 } }
  550. { \MRTtab_cline_get_columns:nNnnw { #1 } #2 { #3 } { #4 } }
  551. }% <<<
  552. \cs_new:Npn \MRTtab_cline_get_right_skip:nNnw #1 #2 #3 [ #4 ]% >>>
  553. {
  554. % #1 fill color
  555. % #2 if star
  556. % #3 left skip
  557. % #4 right skip
  558. %\MRTtab_cline_peek_column_group:nNnn { #1 } #2 { #3 } { #4 }
  559. \MRTtab_cline_get_columns:nNnnw { #1 } #2 { #3 } { #4 }
  560. }% <<<
  561. \cs_new:Nn \MRTtab_cline_peek_right_skip:nNn% >>>
  562. {
  563. % #1 fill color
  564. % #2 if star
  565. % #3 left skip
  566. \peek_meaning_ignore_spaces:NTF [%]
  567. { \MRTtab_cline_get_right_skip:nNnw { #1 } #2 { #3 } }
  568. { \MRTtab_cline_get_columns:nNnnw { #1 } #2 { #3 } { .5\tabcolsep } }
  569. }% <<<
  570. \cs_new:Nn \MRTtab_cline_peek_right:nNn% >>>
  571. {
  572. % #1 fill color
  573. % #2 if star
  574. % #3 left skip
  575. \peek_meaning_remove_ignore_spaces:NTF >
  576. { \MRTtab_cline_peek_right_skip:nNn { #1 } #2 { #3 } }
  577. { \MRTtab_cline_get_columns:nNnnw { #1 } #2 { #3 } { 0pt } }
  578. }% <<<
  579. \cs_new:Npn \MRTtab_cline_get_left_skip:nNw #1 #2 [ #3 ]% >>>
  580. {
  581. % #1 fill color
  582. % #2 if star
  583. % #3 left skip
  584. \MRTtab_cline_peek_right:nNn { #1 } #2 { #3 }
  585. }% <<<
  586. \cs_new:Nn \MRTtab_cline_peek_left_skip:nN% >>>
  587. {
  588. % #1 fill color
  589. % #2 if star
  590. \peek_meaning_ignore_spaces:NTF [%]
  591. { \MRTtab_cline_get_left_skip:nNw { #1 } #2 }
  592. { \MRTtab_cline_peek_right:nNn { #1 } #2 { .5\tabcolsep } }
  593. }% <<<
  594. \cs_new:Nn \MRTtab_cline_peek_left:nN% >>>
  595. {
  596. % #1 fill color
  597. % #2 if star
  598. \peek_meaning_remove_ignore_spaces:NTF <
  599. { \MRTtab_cline_peek_left_skip:nN { #1 } #2 }
  600. { \MRTtab_cline_peek_right:nNn { #1 } #2 { 0pt } }
  601. }% <<<
  602. \cs_new:Npn \MRTtab_cline_individual_color:Nw #1 [ #2 ]% >>>
  603. {
  604. % #1 if star
  605. % #2 fill color
  606. \MRTtab_cline_peek_left:nN { #2 } #1
  607. }% <<<
  608. \cs_new:Nn \MRTtab_cline_peek_color:nN% >>>
  609. {
  610. % #1 fill color
  611. % #2 if star
  612. \peek_meaning_ignore_spaces:NTF [%]
  613. { \MRTtab_cline_individual_color:Nw #2 }
  614. { \MRTtab_cline_peek_left:nN { #1 } #2 }
  615. }% <<<
  616. \cs_new:Nn \MRTtab_cline_peek_star:n% >>>
  617. {
  618. % #1 fill color
  619. \peek_meaning_remove_ignore_spaces:NTF *
  620. { \MRTtab_cline_peek_color:nN { #1 } \c_true_bool }
  621. { \MRTtab_cline_peek_color:nN { #1 } \c_false_bool }
  622. }% <<<
  623. \cs_new:Nn \MRTtab_cline_arg_parser:nn% >>>
  624. {
  625. % #1 fill color
  626. \int_set:Nn \l_MRTtab_tmpa_int { \clist_count:n { #2 } }
  627. \clist_map_inline:nn { #2 }
  628. {
  629. \int_decr:N \l_MRTtab_tmpa_int
  630. \MRTtab_cline_peek_star:n { #1 } ##1 \q_stop
  631. \int_compare:nNnT \l_MRTtab_tmpa_int > 0
  632. { \tl_put_right:Nn \l__MRTtab_cline_output_tl { \omit } }
  633. }
  634. }% <<<
  635. \cs_generate_variant:Nn \MRTtab_cline_arg_parser:nn { xn }
  636. \NewExpandableDocumentCommand \clineReveal { }% >>>
  637. {
  638. \noalign { \vskip \arrayrulewidth }
  639. }% <<<
  640. \NewExpandableDocumentCommand \MRTcline { }% >>>
  641. {
  642. \omit
  643. \MRTtab@cline
  644. }% <<<
  645. \NewDocumentCommand \MRTtab@cline { o m }% >>>
  646. {
  647. \tl_clear:N \l__MRTtab_cline_output_tl
  648. \MRTtab_cline_arg_parser:xn
  649. {
  650. \IfNoValueTF { #1 }
  651. {
  652. \bool_if:NTF \g__MRTtab_head_bool { tablegray }
  653. {
  654. \int_compare:nNnTF
  655. \g__MRTtab_current_row_int > \g__MRTtab_color_upto_int
  656. { white }
  657. { tablegray }
  658. }
  659. }
  660. { #1 }
  661. }
  662. { #2 }
  663. \l__MRTtab_cline_output_tl
  664. \clineReveal
  665. \bool_if:nT
  666. {
  667. \g__MRTtab_head_bool ||
  668. !\int_compare_p:nNn
  669. \g__MRTtab_current_row_int > \g__MRTtab_color_upto_int
  670. }
  671. { \headR }
  672. }% <<<
  673. %%==========================================================================<<<
  674. %% MRTtable >>>
  675. %%=============================================================================
  676. %\cs_generate_variant:Nn \exp_last_unbraced:NNNV { NnNV }
  677. \cs_new:Nn \MRTtab_table_addto_pre_hook:n% >>>
  678. {
  679. \tl_put_right:Nn \l__MRTtab_table_pre_hook_tl { #1 }
  680. }% <<<
  681. \cs_new:Nn \MRTtab_table_clear_pre_hook:% >>>
  682. {
  683. \tl_clear:N \l__MRTtab_table_pre_hook_tl
  684. }% <<<
  685. \cs_new:Nn \MRTtab_table_addto_post_hook:n% >>>
  686. {
  687. \tl_put_right:Nn \l__MRTtab_table_post_hook_tl { #1 }
  688. }% <<<
  689. \cs_new:Nn \MRTtab_table_clear_post_hook:% >>>
  690. {
  691. \tl_clear:N \l__MRTtab_table_post_hook_tl
  692. }% <<<
  693. \cs_new:Nn \__MRTtab_table_caption:% >>>
  694. {
  695. \tl_if_blank:VF \l_MRTtab_table_cap_tl
  696. {
  697. \tl_if_blank:VTF \l_MRTtab_table_scap_tl
  698. {
  699. \caption { \l_MRTtab_table_cap_tl \l_MRTtab_table_lable_tl }
  700. }
  701. {
  702. \caption
  703. [ \l_MRTtab_table_scap_tl ]
  704. { \l_MRTtab_table_cap_tl \l_MRTtab_table_lable_tl }
  705. }
  706. }
  707. }% <<<
  708. \cs_new:Nn \__MRTtab_table_normal_start:% >>>
  709. {
  710. \bool_if:NTF \l_MRTtab_bare_bool
  711. {
  712. \def \@captype { table }
  713. }
  714. {
  715. \bool_if:NTF \l_MRTtab_table_float_bool
  716. {
  717. \def\MRTtab@tmpa{\begin{table}}
  718. \exp_last_unbraced:NNV \MRTtab@tmpa [ \l_MRTtab_table_pos_tl ]
  719. }
  720. {
  721. \def \@captype { table }% make \caption work
  722. \skip_if_eq:nnF { \l_MRTtab_in_text_sep_skip } { \c_zero_skip }
  723. { \vskip \l_MRTtab_in_text_sep_skip }
  724. \noindent
  725. \begin { minipage } { \textwidth }
  726. }
  727. }
  728. \centering
  729. \bool_if:NT \l_MRTtab_caption_above_bool
  730. {
  731. \let \if@captionabove \iftrue
  732. \__MRTtab_table_caption:
  733. }
  734. \l__MRTtab_table_pre_hook_tl
  735. \tl_if_empty:NF \l__MRTtab_env_begin_tl
  736. { \exp_args:NV \l__MRTtab_env_begin_tl \l_MRTtab_table_col_tl }
  737. }% <<<
  738. \cs_new:Nn \__MRTtab_table_normal_end:% >>>
  739. {
  740. \l__MRTtab_env_end_tl
  741. \l__MRTtab_table_post_hook_tl
  742. \bool_if:NF \l_MRTtab_caption_above_bool
  743. {
  744. \let \if@captionabove \iffalse
  745. \__MRTtab_table_caption:
  746. }
  747. \bool_if:NF \l_MRTtab_bare_bool
  748. {
  749. \bool_if:NTF \l_MRTtab_table_float_bool
  750. { \end { table } }
  751. {
  752. \end { minipage }
  753. \skip_if_eq:nnF { \l_MRTtab_in_text_sep_skip } { \c_zero_skip }
  754. { \vskip \l_MRTtab_in_text_sep_skip }
  755. }
  756. }
  757. }% <<<
  758. \cs_new:Nn \__MRTtab_table_long_start:% >>>
  759. {
  760. \msg_if_exist:nnF { MRTtab } { long~not~implemented }
  761. {
  762. \msg_new:nnn { MRTtab } { long~not~implemented }
  763. {
  764. Sorry,~the~option~long~is~currently~not~implemented.~Using~normal~
  765. version~and~ignoring~long~as~fallback.
  766. }
  767. }
  768. \msg_error:nn { MRTtab } { long~not~implemented }
  769. \cs_gset_eq:NN \__MRTtab_table_long_end: \__MRTtab_table_normal_end:
  770. \__MRTtab_table_normal_start:
  771. }% <<<
  772. \cs_new:Nn \__MRTtab_table_long_end:% >>>
  773. {
  774. \end { longtable }
  775. \l__MRTtab_table_post_hook_tl
  776. }% <<<
  777. \NewDocumentEnvironment { MRTtable } { +O{} }% >>>
  778. {% begin >>>
  779. \MRTtabDeclareHeadMacros
  780. \MRTtabSetup { head = 1 }
  781. \MRTtabSetup { #1 }
  782. \bool_if:NT \l_MRTtab_table_striped_bool
  783. {
  784. \rowcolors { \l_MRTtab_table_stripe_start_tl }
  785. { \l_MRTtab_table_scolor_one_tl } { \l_MRTtab_table_scolor_two_tl }
  786. }
  787. \bool_if:NTF \l_MRTtab_table_long_bool
  788. { \__MRTtab_table_long_start: }
  789. { \__MRTtab_table_normal_start: }
  790. }% <<<
  791. {% end >>>
  792. \bool_if:NTF \l_MRTtab_table_long_bool
  793. { \__MRTtab_table_long_end: }
  794. { \__MRTtab_table_normal_end: }
  795. }% <<<
  796. % <<<
  797. \NewDocumentCommand \MRTtabAddtoPreHook { +m }% >>>
  798. {
  799. \MRTtab_table_addto_pre_hook:n { #1 }
  800. }% <<<
  801. \NewDocumentCommand \MRTtabAddtoPostHook { +m }% >>>
  802. {
  803. \MRTtab_table_addto_post_hook:n { #1 }
  804. }% <<<
  805. \NewDocumentCommand \MRTtabClearPreHook {}% >>>
  806. {
  807. \MRTtab_table_clear_pre_hook:
  808. }% <<<
  809. \NewDocumentCommand \MRTtabClearPostHook {}% >>>
  810. {
  811. \MRTtab_table_clear_post_hook:
  812. }% <<<
  813. %%==========================================================================<<<
  814. %% \endfirstfoot addition to longtable >>>
  815. %%=============================================================================
  816. % code from: https://tex.stackexchange.com/questions/68439/
  817. % it should allow a \endfirstfoot in longtable
  818. \newbox\LT@firstfoot
  819. \def\endfirstfoot{\LT@end@hd@ft\LT@firstfoot}
  820. \newdimen\LT@footdiff
  821. \def\LT@start{%
  822. \let\LT@start\endgraf
  823. \endgraf\penalty\z@
  824. \vskip\LTpre
  825. \LT@footdiff-\ht\LT@foot
  826. \advance\LT@footdiff\ht\LT@firstfoot
  827. \dimen@\pagetotal
  828. \advance\dimen@ \ht\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
  829. \advance\dimen@ \dp\ifvoid\LT@firsthead\LT@head\else\LT@firsthead\fi
  830. \advance\dimen@ \ht\ifvoid\LT@firstfoot\LT@foot\else\LT@firstfoot\fi
  831. \dimen@ii\vfuzz
  832. \vfuzz\maxdimen
  833. \setbox\tw@\copy\z@
  834. \setbox\tw@\vsplit\tw@ to \ht\@arstrutbox
  835. \setbox\tw@\vbox{\unvbox\tw@}%
  836. \vfuzz\dimen@ii
  837. \advance\dimen@ \ht
  838. \ifdim\ht\@arstrutbox>\ht\tw@\@arstrutbox\else\tw@\fi
  839. \advance\dimen@\dp
  840. \ifdim\dp\@arstrutbox>\dp\tw@\@arstrutbox\else\tw@\fi
  841. \advance\dimen@ -\pagegoal
  842. \ifdim \dimen@>\z@\vfil\break\fi
  843. \global\@colroom\@colht
  844. \ifvoid\LT@firstfoot
  845. \ifvoid\LT@foot
  846. \else
  847. \advance\vsize-\ht\LT@foot
  848. \global\advance\@colroom-\ht\LT@foot
  849. \dimen@\pagegoal\advance\dimen@-\ht\LT@foot\pagegoal\dimen@
  850. \maxdepth\z@
  851. \fi
  852. \else
  853. \advance\vsize-\ht\LT@firstfoot
  854. \global\advance\@colroom-\ht\LT@firstfoot
  855. \dimen@\pagegoal\advance\dimen@-\ht\LT@firstfoot\pagegoal\dimen@
  856. \maxdepth\z@
  857. \fi
  858. \ifvoid\LT@firsthead\copy\LT@head\else\box\LT@firsthead\fi\nobreak
  859. \output{\LT@output}%
  860. }
  861. \def\LT@output{%
  862. \ifnum\outputpenalty <-\@Mi
  863. \ifnum\outputpenalty > -\LT@end@pen
  864. \LT@err{floats and marginpars not allowed in a longtable}\@ehc
  865. \else
  866. \setbox\z@\vbox{\unvbox\@cclv}%
  867. \ifdim \ht\LT@lastfoot>\ht\LT@foot
  868. \dimen@\pagegoal
  869. \advance\dimen@-\ht\LT@lastfoot
  870. \ifdim\dimen@<\ht\z@
  871. \setbox\@cclv\vbox{\unvbox\z@\copy\LT@foot\vss}%
  872. \@makecol
  873. \@outputpage
  874. \setbox\z@\vbox{\box\LT@head}%
  875. \fi
  876. \fi
  877. \global\@colroom\@colht
  878. \global\vsize\@colht
  879. \vbox
  880. {\unvbox\z@\box\ifvoid\LT@lastfoot\LT@foot\else\LT@lastfoot\fi}%
  881. \fi
  882. \else
  883. \ifvoid\LT@firstfoot
  884. \setbox\@cclv\vbox{\unvbox\@cclv\copy\LT@foot\vss}%
  885. \@makecol
  886. \@outputpage
  887. \global\vsize\@colroom
  888. \else
  889. \setbox\@cclv\vbox{\unvbox\@cclv\box\LT@firstfoot\vss}%
  890. \@makecol
  891. \@outputpage
  892. \global\advance\@colroom\LT@footdiff
  893. \global\vsize\@colroom
  894. \fi
  895. \copy\LT@head\nobreak
  896. \fi
  897. }
  898. %%==========================================================================<<<
  899. %% MRTtable[long] >>>
  900. %%=============================================================================
  901. %\cs_new_protected:Nn \MRTtab_patch_array_long:% >>>
  902. %{
  903. %\cs_set_eq:NN \@@array_original \@@array
  904. %\cs_set_eq:NN \@arraycr_original \@arraycr
  905. %\cs_set_eq:NN \@xarraycr_original \@xarraycr
  906. %\cs_set_eq:NN \@xargarraycr_original \@xargarraycr
  907. %\cs_set_eq:NN \@yargarraycr_original \@yargarraycr
  908. %\cs_set_eq:NN \tabular_original \tabular
  909. %\cs_set_eq:NN \endtabular_original \endtabular
  910. %\cs_set_eq:NN \array_original \array
  911. %\cs_set_eq:NN \endarray_original \endarray
  912. %\MRTtab_pretocmd:Nn \tabular { \MRTtab@unpatcharray }
  913. %\MRTtab_pretocmd:Nn \array { \MRTtab@unpatcharray }
  914. %\MRTtab_pretocmd:Nn \@arraycr { \MRTtab@long@EoLHook }
  915. %\MRTtab_apptocmd:Nn \@yargarraycr { \MRTtab@long@BoLHook }
  916. %\MRTtab_patchcmd:Nnn \@xarraycr { \cr } { \cr \MRtab@long@BoLHook }
  917. %\MRTtab_patchcmd:Nnn \@xargarraycr { \cr } { \cr \MRtab@long@BoLHook }
  918. %}% <<<
  919. %\cs_new:Nn \__MRTtab_table_long_start:
  920. %{
  921. %}
  922. %\cs_new:Nn \__MRTtab_table_long_end:
  923. %{
  924. %}
  925. %%==========================================================================<<<
  926. \endinput
  927. % vim: ft=tex fdm=marker fmr=>>>,<<< sw=2 ts=2 tw=80