GithubHelp home page GithubHelp logo

Comments (3)

cderv avatar cderv commented on June 14, 2024

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

knitr/R/hooks-md.R

Lines 204 to 207 in 42f6b3a

inline = function(x) {
if (is_latex_output()) .inline.hook.tex(x) else {
.inline.hook(format_sci(x, if (length(pandoc_to()) == 1L) 'latex' else 'html'))
}

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...

    knitr/R/utils.R

    Lines 206 to 207 in 42f6b3a

    b = round_digits(x / 10^lx)
    b[b %in% c(1, -1)] = ''

    if not -1 we keep it

     knitr:::format_sci_one(-2*10^7, 'html')
     #> [1] "-2 &times; 10<sup>7</sup>"

    shouldn't we have a special case for -1 ?

    I am in doubt with your implementation of scientific notation

    knitr/R/utils.R

    Lines 227 to 229 in 42f6b3a

    sci_notation = function(format, base, times, power) {
    sprintf(format, base, ifelse(base == '', '', times), power)
    }

    Should it be "-1 &times; 10<sup>7</sup>" or "-10<sup>7</sup>" ?

from knitr.

yihui avatar yihui commented on June 14, 2024

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.

from knitr.

github-actions avatar github-actions commented on June 14, 2024

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.

from knitr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.