
これは、この質問そしてこれです基本的に、以下に示すように、定理のオプション引数内のシーケンス ([...]) を避けたいと思います。

この結果を得るためには、この答え\patchcmd
では、パッケージのマクロを使用しました。しかし、変更のたび に
etoolbox
から に切り替える必要があり 、多くの定理を含む大きな本ではあまり便利ではありません。そのため、単一のコマンドが可能かどうか疑問に思っていました。 と の 2 つの形式を使用していることに注意してください。これにより、状況が少し複雑になります。\patchcmd{\thmhead}{(#3)}{#3}{}{}
\patchcmd{\thmhead}{#3}{(#3)}{}{}
\cite{}
\cite[]{}
\documentclass[10pt]{article}
\usepackage[]{amsmath, amssymb, amsthm}
\newtheorem{theorem}{Theorem}[section]
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\begin{document}
\section{Pythagoras' theorem}
\noindent Correct versions:
\begin{theorem}[Pythagoras]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[Pythagoras, \cite{Pythagoras}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[Pythagoras, {\cite[p.\ 345]{Pythagoras}}]
$a^2 + b^2 = c^2$.
\end{theorem}
\patchcmd{\thmhead}{(#3)}{#3}{}{}
\begin{theorem}[\cite{Pythagoras}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[{\cite[p.\ 21]{Pythagoras}}]
$a^2 + b^2 = c^2$.
\end{theorem}
\noindent To be avoided:
\patchcmd{\thmhead}{#3}{(#3)}{}{}
\begin{theorem}[\cite{Pythagoras}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[{\cite[p.\ 21]{Pythagoras}}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{thebibliography}{HD}
\bibitem[1]{Pythagoras}
Pythagoras' theorem.
\end{thebibliography}
\end{document}
答え1
\cite
引数を、 の後に が 0 回または 1 回出現し[...]
、 が続くことを表す正規表現と照合することができます{...}
。
\documentclass[10pt]{article}
\usepackage[]{amsmath, amssymb, amsthm}
% see https://tex.stackexchange.com/a/17555/4427 for the parameters
\newtheoremstyle{jepinplain}
{\topsep} % ABOVESPACE
{\topsep} % BELOWSPACE
{\itshape} % BODYFONT
{0pt} % INDENT (empty value is the same as 0pt)
{\bfseries} % HEADFONT
{.} % HEADPUNCT
{5pt plus 1pt minus 1pt} % HEADSPACE
{\thmname{#1}\thmnumber{ #2}\thmnote{{\normalfont\ \checkcite{#3}}}} % CUSTOM-HEAD-SPEC
\ExplSyntaxOn
\NewDocumentCommand{\checkcite}{m}
{
\regex_match:nnTF {\A \c{cite}(?:\[[^]]*\])?\{.*\} \Z} { #1 }
{% only \cite
#1
}
{ (#1) }
}
\ExplSyntaxOff
\theoremstyle{jepinplain}
\newtheorem{theorem}{Theorem}[section]
\begin{document}
\section{Pythagoras' theorem}
\noindent Correct versions:
\begin{theorem}
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[Pythagoras]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[Pythagoras, \cite{Pythagoras}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[Pythagoras, {\cite[p.\ 345]{Pythagoras}}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[\cite{Pythagoras}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[{\cite[p.\ 21]{Pythagoras}}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{thebibliography}{1}
\bibitem[1]{Pythagoras}
Pythagoras' theorem.
\end{thebibliography}
\end{document}
標準\thmhead
コマンドを変更する場合を除き、新しい定理スタイルの方が適しています。
答え2
この質問は少々古いものですが、私も同じ問題に対処していたので、その方法を投稿しようと思いました。括弧を追加する必要があるかどうかを何らかの方法でフラグ付けできればよいのですが、私は手動で回避しました。
解決策0:
修正内容をそのまま残し、独自の括弧を追加します。
\patchcmd{\thmhead}{(#3)}{#3}{}{}
\begin{theorem}[(Pythagoras)]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[(Pythagoras, \cite{Pythagoras})]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[\cite{Pythagoras}]
$a^2 + b^2 = c^2$.
\end{theorem}
もちろん、これでは LaTeX マクロの利点の一部が失われます。つまり、1 か所で外観を再定義して、それをどこにでも適用できるという利点です。突然、定理の注釈を別の方法で囲むことに決めた場合、すべてを手動で変更する必要があります。そのため、小さな改善点は次のとおりです。
解決策1:
マクロを定義します。
\patchcmd{\thmhead}{(#3)}{#3}{}{}
\newcommand{\notewrap}[1]{(#1)}
\begin{theorem}[\notewrap{Pythagoras}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[\notewrap{Pythagoras, \cite{Pythagoras}}]
$a^2 + b^2 = c^2$.
\end{theorem}
\begin{theorem}[\cite{Pythagoras}]
$a^2 + b^2 = c^2$.
\end{theorem}