So I am trying to get Latex in my Jupyter Lab going.
If I insert this
\begin{eqnarray}
y & = & ax^2 + bx + c \\
f(x) & = & x^2 + 2xy + y^2
\end{eqnarray}
it gets rendered as expected
But
\begin{itemize}
\item First.
\item Second.
\end{itemize}
gets rendered as the text
I already installed #jupyterlab/latex extension
Related
I would like to manually number equations in a bookdown project. However, bookdown seems to auto number equations according to the chapter. Is there a way to turn this option off?
Here is an example equation in the second chapter:
$$
\begin{aligned}
y = 2x
\end{aligned}(\#eq:1) \tag{1}
$$
then, the rendered output produces
\begin{aligned}
y = 2x
\end{aligned}\tag{1}\tag{2.1}
You can use {equation*}.
Compare:
---
title: "Numbering"
header-includes: \usepackage{amsmath}
output:
pdf_document:
latex_engine: xelatex
---
\begin{equation}
y = mx+b
\end{equation}
\begin{equation}
\tag{}
y = mx+b
\end{equation}
\begin{equation*}
y = mx+b
\end{equation*}
$$
\begin{aligned}
y = mx+b
\end{aligned}(\#eq:1) \tag{1}
$$
I have a latex equation as part of an RMarkdown document that I'm knitting to an HTML file using knitr. I would like to use the LaTeX eqnarray to align the equality signs. However, I would also like to change font sizes from the first equation to the next.
This works, but equality signs are not lined up:
---
title: "Test"
author: "Eric"
date: "5/14/2020"
output: html_document
---
\[
\large a = b \times (c + d)\\
{\small\begin{eqnarray}
a &=& \mathrm{var ~a}\\
b &=& \mathrm{var ~b}\\
c &=& \mathrm{var ~c}
\end{eqnarray}}
\]
The result:
I tried many different arrangements of brackets and terms. Here is an example that does not work:
---
title: "Test"
author: "Eric"
date: "5/14/2020"
output: html_document
---
#### Try to line up equal signs AND change font sizes (doesn't work)
\[
\begin{eqnarray}
\large a &=& b \times (c + d)\\
{\small
a &=& \mathrm{var ~a}\\
b &=& \mathrm{var ~b}\\
c &=& \mathrm{var ~c}}
\end{eqnarray}
\]
#### Try again (doesn't work):
\[
\begin{eqnarray}
{\large a &=& b \times (c + d)}
{\small
\\a &=& \mathrm{var ~a}\\
b &=& \mathrm{var ~b}\\
c &=& \mathrm{var ~c}}
\end{eqnarray}
\]
How do I line up the equal signs using eqnarray while changing font sizes?
This seems to be what you'd want:
\[
\small
\begin{eqnarray}
{\large a}\ & {\large =} & {\large b \times (c + d)}\\
a &=& \mathrm{var ~a}\\
b &=& \mathrm{var ~b}\\
c &=& \mathrm{var ~c}
\end{eqnarray}
\]
The spacing for the a is a little bit off, which is why I added the \ after it. You might want to fiddle with that.
There is the following piece of code on the official Sphinx documentation:
.. math::
:nowrap:
\begin{eqnarray}
y & = & ax^2 + bx + c \\
f(x) & = & x^2 + 2xy + y^2
\end{eqnarray}
I tried for a long time to get it to work, until I changed it to:
.. math::
:nowrap:
$$
\\begin{eqnarray}
y & = & ax^2 + bx + c \\\\
f(x) & = & x^2 + 2xy + y^2
\\end{eqnarray}
$$
How could it be that the official Sphinx documentation is wrong?
Or is something obscure happening here? Even Sagemath documentation seems to suggest that $$ need to be used (see "If you wish to explicitly not wrap the MATH block [...]")
Or is this a bug?
(I use Sphinx 2.2.0 and in my index.rst file I use autofunction for the function whose docstring contains the equation above.)
The Sphinx documentation states that when you put math markup in Python docstrings read by autodoc, you either have to double all backslashes, or use Python raw strings (r"raw"). That happens because Python will interpret the string before Sphinx has the opportunity to parse it.
So, if you want to insert math in a docstring, the following should work:
.. math::
:nowrap:
\\begin{eqnarray}
y & = & ax^2 + bx + c \\\\
f(x) & = & x^2 + 2xy + y^2
\\end{eqnarray}
You may simplify it further with:
.. math::
y & = ax^2 + bx + c \\\\
f(x) & = x^2 + 2xy + y^2
The :nowrap only hints Sphinx that it should not wrap the provided equations in a LaTeX "split" environment (See Section 3 of the amsmath Manual). Instead, you must supply your own as indicated in the first example of this post.
I'm trying to create nicely formatted equations in RMarkdown, but I cannot seem to get it to Knit without errors. The LaTeX chunk I have looks like this:
---
title: "Untitled"
author: "KirkD-CO"
date: "September 18, 2019"
output: pdf_document
---
$$
f(x) = \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3 + \beta_4 (x-\xi)^3_+
\\
\begin{equation}
(x-\xi)^3_+ =
\begin{cases}
(x-\xi)^3 \ , \ x>\xi
\\
0 \ \ \ \ \ \ \ \ \ \ \ \ \ , \ x\leq\xi
\end{cases}
\end{equation}
\\
\
\\
\begin{aligned}
(x \leq \xi) \Rightarrow f(x) &= \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3
\\
(x > \xi) \Rightarrow f(x) &= \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3 + \beta_4(x^3 -3x^2\xi + 3x\xi^2 - \xi^3)
\\
&=(\beta_0 + \beta_4\xi^3) + (\beta_1 + 3\beta_4\xi^2)x + (\beta_2 - 3\beta_4)
\end{aligned}
$$
And in RStudio I see this:
But when I try to Knit it, I get this error:
! LaTeX Error: Bad math environment delimiter.
I've search Google and StackOverflow and found many similar problems with answers suggesting using [ ] instead of \begin{equation}, other suggest using only one $ instead of $$, and still others refer to a variety of LaTeX packages, a few of which I've tried and wound up in installation purgatory.
Any suggestion on a straight forward way to get Kniter to Knit a PDF with the output RStudio displays?
EDIT: I'm using R 3.5.3 and Kniter 1.22 on Fedora 30.
EDIT2: Under Tools -> Global Options -> Sweave -> Typeset LaTeX into PDF using: is set to pdfLaTeX
Following up from the comments, here is a cleaned version:
---
title: "Untitled"
author: "KirkD-CO"
date: "September 18, 2019"
output: pdf_document
---
$$
f(x) = \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3 + \beta_4 (x-\xi)^3_+
$$
$$
(x-\xi)^3_+ =
\begin{cases}
(x-\xi)^3\, ,& x>\xi \\
0 ,& x\leq\xi
\end{cases}
$$
$$
\begin{aligned}
(x \leq \xi) \Rightarrow f(x) &= \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3 \\
(x > \xi) \Rightarrow f(x) &= \beta_0 + \beta_1 x + \beta_2 x^2 + \beta_3 x^3 + \beta_4(x^3 -3x^2\xi + 3x\xi^2 - \xi^3) \\
&=(\beta_0 + \beta_4\xi^3) + (\beta_1 + 3\beta_4\xi^2)x + (\beta_2 - 3\beta_4)
\end{aligned}
$$
Producing
Some specific comments:
Put separate LaTeX math mode chunks into separate $$ ... $$ (or \[ ... \] environments (unless you use a multi-line math environment, see below).
Inside a cases environment, use & for horizontal alignment of different parts in every case
Don't use \\ unless you're using some multi-line math environment (like cases, aligned); conversely, if you do use a multi-line math environment, you must separate lines with \\.
I'm having some difficulty left aligning equations in R Markdown (i.e. putting the equation on the far left side of page, and aligning subsequent lines). I've generally determined that I want to set the [fleqn] option in the amsmath package to left align all equations, but putting the following in my YAML header gives an error
'Option clash for package amsmath'
---
author: "ME"
date: "February 26, 2015"
header-includes:
- \usepackage[fleqn]{amsmath}
output: pdf_document
---
A section from my document:
$$
\begin{aligned}
Bias(\hat{\theta}) &= E(\hat{\theta}) - \theta \\
&= E(2 \bar{X} -1) - \theta \\
&= \frac{2}{n}\sum_{i=1}^n E(X_i) -1 -\theta \\
&= 2E(X) - 1 - \theta \\
&= 2 \cdot \frac{\theta+1}{2} - 1 - \theta \\
&= 0 \\
\end{aligned}
$$
Thanks
Try using $...$ instead of $$...$$.
In the case of $$...$$ in Rmarkdown is center aligned by default
This question has already been asked here: R Markdown Math Equation Allignment
The below works for me:
$\begin{aligned}
Bias(\hat{\theta}) &= E(\hat{\theta}) - \theta \\
&= E(2 \bar{X} -1) - \theta \\
&= \frac{2}{n}\sum_{i=1}^n E(X_i) -1 -\theta \\
&= 2E(X) - 1 - \theta \\
&= 2 \cdot \frac{\theta+1}{2} - 1 - \theta \\
&= 0 \\
\end{aligned}$
$ L(x_{1}, x_{2}, ..., x_{n}| \mu) = \mu * (1-\mu) $
$log (\ L(x_{1}, x_{2}, ..., x_{n}| \mu)) = h * log(\mu) + (m-h) * log(1-\mu) $
$\frac{\partial log(\ L(x_{1}, x_{2}, ..., x_{n}| \mu)}{\partial(\mu)} = \frac{h}{\mu} + \frac{h-m}{1-\mu} $
#### We set this to zero to find the value that maximizes the likelihood
$\frac{h}{\mu} + \frac{h-m}{1-\mu} = 0 $
$h = m * \mu $
$\mu = \frac{h}{m} $