在我的某个命令的键值接口中,有一个 key name style
,我为它定义了一个备用名称,如下所示:
, name-style .meta:n = { name~style = #1 }
, name-style .value_required:n = true
但是,从以下示例中可以看出, 的name-style
行为与 不同name style
。这是什么原因造成的?我该如何修复它?
\documentclass{article}
\usepackage{hyperref}
\RequirePackage { amsmath, amsthm }
\usepackage{xcolor}
\usepackage[name-in-link]{create-theorem}
\CreateTheorem { theorem } { number-within = subsection, create-numberless-version }
\SetTheorem { theorem }
{
name-style = { % "name style" works
, heading style = \color{blue}\textsc
, crefname style = \color{blue}\textsc
, Crefname style = \color{blue}\textsc
, numbering style = \color{red}\textbf
}
}
\begin{document}
Current language: \languagename
\begin{theorem}\label{thm1}
In english.
\end{theorem}
\begin{theorem}\label{thm2}
In english.
\end{theorem}
\begin{theorem*}
An unnumbered theorem.
\end{theorem*}
\Cref{thm1,thm2}
\end{document}
期望结果如下:
以下是完整的按键设置,供您参考:
\keys_define:nn { create-theorem-setting }
{
, name .code:n = { \exp_args:Ne \NameTheorem { \l__crthm_current_env_tl } { #1 } }
, name .value_required:n = true
, name~style .code:n = { \exp_args:Ne \NameTheorem { \l__crthm_current_env_tl } { #1 } }
, name~style .value_required:n = true
, name-style .meta:n = { name~style = #1 }
, name-style .value_required:n = true
, name style .meta:n = { name~style = #1 }
, name style .value_required:n = true
, parent~counter .code:n = { \crthm_counter_within:en { \l__crthm_current_env_tl } { #1 } }
, parent~counter .value_required:n = true
, parent-counter .meta:n = { parent~counter = #1 }
, parent-counter .value_required:n = true
, parent counter .meta:n = { parent~counter = #1 }
, parent counter .value_required:n = true
, number~within .meta:n = { parent~counter = #1 }
, number~within .value_required:n = true
, number-within .meta:n = { parent~counter = #1 }
, number-within .value_required:n = true
, number within .meta:n = { parent~counter = #1 }
, number within .value_required:n = true
, shared~counter .code:n = { \crthm_counter_alias:en { \l__crthm_current_env_tl } { #1 } }
, shared~counter .value_required:n = true
, shared-counter .meta:n = { shared~counter = #1 }
, shared-counter .value_required:n = true
, shared counter .meta:n = { shared~counter = #1 }
, shared counter .value_required:n = true
, number~like .meta:n = { shared~counter = #1 }
, number~like .value_required:n = true
, number-like .meta:n = { shared~counter = #1 }
, number-like .value_required:n = true
, number like .meta:n = { shared~counter = #1 }
, number like .value_required:n = true
, unknown .code:n = {}
}
答案1
记录的行为l3key
与其他 keyval 包类似:从一个值中删除一组外部括号如果存在。 像这样
foo = {bar} ,
和
foo = bar ,
是等效的(因为l3keys
忽略了前导和尾随空格)。这意味着使用如下键设置
name-style = { % "name style" works
, heading style = \color{blue}\textsc
, crefname style = \color{blue}\textsc
, Crefname style = \color{blue}\textsc
, numbering style = \color{red}\textbf
}
将删除外部括号并传递
, heading style = \color{blue}\textsc
, crefname style = \color{blue}\textsc
, Crefname style = \color{blue}\textsc
, numbering style = \color{red}\textbf
至。#1
然后name-style
将其插入到
name~style = #1
导致
name~style =
, heading style = \color{blue}\textsc
, crefname style = \color{blue}\textsc
, Crefname style = \color{blue}\textsc
, numbering style = \color{red}\textbf
换句话说,name style
接收一个空值,然后你直接设置其他键。
一般结论是,当将键值从一个键传递到另一个键时,您应该总是使用一组括号来屏蔽,
或=
标记
name-style .meta:n = { name~style = {#1} }