Equation numbering in colab notebook - latex

I'm using
\begin{equation}.. \end{equation} in markdown mode in a Colab notebook and I don't get equation numbering as I would expect from Latex.
Is there a fix for this?

One option would be to use \tag{}, e.g.
\begin{equation}
y = x \tag{1}
\end{equation}
or
\begin{align}
f(x) &= x \tag{1}, \\
g(x) &= x^2 + 2. \tag{2}
\end{align}

Related

How to align piecewise functions

I thought a properly aligned piecewise function should be something like this:
Commas and character xs are perfectly aligned in two lines.
I tried
\vert x \vert =
\begin{cases}
x, &x \geq 0 \\
-x, &x < 0 \\
\end{cases}
which only aligned the domain parts like this:
In that way, the commas come after x and -x is not aligned, which looks strange.
I tried to solve that problem by adding spaces preceding the x in first line, which is:
\vert x \vert =
\begin{cases}
\enspace \; x, &x \geq 0 \\
-x, &x < 0 \\
\end{cases}
It gives the correct result (as above) but this solution seems rather strange, if the second line changes, then the first line have also to be modified to keep the spaces fit. I reckon there must be some better way to do it.
The default alignment behaviour of cases is left-left for the value and domain components. In this specific case (for aesthetic reasons), you can insert a \phantom negation to align the values:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\lvert x \rvert = \begin{cases}
x, & x \geq 0 \\
-x, & x < 0
\end{cases}
\]
\[
\lvert x \rvert = \begin{cases}
\phantom{-}x, & x \geq 0 \\
-x, & x < 0
\end{cases}
\]
\end{document}

How to control width of a long LaTeX equation in bookdown

I have an align equation that does not fit into my bookdown, especially the tag I am using:
My output is bookdown::gitbook. It works in R markdown though:
---
title: "LaTeX"
output: html_document
---
# Long Equation
This is too long
$$ \begin{align}
\text{outcome} &= f(\text{explanatory}) + \text{noise} \tag{Generic statistical model} \\
\text{outcome} &= \text{intercept} + \text{slope} \cdot \text{explanatory} + \text{noise} \tag{Generic linear model} \\
\end{align}$$
What is the difference between markdown and bookdown in handling LaTeX equations? And how to control the width of the aligned equations? Can I shift the entire formula block to the left?
You can use a div tag with margin right property.
<div style="margin-right:400px;">
\begin{align}
\text{outcome} &= f(\text{explanatory}) + \text{noise} \tag{Generic statistical model} \\
\text{outcome} &= \text{intercept} + \text{slope} \cdot \text{explanatory} + \text{noise} \tag{Generic linear model} \\
\end{align}
</div>
Result:

Variable names with spaces in equations

I want to write a fomula
\begin{equation}
fractional bandwidth = \frac{f_U-f_L}{f_C} \geq 0.25
\end{equation}
but it can't have any space between "fractional" and "bandwidth"
How can I do that? Thank you!
Use \text of package amsmath to format text in math equations.
\usepackage{amsmath}
...
\begin{equation}
\text{fractional bandwidth} = \frac{f_U-f_L}{f_C} \geq 0.25
\end{equation}
However, if these words were intended to be formatted like they are but with a space in between, you can insert spaces in math mode like this (a full list of spacing commands can be found here).
\begin{equation}
fractional \: bandwidth = \frac{f_U-f_L}{f_C} \geq 0.25
\end{equation}

Alternative to Bordermatrix for MathJax

I'm using bordermatrix to write matrix with coefficient on the top and on the left:
I would like to display a similar matrix on my website where I use Mathjax but I get a [Math Processing Error]. Do you have a MathJax-alternative to bordermatrix to get the same result?
You can use the following construction:
\begin{align}
f(x) &= ax^2 + bx + c \\
&= \begin{array}{c c}
& \begin{array} {#{} c c c #{}}
u_1 & \cdots & u_q
\end{array} \\
\begin{array}{c}
e_1 \\ \vdots \\ e_n
\end{array}\hspace{-1em} &
\left(
\begin{array}{#{} c c c #{}}
u_{11} & \cdots & u_{1q} \\
\vdots & & \vdots \\
u_{n1} & \cdots & u_{nq}
\end{array}
\right) \\
\mbox{} % Blank line to match column names so as to align the = vertically
\end{array} \\[-12pt] % Correction for blank line
&= ax^2 + bx + c
\end{align}
Depending on whether you're aligning it with other content, you might not need the vertical adjustment I inserted.
Tested on Math.SE.

How to center a vector in latex

I am using latex for my report. I am stuck in centering a vector. This is my latex code:
\begin{equation}
\centering
X_{i}=
$$\begin{bmatrix}
C_1\\
C_2\\
C_3\\
\vdots\\
\vdots\\
\vdots\\
\vdots\\
C_n\\
OlValue\\
\end{bmatrix}$$
\label{Vect}
\end{equation}
The centering command doesn't work. I tried several things but the vector is not on the center.
You're doing it wrong...
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\noindent
X \dotfill X% To show the horizontal text width/margins
\begin{equation}
X_i =
\begin{bmatrix}
C_1 \\ C_2 \\
\vdots \\
C_n
\end{bmatrix}
\end{equation}
\end{document}
Don't use \centering inside an equation. Also don't use $$...$$. The equation environment automatically centres its contents, period.

Resources