
답변1
환경 을 간접적으로 정의할 수 있습니다 theorem
.
\documentclass{article}
\usepackage{amsthm,marginnote,xparse}
\newtheorem{theoreminner}{Theorem}
\NewDocumentEnvironment{theorem}{o}
{\theoreminner\IfValueT{#1}{\marginnote{\normalfont\footnotesize#1}}}
{\endtheoreminner}
\reversemarginpar
\begin{document}
\begin{theorem}
This theorem has no attribution.
\end{theorem}
\begin{theorem}[theorem name]
This theorem has a name.
\end{theorem}
\end{document}
답변2
귀하의 질문에는 몇 가지 중요한 세부 정보가 부족하며 특히 "정리와 유사한" 환경을 정의하기 위해 특정 패키지를 사용하고 있는지 여부를 지정하지 않았습니다. 를 사용하고 있다고 가정하겠습니다 amsthm
.
다음 솔루션은 amsthm
의 명령 정의를 직접 해킹하므로 \@begintheorem
모든 종류의 "정리와 유사한" 환경(명제, 기본형, 정의…)에 자동으로 적용됩니다. 이는 LaTeX 커널의 명령 사용을 기반으로 합니다 \marginpar
. 이 명령은 "외부 단락 모드에서" 실행되어야 하기 때문에 상황이 좀 더 복잡해집니다. 실제로 나는 원래 명령을 기반으로 한 솔루션이 가능하다는 것을 보여주기 위해 정확하게 코드를 작성했습니다 \marginpar
.
% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly
% declare the paper format.
\usepackage[T1]{fontenc} % Not always necessary, but recommended.
% End of standard header. What follows pertains to the problem at hand.
% \usepackage{amsmath} % not essential, but you probably want it too
\usepackage{amsthm}
\usepackage{etoolbox} % for "\patchcmd"/"\pretocmd"
%%%%%%%% BEGIN WIZARDRY %%%%%%%%
\makeatletter
\wlog{****************************************}
\patchcmd{\@begintheorem}{% search for:
\@ifempty{#3}{\let\thmnote\@gobble}{\let\thmnote\@iden}%
\thm@swap\swappedhead\thmhead{#1}{#2}{#3}%
}{% replace with:
\let\thmnote\@gobble
\thm@swap\swappedhead\thmhead{#1}{#2}{}%
}{% execute if succeeded:
\wlog{>>> 1st patch succeeded.}
}{% execute if failed:
\wlog{>>> 1st patch FAILED!}
}
\pretocmd{\@begintheorem}{% prepended code:
\@ifnotempty{#3}{\def\@thm@marginal@note@text{#3}}%
}{% execute if succeeded:
\wlog{>>> 2nd patch succeeded.}
}{% execute if failed:
\wlog{>>> 2nd patch FAILED!}
}
\wlog{****************************************}
\newcommand*\@thm@marginal@note@text{}
\newcommand*\@thm@marginal@note@helper{%
\begingroup \setbox\z@ \lastbox \endgroup
\marginnote{\@thm@marginal@note@text}%
}
\dth@everypar = \expandafter {%
\expandafter \@thm@marginal@note@helper
\the \dth@everypar
}
\makeatother
%%%%%%%% END WIZARDRY %%%%%%%%
\newcommand*{\marginnote}[1]{%
\marginpar
[\footnotesize\raggedleft #1]%
{\footnotesize\raggedright #1}%
}
\reversemarginpar % ?
\newtheorem{theorem}{Theorem}
\newtheorem{lemma} {Lemma}
\theoremstyle{definition}
\newtheorem{defin}{Definition}
\begin{document}
This text comes before the first definition.
\begin{defin}[Important definition]
A definition is \textbf{important} if and only if it is not
unimportant.
\end{defin}
And, of course:
\begin{defin}
An \textbf{unimportant} definition is one that is not important.
\end{defin}
Now a theorem:
\begin{theorem}[Important Theorem]
All theorems are important, but some theorems are more important
than others.
\end{theorem}
The proof rests on the following
\begin{lemma}[Important lemma]
Not all theorems (or lemmas) are equally important.
\end{lemma}
An unimportant theorem:
\begin{theorem}
Blah blah blah\ldots
\end{theorem}
And an unimportant lemma:
\begin{lemma}
Blah blah blah\ldots
\end{lemma}
Here is a little more text.
\end{document}
구식 "빈티지" 코드와 그 사용에 주목하세요 \expandafter
. ;-)
출력: