tags:

views:

205

answers:

4

I have multi-lingual TeX document mostly in Russian but I also include some terms in English in brackets too to make the reader familiar with international terminology. For example the phrase

Два неотъемлемых свойства языка программирования - синтаксис (syntax) и семантика (semantics).

which simply means

Two attributes of a programming language are its syntax and semantics.

looks like

Два неотъемлемых свойства языка программирования --- \textit{синтаксис} (\textit{\selectlanguage{english}syntax\selectlanguage{russian}}) и \textit{семантика} (\textit{\selectlanguage{english}semantics\selectlanguage{russian}}).

Also I have \usepackage[english,russian]{babel}.

The code looks too verbose because I need to use \selectlanguage twice on each English word to make hyphenation work. Without this I get a couple of

Overfull \hbox ...

messages because TeX is not able to hyphen English words when they appear at the ends of the lines.

Is there any better solution?


In response to Alexey Malistov.

MacTeX distribution has a couple of language.dat files

  • /usr/local/texlive/2009/texmf-dist/source/generic/babel
  • /usr/local/texlive/2009/texmf-dist/doc/generic/babel
  • /usr/local/texlive/2009/texmf/tex/generic/config
  • /usr/local/texlive/2009/texmf-var/tex/generic/config
  • /usr/local/texlive/2009/texmf-dist/tex/lambda/config

I'm not sure which one should I edit. Probably one of the first two. They are identical

% File    : language.dat
% Purpose : specify which hypenation patterns to load 
%           while running iniTeX 
=USenglish
american ushyphen.tex
=english
UKenglish  ukhyphen.tex
=british
french   frhyphen.tex
dutch    nehyph2.tex
german   dehypht.tex 
ngerman  dehyphn.tex 

But which one?

Also there is no initexmf command. Googling around I found out that analogue is updmap-sys. But I'm not sure... I'm afraid to spoil my TeX installation. Please, give me the right direction.

+1  A: 

You can add discretionary hyphens (\-) on every english word as appropriate.

Alternatively, you can define your own environment that handles both the textit and the language selection.

Anon.
+1: But why an environment? The Qn cites usages in horizontal mode; `\def\russeng#1#2{#1(\textit{\selectlanguage{english}syntax\selectlanguage{russian}})}` will do the trick much less cumbersomely.
Charles Stewart
Anon, thanks for mentioning discretionary hyphens.
kemiisto
+1  A: 

I believe that \selectlanguage should follow the usual scope rules, so that you can enclose the part you want to be english in braces, which delimit a local scope:

Два неотъемлемых свойства языка программирования --- \textit{синтаксис} 
({\textit{\selectlanguage{english}syntax}}) и \textit{семантика}
({\textit{\selectlanguage{english}semantics}}).

I can't test this right now, though, so if you find that it doesn't work, I would be glad if you informed me of the fact, so that I can modify or delete this answer.

Svante
Thanks, Svante! Works fine.
kemiisto
+2  A: 

You should combine english and russian hyphens. Change the file language.dat, adding the following:

ruseng ruenhyph
=russian
=english

And recompile all format files:

initexmf --dump

Add

I use MikTeX. I do not know what you have to do exactly. I would try and experiment.

  1. You should add "new language ruseng" which contains english and russian hypens. Then no \setlanguage macro is needed. It works for me very well. I use russian and english words and do not use \setlanguage.

  2. You should recompile your formats file. MikTeX provides initexmf command. I am sure there is similiar command for your MacTeX.

Alexey Malistov
Ooops. I didn't mention that I use MacTeX. Sorry for that. I added some info to my message.
kemiisto
Finally I made it. The command which I used was "sudo texconfig init". Thanks.
kemiisto
+1  A: 

Rather than using \selectlanguage{} twice because is a switch, you can use either the otherlanguage environment, or the \foreighlanguage macro:

\begin{otherlanguage}{english}
   Hello world
\end{otherlanguage}

Or, for inline changes like in your example:

Два неотъемлемых свойства языка программирования --- \emph{синтаксис}
(\foreignlanguage{english}{\emph{syntax}}) и \emph{семантика}
(\foreignlanguage{english}{\emph{semantics}}).

In fact, if you often give the english terms, you can define a macro:

\newcommand{\englishterm}[1]{%
    \foreignlanguage{english}{\emph{#1}}}
Damien Pollet
Finally I accepted this answer. By the way probably something is wrong with macro. In my case working example looks like \newcommand{\englishterm}[1]{\foreignlanguage{english}{\emph{#1}}}. Anyway thanks for mentioning \foreignlanguage and macro. And another thing for people having the same problem: \sloppy command may be very useful.
kemiisto
Oops, sorry for that... the [] are indeed correct :)
Damien Pollet