在下面的源代码中,我有一个环境,当使用时,它会显示其可选参数中namedtheorem
的键的值,而不是通常的“定理” 。name
该名称的首字母大写(连词和介词除外),与任何头衔一样。
但是,在文中引用该定理时,我希望将所有首字母都小写,除了专有名词(例如“Euler”)之外,这些专有名词当然应该保持大写。
如何才能做到这一点?
\documentclass{article}
\usepackage[left=0.75in,right=0.75in]{geometry}
\usepackage{textcase}
\usepackage{amsthm}
\usepackage{thmtools}
\swapnumbers
\makeatletter
\declaretheoremstyle[
headfont= \bfseries,
headpunct={\bfseries.},
postheadspace=0.5em,
notefont=\bfseries,
headformat=\NAME\NUMBER\let\thmt@space\@empty\NOTE,
bodyfont=\mdseries\itshape,
spaceabove=12pt,spacebelow=12pt,
]{thmstyle}
\declaretheoremstyle[
headfont=\bfseries,
notefont=\bfseries, notebraces={}{},
headformat=\NUMBER\let\thmt@space\@empty\NOTE,
bodyfont=\mdseries\itshape,
spaceabove=12pt,spacebelow=12pt,
]{namedthmstyle}
\makeatother
\theoremstyle{thmstyle}
\declaretheorem[name=Theorem,numberwithin=section]{theorem}
\declaretheorem[
style=namedthmstyle,name=Theorem,title = {},numberlike=theorem
]{namedtheorem}
\usepackage[pdftex]{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{crossreftools}
\begin{document}
\section{The theorems}
\begin{theorem}[equalities of \MakeUppercase{E}uclid]
\label{thm:prelim}
$a = b$ and $b = c$
\end{theorem}
\begin{namedtheorem}[name=Fundamental Theorem of \NoCaseChange{Euler}]
\label{thm:euler}
$a = c$.
\end{namedtheorem}
\bigskip
\emph{Original text of name:} Fundamental Theorem of Euler
\bigskip
\emph{Desired modification:} fundamental theorem of Euler
\bigskip
\emph{Attempts:}
\begin{itemize}
\item
\MakeTextLowercase{Fundamental Theorem of \NoCaseChange{Euler}} ---\verb!\MakeTextLowercase{Fundamental Theorem of \NoCaseChange{Euler}}!\\
works OK directly.
\item
\MakeTextLowercase{\nameref*{thm:euler}} --- \verb!\MakeTextLowercase{\nameref*{thm:euler}}! \\
of no use.
\item
\crtnameref*{thm:euler} --- \verb!\crtnameref*{thm:euler}!\\
try starting here now.
\item
%\MakeTextLowercase{\crtnameref*{thm:euler}} ---
\verb!\MakeTextLowercase{\crtnameref*{thm:euler}}! causes error:
\begin{verbatim}
./try.tex:84: Missing \endcsname inserted.
<to be read again>
\relax
l.84 \MakeTextLowercase{\crtnameref*{thm:euler}}
? x
\end{verbatim}
\end{itemize}
\end{document}
在上面的源代码中,有一行被注释掉了,因为它会导致错误而无法输出。
不满意的方法:添加\crefformat
标签
如图所示https://tex.stackexchange.com/a/401600/13492,包括紧随其后\label{thm:euler}
\label[fte]{thm:euler}
\crefformat{fte}{#2fundamental theorem of Euler#3}
然后使用`\cref*{thm:euler} 确实给出了所需的“欧拉基本定理”。
然而:
\cref
如果在带有标签的环境之前出现,则会失败;- 当有相当多这样的
namedtheorem
环境时,确实需要大量额外的标记。
解决方案:\MakeTextLowercase
与来自的命令一起使用crossreftools
这将修改所示的前导码https://tex.stackexchange.com/a/401438/13492, 经过:
- 采用@egreg 的评论来代替
\MakeTextLowercase
;\MakeLowercase
和 \hyperlink{\crtrefanchor{#1}}
从那里的定义中省略该短语\lowernameref
。
即:
\makeatletter
\newcommand{\lowernameref}[1]{{\MakeTextLowercase{\crtrefname{#1}}}}
\def\mynameref#1#2{%
\begingroup
\edef\@mytxt{#2}%
\edef\@mytst{\expandafter\@thirdoffive\@mytxt}%
\ifx\@mytst\empty\else
\space(\nameref{#1})\fi
\endgroup
}
\makeatother
然后在文档正文中,
\lowernameref{thm:euler}
产生所需的输出:
fundamental theorem of Euler
答案1
如果您确定受到\NoCaseChange
保护,则可以使用 Heiko Oberdiek 的 refcount 包中的宏来定义您自己的漂亮宏,确保在传递给之前通过扩展提取形成所需名称的短语\MakeTextLowercase
:
\documentclass{article}
\usepackage[left=0.75in,right=0.75in]{geometry}
\usepackage{textcase}
\usepackage{amsthm}
\usepackage{thmtools}
\swapnumbers
\makeatletter
\declaretheoremstyle[
headfont= \bfseries,
headpunct={\bfseries.},
postheadspace=0.5em,
notefont=\bfseries,
headformat=\NAME\NUMBER\let\thmt@space\@empty\NOTE,
bodyfont=\mdseries\itshape,
spaceabove=12pt,spacebelow=12pt,
]{thmstyle}
\declaretheoremstyle[
headfont=\bfseries,
notefont=\bfseries, notebraces={}{},
headformat=\NUMBER\let\thmt@space\@empty\NOTE,
bodyfont=\mdseries\itshape,
spaceabove=12pt,spacebelow=12pt,
]{namedthmstyle}
\makeatother
\theoremstyle{thmstyle}
\declaretheorem[name=Theorem,numberwithin=section]{theorem}
\declaretheorem[
style=namedthmstyle,name=Theorem,title = {},numberlike=theorem
]{namedtheorem}
\usepackage{refcount}[2010/12/01 v3.2] %!!!!!
\usepackage[pdftex]{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{crossreftools}
\makeatletter
\@ifdefinable\MyNiceLowercaseNameref{%
\DeclareRobustCommand\MyNiceLowercaseNameref{%
\@ifstar{\MyNiceLowercaseNamerefAtStar}{\MyNiceLowercaseNamerefAtNoStar}%
}%
}%
\newcommand\MyNiceLowercaseNamerefAtStar[1]{%
\MyNiceGenericLowercaseNameref{\@firstofone}{#1}%
}%
\newcommand\MyNiceLowercaseNamerefAtNoStar[1]{%
\MyNiceGenericLowercaseNameref{\hyperref[{#1}]}{#1}%
}%
\newcommand\MyNiceGenericLowercaseNameref[2]{%
\refused{#2}%
#1%
{%
\expandafter\expandafter\expandafter\MakeTextLowercase
\expandafter\expandafter\expandafter{%
\getrefbykeydefault{#2}{name}{%
\nfss@text{\reset@font\bfseries ??}%
}%
}%
}%
}%
\makeatother
\begin{document}
\section{The theorems}
\begin{theorem}[equalities of \MakeUppercase{E}uclid]
\label{thm:prelim}
$a = b$ and $b = c$
\end{theorem}
%!!!!!!!!!!!!!!!!!! \protect\NoCaseChange
\begin{namedtheorem}[name=Fundamental Theorem of \protect\NoCaseChange{Euler}]
\label{thm:euler}
$a = c$.
\end{namedtheorem}
\bigskip
\emph{Original text of name:} Fundamental Theorem of Euler
\bigskip
\emph{Desired modification:} fundamental theorem of Euler
\bigskip
\emph{Attempts:}
\begin{itemize}
\item
\MakeTextLowercase{Fundamental Theorem of \NoCaseChange{Euler}} ---\verb!\MakeTextLowercase{Fundamental Theorem of \NoCaseChange{Euler}}!\\
works OK directly.
\item
\MakeTextLowercase{\nameref*{thm:euler}} --- \verb!\MakeTextLowercase{\nameref*{thm:euler}}! \\
of no use.
\item
\crtnameref*{thm:euler} --- \verb!\crtnameref*{thm:euler}!\\
try starting here now.
\item
%\MakeTextLowercase{\crtnameref*{thm:euler}} ---
\verb!\MakeTextLowercase{\crtnameref*{thm:euler}}! causes error:
\begin{verbatim}
./try.tex:84: Missing \endcsname inserted.
<to be read again>
\relax
l.84 \MakeTextLowercase{\crtnameref*{thm:euler}}
? x
\end{verbatim}
\item
\MyNiceLowercaseNameref{thm:euler} --- \verb!\MyNiceLowercaseNameref{thm:euler}!\\
seems to work out
\item
\MyNiceLowercaseNameref*{thm:euler} --- \verb!\MyNiceLowercaseNameref*{thm:euler}! \\
seems to work out
\end{itemize}
\end{document}
顺便一提:
命令\label
、\ref
和\pageref
(以及其他一些命令)已得到 textcase 包的特殊处理,因为这些命令会触发应用于\NoCaseChange
自身及其在\MakeTextLowercase
/内的参数MakeTextUppercase
。
但是,例如,命令\nameref
(以及许多其他未出现在 LaTeX 2ε 内核中但在某些包中定义的命令)没有得到这种特殊处理。
因此,我强烈建议将其包装到\NoCaseChange
任何应进入参数的引用命令中\MakeTextLowercase
:
如果不这样做,非内核引用命令的引用标签名称也将变为小写。
假设您有引用标签foo
和FOO
:
\MakeTextLowercase{\nameref{FOO}}
将创建对 的引用foo
,而不是 的引用FOO
。\MakeTextLowercase{\NoCaseChange{\nameref{FOO}}}
将创建对 的引用FOO
。
或者,看看你自己的例子:
\MakeTextLowercase{\nameref*{thm:euler}}
很不错,不会触发有关未定义引用的警告。(不幸的是,它无法将所需的短语转换为小写形式。)
但是关于:
\MakeTextLowercase{\nameref*{THM:EULER}}
?这难道不会触发有关未定义引用的警告吗?不会。因为THM:EULER
转换为小写thm:euler
,并且该标签已定义。