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

latexdiff cannot find \begin{document} \end{document} pair because it does not see the whole tempfiles #3

Closed
ftilmann opened this issue Feb 24, 2017 · 4 comments

Comments

@ftilmann
Copy link

When trying to run latexdiffcite I get the following error:

> latexdiffcite file test1.tex test2.tex
processing old revision
processing new revision
running latexdiff /tmp/tmp_old_yrB3JS.tex /tmp/tmp_new_IhZx8l.tex
Traceback (most recent call last):
  File "/home/tilmann/.local/bin/latexdiffcite", line 11, in <module>
    sys.exit(main())
  File "/home/tilmann/.local/lib/python2.7/site-packages/latexdiffcite/latexdiffcite.py", line 163, in main
    run(parsed_args)
  File "/home/tilmann/.local/lib/python2.7/site-packages/latexdiffcite/latexdiffcite.py", line 298, in run
    run_latexdiff(Files.tex_old_tmp_path, Files.tex_new_tmp_path)
  File "/home/tilmann/.local/lib/python2.7/site-packages/latexdiffcite/latexdiffcite.py", line 818, in run_latexdiff
    raise ValueError('latexdiff returned with code {}. Error from latexdiff:\n\n'.format(ret_code) + stderr)
ValueError: latexdiff returned with code 255. Error from latexdiff:

\\begin\{document\} and \\end\{document\} not in the correct order or not present as a pair. at /home/tilmann/bin/latexdiff line 1531.

I tried creating a log file but there did not seem to be anything amiss, so I won't post. Bizarrely, if I run interactively latexdiff /tmp/tmp_old_yrB3JS.tex /tmp/tmp_new_IhZx8l.tex, it works! (for this test I had temporally changed latexdiffcite so that it would not delete the temporary files).
I did some more debugging and somehow this problem appears to be related to the file size; for really short files it worked, but when adding material, it breaks; I verified by experimentation that it is not any particular line that causes the problem, but it seems more of a threshold value in file size. The file size of the file, where it fails, is 3938 characters, but my experimentation did not go as far as to get an exact value for the threshold, or check whether it is indeed the number of characters that matters or maybe lines or some other measure of size. (python --version returns 2.7.6). I realise this all might not be enough for you to reproduce the error, so please let me know what info you need.

@cmeeren
Copy link
Collaborator

cmeeren commented Feb 25, 2017

Sorry, I have absolutely no idea why this fails. latexdiffcite simply calls latexdiff [tempfile1] [tempfile2] (see run_latexdiff()), so I don't see why the result would be any different than calling latexdiff manually on the temp files.

The only thing I can think of is if you have specified some latexdiff_args in latexdiffcite's config.

@ftilmann
Copy link
Author

OK, I found what the problem is. At the moment latexdiff is run, the temporary files are still open, and the last part of the write is still in the buffer rather than in the filesystem. There is probably some OS dependence in the way the buffer operates, which would explain why you did not see this. The fix is easy. in latexdiffcite.py in routine write_tex_to_temp force the buffer to flush:

61> diff latexdiffcite.py.orig latexdiffcite.py
802c802,804
<     getattr(Files, 'tex_' + oldnew + '_tmp_hndl').write(getattr(FileContents, 'tex_' + oldnew).encode('utf-8'))
---
>     fh=getattr(Files, 'tex_' + oldnew + '_tmp_hndl')
>     fh.write(getattr(FileContents, 'tex_' + oldnew).encode('utf-8'))
>     fh.flush()

(sorry for not submitting this as a proper pull request, but I just installed latexdiffcite via pip, and have not cloned or forked the git repository - I hope that you can add to master in spite of not developing latexdiffcite any further)

@ftilmann ftilmann changed the title latexdiff cannot find \begin{document} \end{document} pair latexdiff cannot find \begin{document} \end{document} pair because it does not see the whole tempfiles Feb 26, 2017
@cmeeren
Copy link
Collaborator

cmeeren commented Feb 26, 2017

New version released, try now :)

@ftilmann
Copy link
Author

Thanks for the fast response, yes this works now.

twilsonco added a commit that referenced this issue Sep 3, 2024
)

* add tests for commands inside pre- and postnotes

* fix #2

* fix doc links

* fix docs

* update some testenvs to python3.5

* Bump version: 1.0.4 → 1.0.5

* use 2.7 instead of 3.5 for general test envs

* remove coverage tests on travis to avoid fails

* Update changelog

* Fix #3

* Update CHANGELOG.rst

* Bump version: 1.0.5 ? 1.0.6

* Update README.rst

* Switched broken pypip.in badges to shields.io (#8)

* Fix crash when no authors present

Updated `make_author_year_tokens_from_bib()` so that bib items that don't have authors (e.g. books with editor lists) are still handled correctly. Also moved some re.compile() calls outside the loop for efficiency.

* print useful errors for missing author/year data in bib item

* scan for \addbibresource & allow mutliple files

* fix run_latexdiff command arguments and error capturing

* fix invalid escape sequence (deprecated in Python 3.12) and other minor style fixes

---------

Co-authored-by: Christer van der Meeren <[email protected]>
Co-authored-by: Christer van der Meeren <[email protected]>
Co-authored-by: Michael Overmeyer <[email protected]>
Co-authored-by: Tim Wilson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants