# Is there a way to input part of a file that includes sagetex?

I am trying to build a sort of jumbling program for Tex Files. Specifically I want to randomly order problems on quizzes/exams that are generated.

I have gotten most of the work done, but I am left with trying to figure out how to make a clean implementation of inputting the questions themselves. Currently my program seems to work fine as long as I use the /input command and have each question in it's own file, however it would be much nicer if I could have one file with tags or some sort of environment for each problem, then have the master file call the problems by their tags (or environment inputs or whatever)

I have tried to use the CatchFileBetweenTags package, which seems to work fine with regular Tex, but doesn't seem to work once I try to include any sagetex code in the file to catch. Strangely the sagetex code works fine with just the /input command, but catchfilebetweentags doesn't seem to like it. It's possible that I am also not understanding some bit of syntax correctly, as the documentation for catchfilebetweentags seems to be somewhat difficult to parse for me.

So, I'm wondering if there is any way to just use input on only sections of a file instead of the whole thing?

• You know there are packages already written which do this for you? Any particular reason you are rolling your own? The answer to your question is, I believe, 'No.' \input inputs files. You can set up your main file so it ignores bits of the file you input, whereas another main file would read those bits. Or you can have it ignore, say, the preamble or something. But none of that is functionality provided by \input itself. \input is exactly like copy-pasting the entire file into your document at that point. That's all. – cfr Aug 1 '15 at 23:14
• Can you point me to any of the other randomizing packages? Most anything that doesn't work as a direct copy/paste doesn't seem to play well with Sagetex. I have found a few packages that (in theory) do what I want for any number of tasks I'm after, only to find that Sagetex makes it break. A premade package would be wonderful. This started, however, as an exercise to learn how to do deeper things with Latex, and has been ... growing a bit out of hand at this point heh. – Jason Aug 1 '15 at 23:17
• I don't know how these work with Sagetex. However: examdesign, exams and the exam topic. I've used exams though not for quite a while but it worked well for me when I did use it. As I say, though, I can't speak to compatibility with Sagetex. I'm not sure about examdesign but exams lets you have everything in one file for sure, while still randomising things. – cfr Aug 1 '15 at 23:23
• Those are pretty neat, thanks for the links. Unfortunately I can't use most of them. My department has an unfortunately inflexible document class that is mandatory for all exams. Which is why I started doing this work with packages and macros to try and shoehorn in some flexibility to the document class. Most of the stuff you linked are document classes, and the few packages and macros in there that relate to randomization only randomize answer choice order (which I've long since macroed easily enough), not question order. Still, I'll bookmark the Exam Topic for future use, thanks! – Jason Aug 1 '15 at 23:36
• That's too bad. I used to use exams to produce multiple versions of examples with the same questions in different, random orders, for example, and it all worked very smoothly. Anyway, in that case, I think we need a minimal document we can use to reproduce the problem and a link for your department's class file. Otherwise, it will be pretty difficult to make suitable suggestions. Plain \input can't do what you want but if you can give people enough to work with, somebody can likely suggest alternative methods. – cfr Aug 1 '15 at 23:47