On Thursday, May 14, 2020 at 12:14:36 PM UTC+1, Dima Pasechnik wrote: > > Hi David, > > On Wed, May 13, 2020 at 11:53 PM David Sevilla <> wrote: > > > Hi, I have been trying to use SageTeX in a document where I also use the > fancyhdr package, and I am not able to put Sage computations in the header > (or the footer). A minimal example follows. > > > > \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} > > > > > > After pdflatex, and running sage on the .sagetex.sage file, I get the > following 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' > > > > As you can see, "inline formula 0" was generated properly and the > processing ended there; that line (14) is the \maketitle. On the other > hand, inline formula 1 was not resolved because the file was already closed > (note the "Sage processing complete" before); the line 17 where it arose is > the \end{document}. After the second pdflatex, the Sage result appears > correctly in the title but "??" appears instead in the header, and I get > the: > > > > LaTeX Warning: Reference `@sageinline1' on page 1 undefined on input > line 17. > > > > > > > > Any suggestions on how to combine these two packages is very welcome, or > at least an explanation of this behaviour (why did Sage think that there > was nothing else to do after formula 0???). I cannot think of a workaround, > other than avoiding fancyhdr and searching for smart LaTeX to be able to > put things into place. > > > > Thanks for the record. A hotfix is to edit > /usr/lib/python2.7/dist-packages/sagetex.py > and replace the line 285, which is > > self.souttmp.close() > > with the following 2 lines: > > self.souttmp.flush() > os.fsync(self.souttmp.fileno()) > > Then it should work. The problem is that fancyhdr does some kind of > postprocessing, after sagetex thinks all is done. > Indeed, with this fix I see running sage with the pdflatex output of > your file hh.tex > > $ sage hh.sagetex.sage > Processing Sage code for hh.tex... > Code block (line 7) begin...end > Inline formula 0 (line 14) > Sage processing complete. Run LaTeX on hh.tex again. > Inline formula 1 (line 17) > > This should be of course properly fixed - please open an issue on > https://github.com/sagemath/sagetex >
I have opened https://github.com/sagemath/sagetex/issues/47 to fix this proprely. -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-support/8577c067-6367-473e-9ce5-a5a277a5dfd1%40googlegroups.com.