开发者

English words hyphenation in Russian text

开发者 https://www.devze.com 2022-12-19 05:34 出处:网络
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

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

Два неотъемлемых свойства языка про开发者_StackOverflowграммирования - синтаксис (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.


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}}}


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.


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号