Markdown 写数学公式:LaTeX 入门
论文、笔记、技术文档都离不开公式。Markdown 借助 LaTeX 语法就能把数学式写得又准又漂亮,这篇带你从包公式到常用符号过一遍。
Markdown 寫數學公式:LaTeX 入門
論文、筆記、技術文件都離不開公式。Markdown 借助 LaTeX 語法就能把數學式寫得又準又漂亮,這篇帶你從包公式到常用符號過一遍。
Writing Math in Markdown: A LaTeX Primer
Theses, notes, and technical docs all rely on formulas. With LaTeX syntax, Markdown can render math accurately and beautifully—this article walks you from wrapping formulas to common symbols.
一、公式怎么包起来
标准做法是用 LaTeX 的定界符包裹:
| 类型 | 写法 | 效果 |
|---|---|---|
| 行内公式 | $E=mc^2$ | 夹在文字里,和正文同一行 |
| 独立公式 | $$ ... $$ | 单独成行、居中,适合重点式子 |
质能方程 $E=mc^2$ 是物理学的基石。
$$\int_0^1 x^2 \, dx = \frac{1}{3}$$
注意:行内公式的 $ 前后最好留空格,避免和周围文字黏在一起被误判;不是所有预览器都支持公式,先用目标平台试一下。
二、上下标与常用结构
- 上标:
x^2→ x²;多位指数要用花括号x^{10}。 - 下标:
x_1→ x₁;同样x_{max}表示 xmax。 - 根号:
\sqrt{x}或\sqrt[n]{x}(n 次根)。 - 分数:
\frac{a}{b}。 - 向量 / 粗体:
\vec{v}、\mathbf{R}。
a_{n+1} = a_n^2 + \sqrt{2}
三、常用符号速记
| 符号 | 写法 | 说明 |
|---|---|---|
| ∑ 求和 | \sum_{i=1}^{n} i | 带上下限 |
| ∫ 积分 | \int_a^b f(x)dx | 定积分 |
| ∞ 无穷 | \infty | — |
| ≤ ≥ ≠ ≈ | \le \ge \ne \approx | 不等号族 |
| α β π θ | \alpha \beta \pi \theta | 希腊字母 |
| × ÷ ± → | \times \div \pm \to | 运算与箭头 |
四、分式、矩阵与多行公式
复杂一点的结构也常用到:
% 矩阵
\begin{matrix} a & b \\ c & d \end{matrix}
% 带编号的多行对齐
\begin{aligned}
y &= mx + b \\
&= kx + c
\end{aligned}
多行公式里用 & 对齐、\\ 换行。这些属于 LaTeX 的“环境”语法,支持程度因预览器而异。
五、在 365Lab 里实时预览
365Lab 在线编辑器内置公式渲染,左边写 $...$ 或 $$...$$,右边即时出排版好的公式,不用装任何插件。写论文草稿、课程笔记时尤其顺手——边推导边看结果。
- 打开 365Lab 编辑器(免注册,内容本地保存)。
- 把上面的例子粘进左侧。
- 右侧实时看到公式,确认无误后导出备份。
六、常见问题
Q:为什么我的公式显示成原始 $ 符号?
A:两种可能——预览器不支持公式扩展,或定界符写错(比如中文全角 $)。换支持 KaTeX/MathJax 的工具即可。
Q:行内和独立公式怎么选?
A:短式子(如变量 x²)用行内夹在句中;需要强调或较长的推导用独立公式单独成行,更清晰。
Q:公式能导出到 PDF / Word 吗?
A:能。导 PDF 用浏览器打印(基于同一渲染引擎)通常保真;转 Word 见 Markdown 转 Word,但复杂公式建议在导出后核对一遍。
Q:希腊字母和符号记不住怎么办?
A:收藏本页这张速记表,或看 Markdown 语法速查表 里的高亮与进阶部分,随用随查。
公式之外,写作里常见的还有表格与图片:Markdown 表格怎么写 与 Markdown 插入图片 一并收好。
一、公式怎麼包起來
標準做法是用 LaTeX 的定界符包裹:
| 類型 | 寫法 | 效果 |
|---|---|---|
| 行內公式 | $E=mc^2$ | 夾在文字裡,和正文同一行 |
| 獨立公式 | $$ ... $$ | 單獨成行、置中,適合重點式子 |
質能方程 $E=mc^2$ 是物理學的基石。
$$\int_0^1 x^2 \, dx = \frac{1}{3}$$
注意:行內公式的 $ 前後最好留空格,避免和周圍文字黏在一起被誤判;不是所有預覽器都支援公式,先用目標平台試一下。
二、上下標與常用結構
- 上標:
x^2→ x²;多位指數要用花括號x^{10}。 - 下標:
x_1→ x₁;同樣x_{max}表示 xmax。 - 根號:
\sqrt{x}或\sqrt[n]{x}(n 次根)。 - 分數:
\frac{a}{b}。 - 向量 / 粗體:
\vec{v}、\mathbf{R}。
a_{n+1} = a_n^2 + \sqrt{2}
三、常用符號速記
| 符號 | 寫法 | 說明 |
|---|---|---|
| ∑ 求和 | \sum_{i=1}^{n} i | 帶上下限 |
| ∫ 積分 | \int_a^b f(x)dx | 定積分 |
| ∞ 無窮 | \infty | — |
| ≤ ≥ ≠ ≈ | \le \ge \ne \approx | 不等號族 |
| α β π θ | \alpha \beta \pi \theta | 希臘字母 |
| × ÷ ± → | \times \div \pm \to | 運算與箭頭 |
四、分式、矩陣與多行公式
複雜一點的結構也常用到:
% 矩陣
\begin{matrix} a & b \\ c & d \end{matrix}
% 帶編號的多行對齊
\begin{aligned}
y &= mx + b \\
&= kx + c
\end{aligned}
多行公式裡用 & 對齊、\\ 換行。這些屬於 LaTeX 的「環境」語法,支援程度因預覽器而異。
五、在 365Lab 裡即時預覽
365Lab 線上編輯器內建公式渲染,左邊寫 $...$ 或 $$...$$,右邊即時出排版好的公式,不用裝任何外掛。寫論文草稿、課程筆記時尤其順手——邊推導邊看結果。
- 打開 365Lab 編輯器(免註冊,內容本機儲存)。
- 把上面的例子貼進左側。
- 右側即時看到公式,確認無誤後匯出備份。
六、常見問題
Q:為什麼我的公式顯示成原始 $ 符號?
A:兩種可能——預覽器不支援公式擴充,或定界符寫錯(例如中文全形 $)。換支援 KaTeX/MathJax 的工具即可。
Q:行內和獨立公式怎麼選?
A:短式子(例如變數 x²)用行內夾在句中;需要強調或較長的推導用獨立公式單獨成行,更清晰。
Q:公式能匯出到 PDF / Word 嗎?
A:能。匯出 PDF 用瀏覽器列印(基於同一渲染引擎)通常保真;轉 Word 見 Markdown 轉 Word,但複雜公式建議在匯出後核對一遍。
Q:希臘字母和符號記不住怎麼辦?
A:收藏本頁這張速記表,或看 Markdown 語法速查表 裡的高亮與進階部分,隨用隨查。
公式之外,寫作裡常見的還有表格與圖片:Markdown 表格怎麼寫 與 Markdown 插入圖片 一併收好。
1. How to wrap formulas
The standard approach is to wrap them with LaTeX delimiters:
| Type | Notation | Effect |
|---|---|---|
| Inline | $E=mc^2$ | sits inside the text, on the same line as the body |
| Display | $$ ... $$ | its own centered line, good for key equations |
The mass-energy equation $E=mc^2$ is the cornerstone of physics.
$$\int_0^1 x^2 \, dx = \frac{1}{3}$$
Note: it's best to leave a space before and after the inline $ so it isn't misread as glued to the surrounding text; not every previewer supports math, so test on the target platform first.
2. Superscripts, subscripts & common structures
- Superscript:
x^2→ x²; for multi-digit exponents use bracesx^{10}. - Subscript:
x_1→ x₁; likewisex_{max}means xmax. - Root:
\sqrt{x}or\sqrt[n]{x}(n-th root). - Fraction:
\frac{a}{b}. - Vector / bold:
\vec{v},\mathbf{R}.
a_{n+1} = a_n^2 + \sqrt{2}
3. Quick symbol reference
| Symbol | Notation | Note |
|---|---|---|
| ∑ sum | \sum_{i=1}^{n} i | with limits |
| ∫ integral | \int_a^b f(x)dx | definite integral |
| ∞ infinity | \infty | — |
| ≤ ≥ ≠ ≈ | \le \ge \ne \approx | inequality family |
| α β π θ | \alpha \beta \pi \theta | Greek letters |
| × ÷ ± → | \times \div \pm \to | operators & arrows |
4. Fractions, matrices & multi-line formulas
Slightly more complex structures come up often:
% matrix
\begin{matrix} a & b \\ c & d \end{matrix}
% numbered multi-line alignment
\begin{aligned}
y &= mx + b \\
&= kx + c
\end{aligned}
Inside a multi-line formula, use & to align and \\ to break lines. These belong to LaTeX "environments," whose support varies by previewer.
5. Live preview in 365Lab
The 365Lab online editor has built-in formula rendering: write $...$ or $$...$$ on the left and the typeset formula appears on the right instantly—no plugins needed. It's especially handy for thesis drafts and lecture notes, letting you see results as you derive.
- Open the 365Lab editor (no sign-up; content stored locally).
- Paste the examples above into the left side.
- See the formula live on the right, then export a backup once it's correct.
6. FAQ
Q: Why does my formula show as the raw $ symbol?
A: Two possibilities—the previewer doesn't support the math extension, or the delimiter is wrong (e.g. a full-width $). Switch to a tool that supports KaTeX/MathJax.
Q: When do I use inline vs display formulas?
A: Short expressions (like a variable x²) go inline within the sentence; use a standalone formula on its own line when you want emphasis or a longer derivation—cleaner that way.
Q: Can formulas be exported to PDF / Word?
A: Yes. Exporting to PDF via the browser's print (same rendering engine) usually keeps fidelity; for Word see Markdown to Word, but verify complex formulas after exporting.
Q: I can't remember the Greek letters and symbols—what do I do?
A: Bookmark this quick-reference table, or check the highlighting and advanced section of the Markdown syntax cheat sheet—look it up whenever you need it.
Beyond formulas, tables and images are also common in writing: keep How to write Markdown tables and Inserting images in Markdown handy.