The foreword 0.
Recently, I have been learning some knowledge related to machine learning, and I want to record what I have learned online in the form of MD, but I have not started to take action before, because the formula in it is really troublesome. So I thought I’d spend some time today looking at how to insert a mathematical formula into MarkDown, and it turns out that it’s pretty easy to do in an hour or so.
1. Basic knowledge
I think the so-called insert mathematical formula is actually to introduce a rule, and then through the template, right? Render into a formula, do not know this understanding is correct, wrong look correct. In fact, you’ve probably seen blogs before that don’t show formulas when they should, and when you click on them, it links to a new TAB and shows you a picture of the formula, and sometimes it shows you a bunch of code. And here’s what this code parses into a formula and displays.
Here we’re going to pick the MathJax engine. Introduce the script, insert the following code into the MD file, if you are afraid of the online file source other people access to the words, you can put this down to do a source, so that the more stable disadvantage is to manually update their own source.
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=default"></script>
Copy the code
If you know LaTeX, you can see one or two examples. If you don’t, you can write your own code. You can find a tool that can preview MD and keep trying.
1.1 Insertion Mode
There are two ways to do this, one is to insert between rows, and the other is to take another row
1.1.1 Insert between lines
\\(a + b\\)
Copy the code
Insert the formula a + b: \(a + b\) between the lines. The feature is to include the formula by (and), and then escape it by \ for the template engine to be able to distinguish between (not plain text (but formula ()) and (). So it should be pretty easy to understand what the syntax is. Note that this is not the only way, this is the way I like to use, other ways to search. The same goes for the following introduction.
PS: Here is the gold mining using$a + b$
: If you are impressed by what you read, look at the final note, which will not be changed here. thank you
1.1.2 Get another row
$$a + b?
Copy the code
Here’s another row
Characteristic is through? Include formulas.
I think the second way is better, the following is pure guess: between the lines need to consider the current line height and the formula is processed, and the other line is simpler, and may be faster to parse. Very, very, very, very mainly to look pretty ^_^ not too much to worry about the lack of space to wrap lines.
1.2 Insert of basic types
Here is a brief introduction to @Houkai: Basic grammar for LATEX mathematical formulas.
1.2.1 Upper and lower indices
Let’s look at the results first and then summarize the grammar.
$$x_1?
$$x_1^ 2? $$x^ 2 _1? $$x_{22}^{(n)}?
$The ${}^*x^*?
$$x_{balabala}^{bala}?
Copy the code
As you can see, the x element superscript is represented by the content followed by the ^ symbol. The following table is represented by the content followed by the _ symbol. More than one digit is wrapped by {}. I used to write the subscript first and then the upper script, which is consistent with my writing habit: X_ {balabala}^{bala}, no matter which style you use, it is best to pay attention to the unity of your own, do not mix.
1.2.2 fraction
? \frac{x+y}{2}? ? \frac{1}{1+\frac{1}{2}}?Copy the code
Here’s onefrac{}{}
Function of things, again, in order to distinguish this is a function and not just a few letters, pass\frac
Escape, hencefrac
Is parsed into functions, and then the first one{}
The one inside is resolved into the molecule, number two{}
Parsed component parent. You can try interline analysis of fractions here. I want to see while filling effect I need to see inter-row filling effect I want to see inter-row filling effect I need to see inter-row filling effect I want to see inter-row filling effect I need to see inter-row filling effect I want to see inter-row filling effect I need to see inter-row filling effect I want to see inter-row filling effect I need to see inter-row filling effect I want to see inter-row filling effect I need to see inter-row filling effect.
1.2.3 radical
? \sqrt{2}<\sqrt[3]{3}? ? \sqrt{1+\sqrt[p]{1+a^2}}? ? \sqrt{1+\sqrt[^p\!] {1+a^2}}?Copy the code
Now that you know the concept of a function, the syntax is SQRT []{}. [] represents the square roots, {} represents the expression under the square root sign. The difference between the second and third is to fine-tune the position ^_^ for aesthetics.
1.2.4 Sum and integral
? \sum_{k=1}^{n}\frac{1}{k}? $\sum_{k=1}^n\frac{1}{k}$ ? \int_a^b f(x)dx? $\int_a^b f(x)dx$Copy the code
It is easy to see here that the sum-function expression sum_{starting point}^{end point}, the integral function expression int_ lower limit ^ upper limit integrand d integrand. The other interesting thing is that the formulas between the lines are compressed.
1.2.5 Spaces
Close to the$aThe \! B $without space$ab$small space a\,b medium space a\; B large space a\ b quad space$a\quad b$Two quad Spaces$a\qquad b$
Copy the code
The distance is fine-tuned to make the formula more beautiful. Compare the following integral formula:
? \int_a^b f(x)\mathrm{d}x? ? \int_a^b f(x)\,\mathrm{d}x?Copy the code
1.2.6 Formula delimiter
() (\ \ \ \ \ \ \ \ ()) \ \ ([\ \ \ \ \ \ \ \ []) (\ \ {\ \ \ \) (\ \} \ \ \ \ | (\ \) \ \ (\ \ | \ \) the nuggets: $($$$$/ $$$$\ {$$\} $$$$\ | | $Copy the code
The main signs areSo how to use it? through\left
和 \right
This is followed by a delimiter to define simultaneously.
? \left(\sum_{k=\frac{1}{2}}^{N^2}\frac{1}{k}\right)?Copy the code
1.2.7 matrix
? \begin{matrix}1 & 2\\\\3 &4\end{matrix}? ? \begin{pmatrix}1 & 2\\\\3 &4\end{pmatrix}? ? \begin{bmatrix}1 & 2\\\\3 &4\end{bmatrix}? ? \begin{Bmatrix}1 & 2\\\\3 &4\end{Bmatrix}? ? \begin{vmatrix}1 & 2\\\\3 &4\end{vmatrix}? ? \left|\begin{matrix}1 & 2\\\\3 &4\end{matrix}\right|? ? \begin{Vmatrix}1 & 2\\\\3 &4\end{Vmatrix}?Copy the code
Something like left right, begin and end in this case. And it has specific matrix syntax, & distinguishes between the lines and \\\\ stands for newline. You can think of it as an HTML tag or something like that.
1.2.8 Typesetting arrays
\mathbf{X} = \left( \begin{array}{ccc} x\_{11} & x\_{12} & \ldots \\\\ x\_{21} & x\_{22} & \ldots \\\\ \vdots & \vdots & \ddots \end{array} \right)Copy the code
2. Examples of common formulas
Keep updating…
2.1 Multi-line formula
It’s basically expressions of equations
2.1.1 long formula
?
\begin{multline}
x = a+b+c+{} \\\\
d+e+f+g
\end{multline}
?
?
\begin{aligned}
x ={}& a+b+c+{} \\\\
&d+e+f+g
\end{aligned}
?
Copy the code
Not aligned
alignment
2.1.2 formula group
?
\begin{gather}
a = b+c+d \\\\
x = y+z
\end{gather}
?
?
\begin{align}
a &= b+c+d \\\\
x &= y+z
\end{align}
?
Copy the code
2.1.3 Piecewise function
?
y=\begin{cases}
-x,\quad x\leq 0 \\\\
x,\quad x>0
\end{cases}
?
Copy the code
The \(\leq\) symbol is used, and the next chapter will cover common mathematical symbols.
2.2 Other uses of arrays
2.2.1 crossed
?
\left(\begin{array}{|c|c|}
1 & 2 \\\\
\\hline
3 & 4
\end{array}\right)
?
Copy the code
2.2.2 tabulation
?
\begin{array}{|c|c|}
\hline
{1111111111} & 2 \\\\
\hline
3 & 4 \\\\
\hline
\end{array}
?
Copy the code
As you can see, a lot of other things can be expressed very flexibly. I’ll keep writing when I come across other interesting ones.
3. Commonly used mathematical symbols
The document is available for download here, or if the link above is broken, you can download the PDF version on my GitHub site. Here are some examples.
3.1 Greek Letters
? \begin{array}{|c|c|c|c|c|c|c|c|} \hline {\alpha} & {\backslash alpha} & {\theta} & {\backslash theta} & {o} & {o} & {\upsilon} & {\backslash upsilon} \\\\ \hline {\beta} & {\backslash beta} & {\vartheta} & {\backslash vartheta} & {\pi} & {\backslash pi} & {\phi} & {\backslash phi} \\\\ \hline {\gamma} & {\backslash gamma} & {\iota} & {\backslash iota} & {\varpi} & {\backslash varpi} & {\varphi} & {\backslash varphi} \\\\ \hline {\delta} & {\backslash delta} & {\kappa} & {\backslash kappa} & {\rho} & {\backslash rho} & {\chi} & {\backslash chi} \\\\ \hline {\epsilon} & {\backslash epsilon} & {\lambda} & {\backslash lambda} & {\varrho} & {\backslash varrho} & {\psi} & {\backslash psi} \\\\ \hline {\varepsilon} & {\backslash varepsilon} & {\mu} & {\backslash mu} & {\sigma} & {\backslash sigma} & {\omega} & {\backslash omega} \\\\ \hline {\zeta} & {\backslash zeta} & {\nu} & {\backslash nu} & {\varsigma} & {\backslash varsigma} & {} & {} \\\\ \hline {\eta} & {\backslash eta} & {\xi} & {\backslash xi} & {\tau} & {\backslash tau} & {} & {} \\\\ \hline {\Gamma} & {\backslash Gamma} & {\Lambda} & {\backslash Lambda} & {\Sigma} & {\backslash Sigma} & {\Psi} & {\backslash Psi} \\\\ \hline {\Delta} & {\backslash Delta} & {\Xi} & {\backslash Xi} & {\Upsilon} & {\backslash Upsilon} & {\Omega} & {\backslash Omega} \\\\ \hline {\Omega} & {\backslash Omega} & {\Pi} & {\backslash Pi} & {\Phi} & {\backslash Phi} & {} & {} \\\\ \hline \end{array} ?Copy the code
Write too tired 😂😂😂… See PDF for others.
4. To summarize
By combing through the basic formulas, you can insert them, and you can also figure out how to look things up. It will be very helpful for me to learn LaTeX and write papers in the future. The following suggestions are highly subjective and are for reference only.
- All formulas use another line and a blank line at the top and bottom
- A formula a statement, do not write in a
? * * *?
In the guaranteeindependence
, one formula error does not affect the other formula. - Stick to the same style, don’t mix. For example, write up and down:
x_{balabala}^{bala}
- Interline letters can be used
\\(a\\)
Instead ofa
Develop your own writing style.
And finally: my Blog and GitHub, thanks for reading.
5. References
Many thanks to the following authors for their selfless sharing.
- The method of inserting mathematical formulas in Markdown
- Basic syntax for LATEX mathematical formulas
- A very short introductory LaTeX document
Explanation: The Nuggets seem to have some escape not to come out, if want to see the effect can refer to this oneself more try.