如何使用盒裝定理名稱作為 QED 符號

如何使用盒裝定理名稱作為 QED 符號

我想知道是否有相對簡單的方法來實現類似於以下的結果:

在此輸入影像描述

特別是,我希望能夠為定理/引理/命題指定名稱和/或數字,然後用定理/引理/命題名稱的概述版本替換該定理/引理/命題的標準 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

以避免出現問題。在標準英語設定中,不需要這樣做。

除了這兩個改動之外,\@begintheorem與原來相同。

然後我重新定義\qedsymbol。它\qed@thiscurrent與; 進行比較\qed@empty;若相同則排版標準符號,否則排版

\fbox{\scriptsize\qed@thiscurrent}

因為,正如我們將看到的,\qed@thiscurrent包含目前正在證明的定理的編號。

如果最後陳述的定理已編號,則也\proofname可以重新定義以新增「of <number>」 。\qed@thiscurrent

環境proof被修改為(本地)設定\qed@thiscurrent\qed@current; finallyproof*被定義為類似的操作proof,但使用 檢索數字\ref

簡單遵循定理的情況proof很容易:\qed@thiscurrent將包含定理編號。對於 也一樣proof*

如果一個proof環境位於另一個環境中proof,則該語句將全域重置\qed@current,但這不會影響\qed@thiscurrent主證明的末尾,因為\qed@thiscurrent嵌套證明是在本地設定的,並將\end{proof}本地恢復\qed@thiscurrent為先前的值。

答案2

如果我們使用阿姆斯特姆那麼我們可以透過劫持命令\qedsymbol並破解內部構造定理環境的方式來做到這一點。這歸結為添加一些程式碼來\@begintheorem覆蓋\qedsymbol,使其成為最後一個定理數的盒裝版本。

在此輸入影像描述

下面的程式碼有兩個問題。第一個是已經\qedsymbol丟失 - 但你可以使用\realqedsymbol

第二個問題是,如果你陳述一個定理,然後在返回主要結果之前在證明中間證明另一個引理,那麼最後一個盒裝數字將是錯誤的。最簡單的解決方法可能是定義一個類似的命令

\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環境,​​它可以採用兩個可選參數:第一個是經典證明環境的可選參數,但由括號分隔;第二個可選參數是證明結束符號,預設為正方形,但可以是對已證明的定理的引用(實際上,任何引用或任何文字)。在後一種情況下,我選擇將其放在\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} 

在此輸入影像描述

相關內容