[Tex/LaTex] Change only the ending with renewenvironment

amsthmenvironmentstheorems

I have a theorem environment I've made called "ex" (using the theoremstyle "definition"), which I use for examples in a book document class. I like that I can number the examples, but I want a proof symbol to occur at the end of every example.

I have something that looks like:

\newtheorem{ex}{Example}[section]  
\renewenvironment{ex}{}{\qed \\}

However, I want "Example 1.1.1" to show up when I call \begin{ex}. How do I change the environment so that there is no change to the beginning definition, but changes the ending definition to the qed symbol?

Here is a MWE:

\documentclass{book}
\usepackage{amssymb, amsmath, amsthm}
\newtheorem{ex}{Example}[chapter]
\begin{document}
\begin{ex}
This is my example
\end{ex}
\end{document}

Best Answer

You can change just the end environment via:

\let\Oldendex\endex%
\def\endex{\qed\Oldendex}%

Here is a before and after:

enter image description here enter image description here

Code:

\documentclass{book}
\usepackage{amssymb, amsmath, amsthm}

\newtheorem{ex}{Example}[chapter]

\let\Oldendex\endex%
\def\endex{\qed\Oldendex}%

\begin{document}
\begin{ex}
This is my example
\end{ex}
\end{document}