I would like to create variables to hold strings like f(x)=3x+1 to be inputted into an exam questions.
I can create variables like \funA, \funB, … et cetera. The problem is how do I reference them using A, B, … et cetera.
\documentclass[12pt]{exam}
% conditional statements
\usepackage{xifthen}
\newcommand{\exam}{A}
\newcommand{\funA}{$s(t) = 12t^2 -7t + 16$}
\newcommand{\funB}{$s(t) = 16t^2 +3t + 10$}
\newcommand{\funC}{$s(t) = 12t^2 + t + 10.$}
\begin{document}
\begin{questions}
\question % I would like \fun\exam to return \funA when \exam = a. Sadly it doesn't
The position of an object moving along a straight line is given by \fun\exam. Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
\question % this works but is a lot to write when accommodating 10 stored functions
\ifthenelse{\equal{\exam}{A}}
{
\newcommand{\function}{$s(t) = 12t^2 -7t + 16.$}
}
{
\ifthenelse{\equal{\exam}{B}}
{
\newcommand{\function}{$s(t) = 16t^2 +3t + 10.$}
}
{
\newcommand{\function}{$s(t) = 12t^2 + t + 10.$}
}
}
The position of an object moving along a straight line is given by \function\ Find the average velocity of the object over the interval $[1,1+h]$ where $h>0$ is a real number.
\end{questions}
\end{document}
\csname fun\exam\endcsname