I have a number of rows of equations in my shiny app which I want to align by their equal sign but can't seem to get the align function to work properly. The code I have is as follows.
p("$$\\begin{align}
\\ x^2 &= \\text{Chi-Squared}
\\ sum &= \\text{summation}
\\ o &= \\text{the observed values}
\\ e &= \\text{the expected values}
\\end{align}$$")
This doesn't work though and I can't figure out how to align them properly. Any help would be greatly appreciated
You have not terminated alignment rows. You need to add \\\\ at the end of each row (except the last):
p("$$\\begin{align}
\\ x^2 &= \\text{Chi-Squared} \\\\
\\ sum &= \\text{summation} \\\\
\\ o &= \\text{the observed values} \\\\
\\ e &= \\text{the expected values}
\\end{align}$$")
Related
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
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 working on an SVG map, which contains a lot of text elements. The problem is, the old/source file has been generated years ago in Adobe Illustrator, which for some reason printed these elements as, e.g.:
<text transform="matrix(1 0 0 1 604.9754 765.0283)">4</text>
(First four arguments (1, 0, 0, 1) never change.)
What I want to achieve is to translate it into something like
<text x='123' y='456'>4</text>
I've already managed to collect all values needed using regex (text content and the two last transform arguments), but I have no idea what should I do next. I've also found out, that
The matrix( ) transform function specifies a transformation in the form of a transformation matrix of six values. matrix(a,b,c,d,e,f) is equivalent to applying the transformation matrix:
\begin{pmatrix} a & c & e \\ b & d & f \\ 0 & 0 & 1 \end{pmatrix}
which maps coordinates from a previous coordinate system into a new coordinate system by the following matrix equalities:
\begin{pmatrix} x_{\mathrm{newCoordSys}} \\ y_{\mathrm{newCoordSys}} \\ 1 \end{pmatrix} = \begin{pmatrix} a & c & e \\ b & d & f \\ 0 & 0 & 1 \end{pmatrix} \begin{pmatrix} x_{\mathrm{prevCoordSys}} \\ y_{\mathrm{prevCoordSys}} \\ 1 \end{pmatrix} = \begin{pmatrix} a x_{\mathrm{prevCoordSys}} + c y_{\mathrm{prevCoordSys}} + e \\ b x_{\mathrm{prevCoordSys}} + d y_{\mathrm{prevCoordSys}} + f \\ 1 \end{pmatrix}
So my question is:
how can I translate these matrix transform values into X,Y coordinates?
I've found out, that matrix(1 0 0 1 100px 200px) is equivalent to translateX(100px) translateY(200px) which means, that these values are actually the exact values I've been looking for. The reason I didn't realize it earlier was because I didn't adjust them (multiply, add) to my new image. I've also used X as Y coordinates inversely (ouch). I hope it can help someone.
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} $