定理と定義名は余白に記入

定理と定義名は余白に記入

定理の名前を余白に表示したいのですが、余白の注釈を使用してこれを実行しようとしましたが、できませんでした。

これは私がやろうとしていることの図です。上の行は定理環境がデフォルトでどのように動作するかを示しており、下は私が望んでいるものです。 ここに画像の説明を入力してください

これが私がやろうとしたことです。ただし、このようなことをどうやってやるのかよく理解していないことを認めなければなりません。

 \newenivorment{margintheorem}[#2]{
 \begin{theorem}[\marginnote{#2}]

 \end{theorem}
 }

答え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、あらゆる種類の「定理のような」環境 (命題、補題、定義など) に自動的に適用されます。これは\marginpar、LaTeX カーネルの コマンドの使用に基づいています。このコマンドは「外部段落モード」で発行する必要があるため、状況が少し複雑になります。実際、元のコマンドに基づくソリューションが可能であることを示す目的でコードを作成しました\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… ;-)

出力:

コードの出力

関連情報