[Tex/LaTex] Is it possible to solve encoding problems

accentscharactersinput-encodings

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.

\documentclass{article}
\usepackage[italian]{babel}
\usepackage[latin1]{inputenc}
\begin{document}
\section{Section}
à è ì ò ù
\end{document}

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?

Best Answer

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.

Related Question