0

I'd like to typeset a set of exercises from a book, from different chapters and sections, and give the solutions. I'm aware of packages like xsim or exercise, but I have not found a way to change manually the enumeration of the exercises. Here is an MWE illustrating what I'd like to do:

\documentclass{article}

\usepackage{amsthm}

\newcommand{\exer}[1]{\textbf{Exercise #1}}

\begin{document}

\begin{description}
    \item[Exercise 1.2.1] Statement
    \begin{proof}
    
    \end{proof}
    
    \item[Exercise 1.2.3] Statement
    \begin{proof}
    
    \end{proof}
    
    \item[Exercise 1.2.7] Statement
    \begin{proof}
    
    \end{proof}
    
    \item[Exercise 3.5.2] Statement
    \begin{proof}
    
    \end{proof}
    
    \item[Exercise 3.5.3] Statement
    \begin{proof}
    
    \end{proof}
\end{description}

\end{document}

How can I achieve this with any package intended to be used for this purpose? Thanks in advance.

1 Answer 1

1

Edit: Here's a solution very similar to the proposal in the original question using the xsim pacakge, and solves the problem of the number by substituting a custom ExerciseProperty "mynumber".

\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{xsim}

\DeclareExerciseType{myexercise}{
    exercise-env      = myexercise,
    solution-env      = mysolution,
    exercise-name     = \XSIMtranslate{exercise},
    exercises-name    = \XSIMtranslate{exercises},
    solution-name     = \XSIMtranslate{solution},
    solutions-name    = \XSIMtranslate{solutions},
    exercise-template = mytemplate,
    solution-template = mysoltemplate
}
\DeclareExerciseProperty!{mynumber}

\DeclareExerciseEnvironmentTemplate{mytemplate}{
    \begin{description}
        \item[\XSIMmixedcase{\GetExerciseName}~\GetExerciseProperty{mynumber}]
    
}{
    \end{description}
}
\DeclareExerciseEnvironmentTemplate{mysoltemplate}{
    \renewcommand{\proofname}{Solution}\begin{proof}
}{
    \end{proof}
}

\xsimsetup{
    mysolution/print = true
}

\begin{document}

\begin{myexercise}[mynumber=2.2.1]
Statement
\end{myexercise}

\begin{mysolution}
Here is the solution.
\end{mysolution}

\end{document}

My original suggestion is below, and uses a simpler set up using mainly just amsthm.


Is the issue just that you need to manually specify the exercise numbers?

Here are a couple ideas.

Create an environment with an argument which is the exercise number, have it create a custom theorem type environment. (Here you use two separate environments, one for the statement, one for the proof.)

\documentclass[12pt]{article}

\usepackage{xparse}
\usepackage{amsthm}

\theoremstyle{plain}

\NewDocumentEnvironment{exercise}{m}{
    \newtheorem*{ex#1}{Exercise #1}
    \begin{ex#1}
}{
    \end{ex#1}
}

\begin{document}

\begin{exercise}{1.2.1}
Statement
\end{exercise}

\begin{proof}
Cuz I said so.
\end{proof}

\end{document}

Or to achieve the same result with a single environment where the "Statement" is the second argument, and the proof goes in the middle:

\documentclass[12pt]{article}

\usepackage{xparse}
\usepackage{amsthm}

\theoremstyle{plain}

\NewDocumentEnvironment{exercise}{mm}{
    \newtheorem*{ex#1}{Exercise #1}
    \begin{ex#1}{#2}
        \begin{proof}
}{
        \end{proof}
    \end{ex#1}
}

\begin{document}

\begin{exercise}{1.2.1}{Statement}
Proof here.
\end{exercise}

\end{document}

You can specify the style further using the \newtheoremstyle command from amsthm if need be. (Feel free to ask if you need help with that.)

2
  • I'd like to use some exercise package if it's possible. I actually use an exercise template like the one you have posted, but I'd like to typeset the exercises with a package intended to do so. Apr 7, 2022 at 21:37
  • @SebastianMolina I've edited the answer to give a similar solution using the xsim package.
    – frabjous
    Apr 8, 2022 at 0:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .