# Revision history [back]

### Sage code appears in different places on different compiles

Hello!

I write things like exams for math classes, and like to use sagetex to create random problems and the appropriate solutions (for multiple choice exams). Everything with sagetex works fine in terms of the installation (using it on a chromebook, and I have sage fully installed and synced up with the local latex installation). I compile the latex code by doing a pdflatex, then sagetex, then pdflatex again.

The problem I seem to have is that the sagetex code locations seem to appear in the wrong places, and it moves around each time I compile the same code. Thus I will get equations that are suppose to be the questions placed in answers and vice versa, even across different questions.

I've been trying to figure out what the issue is, but haven't had much luck. I originally used code to randomize locations of things, and set the seed to update slowly enough that it wouldn't change over while it was compiling to make sure stuff lined up (and most of it did). Then to try a failsafe I fixed the seed to a static value so that it always locates things to the same places every time, and the problem still persists.

The odd thing is it persists in a totally non-uniform way. Sometimes I will compile the code and everything is where it should be. Sometimes everything after the 10th sage entry is jumbled. Sometimes just the last couple.

When it fails, it always completely fails after a certain point, and what it 'looks' like is the case is that it skips some of the sage input and moves ahead to future input (so that the last few sage inputs are left as ??? after the second pdflatex run). So it works fine up to a point, then jumbles things by skipping seemingly random sagetex code.

So. Any idea what gives? My sample code is sort of involved, so I can post it if you guys want but it involves a long latex file and a rather significant cls file, so I didn't want to post it all here (I can maybe post a link to the files if it helps).

Thanks for the help, I've been trying to figure this quirk out for months with no luck.

PS A MWE doesn't really work because this seems to be a problem that crops up more reliably the longer the example is. Here are the files that seem to (fairly reliably) recreate the problem...

CLS file: HERE MWE: HERE