Just modify the representation of the counter for difficult exercises:
\documentclass{book}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\newtheorem{ex}{Exercise}[chapter]
\newenvironment{ex*}
{\renewcommand\theex{\thechapter.\arabic{ex}\rlap{$^*$}}\ex}
{\endex}
\begin{document}
\chapter{First Chapter}
\section{First section}
\begin{ex}
This is an Exercise
\end{ex}
\begin{ex}
This is an Exercise
\end{ex}
\begin{ex*}
This is a difficult Exercise
\end{ex*}
\end{document}
If the asterisk is not desired in the references to this exercise, then the definition of ex*
can be changed into
\makeatletter
\newenvironment{ex*}
{\renewcommand\theex{\thechapter.\arabic{ex}\rlap{$^*$}}%
\ex\edef\@currentlabel{\thechapter.\arabic{ex}}}
{\endex}
\makeatother
so that the reference will be created without *.
Here is an implementation that provides a \exinline
command, taking a label argument to produce the relevant text.
\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{exercise}[theorem]{Exercise}
\newcommand{\exinline}[1]{(\refstepcounter{theorem}Exercise~\thetheorem\label{#1})}
\begin{document}
\section{Euler's Theorem}
Some text.
\begin{theorem}[Euler]
\label{thm:Euler}
This is Euler's theorem.
\end{theorem}
\begin{proof}
The proof of this theorem is left as an exercise \exinline{ex:Euler}.
\end{proof}
\begin{exercise}
\label{ex:extra}
Reformulate the theorem.
\end{exercise}
Here is the solution to Exercise~\ref{ex:Euler}. By\dots
Note that Exercise~\ref{ex:extra} requires you to provide another formulation
of Theorem~\ref{thm:Euler}.
\end{document}
Note in this example Exercises and Theorems share the same counter. If that is not the case, you need to replace the theorem
counter in definition with the appropriate counter, and change \thetheorem
correspondingly. E.g. if exercises have their own number, declared
via \newtheorem{exercise}{Exercise}[section]
, the command definition should read
\newcommand{\exinline}[1]{(\refstepcounter{exercise}Exercise~\theexercise\label{#1})}
If you are using cleveref
for references then a small modification is needed to the refstepcounter
command so \cref
picks up the correct name.
\documentclass{article}
\usepackage{amsthm}
\usepackage[capitalize]{cleveref}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{exercise}[theorem]{Exercise}
\newcommand{\exinline}[1]{(\refstepcounter[exercise]{theorem}Exercise~\thetheorem\label{#1})}
\begin{document}
\section{Euler's Theorem}
Some text.
\begin{theorem}[Euler]
\label{thm:Euler}
This is Euler's theorem.
\end{theorem}
\begin{proof}
The proof of this theorem is left as an exercise \exinline{ex:Euler}.
\end{proof}
\begin{exercise}
\label{ex:extra}
Reformulate the theorem.
\end{exercise}
Here is the solution to \cref{ex:Euler}. By\dots
Note that \cref{ex:extra} requires you to provide another formulation
of \cref{thm:Euler}.
\end{document}
This produces the same output as the first example, with cleveref
correctly providing the names.
Best Answer
Here is a simple solution with
framed
,fancybox
andthmtools
: