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-vc: generate .bbl files before calling latexdiff #127

Closed

Conversation

cousteaulecommandant
Copy link

@cousteaulecommandant cousteaulecommandant commented Nov 13, 2017

My git project does not track the .bbl files, which made sense at the time of creating it since those files are a product, not a source. As a result, latexdiff-vc fails to generate the bibliography and all references appear as [??].

This patch is a quick and ugly hack I made into the latexdiff-vc code (as downloaded from CTAN, which seems to be slightly different from the one here on github) that calls bibtex into $file1 and $file2 in order to generate the .bbl files before calling latexdiff. However it will probably need some work before being ready to be merged:

  • The code should probably check some conditions (such as $flatten and/or $run) before calling bibtex, but I was not sure what would be the way to go. Or maybe the whole block should be moved inside the if ( defined($flatten) ) parts where $olddir and $newdir are declared.
  • Maybe [pdf]latex should be called with -draftmode in order to improve the speed (then again, maybe this should be done on ALL calls to $CFG{LATEX} except the last one), but I don't know if this option is latex-specific and thus unsupported by other LaTeX compilers (then again, this is probably no different for --interactive=batchmode as well).
  • The documentation should be changed accordingly.
  • I included cd '$fileNpath'; in the latex-and-bibtex call I added because otherwise LaTeX complained about relative '\input's; not sure if this was the most elegant way to go but it Just Works™.
  • I modified the way $olddir and $newdir are generated, because I was having trouble when calling pdflatex on /tmp/me7swkOS1w/latexdiff-vc-HEAD~1/tex/main.tex because of the damned ~. On second thought, maybe having done cd to that directory first and then calling the latex and bibtex commands without the path would have been a better option. (I hope nobody uses this for comparing commits HEAD~2 and HEAD^2 for example... maybe this wasn't such a good idea after all.)

Please do not consider this as a ready-to-use PR but rather as a suggestion for improvement; as I said it was an ugly hack which will likely need some work and reviewing before being ready (in fact my original idea was to report this as a regular issue, but the patch seemed more convenient). Feel free to ditch the whole PR if you like the idea but prefer to rewrite it from scratch :)

I tested the program with my particular use case and it worked, but I didn't perform extensive testing (I did this in a couple of hours; I just learned about this software today... by the way, kudos to the creators!)

Generate .bbl files rather than relying on them being tracked by the VC software (which they shouldn't, because they're a product, not a source).
Additionally, "sanitize" $olddir and $newdir replacing all non-alphanumeric characters with `-` so that `latex` does not complain about e.g. `/tmp/xxx/HEAD~1/main.tex` containing a `~`.
@cousteaulecommandant
Copy link
Author

I have eventually built my own replacement shell script for latexdiff-git, with bibtex, and whole repository snapshot.
https://gist.github.com/cousteaulecommandant/d580f7fd966fa9ab143e919c01f01c61

Specifically, the "whole repository snapshot" feature is nice for my current project, since my "main.tex" is not in the top directory but inside tex/, while the images are in img/, and all .tex files refer to other files relatively to this tex/ directory, so I need to cd it before building.
The script will create a snapshot of the whole project rather than only the tex/ directory, and then cd to tex/ in the snapshot and call bibtex there.
Additionally, if second commit hash is omitted, it copies all the files rather than working on the actual project directory.

(The script is not a fully featured replacement for the current latexdiff-vc Perl script, but it could give some ideas.)

@briochemc
Copy link
Contributor

This looks like a good solution to my uneducated self for those, like me, who did not version-control their .bbl files. @ftilmann have you considered including this into latexdiff-vc?

@ftilmann
Copy link
Owner

Thank you for reminding me of this old suggestions. As the merge request still needed some work according to the OP I had not immediately tackled this and then it dropped off the radar. Unfortunately, I am again quite busy, and it will foreseeable be a few months until I can look into feature request issues.

@ftilmann
Copy link
Owner

Six and a half years later ... this idea is finally implemented. See man page for some additional advice on this.

@ftilmann ftilmann closed this Jul 14, 2024
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

Successfully merging this pull request may close these issues.

3 participants