
이는 후속 조치입니다.이 질문그리고이 하나. 기본적으로 아래와 같이 정리의 선택적 인수에서 시퀀스 ([...])를 피하고 싶습니다.

이 결과를 얻으려면이 답변\patchcmd
, 패키지 의 매크로를 사용했습니다 etoolbox
. 그러나 변경 사항이 있을 때 \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
뒤에 [...]
and by가 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:
매크로를 정의합니다.
\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}