Sure.  The goal is to create a LaTeX package for randomly generated exams. 
 It should let you do something like this:

\documentclass{whatever}

% Create a whole bunch of exam problem construction methods, with this tool:
% \createproblem{name}{Sage setup code}{problem text with \sage calls in it}
% Example:
\createproblem{Derivative of a trig function}{
x = var('x')
f(x) = int(random()*10)%10*sin(x)+int(random()*10)%10*cos(x)
}{
Please differentiate the function $f(x)=\sage{f}$.
}
% Create as many problems as you like using that method.
% What each \createproblem{}{}{} command does is run a \sagesilent that 
does is the following:
% 1. Ensures that a global problem dictionary is defined; if allProblems 
isn't defined globally, do allProblems = {}
% 2. Constructs and stores a new problem object from the other two 
parameters, treated as Python strings, like this:
%       allProblems[r"""#1"""] = new Problem(r"""#2""", r"""#3""")
%       (let's say a problem object is just problem.initStr and 
problem.text, created as above)
% That's it for now.  So \createproblem{}{}{} just puts stuff into a big 
holding pen for later use.
% In fact, you could have your problem definitions stored in an entirely 
different .tex or .sty file,
% like \usepackage{hugecalcproblembank}, and it imports all those 
definitions in one giant pile.

\begin{document}

\title{Exam for Calculus I}
% etc etc

% Then you ask it to provide some random problems in some order:
\insertproblems{Derivative of a trig function, Slope of a tangent line to a 
polynomial, ...}
% This should do the following things:
% 1. Insert a \sagesilent that does the following things:
%     a. Treat the \insertproblems argument as a python string, using the 
r"""#1""" idiom from earlier
%     b. Split that string by commas, and look up the names in the 
dictionary, creating a resulting array
%     c. Randomly permute that array
%     d. Set resultString = ""
%     e. For each element in the array, do the following:
%         i. Initialize an empty dictionary, tmp = {}
%         ii. Run sage_eval('None',problem.initStr,locals=tmp) which stores 
the setup values in tmp
%         iii. Make a copy of problem.text, and for each occurrence of 
\sage{something} in it, do this:
%              - Set value = sage_eval(something,locals=tmp)
%              - Replace the \sage{something} with the computed value in 
the copy of problem.text
%         iv. resultString = resultString + "\begin{exercise}" + the copy 
of problem.text + "\end{exercise}"
% 2. Insert into the document all of this in one big whopping 
\sagestr{resultString}

\end{document}

% You could see how this could easily be extended to include solutions in 
addition to just problems,
% by adding a third parameter to \createproblem{}{}{}.
% You could see how it could be extended to include multiple versions of an 
exam in one document,
% by making something like \begin{copies}{5}...\end{copies} surrounding the 
whole exam.
% You could see how it could be extended to create documents that show off 
big problem banks,
% by making a command like \showproblemlibrary, that operates just like 
\insertproblems,
% except without choosing a subset and permuting; it just inserts a copy of 
every single problem.

But the key to all of this is being able to pass arguments from LaTeX 
commands to Sage routines, and that's the thing I can't do, because I can't 
even do something as simple as this:

\newcommand\addtosum[1]{\begin{sageblock}runningTotal += #1\end{sageblock}}

Now, if the goal were to simply generate random exam problems, and manage a 
giant database of them with manual cutting and pasting, and manually 
copying and permuting to make multiple versions, and so on, then all of 
these issues go away.  But my goal was to make something better than that, 
something that could store a problem database and select out and 
permute/repeat/etc. problems as needed.

Nathan


On Thursday, February 28, 2013 9:05:45 PM UTC-5, Dan Drake wrote:
>
> On Tue, 26 Feb 2013 at 04:50AM -0800, Nathan Carter wrote: 
> > The error is this: 
> > Runaway argument? 
> > \end {document} 
> > ! File ended while scanning use of \next. 
> > <inserted text> 
> >                 \par 
> > 
> > The same error occurs if I use \newcommand instead of \def.  Any tips on 
> > how I can get past the fact that I can't make commands that use 
> > SageTeX? 
>
> The problem here is that the sageblock environment and others are using 
> verbatim mode. Verbatim stuff is somewhat fragile and does not work well 
> with being called from other macros or environments. Fixing this would 
> be very tricky. 
>
> Can you elaborate on what you want to do? There might be another way 
> that doesn't require putting verbatim environments inside \newcommand or 
> similar. 
>
>
> Dan 
>
> -- 
> ---  Dan Drake 
> -----  http://math.pugetsound.edu/~ddrake 
> ------- 
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-edu" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-edu+unsubscr...@googlegroups.com.
To post to this group, send email to sage-edu@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-edu?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to