在 LaTeX 3 中使用 `\declarethoremstyle` 和 `\declarethorem` 时出现错误

在 LaTeX 3 中使用 `\declarethoremstyle` 和 `\declarethorem` 时出现错误

我想删除.头部后面的 ,即 make headpunct = {},但该键headpunct仅在 中可用\declaretheoremstyle,因此我使用它来创建不带 的新样式.,但在 LaTeX 3 中使用它时出现了问题。

以下是 MWE:

\documentclass{ctexbook}
\usepackage{amsthm}
\usepackage{thmtools}
\ExplSyntaxOn
\declaretheoremstyle
  [
    spaceabove = 3pt,
    spacebelow = 3pt,
    headfont = \bfseries,
    bodyfont = \normalfont,
    headpunct = {},
    postheadspace = { },
    headindent = {},
    notefont = { \fontseries \mddefault \upshape }
  ]{ccnustyle}
\cs_new:Npn \__xdyymath_declare_theorem_with_counter_within:n #1
  {
    \declaretheorem
      [
        style = ccnustyle,
        name =  \clist_item:nn {#1} {1} ,
        refname = \clist_item:nn {#1} {2} ,
        within = \clist_item:nn {#1} {3} ,
      ]
      { \clist_item:nn {#1} {4} }
  }
\cs_new:Npn \__xdyymath_declare_theorem_with_counter_sibling:n #1
  {
    \declaretheorem
      [
        style = ccnustyle ,
        name =  \clist_item:nn {#1} {1} ,
        refname = \clist_item:nn {#1} {2} ,
        sibling = \clist_item:nn {#1} {3} ,
      ]
      { \clist_item:nn {#1} {4} }
  }
\clist_map_function:nN
  {
    { 定理, 定理, chapter, theorem }
  }\__xdyymath_declare_theorem_with_counter_within:n

\clist_map_function:nN
  {
    { 定义, 定义, theorem, definition }
  }\__xdyymath_declare_theorem_with_counter_sibling:n
\ExplSyntaxOff


\begin{document}
\begin{definition}[limit]
  test
\end{definition}
\end{document}

致命信息是

Missing number, treated as zero.
<to be read again>

Illegal unit of measure (pt inserted).
<to be read again>

它出什么问题了?

答案1

您的使用与thmtools源代码中的默认设置的区别在于空格字符的catcode。

在 中\ExplSyntaxOn ... \ExplSyntaxOff,空格被忽略,因此postheadspace={ }相当于postheadspace={}。虽然 空格 是 的有效值postheadspace,但 空 不是。要保留空格,请使用postheadspace={~}

接受空格(而不是长度)作为特殊值是 的行为amsthm,请参阅其文档的第 3 条注释\newtheoremstyle

第 8 个论点<space after theorem head>3

3定理头后的空格:{ }= 正常单词间空格; \newline= 换行符

相关代码来自amsthm.sty(2020/05/29 v2.20.6):

\newcommand{\newtheoremstyle}[9]{%
  % [...]
  \def\@tempa{#8}\ifx\space\@tempa
    \toks@\@xp{\the\toks@ \thm@headsep\fontdimen\tw@\font\relax}%
  \else
    \def\@tempb{\newline}%
    \ifx\@tempb\@tempa
      \toks@\@xp{\the\toks@ \thm@headsep\z@skip
        \def\thmheadnl{\newline}}%
    \else
      \toks@\@xp{\the\toks@ \thm@headsep#8\relax}%
    \fi
  \fi
  % [...]
}

因此,当与 一起使用时, thmtools' 选项的完整文档实际上是长度、空格或。请注意,当与 一起使用时,仅接受长度。postheadspaceamsthm\newlinentheorempostheadspace

而且,\declaretheoremstyle在处理用户给出的选项之前总是会将选项设置为其默认值,因此无需重复默认设置。


一个简化的例子:

\documentclass{article}
\usepackage{amsthm}
\usepackage{thmtools}

\ExplSyntaxOn
\declaretheoremstyle[postheadspace={ }]{style1}
\declaretheoremstyle[postheadspace={~}]{style2}

\declaretheorem[style=style1]{defn1}
\declaretheorem[style=style2]{defn2}
\ExplSyntaxOff

\begin{document}
\begin{defn1}
  content % error "Missing number"
\end{defn1}

\begin{defn2}
  content
\end{defn2}
\end{document}

答案2

这是错误消息不具误导性的罕见情况之一Missing number, treated as zero.。事实上,postheadspace必须是数字,但您将其设置为{}

来自thmtools文档
在此处输入图片描述

将其设置为0pt

\documentclass{ctexbook}
\usepackage{amsthm}
\usepackage{thmtools}
\ExplSyntaxOn
\declaretheoremstyle
  [
    spaceabove = 3pt,
    spacebelow = 3pt,
    headfont = \bfseries,
    bodyfont = \normalfont,
    headpunct = {},
    postheadspace = 0pt,
    headindent = {},
    notefont = { \fontseries \mddefault \upshape }
  ]{ccnustyle}
\cs_new:Npn \__xdyymath_declare_theorem_with_counter_within:n #1
  {
    \declaretheorem
      [
        style = ccnustyle,
        name =  \clist_item:nn {#1} {1} ,
        refname = \clist_item:nn {#1} {2} ,
        within = \clist_item:nn {#1} {3} ,
      ]
      { \clist_item:nn {#1} {4} }
  }
\cs_new:Npn \__xdyymath_declare_theorem_with_counter_sibling:n #1
  {
    \declaretheorem
      [
        style = ccnustyle ,
        name =  \clist_item:nn {#1} {1} ,
        refname = \clist_item:nn {#1} {2} ,
        sibling = \clist_item:nn {#1} {3} ,
      ]
      { \clist_item:nn {#1} {4} }
  }
\clist_map_function:nN
  {
    { 定理, 定理, chapter, theorem }
  }\__xdyymath_declare_theorem_with_counter_within:n

\clist_map_function:nN
  {
    { 定义, 定义, theorem, definition }
  }\__xdyymath_declare_theorem_with_counter_sibling:n
\ExplSyntaxOff


\begin{document}
\begin{definition}[limit]
  test
\end{definition}
\end{document}

在此处输入图片描述

相关内容