1

Goal: I want to be able to mark the end of examples and exercises using some sort of symbol, much as $\qedsymbol$ marks the end of proofs. In particular, I want a command that acts like \qedhere for my symbol of choice.

Background: This is in fact one of the potential modifications listed in the amsthm package documentation: to "extend applicability of \qedhere to theorem-class elements as well as to proofs." They say that while this has merit, it requires more work and is essentially on the back burner.

My attempt:

The way I have attempted to implement an exercise environment with its own end-symbol is as follows:

\documentclass{memoir}

\usepackage{amsthm}
\usepackage[varg,bigdelims]{newpxmath}
\usepackage{ifthen}

\newcounter{madesymbol}

\newtheorem{exc}{Exercise}
\newcounter{exc-counter}
\newenvironment{exercise}[1][]
{
    \begin{exc}[#1]~
    \def\mysymbol{$\lozenge$}
    \setcounter{madesymbol}{0}
    \def\tagsymbol{\stepcounter{madesymbol}\tag*{\mysymbol}}
}
{
    \ifthenelse{\equal{\value{madesymbol}}{0}}{\hspace*{\fill}\mysymbol}{}
    \end{exc}
    \stepcounter{exc-counter}
}

\begin{document}

\begin{exercise}
A function $f$...
\end{exercise}

\end{document}

This feels bulky, and I'm looking for a better solution.

Problems with ntheorem: One suggestion I have seen is the ntheorem package. I have tried ntheorem, but it seems to change "everything", e.g. not act at all like amsthm (even with the [amsthm] option loaded). If someone suggests I use this package, please give explicit code for making it act as much like amsthm as possible.

1
  • Could you add a MWE with a definition of \lozenge? Feb 15, 2018 at 13:58

2 Answers 2

3

Try this:

\documentclass{article}
\usepackage{amsthm}
\begin{document}

\newtheorem{ex-inner}{Exercise}
\newenvironment{ex}{%
  %\def\qedsymbol{$\lozenge$}% Set the QED symbol. 
  \pushQED{\qed}%
  \begin{ex-inner}%
}{%
  \popQED
  \end{ex-inner}%
}


\begin{ex}
Here is an exercise.
\end{ex}

\begin{ex}
Hi!
\[x=y\qedhere\]
\end{ex}

\begin{proof}
Hi!
\[x=y\qedhere\]
\end{proof}
\end{document} 
4
  • if you add \usepackage{amssymb}, \lozenge will be available. (i'd need to check more carefully, but i'm pretty sure this is essentially how the enhancement would be made to amsthm. good going.) Feb 15, 2018 at 15:17
  • This is great, thanks Hood. By the way, what's the value of all the %-signs, and why not put one after \popQED ? Feb 15, 2018 at 15:33
  • 1
    Tex by default converts a single new line character into a space, two newlines in a row into a \par. The % at the end of the line prevents tex from putting a space there. After a control sequence, tex is in ignoring spaces mode so no percent is necessary. Feb 15, 2018 at 15:36
  • These %'s are very typical in tex code because newlines are good for code readability and it's generally undesirable for them to change the output. Feb 15, 2018 at 15:37
2

Here is a demo of how it can be done with ntheorem. One distinctive feature is that the placement is automatic, even with therems ending in a multiline display (it may require two compilations, and there must be no blank line at the end of the environment. The QED symbol is quite easy to customise:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage[svgnames, table]{xcolor}
\usepackage{mathtools, nccmath}

\usepackage[thmmarks, thref, amsmath]{ntheorem}
\theoremheaderfont{\itshape\bfseries}% default is \upshape\bfseries
\theoremseparator{. \textemdash}
\newtheorem{thm}{Theorem}[section]
\newtheorem{prop}{Proposition}[section]

\theoremseparator{.}
\theoremheaderfont{\upshape\bfseries}%
\theorembodyfont{\upshape\mdseries}% default is \itshape
\newtheorem{dfn}{Definition}[section]
\theoremsymbol{\raisebox{-0.1\height}{\color{IndianRed}$ \boldsymbol\diamondsuit $}}
\newtheorem{ex}{Exercise}

\theoremstyle{nonumberplain}
\theoremheaderfont{\scshape}
\theoremseparator{:}
\theoremsymbol{\ensuremath{\color{Gainsboro}\blacksquare}}

\newtheorem{proof}{Proof}
\begin{document}
\setcounter{section}{2}

\begin{thm}
Clangle-Wangles’ habits of life are domestic and superfluous, and their general demeanour pensive and pellucid.
\end{thm}

\begin{dfn}
  A \textbf{Snark} is a Boojum.
\end{dfn}

\begin{ex}
Here is an exercise.
\end{ex}

\begin{ex}
Hi!
\[ x=y \]
\end{ex}

\begin{proof}
There are two cases: \useshortskip
\begin{align*}
x & =y \\ u & =v
\end{align*}
\end{proof}

\end{document} 

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .