0

I create physics exercises and at the end of each exercise I give short numerical answers which I want to be on the right, to maintain the numbering of the questions and to be bold.

Τhe important thing is that I want to be able to hide it when I want (in case of examinations). Τo do this I use the very useful tips from my previous question

Comment out lines without using % and comment enviroment

I've got the code.

\newif\ifprolog
\long\def\startprolog#1\stopprolog{%
\ifprolog
\par
\begingroup
\let\\\par
\color{red}\small #1
\par\medskip
\endgroup
\fi}
\prologtrue

and I try to create answers to every exercise with the command to appear and disappear by choosing \answerstrue

\documentclass[b5paper,10pt]{book} 
\usepackage[inline]{enumitem}
\newtheorem{exercise}{}[chapter]%[chapter] %{Άσκηση}%[numberby]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%
\newif\ifanswers
\long\def\startanswers #1 \stopanswers{%
\ifanswers
\par
\begingroup
\let \\ \par
\begin{flushright}
[\textbf{\small Answers: \, #1}]
\end{flushright}
\par\medskip
\endgroup
\fi}
\answerstrue    % is to show or not the answers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\chapter{physics}

\begin{exercise} 
here is the exercise ...
Αnswer the questions:
\begin{enumerate}
  \item quation 1
  \item quation 2
  \item quation 3
  \item quation 4
\end{enumerate}
%%%%%%%%%%%%%%%%%%%%%
\startanswers
 \begin{enumerate*}
  \item % here there is no numerical answer because the question was theoretical
  \item $\sqrt{2}$
  \item $5/3$
  \item $\frac{1}{2}$
 \end{enumerate*}
\stopanswers
 %%%%%%%%%%%%%%%%%%%%%
\end{exercise}
\end{document}

enter image description here

Τhe problem is when I do not import something after \item (because the question was theoretical)

\startanswers
 \begin{enumerate*}
  \item % here there is no numerical answer because the question was theoretical

i take error when a run the .tex file.

enter image description here


My quastion: Ηow can I rid of the error or if you have a more practical idea to get the answers out of a printable file


enter link description here

1 Answer 1

1

As you use the package enumitem, you can use the keys start= and resume/resume*:

\documentclass[b5paper,10pt]{book} 
\usepackage[inline]{enumitem}
\newtheorem{exercise}{}[chapter]%[chapter] %{Άσκηση}%[numberby]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%
\newif\ifanswers
\long\def\startanswers #1 \stopanswers{%
\ifanswers
\par
\begingroup
\let \\ \par
\begin{flushright}
[\textbf{\small Answers: \, #1}]
\end{flushright}
\par\medskip
\endgroup
\fi}
\answerstrue    % is to show or not the answers
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\chapter{physics}

\begin{exercise} 
here is the exercise ...
Answer the questions:
\begin{enumerate}
  \item theoretical question 1
  \item question 2
  \item question 3
  \item question 4
  \item question 5
  \item theoretical question 6
  \item question 7
  \item question 8
\end{enumerate}
%%%%%%%%%%%%%%%%%%%%%
\startanswers
 \begin{enumerate*}[start=2]%
  \item $\sqrt{2}$
  \item $\frac{5}{3}$
  \item $\frac{1}{2}$
  \item $(3,4,5)$
 \end{enumerate*}
 \begin{enumerate*}[start=7, resume*]%
  \item $\left(\frac{a+b}{2}\right)^2-\left(\frac{a-b}{2}\right)^2$
  \item $\frac{n^2+n}{2}$
 \end{enumerate*}
\stopanswers
 %%%%%%%%%%%%%%%%%%%%%
\end{exercise}
\end{document}

By the way:

You can probably use the comment package for turning environments into comments:

\documentclass[b5paper,10pt]{book} 
\usepackage[inline]{enumitem}
\newtheorem{exercise}{}[chapter]%[chapter] %{Άσκηση}%[numberby]
\usepackage{comment}

\specialcomment{answers}{%
  \begingroup
  \let\\=\par
  \flushright
  [\bfseries\small\selectfont Answers: \, \ignorespaces
}{\mdseries\selectfont]\par\medskip\endgroup\ignorespacesafterend}%
%
% Toggle answers on/off via commenting/uncommenting
% the following line:
%\excludecomment{answers}

\begin{document}
\chapter{physics}

\begin{exercise} 
here is the exercise ...
Answer the questions:
\begin{enumerate}
  \item theoretical question 1
  \item question 2
  \item question 3
  \item question 4
  \item question 5
  \item theoretical question 6
  \item question 7
  \item question 8
\end{enumerate}
%%%%%%%%%%%%%%%%%%%%%
\begin{answers}
  \begin{enumerate*}[start=2]%
    \item $\sqrt{2}$
    \item $\frac{5}{3}$
    \item $\frac{1}{2}$
    \item $(3,4,5)$
  \end{enumerate*}
  \begin{enumerate*}[start=7, resume*]%
    \item $\left(\frac{a+b}{2}\right)^2-\left(\frac{a-b}{2}\right)^2$
    \item $\frac{n^2+n}{2}$
  \end{enumerate*}
\end{answers}
%%%%%%%%%%%%%%%%%%%%%
\end{exercise}
\end{document}

You must log in to answer this question.

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