I would like to have a symbol like \blacksquare at the end of the environment \newtheorem{example}{Example}. However, this symbol should be well-behaved in presence of formulae (i.e. no white space between the formula, and the symbol).
For example, the following line of code does not behave correctly, as can be easily checked.
\documentclass[11pt]{article}
\usepackage{mathtools}
\newcommand\xqed[1]{%
\leavevmode\unskip\penalty9999 \hbox{}\nobreak\hfill
\quad\hbox{#1}}
\newcommand\demo{\xqed{$\diamond$}}
\newtheorem{example}{Example}
\begin{document}
\begin{example}
\begin{align*}
f(x) &= \bigg( g(x) \bigg) \\
h(x) &= \bigg(r(x) \bigg).
\end{align*}
\demo
\end{example}
\end{document}
How can I achieve what I am looking for?
Any feedback is greatly appreciated.
Thank you for your time.
ntheoreminstead ofamsthm, there every theorem like construction can be given an end marker, which (is used correctly) can place it self "more correctly" – daleif Jun 30 '16 at 13:03amsthm(most probably kind of an irrational preference, but before getting into something new, I would like to see what happens with in the "known" context). – Kolmin Jun 30 '16 at 13:12\qedhereis the answer – egreg Jun 30 '16 at 16:06\qedherewith whatever symbol I want? – Kolmin Jun 30 '16 at 16:12examplex? If you have a final display in theexampleenvironment, adding\qedhereto the last (or only) line of the display will produce the chosen QED symbol, in that case the triangle. – egreg Jun 30 '16 at 16:16\qedhereinside the align, it is literally after the big bracket, while if you put outside at the end, there is still the undesired spacing. – Kolmin Jun 30 '16 at 16:23