Skip to content

Instantly share code, notes, and snippets.

@n01r
Created June 16, 2020 15:19
Show Gist options
  • Save n01r/36bfe07dbe1746e927ebb7b8707135eb to your computer and use it in GitHub Desktop.
Save n01r/36bfe07dbe1746e927ebb7b8707135eb to your computer and use it in GitHub Desktop.
Find non-ASCII characters in *.bib file that make LaTeX crash

How to find non-ASCII characters in your bibliography if they make your LaTeX compilation fail

Note: I found the answer here: https://stackoverflow.com/questions/13596531/how-to-search-for-non-ascii-characters-with-bash-tools

1. Noticing that you have this problem

If you find the following error message in your editor it is very likely that you have this problem:

Undefined control sequence. \printbibliography[notkeyword=myPaper, title={References}, heading=bibintoc, resetnumbers=true]

I am using biber and if LaTeX complains that it does not know the command \printbibliography there is something wrong with the *.bib file.

2. Define a command line function that scans for non-ASCII characters

nonascii() { LANG=C grep --color=always '[^ -~]\+'; }

Type this into your terminal and then test it like so:

printf 'ŨTF8\n' | nonascii

Now the first U-like character should appear in red.

3. Start combing through your bibliography file

Not all fields in the bibtex entries are also shown in the final bibliography. The title and author fields are good places to start.

cat references.bib | nonascii | grep "title ="
@n01r
Copy link
Author

n01r commented Dec 7, 2021

Or use a text editor and search with CTRL+F, activate also the RegEx Button (which has to be available for this to work) and search for [^\x00-\x7F].

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