Skip to content

cannot put \sage{..} into fancy headers etc. #47

@dimpase

Description

@dimpase

As reported on sage-support

\documentclass{article}
\usepackage{sagetex}
\usepackage{fancyhdr}

\begin{document}

\begin{sagesilent}
n = 1
\end{sagesilent}

\fancyhead[R]{$\sage{n}$}
\title
{$\sage{n}$}
\maketitle
\thispagestyle{fancy}

\end{document}

breaks sagetex with a funny error:

Processing Sage code for test02.tex...
Code block (line 7) begin...end
Inline formula 0 (line 14)
Sage processing complete. Run LaTeX on test02.tex again.
Inline formula 1 (line 17)

**** Error in Sage code on line 17 of test02.tex! Traceback follows.
Traceback (most recent call last):
  File "test02.sagetex.sage.py", line 24, in <module>
    _st_.inline(_sage_const_1 , latex(n))
  File "/usr/lib/python2.7/dist-packages/sagetex.py", line 121, in inline
    '}{{%\n' + s.rstrip() + '}{}{}{}{}}\n')
ValueError: I/O operation on closed file

**** Running Sage on test02.sage failed! Fix test02.tex and try again.
Traceback (most recent call last):
  File "test02.sagetex.sage.py", line 26, in <module>
    _st_.goboom(_sage_const_17 )
  File "/usr/lib/python2.7/dist-packages/sagetex.py", line 264, in goboom
    os.remove(self.filename + '.sagetex.sout.tmp')
OSError: [Errno 2] No such file or directory: 'test02.sagetex.sout.tmp'

Basically, what happends is that sagetex closes sout.tmp too soon, while there is still something to be done. Namely, a hotfix is to replace self.souttmp.close() in line 285 of (generated) sagetex.py
with

   self.souttmp.flush()
    os.fsync(self.souttmp.fileno())

This results in the example above working:

Processing Sage code for hh.tex...
Code block (line 7) begin...end
Inline formula 0 (line 14)
Sage processing complete. Run LaTeX on test02.tex again.
Inline formula 1 (line 17)

So, surely enough, "complete" is not quite complete at this point.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions