Closed fkohrt closed 9 months ago
I think the issue comes from this function we use for printing
knitr:::format_sci((-1)*10^7)
#> [1] "10^{7}"
We use this function in inline hooks
https://github.com/yihui/knitr/blob/42f6b3ad75f8245d26c1de3d3e0b9fa018566af3/R/hooks-md.R#L204-L207
It seems there is several issues here:
@yihui why do we latex
as format and not HTML here ? It seems we should use html
.
knitr:::format_sci_one((-1)*10^7, format = "latex")
#> [1] "10^{7}"
knitr:::format_sci_one((-1)*10^7, format = "html")
#> [1] "10<sup>7</sup>"
Not sure I understand why we do length(pandoc_to()) == 1L
then latex
We still loose the minus sign does not seems right... https://github.com/yihui/knitr/blob/42f6b3ad75f8245d26c1de3d3e0b9fa018566af3/R/utils.R#L206-L207
if not -1 we keep it
knitr:::format_sci_one(-2*10^7, 'html')
#> [1] "-2 × 10<sup>7</sup>"
shouldn't we have a special case for -1 ?
I am in doubt with your implementation of scientific notation https://github.com/yihui/knitr/blob/42f6b3ad75f8245d26c1de3d3e0b9fa018566af3/R/utils.R#L227-L229
Should it be "-1 × 10<sup>7</sup>"
or "-10<sup>7</sup>"
?
Should be fixed now. Thanks for the report!
---
title: "Inline test"
output: html_document
---
The following prints a positive(!) number: $`r (-1) * 10^7`$
Note that you need $ $
around the number.
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.
...leads to...
``` R version 4.3.1 (2023-06-16) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 20.04.6 LTS Locale: LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8 LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C time zone: UTC tzcode source: system (glibc) Package version: evaluate_0.21 graphics_4.3.1 grDevices_4.3.1 highr_0.10 knitr_1.44 methods_4.3.1 stats_4.3.1 tools_4.3.1 utils_4.3.1 xfun_0.40 yaml_2.3.7 ```xfun::session_info('knitr')
By filing an issue to this repo, I promise that
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
.I understand that my issue may be closed if I don't fulfill my promises.