Back in the old days, before I left the hallowed shores of my native country, I didn't much care what encoding my files were in. ASCII was enough for my great-great grandfather so it was enough for me. Now I live in the land of my great-great-...-great grandfathers who have a slightly mangled alphabet and ASCII no longer suffices. That would be fine if it were just me: I've learned to love UTF-8 and have even embraced xelatex. But sometimes I get sent documents in weird encodings, and sometimes I want to resurrect some old document, maybe to include a section in a new document, so from time to time I find myself wanting to change the encoding of a document.

So: how do I do that? (Included subquestion: how do I determine the encoding of a file?)


  1. I realise that this is only tangentially related to TeX and friends, so am fully prepared to be told to look elsewhere, but I think that this is quite common and especially (due to the fact that it seems one has to be super-aware of encodings with TeX) important for TeXers.
  2. I don't have a specific example file in mind here, this is a "generic" question hoping to build a useful resource. So please answer in as full generality as you can and where you need to place restrictions, please make them clear. In particular, this will almost certainly have different answers depending on the OS.
  3. On the other hand, if you do know a super-snazzy-wizzy method that works just brilliantly when using Emacs at midnight with a full moon, then please do post it - just be sure to include whether you are assuming the strong lycanthropic principle or only the weak one.
  4. In light of those last two, I'd be happy for this to be CW with one answer gathering together all the techniques in a sensible grouping.
  5. If this question doesn't get closed and does work as I intend, these notes should probably be removed so as not to distract from the usefulness of the answers (and because we probably don't want TeX-SX to be the number one hit for the "strong lycanthropic principle").
  • 4
    @Andrew: Are you looking for a single-file or a 'job lot' approach? A number of editors can read and write different encodings, so for simple cases it's just a question of your editor. On the other hand, bulk changes sound like a question for SuperUser.
    – Joseph Wright
    Commented May 30, 2011 at 11:37
  • @Joseph: Hadn't thought about that. The scenario I most encounter is "single file". I think that if I had a "job lot" then I'd figure it out once and for all and write a shell script to do it for me. But this happens just infrequently enough that I never remember from one occurrence to the next how to do it. (In case it's not clear, I'm also deliberately playing "new-users' advocate" in that I could probably figure it out for myself but I think that this would be a really useful thing to have on this site.) Commented May 30, 2011 at 11:57
  • 4
    I think that Joseph is right. Propably any decent editor has the capability to change the encoding of a file. Usually moving from ASCI to utf-8 is not a problem. The other way can lead to data loss (data corruption actually). Nowadays, I think that you should always work with Utf-8 regardless of the files contents.
    – pmav99
    Commented May 30, 2011 at 12:14
  • 1
    @pmav99: I agree that one should, and I would tend to convert from "X" to UTF-8 whenever possible. Sometimes, though, I need to send files in particular encodings to people who are ... how shall I put it? ... less aware of encoding issues than myself. I also agree with the first sentence, but then apparently Emacs has the ability to change the universe so that my program is written already, but somehow M-x quantum butterfly doesn't work for me, so having actual instructions for the clueless (ie me) would (I think) be a useful resource for this site. Commented May 30, 2011 at 12:34
  • I was going to mention file (which mostly works), but it failed to detect the encoding of a CP1251 text :-) For conversion, however, iconv is perfectly suited. Commented May 30, 2011 at 13:04

8 Answers 8


Regarding Emacs: Sometimes I stumble upon a *tex-file encoded with latin-1 or latin-9, but the second line usually is \usepackage[latin1]{inputenc}. In Emacs, I delete this line and add via C-c C-m a new \usepackage, wait until Emacs finished looking which packages are installed and type inputenc. Emacs then suggests latin-1, I type utf-8 and Emacs asks, whether the whole buffer should be encoded with utf-8. YES! And Emacs recodes my file.

EDIT: According to comments, it seems useful to add: this is an AUCTeX feature. AUCTeX is a powerful Emacs package which adds much comfort when writing *.tex files.

Otherwise look for the manpage of recode.


  • Looks extremely useful! Are you using any particular Emacs library for TeX files? Commented May 30, 2011 at 12:07
  • Uhm, you know what AUCTeX is? gnu.org/software/auctex You need that. A.
    – Keks Dose
    Commented May 30, 2011 at 15:46
  • 6
    Keks, that this is a facility of AUCTeX should be added to your answer. That's the sort of detail that's quite important. Not every user of Emacs uses AUCTeX (me, for example!). Commented May 30, 2011 at 18:28
  • @KeksDose Please if I add \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} and I hope to write for example Gabès it doen't compilate. However with \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} it complilates well. I use wenedit 5.6. Where is the problem? And how can I fix it? Thank you.
    – Schüler
    Commented Dec 3, 2018 at 6:19
  • @Schüler Ask a new question with a minimal working example!
    – Keks Dose
    Commented Dec 3, 2018 at 7:49

I recently have had some issues with the encodings of different files (*.bbl and *.tex for instance), resulting in missing glyphs or funny combinations in place of accented letters.

A solution that worked for me, in Linux (Ubuntu 10.04 distribution), was using the iconv program:

iconv -f source_encoding -t dest_encoding inputfile.tex > outputfile.tex
  • iconv is also available for Windows via MinGW
    – matth
    Commented Mar 1, 2012 at 16:43

Notepad++ is a very nice editor for Windows, it shows the current encoding and can convert the encoding to a different one. I use UTF-8 without BOM and the files worked well in all other editors afterwards. Notepad++ GUI for encoding conversion


Changing the encoding of a file in emacs is easy, at least in GNU emacs at or beyond version 23, I think. First, visit the file in an emacs buffer. If emacs does not automatically visit the file with its current encoding, close the buffer, then type C-x C-m c to specify the file's current coding system, then open the file (using C-x C-f for example). Second, change the encoding by typing C-x C-m f to specify the new coding system. When you save the file, the new coding system is used.

The second issue is how to ensure emacs picks the right coding system next time you visit the file. For LaTeX files, it is usually not a problem, since latex mode looks at the \usepackage[…]{inputenc} to figure it out. There is a more general mechanism, but discussing that is outside the scope of this site, I think.

  • Or just do M-x revert-buffer-with-coding-system, which is equivalent to what you suggest (afaik).
    – NVaughan
    Commented Dec 3, 2018 at 9:01

For single-file changes, I stick with my editor-of-choice (TeXworks), which can load and save a variety of encodings. The standard setting is UTF-8, but it will work with lots of others. (Auto-detection is based purely on the file itself, with no checking for inputenc or similar, so it may be that Emacs is a better choice in some cases.)

  • I think that inputenc is not a full proof way to detect the file's encoding. You can write whatever you want in the preamble and still save it in a different encoding. Then if you send it to someone else it will be decoded to gibberish. Propably a comment at the start of the file is the way to go (python like)
    – pmav99
    Commented May 30, 2011 at 13:17

iconv is also available for Mac OSX (besides Linux) although I don't know if it came with the OS or if I installed it with the huge MacTex-Works package.

I had to figure out to which encoding I accidentally saved my file. So I had to try out different encoding conversions.

In the terminal, this listed all the encodings available

iconv -l

This way I tried out one possible conversion after the other until my special characters (ü, ß, ...) were displayed correctly in the terminal

iconv -f MAC -t UTF-8 test.tex
iconv -f LATIN1 -t UTF-8 test.tex

This converted from UTF-8-MAC to UTF-8:

iconv -f UTF-8-MAC -t UTF-8 test.tex > test_UTF-8-MAC_UTF-8.tex
  • Useful to know. Checking my Mac system, I find iconv in /usr/bin/iconv. The date of creation matches that of other binaries that I would expect to be there by default (such as gzip and ssh) so I would say it is almost certain that iconv comes with the OS. Commented Aug 22, 2012 at 8:12

There was also a GUI program called Charco that was available for Mac OS X, GNU/Linux and Windows:



I can see that no-one mentioned the konwert utility (it is certainly present in ubuntu repositories). It has a lot of "filters" (for different encodings), can recognize some of them, nad has a lot of nice options, like removing trailing spaces, recoding cr/lf/crlf standards, escaping # $ % & \ ^ _ { | } ~ to TeX, rot13-ing the file and even more.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .