0

I'm making a problem set for a math course in latex. Each problem has a hint and an answer, both should be found at the very end of the document. But for easy editing I want to be able to type problems/hints/answers in the same place in the source file, I want to be able to write something like

\problem{problem text}{hint text}{answer text}

I have a setup like this that is somewhat working - it writes everything in the hints/answers parameters into separate files and then it inputs those file at the end:

\documentclass{article}

% Counters for problems and chapters \newcounter{problem} \setcounter{problem}{0} \newcounter{chap} \setcounter{chap}{1}

% Open files for hints and answers \newwrite\hintsfile \immediate\openout\hintsfile=hints.tex \newwrite\ansfile \immediate\openout\ansfile=answers.tex

% Custom problem command \newcommand{\problem}[3]{% \addtocounter{problem}{1}% \noindent\llap{\textbf{\thechap.\theproblem.} }#1 \ \vspace{1mm}

% Write to hint file
\immediate\write\hintsfile{\string\noindent\string\llap{\string\textbf{\thechap.\theproblem.}}}    
\immediate\write\hintsfile{#2 \par}

% Write to answer file
\immediate\write\ansfile{\string\noindent\string\llap{\string\textbf{\thechap.\theproblem.}}}    
\immediate\write\ansfile{#3 \par}   

}

\begin{document} \section{Problems} \problem{Problem 1 Text}{Hint 1 Text}{Answer 1 Text} Text between problems\ \problem{Problem 2 Text}{Hint 2 Text}{Answer 2 Text} \problem{Problem 3 Text}{Hint 3 Text}{Answer 3 Text}

\immediate\closeout\hintsfile \immediate\closeout\ansfile

\section{Hints} \input{hints}

\section{Answers} \input{answers}

\end{document}

The current problem is that I want to be able to use the \enumerate environment inside the problems/hints/answers, but it currently gives me an error (probably due to some parsing error when I'm trying to pass a whole math problem as a parameter).

What is the best way to do this?

Jompa
  • 75

0 Answers0