Recently I got to list a bunch of BibTeX references in a document. The BibTeX entries were fetched from Crossref API and they all include a DOI field. When I tried to compile the document, an underscore (_) in one BibTeX entry caused the compiler to complain about using subscript in a non-math environment:
Missing $ inserted.
...
I've inserted a begin-math/end-math symbol since I think you left one out. Proceed, with fingers crossed.
I found in an Overleaf Guide that this might be caused by an underscore in the URL field and could be fixed by \usepackage{url}
. This didn’t work. So I thought if there’s a URL package there could also be a DOI package, too. It turned out to be true. \usepackage{doi}
fixed my problem. In the package page, it even mentions specifically it’s meant to fix the troublesome characters like an underscore.