2

I am writing a book in two languages: a Russian version and an English version. Is it possible to do this in the same file?

Something like \tltext{Hello world!}{Здравствуй, мир!}, and mark at the start of the preamble which variant is needed.

The idea is that if I needed to change something, I wouldn't have to do it in both files.

Andrey Vihrov
  • 22,325
newuser
  • 323

2 Answers2

2

This might just work, simply comment out the version that you don't want. You might eventually want to choose a shorter name than \tltext for the command because you're going to be typing it many, many times if you're writing a book.

\documentclass{article}

\newcommand{\tltext}[2]{#1}% use English version
%\newcommand{\tltext}[2]{#2}% use Russian version

\begin{document}
\tltext{Hello world!}{Здраствуй мир!}
\end{document}
doncherry
  • 54,637
2

babel provides \iflanguage, but its usage for large parts of text is cumbersome.

\documentclass{book}
\usepackage[T2A,T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[russian,english]{babel}

\newif\ifenglish
\newcommand{\chooselanguage}[1]{%
  \selectlanguage{#1}%
  \iflanguage{english}{\englishtrue}{\englishfalse}}

\begin{document}
\chooselanguage{english}
%\chooselanguage{russian}

\ifenglish
  Hello world!
\else
  Здраствуй мир!
\fi

\ifenglish
  Thank you
\else
  Спасибо
\fi

\end{document}

In other words, you write each paragraph (or part of text in general) putting between \ifenglish and \else the English version, and between \else and \fi the Russian text.

You choose the language by commenting or uncommenting the lines after \begin{document}.

egreg
  • 1,121,712