
Me pregunto si hay una manera relativamente sencilla de lograr un resultado similar al siguiente:
En particular, me gustaría poder asignar nombres y/o números a teoremas/lemas/proposiciones y luego reemplazar el símbolo QED estándar de ese teorema/lema/proposición con una versión resumida del nombre del teorema/lema/proposición. /número.
No tengo un ejemplo mínimo de trabajo aquí porque, desafortunadamente, mi conocimiento sobre la modificación de entornos de teoremas es tan bajo que no tengo la menor idea de cómo empezar. Cualquier sugerencia será muy apreciada.
Respuesta1
Esto hace lo que quieres, aunque lo encuentro engorroso y poco informativo.
\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}
Si se retrasa una demostración, utilice el proof*
entorno, que quiere como argumento la etiqueta utilizada en el teorema relativo.
Como puede ver, las pruebas se pueden anidar. Solo mostré una prueba anidada dentro de una prueba “retrasada”, pero puedes comprobar que también funciona con el proof
entorno estándar.
Algunas palabras de explicación.
Primero modifico la definición de \@begintheorem
para agregar un par de configuraciones. Si el teorema no está numerado, lo establezco (globalmente, porque ya estamos en un entorno) \qed@current
en \qed@empty
(que se define como el símbolo QED estándar, veremos más adelante por qué); si el teorema está numerado, lo hago \xdef\qed@current{#2}
, porque #2
contiene el número del teorema (pero no en forma explícita, por lo que es necesario expandirlo por completo).
En caso de que los números del teorema contengan instrucciones de formato o cuando se utilicen diferentes sistemas numéricos (números griegos con babel
, por ejemplo), esto debe ser
\protected@edef\@tempa{#2}\global\let\qed@current\@tempa
para evitar problemas. En entornos de inglés estándar, esto no debería ser necesario.
Aparte de estos dos cambios, \@begintheorem
es igual que el original.
Luego lo redefino \qedsymbol
. Se compara \qed@thiscurrent
con \qed@empty
; si es el mismo, escribe el símbolo estándar, de lo contrario escribe
\fbox{\scriptsize\qed@thiscurrent}
porque, como veremos, \qed@thiscurrent
contiene el número del teorema que se está demostrando actualmente.
También \proofname
se redefine para agregar "de <number>
" usando \qed@thiscurrent
si el último teorema indicado está numerado.
El proof
entorno se modifica para establecer (localmente) \qed@thiscurrent
en \qed@current
; finalmente proof*
se define hacer like proof
pero recuperando el número con \ref
.
El caso de proof
seguir un teorema simple es fácil: \qed@thiscurrent
contendrá el número del teorema. Lo mismo para proof*
.
Si un proof
entorno está dentro de otro proof
, la declaración se restablecerá globalmente \qed@current
, pero esto no influirá \qed@thiscurrent
al final de la prueba principal, porque \qed@thiscurrent
la prueba anidada se establece localmente y \end{proof}
revertirá el local \qed@thiscurrent
al valor anterior.
Respuesta2
Si utilizamos elamstmoentonces podemos hacer esto secuestrando el \qedsymbol
comando y pirateando la forma en que se construyen internamente los entornos de teoremas. Esto se reduce a agregar algo de código para \@begintheorem
sobrescribir \qedsymbol
de modo que se convierta en una versión en caja del último número de teorema.
Hay dos problemas con el código siguiente. La primera es que \qedsymbol
se ha perdido, pero puedes utilizarlo \realqedsymbol
en su lugar.
El segundo problema es que si estableces un teorema, digamos, y luego demuestras otro lema en medio de la demostración antes de regresar al resultado principal, entonces el último número en el recuadro será incorrecto. La solución más sencilla para esto es probablemente definir un comando como
\newcommand\QedSymbol[1]{\gdef\qedsymbol{\fbox{\ref{#1}}}}
para configurar manualmente \qedsymbol
igual a un \ref
comando en cuadro. Para usar esto, solo tendrías que escribir \label{MyWondrousTheorem}
para agregar una referencia a tu (maravilloso) teorema y luego usarlo \Qedsymbol{MyWondrousTheorem}
antes del final de la demostración.
Si el entorno similar a un teorema no tiene un número de teorema, entonces \qedsymbol
vuelve a ser \realqedsymbol
el real \qedsymbol
.
No he probado tanto, por lo que es posible que esto rompa algo o que haya otros casos extremos en los que esto no funcione.
Aquí está el código.
\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}
Otra forma de hacer esto, que solucionaría el problema con la aparición de un resultado intermedio en medio de una prueba, se redefiniría \qedsymbol
al inicio del entorno de prueba. Sin embargo, este enfoque solo sería posible si todos los entornos similares a teoremas usaran el mismo contador (como en mi MWE). El código anterior tiene la ventaja de que funcionará (¿debería?:) funcionar incluso si diferentes entornos similares a teoremas utilizan contadores diferentes.
Respuesta3
Esto es una adaptación de lo que he usado en el pasado (no estoy seguro de dónde lo saqué):
Código:
\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}
Respuesta4
El ntheorem
paquete permite redefinir \qedsymbol
de forma bastante sencilla. Combinando con xparse
, defino un Proof
entorno que puede tomar dos argumentos opcionales: el primero es el argumento opcional de un entorno de prueba clásico, pero delimitado por paréntesis; el segundo argumento opcional es el símbolo de fin de prueba, que por defecto es un cuadrado, pero puede ser una referencia al teorema que se demuestra (en realidad, cualquier referencia o cualquier texto). En el último caso, elegí ponerlo en un formato \fcolorbox
.
Ejemplo:
\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}