This is what I do in newunicodechar
that requires the utf8
option either to inputenc
or inputenx
and wouldn't work with other options and without either of those packages:
\def\nuc@stop{\PackageWarningNoLine{newunicodechar}
{This package won't work without loading\MessageBreak
`inputenc' or `inputenx' with the `utf8' option}%
\let\newunicodechar\@gobbletwo\endinput}
\@ifpackageloaded{inputenx}
{\def\nuc@tempa{inputenx}}
{\@ifpackageloaded{inputenc}{\def\nuc@tempa{inputenc}}{\nuc@stop}}
\@ifpackagewith{\nuc@tempa}{utf8}{}{\nuc@stop}
\@ifpackagewith{\nuc@tempa}{utf8x}{\nuc@stop}{}
The \let\newunicodechar\@gobbletwo
is just to enable processing the file nonetheless. If you want to require usage of utf8
you can modify it like this:
\ProvidesPackage{xyz}
% Define an error message
\def\xyz@stop{\PackageError{xyz}
{`inputenc' or `inputenx' loaded with wrong option.\MessageBreak
This is a fatal error}
{This package won't work if either `inputenc' or `inputenx'\MessageBreak
are loaded with the `utf8' option. The LaTeX run will be terminated}%
\fi\@@end} % the `\fi` is to match `\if@tempswa`
% Check for inputenx or inputenc
\@tempswafalse
\@ifpackageloaded{inputenx}
{\def\xyz@tempa{inputenx}\@tempswatrue}
{\@ifpackageloaded{inputenc}
{\def\xyz@tempa{inputenc}\@tempswatrue}
{\RequirePackage[utf8]{inputenc}}%
}
% Check for the right option
\if@tempswa
\@ifpackagewith{\xyz@tempa}{utf8}{}{\xyz@stop}
\@ifpackagewith{\xyz@tempa}{utf8x}{\xyz@stop}{}
\fi
So if the user types
\usepackage[utf8]{inputenc}
\usepackage{xyz}
nothing will be done. But if inputenc
(or inputenx
) is not loaded before it, xyz
will load it. If a wrong option is passed to inputenc
, the package will terminate the LaTeX run.
You appear to be using TeXShop, for which there's a very easy solution: add
% !TEX encoding = UTF-8 Unicode
at the top of your file and save it. Now it should compile properly.
Next, open the preferences for TeXShop and go to the “Source” tab. You probably will have a window like
(at least in the “Encoding” box): for historical reasons, TeXShop keeps MacRoman as the default text encoding.
From the “Encoding” pull-down menu, choose “Unicode (UTF-8)”
Close the preferences and from now on, all files will be saved as UTF-8.
Having the “magic line” makes no harm, so you can keep it for greater safety.
If you have older files where \usepackage[applemac]{inputenc}
is used, be sure to add the magic line corresponding to MacRoman, which you can add from the “Macros>Encoding” menu.
Do this addition before changing the default encoding.
Best Answer
If you can: do not use
\usepackage[utf8]{inputenc}
nor\usepackage[latin1]{inputenc}
. Use LuaTeX:This will give you access to all modern things (OpenType fonts for example) while keeping most of the backward compatibility.
Wait for TeXlive 2010 (or get the pretest) and you have a decent environment for LuaTeX. Million thanks to the few people who make the LuaLaTeX packages!
If you are able to read german: see the site http://www.luatex.org for more examples (especially on
fontspec
).