[Tex/LaTex] Flushright square mark

horizontal alignmentmath-modesymbols

I write the codes below to get a square as if to say q.e.d.

$$equation$$\textbox{\hfill\square}

Text\textbox{\hfill\square}

I want the square at the right extreme of the same line. I succeed only when the rest of the line has text and/or an equation within $ $, but not when it has an equation within $$ $$. In this case the square appears in the extreme right but in the next line but I want it on the same line.

Any help is appreciated.

Best Answer

Use amsthm and its proof environment. If a proof ends with a displayed equation, itemize or enumerate, use \qedhere in the last line.

Example:

\documentclass{article}
\usepackage{amsthm}
\begin{document}
\begin{proof}
This proof ends with a displayed equation
\[
1+1=2.\qedhere
\]
\end{proof}

\begin{proof}
This proof ends normally,
\end{proof}
\end{document}

enter image description here

Never use $$...$$ in LaTeX, see Why is \[ ... \] preferable to $$ ... $$?