-
-
Notifications
You must be signed in to change notification settings - Fork 878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decimal separator and $$ notation #348
Comments
You can hack at the inline hook to add knit_hooks$set(inline = function(x) {
if (is.numeric(x)) x = sprintf('\\text{%s}', knitr:::format_sci(x, 'latex'))
knitr:::.inline.hook(x)
}) but in the non-math mode that will be problematic. However, you can continue hacking at it, e.g. let |
yeah, I'm not sure, maybe that's more fragile to corner cases than adding \text{} altogether. Reading this makes me think that maybe knitr could check if outdec is something other than '.', and then to use siunitx or numprint inside for numbers. But I'm not sure if this is too a corner case to handle in the package or not. |
You can design an inline hook first, and I may accept a pull request after it works well for you. Frankly speaking, I was not even aware of the |
I have to think about this... what if x is an expression and not just a number? is the expression evaluated before the hook is called or after? e.g. \Sexpr{0.6*2} vs \Sexpr{1.2} or worse \Sexpr{paste('a = ', 1.2)} |
The expression is always evaluated before being passed to the hook. |
Ok, I don't understand what you mean with
and the need to check using inherits. I also don't know why you said the hook you provided will be problematic outside a math environment. Could you clarify that? I tried it and it works (in and out of math environments)... it adds \text{} always, but I could live with that. Here's the example I created: \documentclass[a4paper]{article}
\usepackage{amsmath}
\begin{document}
\title{Test}
\maketitle
<<>>=
options(OutDec = ',')
@
<<>>=
knit_hooks$set(inline = function(x) {
if (is.numeric(x)) x = sprintf('\\text{%s}', knitr:::format_sci(x, 'latex'))
knitr:::.inline.hook(x)
})
@
\section{Test}
This is the first test. abc \Sexpr{0.6} def
another test $a = \Sexpr{0.6}$.
\end{document}
at least for these simple cases it works. An issue I see is that |
sorry I thought
for |
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. |
Hi,
I'm using comma as a decimal separator:
options(OutDec = ',')
.I have this small formatting issue:
When I use
\Sexpr{0.5}
inline with text, the output0,5
is nicely formatted.However, if I have to use it inside a math expression, like
$\alpha = \Sexpr{0.5}$
, then the0, 5
is output with an extra space after the comma. If I write$\alpha = \text{\Sexpr{0.5}}$
then it works ok.is there another simpler (more elegant) workaround or a fix for this?
thanks!
Cássio
The text was updated successfully, but these errors were encountered: