Open inoue0426 opened 1 year ago
Hi,
this is a result of the regex search not finding any linked bibliography files in the tex file. This can be due to other commands being used to specify the bibliography files, e.g., \addbibresource
instead of \bibliography
.
One way out is to specify to use the BBL file directly using the --bbl
option explicitly. latexdiffcite file -h
is a bit ambiguous here, as the default is actually to not look for one, but setting it to the working directory should work.
The (in my opinion) better alternative is to fix the latexdiffcite.py
script to simply look for those other commands. Here's what I changed in my local version to make everything work again, including with multiple files:
@@ -478,8 +478,9 @@ def read_bibfile(oldnew):
'''Reads contents of bibtex files'''
# get bibtex file
- bibarg = find_bibliography_arg(getattr(FileContents, 'tex_' + oldnew))
- find_bibfiles(bibarg, oldnew)
+ bibargs = find_bibliography_args(getattr(FileContents, 'tex_' + oldnew))
+ for bibarg in bibargs:
+ find_bibfiles(bibarg, oldnew)
bibfiles = getattr(Files, 'bib_' + oldnew + '_path')
# read bibtex files
@@ -489,13 +490,16 @@ def read_bibfile(oldnew):
getattr(FileContents, 'bib_' + oldnew).append(f.read())
-def find_bibliography_arg(s):
+def find_bibliography_args(s):
'''Looks through string for \bibliography{} command and retrieves the argument'''
+ bibfiles = []
log.debug('searching for \\bibliography{} entry in tex file')
- bibfile = re.search(r'$[^%]*\\bibliography\s*{(.*?)}', s, flags=re.M).group(1)
- log.debug('bibliography argument found: %s', bibfile)
- return bibfile
+ bibfiles.extend(re.findall(r'^\s*\\bibliography\s*{(.*?)}', s, flags=re.M))
+ log.debug('searching for \\addbibresource{} entries in tex file')
+ bibfiles.extend(re.findall(r'^\s*\\addbibresource\s*{(.*?)}', s, flags=re.M))
+ log.debug('bibliography arguments found: %s', str(bibfiles))
+ return bibfiles
Hope that helps! Happy to submit a PR if it's welcome @twilsonco @cmeeren .
Cheers
Thanks @tobiscode,
I agree the best approach is to modify the source to check for all applicable bibliography commands.
I’ll be using this tool again for some paper revisions soon, and will update things then.
A PR would be welcome since you already have the changes working.
Thanks!
Hi,
I got this error, maybe related to parse error.
Do you know how to fix this?