Jupyter notebook Latex - math

I need to type a math formula and its notations. The formula works but the notation format is not correct. Could you help me with that? Thank you.
$$
(x)\approx\frac{\phi\prime (x)\times(1-p\prime)\times p}
{\phi\prime(x)\times(1-p\prime)\times p +(1-\phi\prime(x)\times
p\prime\times(1-p)}\\
$$
$$p$$: notation1
$$p\prime$$: notation2
$$\phi$$: notation3
$$\phi\prime$$: notation4

You are using the $$ which forces a new line around an equation. Using a single $ creates an inline expression, which is what you want. So change the code to be:
$$
(x)\approx\frac{\phi\prime (x)\times(1-p\prime)\times p}
{\phi\prime(x)\times(1-p\prime)\times p +(1-\phi\prime(x)\times
p\prime\times(1-p)}\\
$$
$p$: notation1
$p\prime$: notation2
$\phi$: notation3
$\phi\prime$: notation4
Alternatively, to break the lines a little better you can use the <br/> tag
$$
(x)\approx\frac{\phi\prime (x)\times(1-p\prime)\times p}
{\phi\prime(x)\times(1-p\prime)\times p +(1-\phi\prime(x)\times
p\prime\times(1-p)}\\
$$
$p$: notation1<br/>
$p\prime$: notation2<br/>
$\phi$: notation3<br/>
$\phi\prime$: notation4<br/>
You also mentioned right align - for this you'll need to use a div and align it, like so:
$$
(x)\approx\frac{\phi\prime (x)\times(1-p\prime)\times p}
{\phi\prime(x)\times(1-p\prime)\times p +(1-\phi\prime(x)\times
p\prime\times(1-p)}\\
$$
<div align="right">
$p$: notation1<br/>
$p\prime$: notation2<br/>
$\phi$: notation3<br/>
$\phi\prime$: notation4<br/>
</div>
Note that the latter two solutions will only really work in the live notebook and I presume HTML output (Markdown may work too). If you plan to convert to latex/pdf afterwards then you'll need the first solution or the solution below:
$$
(x)\approx\frac{\phi\prime (x)\times(1-p\prime)\times p}
{\phi\prime(x)\times(1-p\prime)\times p +(1-\phi\prime(x)\times
p\prime\times(1-p)}\\
$$
$\begin{align}
p: notation1
\newline
p\prime: notation2
\newline
\phi: notation3
\newline
\phi\prime: notation4
\end{align}
$
With this solution you can have either left alignment (using single $ around the align environment) or centre alignment (using $$ around the align environment) but I don't think you can have right alignment. Plus this way the notations are in maths font rather than regular font, which may not be desired.

Related

Remove space between symbol and text when using 'expression'

I want to use the function 'expression' in r to be able to add symbols as '≤'
Example:
plot(1:10,1:10)
legend(3,8, c(expression(""<="test ")))
With this code there will be a space between ≤ and test, I want there to be no space: ≤test, how to accomplish this?
Thanks
You could use unicode symbols (\U2264 for ≤) and do it without the expression?
plot(1:10,1:10)
legend(3,8, "\U2264test") # legend(3,8, "≤test")

R Markdown Inline LaTeX Equations: `$` ... `$` vs `\(` ... `\)`

---
title: "esc"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
A. An amount between $5 and $10.
B. An amount between \$5 and \$10.
C. An amount between \\$5 and \\$10.
X. An equation $1 and 1 = 2$.
Y. An equation \$1 and 1 = 2\$.
Z. An equation \\$1 and 1 = 2\\$.
I've got a similar, but different question here. Please comment if I need to add clarification to differences. I'm asking two different questions and hope that's obvious.
Anyways, the output of knitting the .Rmd above is shown below. Why does example X properly invoke LaTeX, where example A does not? X and A seem almost identical to me, and I'm left wondering why they both don't transform whatever is inside the dollar signs $ into LaTeX text?
I'm aware I could use \( and \) to replace $ and $. I just want to know why $ and $ doesn't properly call LaTeX in my example. It seems arbitray that it works for X, but not A, although I doubt it's arbitrary.
Pandoc's manual, under the Pandoc's Markdown > Math section, probably explains it best:
Anything between two $ characters will be treated as TeX math. The opening $ must have a non-space character immediately to its right, while the closing $ must have a non-space character immediately to its left, and must not be followed immediately by a digit. Thus, $20,000 and $30,000 won’t parse as math. If for some reason you need to enclose text in literal $ characters, backslash-escape them and they won’t be treated as math delimiters.

How to add space in text of the equation Jupyter notebook?

I want to write an equation in Jupyter notebook's markdown cell which contains text with space. I tried writing the following.
\begin{equation*}
e^{i\pi} + 1 + some text = 0
\end{equation*}
Which results like this.
How to add space between "some" and "text"? Thank you.
You can try wrapping your text in \text{}.
\begin{equation}
e^{i\pi} + 1 + \text{some text} = 0
\end{equation}
Note: this is more of a latex question, to which you can get answers from here.
In addition, you could consider " \ " and "\quad" directives to add horizontal space between elements in a LaTeX environment, also "\hskip".

How can I write quotation marks inside an Rmarkdown Latex equation?

How can I write quotation marks inside an Rmarkdown Latex equation? I tried the below, but the quotation marks get turned into dashes/derivative notation
$$
'Quoted Text'
$$
I tried many other suggestions like
$$
``Quoted Text"
$$
But nothing seems to display the quote marks properly.
This works for me:
$$
H_{0}: \text{Hello, } `` \text{World”}
$$

utltsnips - surround with space

I have the following utilsnips script that I use for Vim:
snippet - "assignment"
<-
endsnippet
I use it for R to expand a dash to the assignment operator. I would like to make it so that a space is put both before and after the <- on expansion. However, when I put a space before it in the snippet like <-, it won't expand on hitting Tab. How should I modify the script to have spaces around the operator? Desired result: <-.
You could use r option to include head and trailing spaces around snippets. r will treat snippet as a python regular expression and you should define your snippet within quotes when using this flag.
snippet " -" "assignment" r
<-
endsnippet
Note that there is a space before and after <- in snippet definition.
As a bonus, It's more interesting to define the snippet like the following:
snippet " - " "assignment" rA
<-
endsnippet
A is autoexpansion. so now you dont need to hit tab anymore! just type - and as soon as you type space after - it will expand to <- Automatically.

Resources