1

Following wikibooks I have tried to make multilingual version of document in overleaf. However it doesn't seem to work. Instead of printing version for main language it prints all languages at once. Minimal example:

\documentclass[a4paper,11pt]{article} % Default font size and paper size
\usepackage[german, french, english]{babel} % multi-language support
\selectlanguage{english}
\usepackage[utf8]{inputenc} % for unicode input characters
\usepackage[T1]{fontenc}

\begin{document}

\babeltags{de = german, fr = french}
\textbf{Hello \textde{Hallo}}

\end{document}

The code results in:

Code result

Did I miss something out or Overleaf is just broken? How to do multilingual document properly?

  • What exactly did you expect to happen? – daleif Jul 12 '19 at 11:09
  • Did you read up on what \textde{...} actually is? it is shorthand for \foreignlanguage{german}{...} so it just typesets whatever you give it under german language settings. – daleif Jul 12 '19 at 11:16
  • If english language is the main language I expected to print "Hello" only. If I'd set german language it should print "Hello Hallo". So basically I'm trying to do a translation of document. Isn't it what those commands are supposed to do? – Nachos Tolstoy Jul 12 '19 at 11:24
  • Oh I see then I didn't know it's just a shorthand for \foreignlanguage – Nachos Tolstoy Jul 12 '19 at 11:29
  • 1
    You'd probably have to read through the babel manual. There might be some iflanguage tools. Just remember that overleaf is often behind in their package versions, so if you read about a cool new babel feature, you might not have it in overleaf. – daleif Jul 12 '19 at 11:40
  • 1
    I also learnt something: \foreignlanguage just changes the hypernation patters etc, not names like \contentsname, whereas \selectlanguage and the otherlanguage does. – daleif Jul 12 '19 at 11:41
  • Thanks for help. I was mislead by wikibooks which states "It is possible in LaTeX to typeset the content of one document in several languages and to choose upon compilation which language to output". Then after this paragraph it includes code snippet with \babeltags and \textde. The article also mentions iflang package to make translations though so I'll definitely take a look at it. – Nachos Tolstoy Jul 12 '19 at 13:09
  • 3
    Always be careful with all things wiki. They are often not written by someone who knows what they are writing about. You also see this in many YT videos on how to use LaTeX, they recommend stuff that users never should do. – daleif Jul 12 '19 at 13:12
  • (I'm on support staff at Overleaf.) The problem is not specific to Overleaf: I get the very same output when compiling your code on a local installation of TeX Live. While the wikibooks article seems to imply that code would print only the text for the selected language, it simply doesn't. As mentioned in the article, the iflang package has some conditionals that can be used to typeset different versions of text depending on the selected language. Here's an example in Overleaf, showing how these can be nested for multiple translations: https://www.overleaf.com/read/gtwhngjdqbby – Paul Gessler Jul 12 '19 at 15:26
  • @PaulGessler Thanks for your response. It is indeed misleading wikibooks article not a bug in overleaf or babel. – Nachos Tolstoy Jul 14 '19 at 10:41

1 Answers1

1

The wikibooks article is quite misleading. \textde is just a shorthand for \foreignlanguage{german}. It doesn't involve any conditional rendering.

The proper solution for doing a translation:

\documentclass[a4paper,11pt]{article} % Default font size and paper size

\usepackage[german, french, english]{babel} % multi-language support
\usepackage{iflang}
\newcommand{\lang}{english} % Control output language

\newcommand{\translation}[2]{\IfLanguageName{#1}{#2}{}}
\newcommand{\en}[1]{\translation{english}{#1}}
\newcommand{\ger}[1]{\translation{german}{#1}}

\usepackage[utf8]{inputenc} % for unicode input characters
\usepackage[T1]{fontenc}

\begin{document}

\expandafter\selectlanguage\expandafter{\lang}

Hello
\en{tank} 
\ger{Panzerkampfwagen}

\end{document}