Closed mikkelee closed 1 year ago
- The formatting works fine, but I'm currently abusing the
font
key to set up some of my own keys based on the column config, as I can only pass one parameter (the cell contents) through tocmd
.
The total effects of options cmd
, font
, preto
and appto
are
<font> \selectfont <cmd> { <preto> <cell-content> <appto> }
Here <cmd>
can be any token list that optionally takes a mandatory argument. Hence you can use
\keys_define:nn { non-decimal-units }
{
tabularray~column~type .code = {
\NewColumnType {#1}[2] { Q[r, cmd=\ndu_tblr_cell:nnn {##1} {##2}] }
} ,
}
and then use \ndu_tblr_configure_column:nn {#1} {#2}
inside new \ndu_tblr_cell:nnn
.
- The arithmetic fails (result is exactly 4 times too big) because it appears
cmd
is called 4 times per cell: twice for each cell ordered by (row, column), and then that loop runs once again.
Yes each cell is typeset multiple times. For your specific config, the exact number is 4.
tabularray
provided expl3 bool \lTblrMeasuringBool
to expose the measuring and building phases, but unfortunately, even in building phase (when \lTblrMeasuringBool
is false) each cell may be typeset once or twice, depending on whether the corresponding column width is set. See #179.
A general scheme is shown in https://github.com/lvjr/tabularray/issues/179#issuecomment-1037692123. Because whether doing math (\nduMath
) in non RESULT cells doesn't affect the content of current cell itself (unlike the acro
example in #179), special workarounds exist. For example, If the total number of ndu tabularray columns (and cells) in a document is relatively small, one can construct a distinct control sequence per table per cell to mark if math is done for it, hence make sure math is done only once per cell.
My attempt (also pushed to my fork, see https://github.com/mikkelee/latex-units/compare/dev/expl3...muzimuzhi:latex-non-decimal-units:arithmatic-in-tblr)
Update: I'm deleting my branch arithmatic-in-tblr
since the patch is now part of the upstream repo, see https://github.com/mikkelee/latex-units/compare/b214f187...1501145c.
```diff
From 7fc24fc9020fc9a0ea5e1867f6e5466eaaf40885 Mon Sep 17 00:00:00 2001
From: Yukai Chou
PS: I used \<module>__<description>:<arg-spec>
to represent private functions (two _
after <module>
, not just one), as texdoc expl3
, sec. 3.2.1 "Separating private and public material" suggested. You may find texdoc l3styleguide
also helpful.
Oh wow! That is an incredible answer, that you so much. I've merged it locally and will get back tomorrow or monday (not at home right now, parents' old imac :))
I'm back. Everything works perfectly, so I will likely be publishing the next version of my package on CTAN in the coming week. Thanks again! I'm adding a short thank you in the documentation :-)
For future reference, the update was published: https://ctan.org/ctan-ann/id/mailman.3270.1697052309.3764.ctan-ann@ctan.org
No worries about deleting the branch
First off, excellent package!
I'm working on a package that can display and perform arithmetic with older non-decimal unit systems. Since I often use tabular data, I've been experimenting with a
tblr
column type.I have two questions:
The formatting works fine, but I'm currently abusing the
font
key to set up some of my own keys based on the column config, as I can only pass one parameter (the cell contents) through tocmd
. Is there a better way to do pass in a "pre-cmd
" via the column config?The arithmetic fails (result is exactly 4 times too big) because it appears
cmd
is called 4 times per cell: twice for each cell ordered by (row, column), and then that loop runs once again. Presumably this has to do with the layout algorithm? Before going further with a solution (tried a quick hacky division by 4, but it did not work as it was of course also called twice at the end of each "outer loop" with additions in each, resulting in an even more mangled sum), I wanted to make sure that the multiple calls to thecmd
are intentional (perhaps I am defining thecmd
option incorrectly?).I set up the column like so, with a call that amounts to
\NewColumnType {U}[2] { Q[r, font={\ndu_tblr_configure_column:nn{##1}{##2}}, cmd=\ndu_tblr_cell:n] }
: https://github.com/mikkelee/latex-units/blob/dev/expl3/latex/non-decimal-units.sty#L640-L700Below is a small example that can be tested with the dev/expl3 branch of my package: https://github.com/mikkelee/latex-units/blob/dev/expl3/latex
(6 mk/mark = 1 rdl/rigsdaler, so the true result 3 becomes multiplied by 4 = 12 mark, which is converted into 2 rigsdaler on top of the already quadrupled 101)
Cheers!