# How to make an environment star Exercise?

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{*}$.

-
What do you want? Please explain your intention? – Marco Daniel Oct 20 '12 at 7:04
An alternative to the nice (accepted) answer: write the ex environment so that it accepts an optional * argument. That's easy with the xparse package. – Ethan Bolker Oct 20 '12 at 13:30

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

-
I had a problem like this once. I can use it again. Thanks @egreg. – hpesoj626 Oct 20 '12 at 7:29
@hpesoj626 There may be a problem if you want to \label the exercise and then refer to it: with this solution the * will be printed also by \ref. It can be changed, if needed: please, let me know – egreg Oct 20 '12 at 7:31
Yes I see the *. Can you update the answer to so that the asterisk is not included by \ref? I was supposed to ask in chat but connection is slow at the moment. – hpesoj626 Oct 20 '12 at 7:50
@hpesoj626 I've put the addition you requested. – egreg Oct 20 '12 at 19:44
Thanks. What does the new line \ex\edef\@currentlabel{\thechapter.\arabic{ex}} actually do? I don't know what \edef does to \@currentlabel. Is there already a question here or material that explains these? Let me know if I have to ask this in a separate post or in chat. Thanks. – hpesoj626 Oct 20 '12 at 23:20

The package Exercise can help here:

\documentclass{article}

\usepackage{exercise}

\begin{document}
\begin{Exercise}
This is an exercise.
\end{Exercise}

\begin{Exercise}[difficulty=1]
This is a difficult exercise.
\end{Exercise}
\end{document}


The result:

-

I have just found an answer

 \documentclass[12pt,openany,twoside]{book}
\usepackage{fouriernc}
\usepackage[thmmarks,standard,thref]{ntheorem}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}

\theoremseparator{.}
\theorembodyfont{\upshape}
\newtheorem{ex}{Exercise}[chapter]
\theoremseparator{$^\text{*}$.}
\newtheorem{dex}[ex]{Exercise}

\Newassociation{sols}{ansF}{loigiaichung}
\newcommand{\preansF}{}
\renewcommand{\ansFlabel}[1]{{\bfseries #1*.}}
\begin{document}
\chapter{First Chapter}
\Opensolutionfile{loigiaichung}[ex]
\section{First section}
\begin{ex}
This is an exercise
\begin{sol}
This is a solution
\end{sol}
\end{ex}

\begin{dex}
This is an exercise
\begin{sols}
This is a solution
\end{sols}
\end{dex}

\chapter{Second Chapter}
\Opensolutionfile{loigiaichung}[ex]
\section{Second  section}
\begin{ex}
This is an exercise
\begin{sol}
This is a solution
\end{sol}
\end{ex}

\begin{dex}
This is an exercise
\begin{sols}
This is a solution
\end{sols}
\end{dex}

\Closesolutionfile{loigiaichung}
\section{Hint, anserw}
\input{ex}

\end{document}

-
You shouldn't be using $^\text{*}$, which produces too high an asterisk: either $^{*}$ or simply *. However, the position of the asterisk will be wrong if you use the optional argument to dex: \begin{dex}[From \cite{xyz}] will have the asterisk after the attribution. – egreg Oct 20 '12 at 22:12