6

I try to typeset russian character by ascii letter, so I referenced latex_cyrillic. It works but failed in section title. How to solve it?

\documentclass{article}

\usepackage[OT2,OT1]{fontenc}
\newcommand\cyr{%
\renewcommand\rmdefault{wncyr}%
\renewcommand\sfdefault{wncyss}%
\renewcommand\encodingdefault{OT2}%
\normalfont
\selectfont}
\DeclareTextFontCommand{\textcyr}{\cyr}
\def\Eob{\char3}
\def\eob{\char11}
\def\cpr{\char126}
\def\cdpr{\char127}
\def\Cpr{\char94}
\def\Cdpr{\char95}  

\begin{document}

\section{{\cyr L{ya}punov} theorem}
{\cyr Poslednee dokazatel\cpr stvo mozhno obobshchit\cpr
sleduyushchim zamechaniem, kotoroe nam eshche prigodit\mbox{}sya.}

\end{document}

1 Answers1

8

Define \cyr as a robust command:

\DeclareRobustCommand\cyr{%
  \renewcommand\rmdefault{wncyr}%
  \renewcommand\sfdefault{wncyss}%
  \renewcommand\encodingdefault{OT2}%
  \normalfont
  \selectfont}

By the way, your definitions such as

\def\Eob{\char3}

are wrong. Use either

\chardef\Eob=3

(more efficient) or

\newcommand\Eob{\symbol{3}}

They are not needed, anyway: you get the “e oborotnoye” by typing e1 (lowercase) or E1 (uppercase). Similarly, the soft sign is p1 or P1 and the hard sign is p2 or P2. The break between t and s is more conveniently obtained by \/.

\documentclass{article}

\usepackage[OT2,OT1]{fontenc}

\DeclareRobustCommand\cyr{%
  \renewcommand\rmdefault{wncyr}%
  \renewcommand\sfdefault{wncyss}%
  \renewcommand\encodingdefault{OT2}%
  \normalfont
  \selectfont}
\DeclareTextFontCommand{\textcyr}{\cyr}

\newcommand\Eob{\symbol{3}} % or \chardef\Eob=3
\newcommand\eob{\symbol{11}}
\newcommand\cpr{\symbol{126}}
\newcommand\cdpr{\symbol{127}}
\newcommand\Cpr{\symbol{94}}
\newcommand\Cdpr{\symbol{95}}

\begin{document}

\section{{\cyr Lyapunov} theorem}
{\cyr Poslednee dokazatelp1stvo mozhno obobshchitp1sleduyushchim 
zamechaniem, kotoroe nam eshche prigodit\/sya.}

{\cyr \Eob\eob\Cpr\cpr\Cdpr\cdpr}

{\cyr E1e1P1p1P2p2}

\end{document}

enter image description here

What's the problem? The boldface attribute is not honored because of \normalfont.

You can solve this by using

\makeatletter
\DeclareRobustCommand\cyr{%
  \fontfamily{wncy\ifnum\pdfstrcmp{\f@family}{\sfdefault}=0 ss\else r\fi}%
  \fontencoding{OT2}%
  \selectfont}
\makeatother

enter image description here


An even more robust solution is to define the Washington University fonts as belonging to the cmr and cmss font family in the OT2 encoding.

\documentclass{article}

\usepackage[OT2,OT1]{fontenc}

\DeclareFontFamily{OT2}{cmr}{\hyphenchar\font45 }
\DeclareFontShape{OT2}{cmr}{m}{n}{<->wncyr10}{}
\DeclareFontShape{OT2}{cmr}{m}{it}{<->wncyi10}{}
\DeclareFontShape{OT2}{cmr}{m}{sc}{<->wncysc10}{}
\DeclareFontShape{OT2}{cmr}{b}{n}{<->wncyb10}{}
\DeclareFontShape{OT2}{cmr}{bx}{n}{<->ssub*wncyr/b/n}{}

\DeclareFontFamily{OT2}{cmss}{\hyphenchar\font45 }
\DeclareFontShape{OT2}{cmss}{m}{n}{<->wncyss10}{}

\DeclareRobustCommand\cyr{\fontencoding{OT2}\selectfont}
\DeclareTextFontCommand{\textcyr}{\cyr}

\newcommand\Eob{\symbol{3}} % or \chardef\Eob=3
\newcommand\eob{\symbol{11}}
\newcommand\cpr{\symbol{126}}
\newcommand\cdpr{\symbol{127}}
\newcommand\Cpr{\symbol{94}}
\newcommand\Cdpr{\symbol{95}}

\begin{document}

\section{{\cyr Lyapunov} theorem}
{\cyr Poslednee dokazatelp1stvo mozhno obobshchitp1sleduyushchim 
zamechaniem, kotoroe nam eshche prigodit\/sya.}

{\cyr \Eob\eob\Cpr\cpr\Cdpr\cdpr}

{\cyr E1e1P1p1P2p2}

{\sffamily Abcdef\cyr Abcdef}

\end{document}

enter image description here

As you see, all font attributes are honored (so long as the corresponding font in the OT2 encoding is available).

egreg
  • 1,121,712