I have a question regarding utf-8 encoding and the interaction of TextMate and TeXShop. I have been using utf-8 encoding now for a while. Many of my files have been prepared in TeXShop, in utf8 encoding. Now that I can open them in TextMate and use Latex Watch, with the variable TM_LATEX_VIEWER TeXShop on---a terrific combination---, I get the following TeXShop message which I'd like to avoid:
``This file was opened with MacOSRoman encoding. The file could not be opened with Unicode (UTF-8) encoding because it was not saved with that encoding. If you wish to open in another encoding, close the window and open again.''
The pdf shows perfectly in TeXShop viewer, which I prefer for now. How can I avoid the message I get from TeXShop?
Top of my file is:
\documentclass{article} \usepackage{fancyhdr} \usepackage[utf8x]{inputenc} \usepackage{lmodern} \usepackage[french,english]{babel} \usepackage{textcomp}
--Gildas Hamel
Quote from Koch of TeXShop to Bastian Philipps at http://ftp.tug.org/mail-archives/macostex-archives/2006-February/020357.html
Here is how TeXShop works: Internally it uses unicode. When it comes time to write out the file, the internal representation is converted to a string using an encoding. (This is necessary even if the encoding is a Unicode encoding, because the Unicode standard doesn't specify a particular way of writing unicode to disk. So utf-8 is one possible unicode
encoding, but
not the only one.)
What happens if there is a unicode character in the text which is not available in the particular encoding chosen? Apple's routines contain a parameter which indicates whether this should create an error or if instead the character should just be ignored or converted to something else. I choose "ignore or convert to something else." So if you type, say, a Euro symbol, but the encoding doesn't support it, then TeXShop will still write out the file.
There is somewhat similar code when you read text from disk. Apple's routines require that an encoding be specified, and then the file is converted into Apple's internal unicode form and displayed in the editor.
But this time there is another problem. Suppose the encoding is utf-8 unicode, and the file isn't legal urtf-8. Then when Apple's code reads the file, it suddenly says "wait, this doesn't make sense." In that case, it stops reading and reports an error to TeXShop. TeXShop then puts up the dialog you have reported and reads the file again in MacOSRoman. (Every file is a legal MacOSRoman file.)
If I understand you correctly, you need to add the comment
%!TEX encoding = UTF-8 Unicode
to the beginning of your tex file, to tell TeXShop that the source is UTF-8. Otherwise it assumes MacRoman.
Robin
Robin Houston wrote:
If I understand you correctly, you need to add the comment
%!TEX encoding = UTF-8 Unicode
to the beginning of your tex file, to tell TeXShop that the source is UTF-8. Otherwise it assumes MacRoman.
I thought of that, trashed my auxiliary files and still get the same message from TeXShop that it was opened in MacOSRoman. I might have to switch to Skim... --gildas
On 6/26/07 1:17 AM, "Gildas Hamel" gweltaz@ucsc.edu wrote:
[...] I might have to switch to Skim... --gildas
You'll love it and be glad you did.
Best wishes David
Thanks to Gildas for clarifying the problem off-list.
This appears to be a bug in TeXShop: if you set the default encoding to UTF-8, and then open a PDF file (not a TeX file) in TeXShop, then you get this warning message.
I will add a workaround to the next release of Watch, but this should probably be reported to the developers of TeXShop.
Robin