/usr/lib/python2.7/dist-packages/sagenb/notebook/sagetex.py is in python-sagenb 1.0.1+ds1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # -*- coding: utf-8 -*
import os
from .notebook_object import notebook
def sagetex(filename, gen=True, **kwds):
"""
Turn a latex document into an interactive notebook server.
THIS IS ONLY A PROOF-of-CONCEPT.
EXAMPLES::
sage: sagetex('foo.tex') # not tested
[pops up web browser with live version of foo.tex.]
"""
if not os.path.exists(filename):
raise IOError("No such file: '%s'" % filename)
if not filename.endswith('.tex'):
raise ValueError("File must be a latex file (end in .tex): '%s'" % filename)
if not '\\document' in open(filename).read():
raise ValueError("File must be a latex file (contain \\document...): '%s'" % filename)
if gen:
os.system('latex2html -no_images %s'%filename)
base = os.path.splitext(os.path.split(filename)[1])[0]
absp = os.path.abspath(filename)
path = os.path.splitext(absp)[0]
for F in os.listdir(base):
fn = os.path.join(base, F)
if not fn.endswith('.html'):
continue
r = open(fn).read()
r = r.replace('<PRE>', '<div class="verbatim"><pre>')
r = r.replace('</PRE>', '</pre></div>')
open(fn,'w').write(r)
notebook(sagetex_path=path, start_path="/sagetex/index.html", **kwds)
|