[Tex/LaTex] How to make an environment star Exercise

environmentsstarred-version

I want to create an environment star Exercise, but I can not. Please help me.

\documentclass{book} 
    \usepackage{amsfonts}
    \usepackage{amssymb}
    \usepackage{amsmath}
    \newtheorem{ex}{Exercise}[chapter]
    \begin{document}
    \chapter{First Chapter}
    \section{First section}
    \begin{ex}
    This is an Exercise
    \end{ex}

    \begin{ex}
    This is an Exercise
    \end{ex}

    \end{document}

If next is a difficult Exercise, how to define new environment Exercise star, for example \textbf{Exercise} $1.3^\text{*}$.

Best Answer

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}

enter image description here


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 *.

Related Question