I have some tex files that are corrupted, meaning that characters like accented letters have been replaced with weird symbols. Is it possible to solve this kind of problem after the weird symbols appear, or is it already too late?

Sometimes when I save some tex files (where the encoding has been set to latin1) and open them again, maybe in some other editors, all the special characters are lost and I need to manually retype them in.

à è ì ò ù

In this example, the five accented letters would be replaced with other symbols, and I haven't found any way to recover the original version of the file.

I know that setting utf8 in the inputenc package solves this problem when I create new files, but what about recovering older latin1 files which, upon opening, are filled with corrupted characters?

  • Could you please provide a Minimum Working Example (MWE) that includes all packages dependencies and some text that produces you problem. – Peter Jansson Jan 12 '13 at 10:20
  • 3
    Tools such as recode or iconv can help. – Paul Gaborit Jan 12 '13 at 10:22
  • 1
    Your question applies to text files in general; this suggests that it might be easiest to search for such general solutions, using keywords such as "repair", "encoding", "email", "fix", and "text". – Lover of Structure Jan 12 '13 at 10:24
  • 2
    @user1301428 If you use OSX or Linux, you are lucky. Both include the program iconv which you can use from a terminal with the following syntax iconv -f utf-8 -t latin1 < your-weird-file > new-fixed-file. Alternatively, you can use an editor which properly shows utf8. – JLDiaz Jan 12 '13 at 12:32
  • 1
    You might also want to check out a konwert tool (is in Ubuntu repo, I don't know about Mac). It is kind of a Swiss-army knife for converting files between encodings, imho better than iconv. Among others, it can (try to) recognize the encoding. – mbork Mar 20 '13 at 6:34

The "weird symbols" most probably are UTF-8 characters displayed in another encoding, and the file itself is fine. Use UTF-8 throughout (set your LOCALE properly in Unix/Linux is probably the most important measure). There are commands like recode that help changing the encoding, but be careful to use them right, they overwrite the original and can mess it up royally.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.