# Can sagetex generate tex files?

I'm writing a latex document that will eventually need to be compiled on a machine that does not have sage on it. However, right now I'm using sagetex to write this document. I'm curious if it is somehow possible to generate a latex document with all of the \sage invocations replaced with the corresponding latex code.

edit retag close merge delete

Yes, I did it just to convince myself it's possible. It's extremely tedious and I would discourage it. It involved creating a string that will be the contents of the tex file. So in the sagesilent part of the tex document I'd have: f = open(r"Answers.tex",'w') f.write(r"\documentclass[a4paper,addpoints,12point]{exam}") f.write("\n") f.write(r"\usepackage{amsmath, amsfonts, amssymb}") f.write("\n") f.write(r"\usepackage{xcolor}") and so on.

( 2020-08-31 17:50:34 +0100 )edit

Sort by » oldest newest most voted

The latex document you need to provide is the same you use. You only need to also provide the .sout file (containing the results of the \sage invocations), the image folder generated by Sage if any and possibly the sagetex.sty file.

more

Since you didn't provide an example I'm not 100% sure what you want to do. Anyway you should have a look at jinja:

https://pypi.org/project/Jinja2/

more