3

I am writing a text where the editor suggested to close all the definitions with a diamond.

So I was wondering, is there a easy way to automatically add a command to all the \end{definition} ? I looked the documentation of \theoremstyle, but it does not really seem to help.

Here is a working example where I did it manually...

\documentclass{article}

\usepackage{amssymb}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]

\newcommand{\xqed}[1]{%
   \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
   \quad\hbox{\ensuremath{#1}}}
\newcommand{\Endofdef}{\xqed{\lozenge}}

\begin{document}

\begin{definition}
(Stack Overflow) Stack Overflow is a privately held website, the flagship site
of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky,
as a more open alternative to earlier Q\&A sites such as Experts Exchange.\Endofdef
\end{definition}

\end{document}
  • Your copy editor is wrong, but unfortunately you can't do much about this, save insisting you don't want it. Anyway, it's a duplicate (where the \xqed command seems to come from). My solution there works even for definitions nested in proof environments. – egreg Feb 03 '15 at 17:35
  • I am not sure, are you the author of ftp://ftp.ams.org/pub/author-info/documentation/howto/extra-qed.tex ? There is where I read the xqed definition. – Paolo.Bolzoni Feb 03 '15 at 17:48
  • 2
    egreg is not the author of your cited reference; i am. adding the ability to insert an end-of-theorem mark comparable to the end-of-proof mark is on the list of requested features for amsthm, to be considered the next time that is updated. (but i can't predict when an update might happen.) – barbara beeton Feb 03 '15 at 17:57
  • @barbarabeeton Still I'd prefer the \pushQED approach. – egreg Feb 03 '15 at 18:07
  • @egreg -- well, \pushQED is how the end-of-proof mark is implemented, so (of course) that's how we'd implement the comparable feature for theorems. the document cited by the original poster in his comment is just a stopgap until an update to amsthm is undertaken. what do you think of the idea of putting in a test for vertical mode, and issuing a warning if that's true? (maybe even an error, but many variations of "endings" would have to be tested first to make sure we're not backing ourselves into a corner.) – barbara beeton Feb 03 '15 at 19:31
  • @barbarabeeton A blank line before \end{<env>} would indeed be disastrous. Users should be made aware of \qedhere. A test should check for vertical mode or nothing in the current horizontal list (the latter is not easy). – egreg Feb 03 '15 at 21:02
  • @egreg -- we see blank lines in this situation all the time, sometimes with the tombstone broken to the next page, and it makes the production editors earn their keep. i think the "nothing in the horizontal list" is not nearly so common -- that would require real effort. i'll add the suggestion about a vertical mode check to the amsthm request list. (we do try to make authors aware of \qedhere, but so many are so proud that they don't ever read documentation!) – barbara beeton Feb 03 '15 at 21:21

2 Answers2

3

Define a new environment mydef and insert the symbol just before to close it.

\documentclass{article}

\usepackage{amssymb}
\usepackage{amsthm}
\theoremstyle{definition}
\newtheorem{definition}{Definition}[section]
\newenvironment{mydef}[1]{%
    \begin{definition}#1}{%
    \Endofdef\end{definition}%
}

\newcommand{\xqed}[1]{%
    \leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
    \quad\hbox{\ensuremath{#1}}}
\newcommand{\Endofdef}{\xqed{\lozenge}}

\begin{document}

    \begin{mydef}[Stack Overflow] Stack Overflow is a privately held website, the flagship site
        of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky,
        as a more open alternative to earlier Q\&A sites such as Experts Exchange.
    \end{mydef}

\end{document}

enter image description here

Sigur
  • 37,330
  • Thought of that, but if I leave an empty line before the \end it won't show well. It is true that the proof environment does the same, but I was hoping in more robust solution. But ok. – Paolo.Bolzoni Feb 03 '15 at 17:39
  • @Paolo.Bolzoni, since AMS proof also does this I believe that it is not possible to remove new paragraphs before the closing. – Sigur Feb 03 '15 at 17:41
  • You are probably right, accepted. – Paolo.Bolzoni Feb 03 '15 at 17:44
  • 4
    @Paolo.Bolzoni -- it is not possible to backtrack out of vertical mode when the input of a theorem or proof ends with a blank line. however, a test for vertical mode could be added to the definition of \xqed, and a warning issued if it is true. – barbara beeton Feb 03 '15 at 18:01
0

If you can consider using ntheorem, it's easy to incorporate a symbol at the end of any theorem type environment. It has the advantage that its placement is automatic, even if the environment ends up in displayed equations:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amssymb}
    \usepackage[thmmarks, amsmath, thref]{ntheorem}
\theoremstyle{plain}
\theoremheaderfont{\bfseries}
\theorembodyfont{\upshape}
\theoremsymbol{\scalebox{1}[1.4]{\large$ \diamond $}}
\newtheorem{definition}{Definition}[section]

\begin{document}
\section{A Demo Section}
\begin{definition}
(Stack Overflow) Stack Overflow is a privately held website, the flagship site
of the Stack Exchange Network, created in 2008 by Jeff Atwood and Joel Spolsky,
as a more open alternative to earlier Q\&A sites such as Experts Exchange.
\end{definition}

\begin{definition}
A \textbf{Pythagorean triple} is a triple $ (x, y, z) $ of integers such that
    \[ x² + y² = z² . \]%
\end{definition}

\end{document} 

enter image description here

Bernard
  • 271,350