Is there a LaTeX package that automatically detects which foreign language a particular part of a multi-language TeX document is so that it can hyphenate it appropriately, or do I have to manually specify the foreign language, using, e.g., the Babel package's command \foreignlanguage{}?

  • 3
    \foreignlanguage is usually used for up to a couple of words, maybe a sentence. For whole passages I'd use \selectlanguage. Cause you talking about language detection, this usually only makes sense for longer stretches of text in a particular language, not for the odd foreign word (I mean after all, is "die" English or German?). And no, I don't think such a package exists, nor would it vibe well with LaTeX since it's too unclear what it will actually do. Update the dictionary and suddenly the whole text is recognized as a different language? That's not something I'd be comfortable with.
    – Christian
    Apr 10, 2014 at 20:10
  • Yes, the auto-detection would have to apply to whole sentences or paragraphs, not single words.
    – Geremia
    Apr 10, 2014 at 20:44
  • 1
    Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. Oct 24, 2016 at 19:05

1 Answer 1


No, but there are things you can do that makes it less of a burden. It's not that common that a document switches language just like that, since that can be confusing not only for LaTeX, but for readers as well. Often the foreign text is divided from the text around it in some way that you have markup for anyway. Then let that markup do the language switch for you as well!

One simple example is italicized foreign words. Say you are writing in English about something Swedish and therefore use some foreign words in your text.


When celebrating \swe{Valborgsmässoafton} (Walpurgis Night) the Swedes

The point is that you would have needed markup for those words anyway. Another common example is quotes in a foreign language. The package csquotes has some readymade commands for that. You can with advantage use these in your own shorter macros that are for the languages you happen to use, like \swe above.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .