# Compiler gives hundreds of "invalid character" suddenly

I am writing my latex document in TexMaker and suddenly in one of the thousands of compilations I make there is a error and I cant get rid of it. The error is:

! Text line contains an invalid character.


The "funny" thing is that the error is in line 2, where I haven't changed anything for weeks and it turn out that there are 100 errors like this in the compilation, each of them with 1 more invalid character. Starts with one and then every error gives +1 character more to the string. Weird.

Has anyone had this error before? It is clear that the error is not because of the invalid character, it doesn't exist! Any ideas?

• Perhaps the whole log could be useful, but I don't think it is worth to include it in the question. Can you upload it to some pastebin site and give the url in a comment? Nov 30 '12 at 11:28
• @JLDiaz I actually can't copy paste the part where the invalid characters appear in the log file, but this is the log file: pastebin.com/YBYDpBxJ In the end there are 100 of invalid character Nov 30 '12 at 11:35
• You have removed the essential information. However it seems that the problem is in the .aux file. Delete it and retry. Nov 30 '12 at 11:39
• @Ander_Biguri Ok, the log didn't help much, but apparently the invalid chars are in the file Memoria.aux and not in Memoria.tex. Try removing that file. Nov 30 '12 at 11:40
• Actually YES! I removed the .aux and everything works. Thanks. Post your comment as answer so I can accept it! PD: i didnt remove the important info, I just cant copy it, windows doesnt allow me hehe Nov 30 '12 at 11:41

The following comes from the .log file you reported:

("C:\Documents and Settings\ander.biguri\Escritorio\Memoria\LaTeX\Memoria.aux"
! Text line contains an invalid character.
l.2 ! Text line contains an invalid character.


This means that the invalid character is found in the .aux file. Remove the file and retry.

Errors during a compilation may, sometimes, cause a corruption of the .aux file that is rewritten each time. The removal is a safe operation, which has the only consequence that some more LaTeX runs are needed for synchronizing cross references.

• Problem source in my LaTEX :aux(2) ! Text line contains an invalid character. Solution: This means that the invalid character is found in the .aux file. Remove the file and retry. Thanks guys:
– user32958
Jun 28 '13 at 17:25
• In my case, Dropbox interfered with the compilation and locked the aux-file, while it was being written and thus corrupted it. Feb 20 '18 at 13:12

The following line of the error message (which you haven't shown) should show the character for example

! Text line contains an invalid character.
l.7 \begin{document}^^?


In fact I think in the default setup that is the only invalid character (delete, U+007F). So You need to delete the delete character.

Possibly your file has been saved in an incorrect encoding?

• the characters are shown as small squares, and I am not able to copy them! But where should i delete the Delete character? the error is in line 2, where there has been nothing changed for the previous thousands of compilations. Also there is not 1 error of those, but 100 and the amount of "squares" in the errors goes uo by one each error. so error 45 has 45 squares as invalid character Nov 30 '12 at 11:38
• see egreg's answer, now you have posted the log file, it shows the character is in the aux file so you can simply delete the file and latex will regenerate it. Also even if it shows as a small square it could have been identified had you pasted it in to your question, even though missing glyphs look the same they retain their original character code internally, even on this web page. Nov 30 '12 at 11:59
• Hi : I had this error and deleted the .aux file but I am still getting the error! Jan 5 '15 at 6:49
• @Naema the full log shows which file is being read look for matching (...) in the log. the log shows which file and which line number the character is on. Without that impossible to guess. If you can not find it ask a new question and put the relevant log in a code section in your question Jan 5 '15 at 7:47
• David, yes I found a file .out in the log file and when I came back to the folder and deleted it , I was able to compile my thesis.Thanks! Jan 5 '15 at 17:19

I encountered the same problem, a simple way to avoid these error is changing the build system to xelatex

for example, if you are using sublime text, then add the following line to the head of your .tex file:

%!TEX program = xelatex


Some people might not want to change the build system. Now let me introduce another solution. This problem is caused by the wrong file encode format. Thus you should change the file encoding format to UTF-8 (Notepad++ can help you do it).

For example, windows users might got error like zhwindowsfonts.tex:1: Text line contains an invalid character. [^^@]

xxx\texlive\texmf-dist\tex\generic\ctex\zhwindowsfonts.tex:1: Text line contains an invalid character. [^^@]
xxx\texlive\texmf-dist\tex\generic\ctex\zhwindowsfonts.tex:1: Text line contains an invalid character. [^^@^^@]


In that case, you should change the file format of zhwindowsfonts.tex. You might got error like

xxx\texlive\texmf-dist\tex\context\base\mkii\supp-pdf.mkii: Text line


In that case, you should change the file format of supp-pdf.mkii.

The errors will be fixed after correcting the encoding format.