kable() in LaTeX mode to typeset numeric columns in math mode. - #1850
Conversation
|
Looks like the I don't think it's anything in the PR. |
f6f96a0 to
139253a
Compare
139253a to
73ebdde
Compare
|
It no looks like the problem is with |
b98f3dc to
73ebdde
Compare
…lumns in math mode (PR yihui/knitr#1850).
|
I've now updated the |
73ebdde to
9247b54
Compare
9247b54 to
9cc3097
Compare
9cc3097 to
644e593
Compare
644e593 to
b320135
Compare
bc82afc to
5ecdc1a
Compare
…lumns in math mode (PR yihui/knitr#1850).
5ecdc1a to
6c77ffc
Compare
…lumns in math mode (PR yihui/knitr#1850).
6c77ffc to
225e901
Compare
88dba01 to
aed7640
Compare
aed7640 to
0cba8f2
Compare
0cba8f2 to
f3b6739
Compare
ae02f5b to
a79c1d9
Compare
|
Thanks for the PR! Typesetting numbers in math mode for better minus signs is a nice improvement! My main concern is that this changes the default LaTeX output: every numeric column now emits Could you gate it behind an argument that defaults to off, following the same pattern as the other numeric.math = getOption('knitr.table.latex.numeric.math', FALSE)That way users can flip it per-call via Two smaller things:
Also, the branch currently conflicts with |
…looking minus signs. Commas, if present (as decimal or thousands separator), are wrapped in braces to prevent additional space being added after. Improves yihui#1709.
…n math mode. Improves yihui#1709.
… typesetting change. Improves yihui#1709.
|
Thanks for looking into this! Happy to make all these changes. While we are at it, would it make sense to also pretty-print the scientific notation, i.e., replace |
a79c1d9 to
5db95c3
Compare
|
Also, |
… by numeric.math= argument to kable() or globally by options(knitr.table.numeric.math=). Infinite values and scientific notation are now properly typeset; non-numerical values such as NA and NaN are passed through. Improves yihui#1709.
…de. The test for it now also tests infinite values and scientific notation. Improves yihui#1709.
…ng of numeric columns in LaTeX. Improves yihui#1709.
|
@yihui , I've pushed changes addressing the comments. For consistency with the argument name, I went with option name In the longer term, a similar function can be made for Markdown and HTML output. |
|
Two follow-ups on the latest changes: Reuse Scientific notation. I'd rather keep this PR focused on the math-mode typesetting only — math-mode wrapping, minus signs, comma-bracing, and Inf/-Inf. Rendering |
This might require quite a bit of rearchitecting:
Though I am not very happy with the regex approach either, it has the benefit of outsourcing the scientific notation and the trailing zero decisions to
I can split it out, but I would rather keep it in the same patch. If we keep the regex approach, it's just another branch in the You are the maintainer, so I defer to you on the revdep issues, but the scientific notation typesetting will only kick in if |
- Remove numeric.math from kable() formals; it flows through ... to
kable_latex() like other format-specific args
- Store is_num as attr(x, 'is_num') on the matrix (same pattern as
align), so kable_latex() reads it without needing an explicit arg
- Rename transform_num_for_latex() -> latex_num(); rewrite from nested
ifelse() to flat logical vectors for readability
- Fix 0e+00 rendering as \(0\) instead of \(0\times 10^{0}\)
- Move numeric.math docs from @PARAM to a dedicated @section for
LaTeX-specific arguments; regenerate kable.Rd
- Add test for zero in a sci-notation column
|
Good points and largely agreed. Thanks! I pushed one more fix: |
This is a partial fix for #1709, addressing the
LaTeXcase by typesetting numeric columns in math mode and wrapping commas (as decimal or thousands separators) in braces ({}) for correct spacing. This is, in my opinion, the cleanest option that does not require additionalLaTeXpackages.I've looked into the other output types (
pandoc,html,md, etc.), but I am not quite sure what should be their output.I've updated
NEWS.mdandDESCRIPTIONto save time, and apologise for the presumption of adding myself as a contributor and adding "thanks" to myself. If this PR doesn't merit a line in theDESCRIPTION, I'll be happy to remove it.