I use TeX on my laptop (OS X) and on my workstation (Linux RHEL 6) and I have issues with the encoding of some files where I use accents (mostly in authors names, but also because I'm French and I have some documents in French). I guess my issues is that I sometimes rely on the more flexible encoding on the Mac side to use accented characters directly like é instead of doing {\'{e}} for example. Then through Dropbox, or maybe because I then open these files on UNIX, these accents get mangled differently on both sides, and I obtain 2 different looking files on both sides. I'm pretty sure I could fix all this by using only the escape way but I might be able to do something more elegant (maybe I need to explicitly set the encoding both in the .tex file and in vi). I'm not sure what happens if I go to another editor then like TeXshop...

Do you have some pointers or a more elegant solution to my problem? Let me know if you need more information ! Thanks !

UPDATE: Thanks to some of the pointers given, I know a little bit more about the issues now. I created a small sample file to reproduce the issue. If I create it in TeXShop, it seems to work fine whereas the issue exists if I create the file with vim. Additionally, the file --mime-encoding test.tex yields different output depending on the way of creating the file:

$ file --mime-encoding test.tex 
test.tex: unknown-8bit
$ file --mime-encoding test2.tex 
test2.tex: utf-8
kheldar@shadowfax /Users/kheldar/Dropbox/Boulot/CV/csuros/2011
$ vi test.tex 
kheldar@shadowfax /Users/kheldar/Dropbox/Boulot/CV/csuros/2011
$ vi test2.tex 

\title{Test encoding}

Test accents: é è ê ë

Test accents: é è ê ë

Test accents: \'{e} \`{e} \"{e}

Test accents: \'{e} \`{e} \"{e}


Note that even with the TeXShop created file with utf-8, I don't see utf-8 in the status bar described by @Daniel. So it must be my vimrc right? Somehow I have other options that interfere with the set filencoding command. Any idea?

  • 2
    Check the default encoding in the preferences of TeXShop; they should be "Unicode UTF-8", as probably vi on the Unix side will be using that encoding. – egreg Dec 3 '11 at 22:40
  • 1
    Copying between platforms is usually fine provided the editors are set up correctly. Have you tried using a cross-platform editor where you can know that this is correct (for example TeXworks, which is native UTF-8 and cross-platform)? – Joseph Wright Dec 3 '11 at 23:02
  • To speed up the process, please provide us with a MWE? Just put two files linux.tex and mac.tex created on the respective platform and with accented characters into the Public folder of your dropbox and post the links to them here. – Daniel Dec 5 '11 at 7:54
  • @Daniel So the example files both work now, you can check them at dl.dropbox.com/u/167859/OSX_vim.tex and dl.dropbox.com/u/167859/LINUX_vim.tex – FrenchKheldar Dec 5 '11 at 18:32
  • 1
    To get the actual buffer encoding independently from the statusline just do a set enc. To convert existing files there is the iconv program (iconv -cs -f ISO-8859-1 -t UTF-8 latin.tex > utf8.tex, details available with man iconv. Another option is to load them into vim and then do a set fenc=utf8 (whereas enc should remain latin1) and then write the buffer back to disk. Whenever fenc is different from enc, vim converts (using iconv, by the way) the buffer to fenc on write. – Daniel Dec 5 '11 at 20:49

The two most important pieces of advice:

  • Use utf8 for the encoding of your documents (\usepackage[utf8]{inputenc}). In vim you set this encoding by set filencoding=utf8; depending on your shell's locale settings (locale) this might already be the default. In TexShop, you have to set the file encoding explicitly in the preferences.

  • Refrain from using accented characters in your file names! MacOS's "special" interpretation of UTF8 in filenames (they are stored in decomposed form) causes all sorts of troubles.

For vim it is furthermore a good idea to define a status line that shows indicators for the actual text encoding and line-ending encoding (if you put the following lines into you ~/.vimrc the file type, line ending and text encoding is shown on the right):

" show statusline
hi StatusLine ctermbg=black ctermfg=white guibg=black guifg=white gui=none
hi EMPH ctermfg=yellow ctermbg=black guibg=black guifg=yellow gui=none
set statusline=%F\ \|%c,%l:\ 0x%-02B\|%=\ \|%{strftime(\"%c\",getftime(expand(\"%:p\")))}\|\ %y\ %{&ff}\ %#EMPH#%{(&fenc==\"\"?&enc:&fenc)}
set ls=2

enter image description here

Thereby, you can quickly grasp if the encoding is right. If you google for "vim statusline" you will find a plethora of guides and tutorials on how to setup a good status line. Mine is still relatively simple.

| improve this answer | |
  • I actually have all these set up but I still can't get it to work. I just typed an accented character in my tex file, closed the file and reopened (on OS X) and I got the mangled characters... One more piece of information, the output of the file command on my tex file: LaTeX 2e document text – FrenchKheldar Dec 3 '11 at 22:57
  • 1
    @FrenchKheldar That seems a problem with the default encoding on TeXShop. Put the line % !TEX encoding = UTF-8 when on the Unix side and try reopening in TeXShop – egreg Dec 3 '11 at 23:08
  • OK so I put your status line and I can see that the utf-8 tag doesn't appear. That means that despite what I have in my ~/.vimrc and in the header of the tex, it is not taking it into account... Any clue as to what is happening? Thanks for your help... – FrenchKheldar Dec 3 '11 at 23:10
  • It's 2011 and XeTeX and LuaTeX exist, which both can handle Unicode directly; there's no need to stick with pdftex and use [utf8]{inputenc} anymore. – Martin Schröder Dec 3 '11 at 23:11
  • 1
    @Daniel That's the thing I see nothing after the [vim] unix. I'm updating the question with my new findings... – FrenchKheldar Dec 5 '11 at 7:01

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.