
次のような結果を達成する比較的簡単な方法があるかどうか疑問に思っています。
特に、定理/補題/命題に名前や番号を割り当て、その定理/補題/命題の標準 QED シンボルを定理/補題/命題の名前/番号の概要バージョンに置き換えることができるようにしたいと考えています。
残念ながら、定理環境の変更に関する私の知識があまりにも乏しく、どこから始めればよいのか全く見当がつかないため、ここでは最小限の動作例を示しません。 ご提案があれば、大変ありがたく思います。
答え1
これはあなたが望むことを行いますが、面倒であまり有益ではないと思います。
\documentclass{book}
\usepackage{amsthm,xpatch}
\makeatletter
\let\qed@empty\openbox % <--- change here, if desired
\def\@begintheorem#1#2[#3]{%
\deferred@thm@head{%
\the\thm@headfont\thm@indent
\@ifempty{#1}
{\let\thmname\@gobble}
{\let\thmname\@iden}%
\@ifempty{#2}
{\let\thmnumber\@gobble\global\let\qed@current\qed@empty}
{\let\thmnumber\@iden\xdef\qed@current{#2}}%
\@ifempty{#3}
{\let\thmnote\@gobble}
{\let\thmnote\@iden}%
\thm@swap\swappedhead
\thmhead{#1}{#2}{#3}%
\the\thm@headpunct\thmheadnl\hskip\thm@headsep
}\ignorespaces
}
\renewcommand{\qedsymbol}{%
\ifx\qed@thiscurrent\qed@empty
\qed@empty
\else
\fbox{\scriptsize\qed@thiscurrent}%
\fi
}
\renewcommand{\proofname}{%
Proof%
\ifx\qed@thiscurrent\qed@empty
\else
\ of \qed@thiscurrent
\fi
}
\xpretocmd{\proof}{\let\qed@thiscurrent\qed@current}{}{}
\newenvironment{proof*}[1]
{\def\qed@thiscurrent{\ref{#1}}\proof}
{\endproof}
\makeatother
\newtheorem{thm}{Theorem}[section]
\newtheorem{lem}[thm]{Lemma}
\newtheorem*{nthm}{Theorem}
\begin{document}
\chapter{Title}
\section{Title}
\begin{thm}
Pigs can fly.
\end{thm}
\begin{proof}
Would you doubt it?
\end{proof}
\begin{nthm}
Unnumbered.
\end{nthm}
\begin{proof}
What should we say?
\end{proof}
The following theorem will be proved later.
\begin{thm}\label{thm:later}
$P=NP$.
\end{thm}
Long text here.
\begin{proof*}{thm:later}
Oh, well! Should I really do it? We'll use the following lemma.
\begin{lem}
Something surely can fly.
\end{lem}
\begin{proof}
Clear.
\end{proof}
Now use the lemma and apply the well known identity
\[
1=0.\qedhere
\]
\end{proof*}
\end{document}
証明が遅れる場合は、proof*
相対定理で使用されるラベルを引数として必要とする環境を使用します。
ご覧のとおり、証明はネストできます。ここでは「遅延」証明内のネストされた証明のみを示しましたが、標準proof
環境でも動作することを確認できます。
いくつかの説明の言葉。
まず、 の定義を変更して、\@begintheorem
いくつかの設定を追加します。定理に番号が付いていない場合は、(すでに環境内にあるため、全体的に)\qed@current
を に設定します\qed@empty
(これは標準の QED シンボルとして定義されています。理由は後で説明します)。定理に番号が付いている場合は、 に設定します。 には定理番号が含まれている\xdef\qed@current{#2}
ためです#2
(ただし、明示的な形式ではないため、完全に展開する必要があります)。
定理の数字に書式指定が含まれている場合や、異なる数体系が使用されている場合(babel
たとえばギリシャ数字)は、次のようにします。
\protected@edef\@tempa{#2}\global\let\qed@current\@tempa
問題を回避するためです。標準的な英語の設定では、これは必要ありません。
これら 2 つの変更以外は、\@begintheorem
オリジナルと同じです。
次に を再定義します。と\qedsymbol
比較し、同じ場合は標準シンボルをタイプセットし、そうでない場合は\qed@thiscurrent
\qed@empty
\fbox{\scriptsize\qed@thiscurrent}
なぜなら、後でわかるように、には\qed@thiscurrent
現在証明されている定理の番号が含まれているからです。
また、最後に述べた定理に番号が付けられている場合は、を使用して\proofname
「of」を追加するように再定義されます。<number>
\qed@thiscurrent
環境がにproof
(ローカルに)設定されるように変更され、最終的に はと同様に動作するように定義されますが、 で数値を取得します。\qed@thiscurrent
\qed@current
proof*
proof
\ref
proof
単純な定理の場合、そのケースは簡単です。\qed@thiscurrent
には定理番号が含まれます。 の場合も同様ですproof*
。
proof
環境が別の の中にある場合proof
、文は をグローバルにリセットしますが、ネストされた証明はローカルに設定され、はローカルを以前の値に戻すため、メインの証明の最後に\qed@current
は影響しません。\qed@thiscurrent
\qed@thiscurrent
\end{proof}
\qed@thiscurrent
答え2
もし、アムスムパッケージの場合、コマンドを乗っ取り、定理環境が内部的に構築される方法をハッキングすることでこれを実行できます。これは、最後の定理番号のボックス化されたバージョンになるように上書きする\qedsymbol
コードを追加することになります。\@begintheorem
\qedsymbol
以下のコードには 2 つの問題があります。1 つ目は、 が\qedsymbol
失われていることですが、\realqedsymbol
代わりに を使用できます。
2つ目の問題は、例えば1つの定理を述べ、証明の途中で別の補題を証明してから主結果に戻ると、最後の四角で囲まれた数字が間違ってしまうことです。これを最も簡単に修正するには、次のようなコマンドを定義するのがよいでしょう。
\newcommand\QedSymbol[1]{\gdef\qedsymbol{\fbox{\ref{#1}}}}
\qedsymbol
手動でボックス化されたコマンドに等しい値を設定するため。これを使用するには、(素晴らしい)定理への参照を追加して、証明の終わりの前に使用するように\ref
記述するだけです。\label{MyWondrousTheorem}
\Qedsymbol{MyWondrousTheorem}
定理のような環境に定理番号がない場合、 は実数\qedsymbol
に戻ります。\realqedsymbol
\qedsymbol
まだ十分にテストしていないので、これによって何かが壊れたり、これが機能しない特殊なケースが存在する可能性があります。
ここにコードがあります。
\documentclass{article}
\usepackage{amsmath,amsthm}
\makeatletter% the hack to change the qedsymbol automatically
\let\@@begintheorem=\@begintheorem% save real AMS theorem environment
\let\realqedsymbol\qedsymbol
\def\@begintheorem#1#2[#3]{%
\@@begintheorem{#1}{#2}[#3]% start the theorem
\@ifempty{#2}{\let\qedsymbol\realqedsymbol}{\gdef\qedsymbol{\fbox{#2}}}
}
\makeatother
\swapnumbers\numberwithin{equation}{section}
\newtheorem{Proposition}[equation]{Proposition}
\newtheorem{Lemma}[equation]{Lemma}
\begin{document}
\section{Important facts}
\begin{Lemma}
$1+1=2$
\end{Lemma}
\begin{proof}Count.
\end{proof}
\begin{Proposition}
$1+3=4$
\end{Proposition}
\begin{proof}Count more carefully.
\end{proof}
\begin{Proposition}
$2+2=4$
\end{Proposition}
\begin{proof}Count more carefully.
\end{proof}
\end{document}
\documentclass{article}
\usepackage{amsmath,amsthm}
\makeatletter
\let\@@begintheorem=\@begintheorem% save real AMS theorem environment
\let\@qedsymbol\qedsymbol
\def\@begintheorem#1#2[#3]{%
\@@begintheorem{#1}{#2}[#3]% start the theorem
\@ifempty{#2}{\let\qedsymbol\@qedsymbol}{\gdef\qedsymbol{\fbox{#2}}}
}
\makeatother
\swapnumbers\numberwithin{equation}{section}
\newtheorem{Proposition}[equation]{Proposition}
\newtheorem{Lemma}[equation]{Lemma}
\begin{document}
\section{Important facts}
\begin{Lemma}
$1+1=2$
\end{Lemma}
\begin{proof}Count.
\end{proof}
\begin{Proposition}
$1+3=4$
\end{Proposition}
\begin{proof}Count more carefully.
\end{proof}
\begin{Proposition}
$2+2=4$
\end{Proposition}
\begin{proof}Count more carefully.
\end{proof}
\end{document}
証明の途中で中間結果が表示される問題を修正する別の方法は、\qedsymbol
証明環境の開始時に再定義することです。ただし、このアプローチは、すべての定理のような環境で同じカウンターが使用されている場合にのみ可能です (私の MWE のように)。上記のコードには、異なる定理のような環境で異なるカウンターが使用されている場合でも機能する (機能するはず?:) という利点があります。
答え3
これは私が過去に使用したものを改変したものです(どこから入手したかはわかりません)。
コード:
\documentclass{article}
\usepackage{amsmath}
\newcommand*{\QED}[1]{%
\ifmmode% Check for math mode.
\tag*{\fbox{#1}}%
\else%
{\rightskip\fill\parfillskip-\rightskip%
\linepenalty100%
\exhyphenpenalty0%
\linebreak[0] % <-- Need space here (allows for a break.
\hspace*{\fill}\fbox{#1}}%
\fi%
}%
\begin{document}
In text mode you can use \verb|QED| as shown here.\QED{2.2}
You can also use it in math mode
\begin{align*}
F &= ma \\
\implies E &= mc^2\QED{2.3}
\end{align*}
\end{document}
答え4
パッケージを使用すると、 を非常に簡単にntheorem
再定義できます\qedsymbol
。 と組み合わせてxparse
、 という環境を定義します。Proof
この環境は、2 つのオプション引数を取ることができます。最初の引数は、従来の証明環境のオプション引数ですが、括弧 で区切られます。2 番目のオプション引数は、証明終了シンボルです。このシンボルは、デフォルトでは四角形ですが、証明された定理への参照 (実際には、任意の参照または任意のテキスト) にすることができます。後者の場合、 に配置することにしました\fcolorbox
。
例:
\documentclass[A4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[svgnames]{xcolor}
\usepackage{amsfonts,empheq}
\usepackage[amsmath, thref, thmmarks]{ntheorem}
\usepackage{cleveref}
\usepackage{xparse}
\usepackage{chngcntr}
\theoremstyle{plain}
\theoremseparator{.} \theoremheaderfont{\bfseries}
\theorembodyfont{\itshape}
\newtheorem{Thm}{Theorem}[section]
\newtheorem{Lem}{Lemma}%[section]
\theoremstyle{nonumberplain}
\theoremheaderfont{\itshape}
\theorembodyfont{\upshape}
\newtheorem{proof}{Proof}
\NewDocumentEnvironment{Proof}{d() o}
{\IfNoValueTF{#1}{\begin{proof}}{\begin{proof}[#1]}
\IfNoValueTF{#2}{\qedsymbol{\ensuremath{\Box}}}{\qedsymbol{\fcolorbox{red}{Lavender}{\color{red}\upshape#2}}}}%
{\qed\end{proof}}%
\counterwithin{Lem}{Thm}
\begin{document}
\section{Some Not So Standard Results}
\begin{Thm}\label{special}
$ \mathrm{SL}_n(\mathbb{K}) ⊂ \mathrm{ GL}_n(\mathbb{K})$.
\end{Thm}
\begin{Proof}[\Cref{special}]
We shall prove first:
\begin{Lem}\label{basic}
$ \mathrm{SL}_n(\mathbb{K}) ⊂ \mathrm{ GL}_n(\mathbb{K})$.
\end{Lem}
%% First proof of lemma
\begin{Proof}(of the lemma)[\Cref{basic}]
Easy enough.
\end{Proof}
%% Second proof of lemma
\begin{Proof}(another one)
Still easier proof.
\end{Proof}
%% End of theorem proof
Left as an exercise ;\,o)
\end{Proof}
\end{document}