I have managed to write the whole equation
using the following code in Rmarkdown
$$MAPE = \frac{1}{n} \sum_{d_i} (\frac{1}{q} \sum_{t_j}
\abs{\frac{gap_{i,j}-s_{i,j}}{gap_{i,j}}} )$$
However, in Rmarkdown, the code above returns:
Could anyone help figure out how to get abs right here?
Thanks
Expanding on Andrie's answer:
Another way to write absolute value is
\lvert -3 \rvert
To automatically adjust the size of the vertical lines to what's inside them, use
\left\lvert -3 \right\rvert
In your case, this becomes:
$$MAPE = \frac{1}{n} \sum_{d_i} (\frac{1}{q} \sum_{t_j}\left\lvert{\frac{gap_{i,j}-s_{i,j}}{gap_{i,j}}}\right\rvert)$$
edit: When I originally posted this answer, I couldn't embed images yet. Now replaced link with embed.
Using mathjax, you can use the "pipe" symbol |to indicate absolute values.
Try this:
$$ |-3| $$
In your case:
$$MAPE = \frac{1}{n} \sum_{d_i} (\frac{1}{q} \sum_{t_j} |\frac{gap_{i,j}-s_{i,j}}{gap_{i,j}}| )$$
This gives:
Related
I need to indent some math stuff in the \details section of my .Rd documentation to enhance its readability. I am using mathjaxr. Is there any way to indent without installing roxygen2 or similar?
The math stuff is inline, so simply setting to display using \mjdeqn won't solve this.
I seem to have a reasonable "cheating" work around for indenting the first line using mathjaxr, at least for the PDF and HTML output.
We need to do two things:
Use the mathjax/LaTeX phantom command. phantom works by making a box of the size necessary to type-set whatever its argument is, but without actually type-setting anything in the box. For my purposes, if I want to indent, say, about 2 characters wide, I would start the line with a \mjeqn{\phantom{22}}{ } and following with my actual text, possibly including actual mathy bits. If I want an indent of, say, roughly 4 characters wide, I might use \mjeqn{\phantom{2222}}{ }.
Because mathjaxr has a problem with tacking on unsolicited new lines when starting a line with mjeqn, we need to prefix the use of phantom in 1 above with an empty bit of something non-mathjaxr-ish like \emph{}.
Putting it all together, I can indent by about 2 characters using something like this:
\emph{}\mjeqn{\phantom{22}}Here beginneth mine indented lineā¦
I need to explore whether the { } business actually indents for ASCII output, or whether I might accomplish that using or some such.
when displaying a number with inline-code with more than four digits like
`r 21645`
the result in a knitted html-file is this: 2.164510^{4} (in reality inside the inline-hook there is a calculation going on which results in 21645). Even though I just want it to print the number, like so: 21645. I can easily fix this for one instance wrapping it inside as.integer or format or print, but how do I set an option for the whole knitr-document so that it prints whole integers as such (all I need is to print 5 digits)? Doing this by hand gets very annoying. Setting options(digits = 7) doesnt help. I am guessing I would have to set some chunk-optionor define a hook, but I have no idea how
I already solved it, just including the following line of code inside the setoptions-chunk in the beginning of a knitr document:
options(scipen=999)
resolves the issue, like one can read inside this answer from #Paul Hiemstra:
https://stackoverflow.com/a/25947542/4061993
from the documentation of ?options:
scipen: integer. A penalty to be applied when deciding to print
numeric values in fixed or exponential notation. Positive values bias
towards fixed and negative towards scientific notation: fixed notation
will be preferred unless it is more than scipen digits wider.
If you don't want to display scientific notation in this instance, but also don't want to disable it completely for your knitr report, you can use format() and set scientific=FALSE:
`r format(21645, scientific=FALSE)`
Note that if you type your numeric as integer it will be well formatted:
`r 21645L`
Of course you can always set an inline hook for more flexibility( even it is better to set globally options as in your answer):
```{r}
inline_hook <- function(x) {
if (is.numeric(x)) {
format(x, digits = 2)
} else x
}
knitr::knit_hooks$set(inline = inline_hook)
```
As part of my work, I am expected to show calculation steps with sample values. To do this, I usually just replace the variable names with \Sexpr{} to add in the values. For some reason \Sexpr{} escapes math mode and breaks some of my tags. For instance, this works well:
$r_{pump} = \sqrt{(x_{pump} - x_{obs})^{2} + (y_{pump} - y_{obs})^{2}}$
It results in all values being correctly placed under the square root tag like this:
However, when I try to include \Sexpr{} tags to incorporate values like this...
$\sqrt{(\Sexpr{x[1]}(m) - \Sexpr{x[2]}(m))^{2} + (\Sexpr{y[1]}(m) - \Sexpr{y[2]}(m))^{2}}$
...I get results that look like this:
This happens when I try to include \Sexpr{} in a \frac{}{} tag as well.
Am I applying math mode ($\Stuff$) incorrectly?
The following piece of reStructuredText does not give the result I expect.
*:sup:`superscript`*
Expected result: superscript
Actual result: :sup:`superscript`
The reason why it is happening is clear (reST text roles cannot be nested), however how can I obtain the expected result?
As specified in a FAQ, this is not currently possible without using the raw directive or without using a custom, ad-hoc directive.
You can use substitution:
The chemical formula for pure water is |H2O|.
.. |H2O| replace:: H\ :sub:`2`\ O
See the reStructuredText spec for further information on character-level markup and the substitution mechanism.
For example, in http://homepages.cwi.nl/~paulv/papers/algorithmicstatistics.pdf at the bottom of page 5 and top of page 6, he uses a plus/equal symbol and a similar plus/lessthan symbol. I can't figure out how to make that symbol, and I'd like to quote him.
Any help?
Try $\stackrel{top}{bottom}$
You'd want something like this:
$X \stackrel{+}{=} Y$
This positions the plus sign above the equals sign. For example, the following code:
$K(x,y|z) \stackrel{+}{=} K(x|z) \stackrel{+}{<} I(x:y|z)$
produces the following output:
The Comprehensive LaTeX Symbol List (from here) is a great resource, and start for questions like this. You could also contact the author, it's possible he did some LaTex voodoo (math accents and such) to get it to work.
Best of luck.
PS: isn't \pm plus-minus, not plus-equals?
Here's the list of Latex Math Symbols. I don't see the two from the PDF you linked to. Do you know what they mean? You might be able to find an equivalent in the Latex list.