A simple LaTeX package that conditionally renders questions and solutions in pretty boxes.
Problems and problem solutions can be added to the same document and toggled with the boolean optional params problems
and solutions
.
Provides numbered problem
and solution
environments.
Both environemnts take a question title as a parameter.
Also provides \problemsec{}
and \solutionsec{}
commands that create sections divided by bars within the problem and solution boxes; each command takes a subsection heading as a parameter.
For example, the following:
\documentclass[10pt]{article}
\usepackage{minted}
\usepackage[problems,solutions]{questions}
% Change this to:
% \usepackage[problems]{questions} % for problem-only rendering
% \usepackage[solutions]{questions} % for solution-only rendering
\begin{document}
\begin{problem}[Greeting]
Write a function called \mintinline{python}{hello} that takes a name
(\mintinline{python}{str}) as a parameter.
The function should print ``Hello, [name]!''
\problemsec{For Example:}
\begin{minted}{python}
>>> hello("James")
# Hello, James!
\end{minted}
\end{problem}
\begin{solution}[Greeting]
\begin{minted}{python}
def hello(name: str):
print(f"Hello, {name}!")
\end{minted}
\solutionsec{Explanation:}
f-strings (strings that start with the letter f) can be used to fill placeholders
(surrounded by curly braces) with variables.
\end{solution}
\end{document}
Would produce:
Loading the questions package as \usepackage[problems]{questions}
would only render the problems.
Conversely, loading \usepackage[solutions]{questions}
would only render the solutions.
Note: I have had some issues with indentation – Make sure the \begin
and \end
commands for the problem and solution environments are NOT indented.