Skip to content

Bibtex fails on common strings that can be variables on latex #78

Open

Description

@ifenghm

I had an issue where the download fails upon certain papers with month abbreviation. adding an option to parse common strings not as variables fixes it.

python -m PyPaperBot --query "delve" --min-year 2024 --dwn-dir ./delvepapers --scholar-pages 1
                                                                                                                                                  

⎿ Traceback (most recent call last):
File "/Users/feng/theoreticalcs/automataproject/.venv/lib/python3.12/site-packages/bibtexparser/bibdatabase.py", line 105, in expand_string
self.strings[name])

in Paper.py, these below changes will fix the problem.

        parser = bibtexparser.bparser.BibTexParser(common_strings=True)
         x = bibtexparser.loads(bibtex, parser=parser)

I want to push to the DEV branch as listed in the README.md but do not have push access; I can push to a fork if necessary, thank you.

Activity

  1. rimerinos commented on May 15, 2026

    @rimerinos

    I've ran into this exact issue, and although enabling common_strings for the parser does help the majority of cases, any non abbreviated months or months using different non 3 character abbreviations (such as sept for september) produce download failures again.

      File "./venv/lib/python3.12/site-packages/bibtexparser/bibdatabase.py", line 105, in expand_string
        self.strings[name])
        ~~~~~~~~~~~~^^^^^^
    KeyError: 'july'
    

    so to add on to your solution, I propose to shorten months to their first 3 characters before parsing them:

    pattern = r'(month\s*=\s*[\{\"]?)([A-Za-z]{3})[A-Za-z]*([\}\"]?)'
    bibtex = re.sub(pattern, r'\1\2\3', bibtex, flags=re.IGNORECASE)
    parser = bibtexparser.bparser.BibTexParser(common_strings=True)
    x = bibtexparser.loads(bibtex, parser=parser)
    

    I'll write both of our suggested changes into a new branch and I'll submit a pull request to solve the problem, but the repository seems to be mostly abandoned so forking the project is not a bad idea either

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions