基于LaTeX_工作室的2020年8月开始的直播内容,该系列文章将用图文的模式记录下其中的重要内容,方便查阅与学习。

编译环境: $\textrm{Tex Live}$

编辑环境: $\textrm{vscode}$

相关视频:LaTeX 直播之八 – amsthm 宏包使用与 LaTeX 代码规范

本次视频内容包括

  • $\textrm{amsthm}$宏包的使用
    • $\textrm{amsthm}$基础
    • $\textrm{amsthm}$进阶
    • $\textrm{amsthm}$高级应用
  • $\textrm{LaTeX}$代码的规范性
    • 不规范的$\textrm{LaTeX}$代码
    • 内容与样式分离

$\textrm{amsthm}$宏包的使用

$\textrm{amsthm}$用于定理和证明类环境的配置

加载$\textrm{amsthm}$宏包: $\textrm{\usepackage{amsthm}}$
新定义一个定理类环境: $\textrm{\newtheorem{name}[counter]{text}[section]}$

  • $\textrm{name}$:标识这个环境的关键字(用于编程)
  • $\textrm{text}$:真正在文档中打印出来的定理环境的名字
  • $\textrm{counter}$:计数器;一般新定义的定理环境会自己用一个新的计数器,但是可以在 $\textrm{counter}$中传入其他的定理环境,表示和这个环境共用计数器。
  • $\textrm{section}$:定理编号依赖于某个章节层次(比如:定理$\textrm{1.1}$)

使用方法:$\textrm{\begin{环境名} … \end{环境名}}$

例如

\documentclass{article}

%导言区
\usepackage{amsthm}
\usepackage{ctex}
\newtheorem{lem}{Lemma} %定义了名为lem的环境,调用时显示Lemma文本

\begin{document}

\begin{lem} This is a sentence. \end{lem} %调用lem,可以看到在pdf界面会自动编号

\end{document}

如果不需要编号,那么加上星号:$\textrm{\newtheorem*{lem}{Lemma}}$

可以发现上述编译的定理环境有两个特点

  • 文本为斜体
  • 标题文本为粗体

这是因为使用$\textrm{amsthm}$宏包的时候,如果没有指定定理类环境的风格命令:$\textrm{\theoremstyle}$,那么显示的样式即为$\textrm{plain}$

  • $\textrm{plain}$:斜体文字,上面和下面留有额外的空间,常用的结构类型有
    $\textrm{Theorem,Lemma,Corollary,Proposition,Conjecture,Criterion,Assertion}$
  • $\textrm{definition}$:直立文字,上面和下面留有额外的空间,常用的结构类型有$\textrm{Definition,Condition,Problem,Example,Exercise,Algorithm,Question,Axiom,Property,Assumption,Hypothesis}$
  • $\textrm{remark}$:直立文字,上面或下面没有额外的空间,常用的结构类型有$\textrm{Remark,Note,Notation,Claim,Summary,Acknowledgement,Case,Conclusion}$
\documentclass{article}

%导言区
\usepackage{amsthm}
\usepackage{ctex}
\newtheorem{lem}{Lemma}

\theoremstyle{definition}
\newtheorem{defn}{Definition}

\theoremstyle{remark}
\newtheorem{rem}{Remark}


\begin{document}

\begin{lem} This is a sentence. \end{lem}
\begin{defn} This is a sentence. \end{defn}
\begin{rem} This is a sentence. \end{rem}

\end{document}

可以使用$\textrm{\newtheoremstyle}$来定义自己的风格

\newtheoremstyle
{note}                %名字
{3pt}{3pt}            %上面的空间、下面的空间
{}                    %主体的字体
{}                    %缩进量
{\itshape}            %定理头字体
{:}                   %定理头后标点符号
{.5em}                %定理头后的空间
{}                    %定理头规范,可以为空,表示normal

%示例
\newtheoremstyle
{mystyle}             %名称为mystyle
{0pt}{0pt}            %环境前后的纵向距离为0pt
{\kaishu}             %设置字体为楷书
{2\ccwd}              %缩进量为2\ccwd
{\bfseries}           %定理头字体为bfseries
{.}                   %定理头后标点符号为.
{0pt}                 %定理头后的空间为0pt
{}                    %定理头规范为normal

$\textrm{LaTeX}$代码的规范性

不规范的代码有:

  • 宏包相互冲突,例如$\textrm{\usepackage{indentfirst}}$和$\textrm{\setlength{\parindent}{2em}}$
  • 宏包加载顺序不佳,例如$\textrm{hyperref}$一般是最后几个加载的
  • 宏包重复加载,如$\textrm{color}$和$\textrm{xcolor}$
  • 使用无效代码,例如$\textrm{\contentsname}$
  • 手写章节编号,图标编号
  • 手动调节样式

我们需要做到:内容与样式分离

一篇文档的实际内容和逻辑结构与这篇文档呈现给读者看到的样式是相互独立的,要将排版的内容分隔,赋予其不用的意义,从而保留样式的可变性,自由度。

$\textrm{Author}$@$\href{http://kuroko.info}{\textrm{Kuroko}}$

$\textrm{GitHub}$@$\href{https://github.com/SuperKuroko}{\textrm{SuperKuroko}}$

$\textrm{LeetCode}$@$\href{https://leetcode-cn.com/u/kuroko177/}{\textrm{kuroko177}}$

$\textrm{Last Modified: 2021-01-28 20:51}$