# Option clash for package inputenc when using Lyx with LaTeX class that already uses inputenc

I use Lyx to edit document whose class declares `\usepackage[latin2]{inputenc}` in its .cls file. While I only use languages for which Lyx uses the same encoding it only adds the same command (`\usepackage[latin2]{inputenc}`) to preamble of the document. However when I started to use some more languages the command that is added by Lyx to preamble is changed to something like `\usepackage[latin9, latin2]{inputenc}`. Then I get following error:

``````LaTeX Error: Option clash for package inputenc.
\setcounter
{secnumdepth}{3}
[latin2]
There has now been an attempt to load it with options
[latin9,latin2]
``````

Lyx does not seem to expect that classes may use `inputenc` themselves. What is the right solution to this problem? Should I prevent Lyx from adding any `inputenc` to preamble? Is there some LaTeX command that can override `\usepackage`? Or is this problem of the class I'm using so I should modify it? Perhaps I should delete that `\usepackage[latin2]{inputenc}` from that class or replace it by something...

## Edit

Important note: I'm not really asking for some quick dirty fix (I could figure out some myself). I'm trying to make that class work with Lyx also for other users (writing Lyx layout file for it etc.). So I want to do this the right way. If the problem is poor design of LaTeX class I should fix that one. If it is poor Lyx design I should try to submit bug report or fix it myself.

-
Are you really sure you want to use two input encodings in the same document? –  egreg Dec 25 '12 at 22:27
@egreg I'm not sure but Lyx seems to be. When I mark some paragraphs to be using different language it adds those 2 encodings to preamble. Anyway, it looks like this is poorly implemented by Lyx developers... It should at least consider the case that `inputenc` package has already been loaded by the class and use what @Harish Kumar suggested automatically... –  drasto Dec 25 '12 at 22:31
@drasto The real solution is to use UTF-8. –  egreg Dec 25 '12 at 22:36
@Harish Kumar I do not think Lyx is going to let me add anything before `\documentclass{....}`. Why does that class use `latin2` encoding instead of something like `utf8x` anyway? Well, why does it use `inputenc` at all? Other classes do not seem to use anything like `\usepackage[whatever]{inputenc}`. –  drasto Dec 25 '12 at 22:37
@Harish Kumar Indeed there is. But all edits to preamble are placed after `\documentclass{....}` unless I'm missing something. Please also see my edit to the original question. –  drasto Dec 25 '12 at 22:44

This is essentially a flaw in the class in question: classes really shouldn't load `inputenc` as that is down to the user and how their files are set up. I would strongly suggest not using a class set up this way, whether with Lyx or directly with LaTeX.
Good to know. @drasto if this were to be implemented in LyX, it would probably be implemented via the 'provides' parameter. See "5.3.4 General text class parameters" in Help > Customization. This instructs list that your module/document/layout "provides" a feature (e.g. LaTeX package) so LyX shouldn't load it itself. However, I trust Joseph Wright and thus am guessing `provides` should not be extended to support this. –  scottkosty Aug 5 '13 at 4:17