4

I'm trying to compile one main file of exercises where each exercise is a standalone TeX file. standalone is the perfect package for that but it lacks the customizability to choose a specific part of the subfile to be added.

In this case, I'm using documentclass{exam} which takes individual questions in \question and enumerates them. The problem with the standaloneis when each exercise is a standalone TeX file, combining them assigns each of the exercises in the main file the number 1., they won't enumerate.

My goal main file:

\documentclass{exam}
\usepackage{standalone} %or any suitable package

\begin{document}
  \begin{questions}
     \input{exercise1}
     \input{exercise2}
     \input{exercise3}
  \end{questions}
\end{document}

A sample exercise file:

% exercise1.tex
\documentclass{exam}
\begin{document}
   \begin{questions}
      \question A sample question
        \begin{solution}
            Solution Here
        \end{solution}
   \end{questions}
\end{document}

Since this approach includes \begin{questions} field to the main file it does not work. It ends up with two nested \begin{questions}

So is there a package to include what's inside a specific tag or environment (question env. in my case) or another workaround for this. Thanks!

1 Answer 1

3

This could work:

\documentclass{exam}
\usepackage{standalone} %or any suitable package

\begin{document}
  \begin{questions}
  \begingroup
     \renewenvironment{questions}{}{}
     \input{exercise1}
     \input{exercise1}
     \input{exercise1}
  \endgroup
  \end{questions}
\end{document}
3
  • Welcome... Happy TeXing!
    – koleygr
    Mar 4, 2019 at 17:18
  • 1
    The \renewenvironment and \inputs should all be enclosed in { }. Without this, the outer \end{questions} has no effect and the exam class' "addpoints" option breaks. Jan 2, 2021 at 1:59
  • fixed @user1476176 ... Thanks
    – koleygr
    Jan 2, 2021 at 7:32

You must log in to answer this question.

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