7

I have a question about making an ending symbol.

It is a LaTex-default that every proof environment has an ending symbol. I want to make every theorem-alike environment such as the example environment have also an ending symbol. But how to manually set this up? Specifically, I want to make all these environments ended by a square symbol.

\newtheorem{thm}{Theorem}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{cor}[thm]{Corollary}
\newtheorem{pro}[thm]{Proposition}
\newtheorem{assump}{Assumption}
\newtheorem{axiom}{Axiom}
\newtheorem*{conj}{Conjecture}
\theoremstyle{definition}
\newtheorem{defi}[thm]{Definition}
\newtheorem{exam}{Example}
\newtheorem{exer}{Exercise}
\newtheorem*{rem}{Remark}
\newtheorem*{notation}{Notation}
\newtheorem*{note}{Note}

I am looking for, with gratitude, a comprehensive setup.

6
  • What do you mean by "theorem-alike"? Do you mean amsthm? Or you want to modify any environments such as quote or center?
    – Symbol 1
    Sep 19, 2014 at 6:53
  • Thank you so much for your attention. I meant all the following environments: \newtheorem{thm}{Theorem} \newtheorem{lem}[thm]{Lemma} \newtheorem{cor}[thm]{Corollary} \newtheorem{pro}[thm]{Proposition} \newtheorem{assump}{Assumption} \newtheorem{axiom}{Axiom} \newtheorem*{conj}{Conjecture} \theoremstyle{definition} \newtheorem{defi}[thm]{Definition} \newtheorem{exam}{Example} \newtheorem{exer}{Exercise} \newtheorem*{rem}{Remark} \newtheorem*{notation}{Notation} \newtheorem*{note}{Note}
    – Megadeth
    Sep 19, 2014 at 7:03
  • There's no need, in general, of marking the end of a statement: italic type and the spacing around the statement are sufficient. I use an end marker only for examples that are set in Roman type.
    – egreg
    Sep 19, 2014 at 8:53
  • @egreg: Right, thank you. I use it for a special need; I guess the reader may not have this mathematical mindset.
    – Megadeth
    Sep 19, 2014 at 8:55
  • The ntheorem package has a theoremsymbol{your_preferred_symbol} command, after which all declared theorems use the symbol, until another symbol is declared. Thus you can have each theorem-like environment have an end-of-theorem symbol (and even have its own).
    – Bernard
    Sep 19, 2014 at 9:46

2 Answers 2

4

Asssume you are using \newtheorem from amsthm. Here \newtheorem defines new theorem-alike environments and ends them by \@endtheorem. The later is originally defined as \def\@endtheorem{\endtrivlist\@endpefalse } and you can insert your ending symbol here.

\documentclass{article}
\usepackage{amsthm}
\usepackage{manfnt}
\makeatletter
    \def\@endtheorem{\hfill\dbend\endtrivlist\@endpefalse }
\makeatother
\begin{document}
    \newtheorem{thm}{Theorem}
    \begin{thm}
        Zigzagging is dangerous.
    \end{thm}
\end{document}

(Ideas come form here)

Caution!

As mentioned by egreg and barbara beeton below, this construction is not perfect. Neither it is as good as the proof environment from amsmath. One of the fatal defects is

if the text happens to end near the right margin, the symbol will be flush left, not flush right.

Therefore if you want an ending symbol exactly as the one from proof, you need either (see egreg's answer for details)

  • deal with glues and penalties.

  • pack your theorem-alike environment by adding \pushQED{your symbol} before and \popQED after. It is amsthm provides these two commands which take care of everything. (You can even use \qedhere).

10
  • It works well! Much appreciated. I wish I can vote your answer up more than once
    – Megadeth
    Sep 19, 2014 at 8:42
  • With the problem that, if the text happens to end near the right margin, the symbol will be flush left, not flush right.
    – egreg
    Sep 19, 2014 at 8:51
  • in the unlikely event that the theorem ends with a list, the symbol will always be on a new line, and if, moreover, the theorem falls at the bottom of the page, the symbol will likely break to the next page. (similarly with display math, but that's highly unlikely in a theorem.) that's why the amsthm proof environment goes to great lengths to cope with those contingencies. (a request has been made to add this facility to amsthm, and it has been seriously considered, but won't happen soon, even if accepted.) Sep 19, 2014 at 13:09
  • @barbarabeeton I read amsthm before I gave this answer. I saw that amsmath defined \pushqed and \popqed to make sure everything good. Yet I do not clearly understand what kind of contingency is bad and how amsthm handles it. So I simply provided an idea about hacking \@endtheorem. I guess it will be fine if I insert \popqed into \@endtheorem and insert \pushqed into, say, \@begintheorem. I would like to thank you (and egreg, as always) about these tips.
    – Symbol 1
    Sep 19, 2014 at 14:41
  • i'm not sure exactly how \@endtheorem would need to be coded to make this work without testing; i hope to have time to do that soon. i'll be delighted if the simple suggestion you make is sufficient. however, i don't think you have yet taken egreg's comment about a long last line into account, and that's necessary too. Sep 19, 2014 at 14:49
6

Use a variant of the \tmark command defined in my answer to Moving an object to the right margin

\documentclass{article}
\usepackage{amsthm}
\makeatletter
\renewcommand\@endtheorem{\vvv@endmarker\endtrivlist\@endpefalse}
\newcommand\vvv@endmarker{%
  {\unskip\nobreak\hfil\penalty50
  \hskip2em\vadjust{}\nobreak\hfil\openbox
  \parfillskip=0pt \finalhyphendemerits=0 \par
  \penalty 10000 \parskip=0pt\noindent}\ignorespaces}
\makeatother

\newtheorem{thm}{Theorem}

\begin{document}

\begin{thm}
Zigzagging is dangerous.
\end{thm}
\begin{thm}
Zigzagging is very dangerous.
Zigzagging is very very dangerous.
\end{thm}

I want to show that the \verb|\hfill| approach can fail.

\makeatletter
\def\vvv@endmarker{\hfill\openbox}
\makeatother

\begin{thm}
Zigzagging is dangerous.
\end{thm}
\begin{thm}
Zigzagging is very dangerous.
Zigzagging is very very dangerous.
\end{thm}

\end{document}

I added an example showing that the simple \hfill approach can fail.

enter image description here

A method that allows for itemized lists or displayed equations at the end, with correct marking using \qedhere is

\documentclass{article}
\usepackage{amsthm}

\newcommand{\newmarkedtheorem}[1]{%
  \newenvironment{#1}
    {\pushQED{\qed}\csname inner@#1\endcsname}
    {\popQED\csname endinner@#1\endcsname}%
  \newtheorem{inner@#1}%
}

\newmarkedtheorem{thm}{Theorem}[section]

\begin{document}

\section{Test}

\begin{thm}
Zigzagging is dangerous.
\end{thm}

\begin{thm}
Zigzagging is very dangerous.
Zigzagging is very very dangerous.
\end{thm}

\begin{thm} These activities are dangerous.
  \begin{itemize}
  \item Zigzagging
  \item Jaywalking\qedhere
  \end{itemize}
\end{thm}

\end{document}

The command \newmarkedtheorem has the same syntax as \newtheorem.

enter image description here

4
  • but see what happens with this: \begin{thm} These activities are dangerous. \begin{itemize} \item Zigzagging \item Jaywalking \end{itemize} \end{thm} Sep 19, 2014 at 13:19
  • @barbarabeeton It's dangerous indeed. ;-) One should probably use the \qed method. I'll think to it.
    – egreg
    Sep 19, 2014 at 13:42
  • I used this for a while, but then switched to this method because autoref was giving me problems to do with inner@thm
    – Ian Hincks
    May 23, 2018 at 17:40
  • @IanHincks Maybe you’re luckier with cleveref
    – egreg
    May 23, 2018 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.