yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.36k stars 873 forks source link

Inline code prints negative number without sign #2288

Closed fkohrt closed 9 months ago

fkohrt commented 9 months ago
---
title: "Inline test"
output: html_document
---

The following prints a positive(!) number: `r (-1) * 10^7`

...leads to...

Screenshot 2023-09-19 at 15-50-31 Inline test

xfun::session_info('knitr') ``` 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 ```

By filing an issue to this repo, I promise that

I understand that my issue may be closed if I don't fulfill my promises.

cderv commented 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 commented 9 months ago

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.

github-actions[bot] commented 3 months ago

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.