TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I seem to have messed up the encoding of my tex document in TexShop and I wonder if anyone can explain to me what's going on?

I had a short document which was fine, until I needed to add some Japanese, so I added

%!TEX encoding = UTF-8 Unicode

at the top line and then


% Packages

\begin{CJK}{UTF8}{goth} % for gothic (sans serif) font

% Cite English reference

% Cite Japanese reference



After doing this, all my backslashes changed to yen signs, and any backslash I typed came up in the editing window as a yen sign.

Now when I compile it has an error

"Missing \begin{document}"

and shows an error

DOT documentclass[a4paper,12pt]{article}

where DOT is literally a dot.

So it's clear that the backslashes have all been lost.

Can anyone explain to me what's going on with the encoding, and how I can fix it?

I am aware of XeTeX, but I heard that by adding lines from the package CJKutf8 as I have done above, it is possible to avoid having to install another huge Latex implementation just for the use of Japanese characters.

share|improve this question

closed as off-topic by Joseph Wright Aug 6 '13 at 7:28

  • This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

Welcome to TeX.SX. Usually, we don't put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – Claudio Fiandrino Feb 3 '13 at 14:25
To me this sounds very much like a problem TeXShop is having, as I am able to compile your source code without any problems. I have experienced that TeXShop somehow does not like you changing the file’s encoding afterwards (e. g. by adding %!TEX encoding = UTF-8 Unicode after you have saved it for the first time). One solution I have found is opening the corrupt file in an editor which lets you choose the file’s encoding in the opening dialog (TextWrangler, SublimeText 2, …) and then saving/exporting it again with the correct encoding. I am not sure if this answers your question ;) – brian-ammon Feb 3 '13 at 19:21
The change from backslash to the yen symbol seems to be characteristic of the Shift-JIS encoding. I tried changing the encoding in TeXShop, but I didn't succeed in reproducing the problem. – egreg Feb 3 '13 at 21:08
Thanks for the suggestions. Following your hints I switched from Texshop (to vim), and now there are no encoding problems. – Tetsuo Feb 19 '13 at 8:22
FYI, XeTeX should already be included in your distribution, and would allow you to use much nicer Japanese fonts. Try changing the typesetting engine in TeXShop, or just add %!TEX TS-program = xelatex to your file header. – erik Apr 11 '13 at 3:55