"sh" gets rendered as "7" using OT2

I am trying to write a paper in Cyrillic using OT2, but in some cases instead of rendering "sh" as "ш", it renders it as "7". Here's an example.

\documentclass{memoir}
\usepackage[utf8]{inputenc}
\usepackage[T1, OT2]{fontenc}

\begin{document}

Ovim jednachinama se sa velikom preciznoshc1u mozhe opisati kretanje tela \textbf{pri nerelativistichkim brzinama}, tj. pri brzinama mnogo manjim od brzine svetlosti.

\end{document}


It is supposed to yield this:

Овим једначинама се са великом прецизношћу може описати кретање тела при нерелативистичким брзинама, тј. при брзинама много мањим од брзине светлости.

When I add a \relax before c1, the ћ gets rendered but ш still doesn't:

I have no idea what might be causing this issue.

• With a hint from here, preciznosh\/c1u works. May 3, 2019 at 2:51
• @DavidPurton Thanks, that works! I have a few more related questions. Firstly, what is the difference between \/ and \relax? Also, why does it get rendered as 7? May 3, 2019 at 22:59
• Workaround: load fontspec and use Unicode throughout instead of OT2, unless you are required to use PDFLaTeX. May 4, 2019 at 2:39
• Alternative workaround: use whichever of T2A, T2B or T2C meets your needs. May 4, 2019 at 2:41
• Just typing your document in UTF-8 on a modern version of LaTeX might work, since \usepackage[utf8]{inputenc} is now the default. May 4, 2019 at 2:47

This is from memory (I don't have access to a TeX system at the moment).

In 1982 or thereabouts, I developed the code for the input of Cyrillic according to the transliteration system used by Math. Reviews. The Russian letters represented by multiple Latin letters were implemented as ligatures. Non-Russian letters were implemented as ligatures of one Latin letter plus a digit (I don't remember the MR equivalent, if any).

One letter is represented in transliteration by four Latin letters -- "shch" (I don't have access to a Cyrillic alphabet either at present). This required several ligaturing steps, and to avoid conflicts with "real" letters (there are more letters in the Russian alphabet than in the Latin one), used digits as interim values. So "shc" becomes "7", which, when followed by "h", becomes the intended distinct Russian/Cyrillic letter.

That explains the "7".

The problem described here is the result of the difficulty in planning for the possibility that "sh" can be followed by "c1" in a non-Russian Cyrillic text. It's a situation that can't easily be handled by TeX's ligaturing mechanism, but application of /' (which explicitly disables ligatures) provides the necessary separation.

I don't believe that this exceptional situation is properly documented in the amsfonts user's guide, which is the canonical reference for this font. (I haven't checked, but in any case, the official policy is that the amsfonts fonts and user's guide will no longer be updated.)

A workaround is to load fontspec and enter your text in Unicode.

\documentclass{article}
\usepackage[paperwidth=10cm]{geometry} % Solely to make the MWE fit on TeX.SX.
\usepackage{babel} % Needed for hyphenation.
\usepackage{fontspec}
\usepackage{microtype} % Allows font expansion.

\babelprovide[import, main]{serbian-cyrillic}

\setmainfont{CMU Serif}[Scale = 1.0,
Ligatures = {Common, TeX},
Script = Cyrillic,
Language = Serbian]

\begin{document}

Овим једначинама се са великом прецизношћу може описати кретање тела
\textbf{при нерелативистичким брзинама,} тј. при брзинама много мањим
од брзине светлости.

\end{document}


The above works with LuaLaTeX in TeX Live 2019. Unfortunately, TeX Live 2018 ships with a broken version of microtype and you will need to apply a workaround to get this example to compile, or comment out the line %\usepackage{microtype} and accept uglier hyphenation.

If you need to use PDFLaTeX for a Serbian document, you will want to load a legacy 8-bit encoding that supports it, either T2A or X2, along with a Type 1 font package that supports the encoding. Otherwise, you’ll get a blurry, mismatched bitmap font. This example selects the CM-super fonts (by loading the T1 encoding) and then Babel for localization and hyphenation:

\documentclass{article}
\usepackage[paperwidth=10cm]{geometry} % Solely to make the MWE fit on TeX.SX.
\usepackage[T1,T2A]{fontenc}
\usepackage{textcomp}
\usepackage[utf8]{inputenc} % The default since 2018
\usepackage{babel} % Needed for hyphenation.

\babelprovide[import, main]{serbian-cyrillic}

\begin{document}

Овим једначинама се са великом прецизношћу може описати кретање тела
\textbf{при нерелативистичким брзинама,} тј. при брзинама много мањим
од брзине светлости.

\end{document}
`