Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dimpase opened this issue May 14, 2020 · 3 comments
Open

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

dimpase opened this issue May 14, 2020 · 3 comments

Comments

@dimpase
Copy link
Member

dimpase commented May 14, 2020

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.

@dimpase
Copy link
Member Author

dimpase commented May 14, 2020

The problem is, however, in sagetex LaTeX class, in the part that generates the *.sage file. For the example above one gets

_st_ = sagetex.SageTeXProcessor('hh', version='2019/11/14 v3.4', version_check=True)
_st_.current_tex_line = 7
_st_.blockbegin()
try:
 n = 1
except:
 _st_.goboom(9)
_st_.blockend()
try:
 _st_.current_tex_line = 14
 _st_.inline(0, latex(n))
except:
 _st_.goboom(14)
_st_.endofdoc()
try:
 _st_.current_tex_line = 17
 _st_.inline(1, latex(n))
except:
 _st_.goboom(17)

and so endofdoc() is issued too early.

@dimpase
Copy link
Member Author

dimpase commented May 18, 2020

@dandrake - perhaps you could quickly see how to fix this?

@jocelynetienne
Copy link

I have the same problem when using sage in a tikzpicture.
Fix suggested works distributed 2020/08/12 v3.5 version of sagetex.py if applying at both line 264 and line 285.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants