使用 LaTeX 编写文章
Abstract
MetaBlog 支持一个面向网页文章写作的 LaTeX 子集。这篇文章展示 Go 渲染器可以直接解析的常见结构,以及交给 LaTeXML 处理的表格和伪代码块。
1章节和文本样式
可以使用 \section、\subsection、\subsubsection 和 \subsubsubsection 组织文章结构。
1.1行内样式
行内文本可以使用 粗体、斜体、强调、等宽字体、无衬线字体、衬线字体、小型大写、下划线 和 彩色文本。
声明式样式也可以用在文本型参数中。例如,下面这个 tcb 标题使用了居中和较大字号:
带样式的 TCB 标题
tcb 环境会渲染为可折叠文本框,包含标题栏、正文区域和左侧强调竖线。
1.2显式换行
使用 \\ 可以显式换行,但不会创建新的段落。
这一行会出现在生成 HTML 的 <br> 后面。
2列表
支持多层嵌套列表:
站点内容
关于页面
文章页面
索引页面
站点元数据
config.toml
articles.toml
描述列表可以使用标签:
- Build
生成静态 HTML 到输出目录。
- Serve
启动本地 HTTP 服务器用于预览。
- Watch
服务器运行时自动重建发生变化的文档。
3表格
table 环境的外壳由 MetaBlog 解析,因此 caption、label 和交叉引用由站点生成器统一管理。真正复杂的 tabular 或 tabularx 主体会交给 LaTeXML 转换。
表 1 展示了一个示例站点中最常见的配置文件。其代码如下:
| 1 | \begin{table} |
| 2 | \caption{\centering 示例站点常见文件} |
| 3 | \label{tab:example-files} |
| 4 | \begin{tabular}{lll} |
| 5 | \hline |
| 6 | 文件 & 作用 & 是否必须 \\ |
| 7 | \hline |
| 8 | \texttt{data/config.toml} & 站点标题、logo、icon 和分页配置 & 是 \\ |
| 9 | \texttt{data/articles.toml} & 注册需要构建的文章 & 是 \\ |
| 10 | \texttt{data/about_page/main.tex} & 关于页面源文件 & 否 \\ |
| 11 | \texttt{data/custom_components/page_footing.tex} & 全站页尾组件 & 否 \\ |
| 12 | \hline |
| 13 | \end{tabular} |
| 14 | \end{table} |
4伪代码
algorithm 和 algorithm* 属于复杂块,会整体交给 LaTeXML 处理。适合在文章中放置论文风格的algorithm2e伪代码描述。
上面Algorithm 1的伪代码描述了 MetaBlog 的文档级增量构建判断。
其代码如下:
| 1 | \begin{algorithm}[tbp] |
| 2 | \small |
| 3 | \caption{algorithm2e Example} |
| 4 | \label{alg:alg_example} |
| 5 | \SetKwInput{KwData}{Input} |
| 6 | \SetKwInput{KwResult}{Output} |
| 7 | \KwData{The Raw LaTeX algorithm block} |
| 8 | \KwResult{Rendered pseudo code block} |
| 9 | \SetKw{To}{to} |
| 10 | \SetKw{Append}{append} |
| 11 | \SetKw{Into}{into} |
| 12 | \SetKw{Break}{break} |
| 13 | \SetKw{Return}{return} |
| 14 | \SetKwComment{EmptyLine}{ }{ } |
| 15 | \SetNoFillComment |
| 16 | \For{all block \(\in\) articles}{ |
| 17 | \If{block is algorithm(*) or /tabular(x)}{ |
| 18 | Render the block by \texttt{LaTeXML}\; |
| 19 | }{ |
| 20 | Render the block by inside complier\; |
| 21 | } |
| 22 | } |
| 23 | \Return All Blocks |
| 24 | \end{algorithm} |
5公式
行内公式会交给 KaTeX 渲染,例如 \(f(x)=x^2+\alpha\) 。
块级公式也会保留给 KaTeX:
带编号的公式可以设置 label:
公式 1 可以在普通文本中引用。
6链接
可以使用 \url{https://example.com} 显示完整 URL,也可以使用 \href{https://github.com}{GitHub} 指定自定义链接文字。