# [texhax] On \qed macros

Fri Jan 4 16:17:54 CET 2008

Steve Schwartz :

> On Wed, 2008-01-02 at 10:19 -0500, Barbara Beeton wrote:
>> it's really a rather nasty problem to get
>> something that's both robust and works in
>> all possible situations.
>>
>> i think no one has mentioned that this is
>> built in to the amsthm package,
> ....snip...
>>  the code is pretty nasty, but
>> comments in amsclass.dtx (from which amsthm
>> and the documentclasses are generated) are
>
> Thanks Barabar. You've now nearly scared me off this task completely.
> But I've learned in the process that what I tried to do using \eqno
> works in TeX-style display math $$...$$ but throws a bad math delimiter
> error with  and a "you can't use \eqno in math mode" :-) in
> $$...$$ constructs [it's the equation
> numbering implicit \eqno that throws this - because the first \eqno has
> changed the mode to a non-display math mode]. Interestingly, pressing s
> to ignore the errors and press on yields the desired results, with latex
> doing what it needs to fix things. As predicted, with ordinary equation
> numbers the result is not great, as my marks and the equation number are
> typeset one after the other, but using leqno yields (apart from the
> error message) exactly what is desired. (including pushing my marks to
> the next line if the equation is too long).
>
> So here's my "final" version:
>
> \newcommand{\qmarks}[1]{\ifmmode \eqno \hbox{[#1~qmarks]} \else
>
> This, combined with leqno, covers everything I need, with the nuisance
> of throwing errors.
>
> So, is there a way for me to trap the errors myself and ignore them? I
> realise this is (a) very bad style (b) probably taboo (c) unaesthetic.
> But the real programmers and the hackers live side-by-side in harmony
> most of the time.
>

If one can use environments instead of inserting macros (I like
environments), then one might use something like this

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage[amsmath,thmmarks]{ntheorem}

\theoremsymbol{xxx} % just a dummy
\newtheorem{innerenv}{Dummy} % header not used anyway
\makeatletter
\newenvironment{test}[1][]{%
\begin{innerenv}}{\end{innerenv}}
\makeatother
\begin{document}

\begin{test}[5~marks]
$3^2+4^2 = ?$
\end{test}

\begin{test}[15~marks]
\input tufte
\end{test}

\end{document}

only problem is that if a paragraph ends before \end{test}, either via a
blank line or via the use of \par, then the placement engine breaks down.

Note that the math stuff requires a few passes.

The above have the advantage that it can be used with align etc. which