38

I've been trying to change the language of my LaTeX document by replacing \usepackage[swedish]{babel} with \usepackage[english]{babel} but I only get this message:

! Package babel Error: You haven't loaded the option swedish yet.

I've read in an other question at this forum that compiling enough would solve the problem, but that doesn't work for me. Does anyone know what I should do?

lockstep
  • 250,273
Djamillah
  • 483
  • 12
    When you change languages you also need to delete your .aux file. Try that and recompile and the error should disappear. – Alan Munn Aug 08 '13 at 14:09
  • 2
    In addition to Alans comment, that comment you have read that it is enough to recompile, depends on how which options the editor passes to latex. – daleif Aug 08 '13 at 14:13
  • 2
    It is sufficient if you just compile once again. The inappropriate .aux has been overwritten with the first compiler run and will now be read correctly. – Thorsten Donig Aug 08 '13 at 14:47
  • Yes, I read that question before I posted and it says that bad things happens in the .aux file, but not really that you should remove it and everything would work. A newcomer to LaTeX like me would not dare to remove a file just because it was causing the trouble. – Djamillah Aug 08 '13 at 14:51
  • @ThorstenDonig Whether or not you need to delete the .aux depends a lot on your editing environment. With TeXShop for example, recompiling is not sufficient to remove the error. – Alan Munn Aug 08 '13 at 15:42
  • @Djamillah you could always rename it to myfile_junk.aux if you were worried. Also you can look at the creation time and date - it was clearly created at compile time. Personally my default compile macro kills the .aux (etc.) after compiling - I have to hit a different key if I want to keep my .aux (or more likely .log and .bbl) – Chris H Aug 08 '13 at 15:43
  • 1
    I'm not seeing this as a dupe: this is very focussed on a specific issue, and is a pretty common problem. In particular, it's not caused by an error in the auxiliary files. – Joseph Wright Aug 08 '13 at 15:49
  • 1
    Please, close voters, this is not really a duplicate, even though the answer is contained in the linked question. The supposed duplicate is much more general. I've linked to it in my answer, but I think we should leave this question open. – Alan Munn Aug 08 '13 at 16:40
  • I had the same issue and I solved as below choose recompile from scrach, in the Recompile options. – bz_benzait Aug 22 '21 at 10:15

1 Answers1

35

This is a very common error with babel, and is solved by removing the .aux file whenever you change languages.

When you use babel it writes information to the .aux file that refer specifically to the language you have chosen. In your case, for example, when you select swedish as the babel language it does two things: (i) it loads a set of macros related to Swedish and (ii) it (minimally) writes the following to the .aux file.

\select@language{swedish}
\@writefile{toc}{\select@language{swedish}}
\@writefile{lof}{\select@language{swedish}}
\@writefile{lot}{\select@language{swedish}}

The command \select@language{swedish} tells TeX to use the specific macros defined for Swedish.

The .aux file is used for storing information that will be reused on the next compilation. See

for some more information on this.

babel writes to the .aux file because it changes the names of things like the table of contents and list of figures according to the chosen language.

Now, when you change the language without deleting the .aux file, and compile your file, TeX reads in the .aux file and encounters the \select@language command. But since you have changed the language, the macros for Swedish haven't been loaded, and you get the error you received.

The babel package is not the only package that can sometimes require you to delete the .aux file. See the following more general question for information about them:

Newer versions of babel

If you are using an up-to-date system with babel version 3.22 or greater, you should no longer receive this error, but instead should see a warning like the following:

Package babel Warning: Unknown language `swedish'. Very likely you
(babel)                requested it in a previous run. Expect some
(babel)                wrong results in this run, which should vanish
(babel)                in the next one. Reported on input line xxx.
Alan Munn
  • 218,180
  • 1
    Starting from babel 3.22 unknown languages are not errors any more, they have been downgraded to warnings: https://lists.dante.de/pipermail/ctan-ann/2018-June/011573.html – moewe Aug 18 '18 at 19:57
  • @moewe Finally. :) I noticed that looking through the code. But there are still enough older systems around for this question to be relevant. I've updated the answer though. – Alan Munn Aug 18 '18 at 20:03