5

Consider this for Greek

\documentclass{article}

\usepackage[LGR,T1]{fontenc}
\usepackage{textalpha}
\begin{document}
φύσις
\end{document

As the default font supports LGR encoding, it renders correctly:

enter image description here

I am looking for similar effect for occasional Cyrillic letters.

\documentclass{article}

\usepackage[T2A,T1]{fontenc}
% ? \usepackage
\begin{document}
До свидания!
\end{document}

Currently this fails with

LaTeX Error: Command \CYRD unavailable in encoding T1.

I must add manually

\documentclass{article}

\usepackage[T2A,T1]{fontenc}
\DeclareTextSymbolDefault{\CYRD}{T2A}
\begin{document}
До свидания!
\end{document}

then it fails at next letter:

LaTeX Error: Command \cyro unavailable in encoding T1.

So

\documentclass{article}

\usepackage[T2A,T1]{fontenc}
\DeclareTextSymbolDefault{\CYRD}{T2A}
\DeclareTextSymbolDefault{\cyro}{T2A}
\DeclareTextSymbolDefault{\cyrs}{T2A}
\DeclareTextSymbolDefault{\cyrv}{T2A}
\DeclareTextSymbolDefault{\cyri}{T2A}
\DeclareTextSymbolDefault{\cyrd}{T2A}
\DeclareTextSymbolDefault{\cyra}{T2A}
\DeclareTextSymbolDefault{\cyrn}{T2A}
\DeclareTextSymbolDefault{\cyrya}{T2A}
\begin{document}
До свидания!
\end{document}

enter image description here

I need some such automated font encoding substitution, and no extra mark-up.

I tried

\documentclass{article}

\usepackage[T2A,T1]{fontenc}
\usepackage[russian,main=english]{babel}

\begin{document}
До свидания!
\end{document}

but this still fails.

This is pdflatex only question. No extra mark-up in body of the type \textcyrillic is allowed. As indicated above I have an idea of what to do, but this is a bit fastidious and I will not know how to handle accents (this is optional; basic cyrillic support only is asked for. No hyphenation is needed).


(moved from comments)

The suggestion T1,T2A in place of T2A,T1 has the problem that Latin accented letters will be rendered with accent macros and not be copyable-pastable from the PDF. Here is for example for é:

....\kern -0.27771 (for accent)
....\T2A/cmr/m/n/10 ^^A
....\kern -4.72107 (for accent)
....\T2A/cmr/m/n/10 e

I do need to support European languages. Typically the document will use babel with a Latin language as main language, and the goal is support for occasional Cyrillic letters or words (without caring for proper hyphenation) with minimal overhead and no extra mark-up in body.

  • 2
    I am probably missing something obvious, but... loading \usepackage[T1,T2A]{fontenc} seems to work (i.e. changing the order of T1 and T2A). – Phelype Oleinik Nov 16 '18 at 10:46
  • @PhelypeOleinik good idea but unfortunately it slows down diacritics in Latin language such as é, è, ç and typesets them as accents, so that copy paste from PDF does not work. However for pure English this could be good option. But I do need support for European languages. – user4686 Nov 16 '18 at 10:53
  • Strange... although the accent is different in the log, the copy-paste still works for me. Here's my theory: It's not possible without switching the encoding. If you do \fontencoding{T1}\selectfont éèç\fontencoding{T2A}\selectfont До свидания! you can see in the log that the и cyrillic letter is written as \T2A/cmr/m/n/10 è, so it's probably in the same position as the latin è so, for me it looks like you will, at least, need an encoding witch. Beware that my level of certainty is pretty much null :-) – Phelype Oleinik Nov 16 '18 at 11:08
  • @PhelypeOleinik The \DeclareTextSymbolDefault in my OP are there to activate such an automatic font encoding switch. I hope for a package having them all prepared so that I don't have to do it myself. – user4686 Nov 16 '18 at 11:10
  • 1
    Oh, there goes the obvious thing I'm missing :P (and the "encoding witch", which I thought too funny to correct :) – Phelype Oleinik Nov 16 '18 at 11:14
4

A variant of your own answer:

\documentclass{article}
\usepackage[T2A,T1]{fontenc}

\makeatletter
\@tfor\next:=%
  {А}{а}{Б}{б}{В}{в}{Г}{г}{Д}{д}{Е}{е}
  {Ё}{ё}{Ж}{ж}{З}{з}{И}{и}{Й}{й}{К}{к}
  {Л}{л}{М}{м}{Н}{н}{О}{о}{П}{п}{Р}{р}
  {С}{с}{Т}{т}{У}{у}{Ф}{ф}{Х}{х}{Ц}{ц}
  {Ч}{ч}{Ш}{ш}{Щ}{щ}{Ъ}{ъ}{Ы}{ы}{Ь}{ь}
  {Э}{э}{Ю}{ю}{Я}{я}%
\do{%
  \begingroup\def\IeC{\protect\DeclareTextSymbolDefault}%
  \protected@edef\@temp{\endgroup\next{T2A}}\@temp}
\makeatother

\begin{document}

До свидания! See you soon!

\end{document}

Add other Cyrillic characters you need. Remember that, if you're running an older LaTeX release (prior to 2018-04-01), you need also \usepackage[utf8]{inputenc}.

enter image description here

Using the X2 encoding, that covers a larger number of characters in the encodings T2A, T2B and T2C:

\documentclass{article}
\usepackage[X2,T1]{fontenc}
\makeatletter
\@tfor\next:=
{Ё} {Ђ} {Є} {Ѕ} {І} {Ј} {Љ} {Њ} {Ћ} {Ў} {Џ} {А} {Б} {В} {Г} {Д}
{Е} {Ж} {З} {И} {Й} {К} {Л} {М} {Н} {О} {П} {Р} {С} {Т} {У} {Ф}
{Х} {Ц} {Ч} {Ш} {Щ} {Ъ} {Ы} {Ь} {Э} {Ю} {Я} {а} {б} {в} {г} {д}
{е} {ж} {з} {и} {й} {к} {л} {м} {н} {о} {п} {р} {с} {т} {у} {ф}
{х} {ц} {ч} {ш} {щ} {ъ} {ы} {ь} {э} {ю} {я} {ё} {ђ} {є} {ѕ} {і}
{ј} {љ} {њ} {ћ} {ў} {џ} {Ѣ} {ѣ} {Ѫ} {ѫ} {Ѵ} {ѵ} {Ґ} {ґ} {Ғ} {ғ}
{Ҕ} {ҕ} {Җ} {җ} {Ҙ} {ҙ} {Қ} {қ} {Ҝ} {ҝ} {Ҟ} {ҟ} {Ҡ} {ҡ} {Ң} {ң}
{Ҥ} {ҥ} {Ҧ} {ҧ} {Ҩ} {ҩ} {Ҫ} {ҫ} {Ҭ} {ҭ} {Ү} {ү} {Ұ} {ұ} {Ҳ} {ҳ}
{Ҵ} {ҵ} {Ҷ} {ҷ} {Ҹ} {ҹ} {Һ} {һ} {Ҽ} {ҽ} {Ҿ} {ҿ} {Ӏ} {Ӄ} {ӄ} {Ӆ}
{ӆ} {Ӈ} {ӈ} {Ӌ} {ӌ} {Ӎ} {ӎ} {Ӕ} {ӕ} {Ә} {ә} {Ӡ} {ӡ} {Ө} {ө}
\do{%
  \begingroup\def\IeC{\protect\DeclareTextSymbolDefault}%
  \protected@edef\@temp{\endgroup\next{X2}}\@temp}
\makeatother

\begin{document}

Ё Ђ Є Ѕ І Ј Љ Њ Ћ Ў Џ А Б В Г Д
Е Ж З И Й К Л М Н О П Р С Т У Ф
Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д
е ж з и й к л м н о п р с т у ф
х ц ч ш щ ъ ы ь э ю я ё ђ є ѕ і
ј љ њ ћ ў џ Ѣ ѣ Ѫ ѫ Ѵ ѵ Ґ ґ Ғ ғ
Ҕ ҕ Җ җ Ҙ ҙ Қ қ Ҝ ҝ Ҟ ҟ Ҡ ҡ Ң ң
Ҥ ҥ Ҧ ҧ Ҩ ҩ Ҫ ҫ Ҭ ҭ Ү ү Ұ ұ Ҳ ҳ
Ҵ ҵ Ҷ ҷ Ҹ ҹ Һ һ Ҽ ҽ Ҿ ҿ Ӏ Ӄ ӄ Ӆ
ӆ Ӈ ӈ Ӌ ӌ Ӎ ӎ Ӕ ӕ Ә ә Ӡ ӡ Ө ө


\end{document}

enter image description here

To your delight, an implementation with expl3:

\documentclass{article}
\usepackage[X2,T1]{fontenc}
\usepackage{expl3}

\ExplSyntaxOn
\cs_new_protected:Nn \__recode:N
 {% #1 is \u8:<bytes> which expands to \IeC{<LICR>}
  \exp_last_unbraced:No \__recode_aux:nn #1
 }
\cs_new_protected:Nn \__recode_aux:nn { \DeclareTextSymbolDefault#2{X2} }
\cs_generate_variant:Nn \__recode:N { c }
\tl_map_inline:nn
 {
  {Ё} {Ђ} {Є} {Ѕ} {І} {Ј} {Љ} {Њ} {Ћ} {Ў} {Џ} {А} {Б} {В} {Г} {Д}
  {Е} {Ж} {З} {И} {Й} {К} {Л} {М} {Н} {О} {П} {Р} {С} {Т} {У} {Ф}
  {Х} {Ц} {Ч} {Ш} {Щ} {Ъ} {Ы} {Ь} {Э} {Ю} {Я} {а} {б} {в} {г} {д}
  {е} {ж} {з} {и} {й} {к} {л} {м} {н} {о} {п} {р} {с} {т} {у} {ф}
  {х} {ц} {ч} {ш} {щ} {ъ} {ы} {ь} {э} {ю} {я} {ё} {ђ} {є} {ѕ} {і}
  {ј} {љ} {њ} {ћ} {ў} {џ} {Ѣ} {ѣ} {Ѫ} {ѫ} {Ѵ} {ѵ} {Ґ} {ґ} {Ғ} {ғ}
  {Ҕ} {ҕ} {Җ} {җ} {Ҙ} {ҙ} {Қ} {қ} {Ҝ} {ҝ} {Ҟ} {ҟ} {Ҡ} {ҡ} {Ң} {ң}
  {Ҥ} {ҥ} {Ҧ} {ҧ} {Ҩ} {ҩ} {Ҫ} {ҫ} {Ҭ} {ҭ} {Ү} {ү} {Ұ} {ұ} {Ҳ} {ҳ}
  {Ҵ} {ҵ} {Ҷ} {ҷ} {Ҹ} {ҹ} {Һ} {һ} {Ҽ} {ҽ} {Ҿ} {ҿ} {Ӏ} {Ӄ} {ӄ} {Ӆ}
  {ӆ} {Ӈ} {ӈ} {Ӌ} {ӌ} {Ӎ} {ӎ} {Ӕ} {ӕ} {Ә} {ә} {Ӡ} {ӡ} {Ө} {ө}
 }
 {
  \__recode:c { u8: \tl_to_str:n { #1 } }
 }
\ExplSyntaxOff

\begin{document}

Ё Ђ Є Ѕ І Ј Љ Њ Ћ Ў Џ А Б В Г Д
Е Ж З И Й К Л М Н О П Р С Т У Ф
Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д
е ж з и й к л м н о п р с т у ф
х ц ч ш щ ъ ы ь э ю я ё ђ є ѕ і
ј љ њ ћ ў џ Ѣ ѣ Ѫ ѫ Ѵ ѵ Ґ ґ Ғ ғ
Ҕ ҕ Җ җ Ҙ ҙ Қ қ Ҝ ҝ Ҟ ҟ Ҡ ҡ Ң ң
Ҥ ҥ Ҧ ҧ Ҩ ҩ Ҫ ҫ Ҭ ҭ Ү ү Ұ ұ Ҳ ҳ
Ҵ ҵ Ҷ ҷ Ҹ ҹ Һ һ Ҽ ҽ Ҿ ҿ Ӏ Ӄ ӄ Ӆ
ӆ Ӈ ӈ Ӌ ӌ Ӎ ӎ Ӕ ӕ Ә ә Ӡ ӡ Ө ө

\end{document}
  • clever... but was loading xparse needed? :) – user4686 Nov 16 '18 at 20:23
  • this is elegant but problem is how to know offhand one will not (if extending the list from the picking additional Unicode Cyrillic letters) assign T2A to a letter actually available only in T2B/T2C ? – user4686 Nov 16 '18 at 20:27
  • @jfbu That's the standard Russian Cyrillic alphabet. For glyphs in other encodings the method is the same. – egreg Nov 16 '18 at 21:08
  • I think I will award the green tick, now that answer is freed from automatic xparse loading template... :). (waiting a while) – user4686 Nov 16 '18 at 23:46
  • @jfbu I added a larger list using X2 – egreg Nov 17 '18 at 0:45
3

If no package exists, I might end up doing something like this:

\documentclass{article}
\usepackage[T2A,T1]{fontenc}
\makeatletter
\@tfor\@tempa:=%
{ae}{a}{b}{chrdsc}{chvcrs}{ch}{c}{dje}{dze}{dzhe}{d}{erev}{ery}{e}%
{f}{ghcrs}{gup}{g}{hdsc}{hrdsn}{h}{ie}{ii}{ishrt}{i}{je}%
{kbeak}{kdsc}{kvcrs}{k}{lje}{l}{m}{ndsc}{ng}{nje}{n}{otld}{o}{p}{r}%
{schwa}{sdsc}{sftsn}{shch}{shha}{sh}{s}{tshe}{t}{ushrt}{u}{v}%
{ya}{yhcrs}{yi}{yo}{yu}{y}{zdsc}{zhdsc}{zh}{z}\do{%
    \expandafter\DeclareTextSymbolDefault\expandafter
               {\csname cyr\@tempa\endcsname}{T2A}%
    \expandafter\uppercase\expandafter{\expandafter
                 \def\expandafter\@tempa\expandafter{\@tempa}}%
    \expandafter\DeclareTextSymbolDefault\expandafter
      {\csname CYR\@tempa\endcsname}{T2A}%
}%
\makeatother
\DeclareTextSymbolDefault{\CYRpalochka}{T2A}

%\listfiles
\begin{document}
До свидания!

%\makeatletter
%\show\@uclclist
\end{document}

This was based on regex manipulation of t2aenc.dfu (I compared with t2aenc.def which has also \cyrq, \cyrw, but examination of Unicode Cyrillic block seems to indicate these stand simply for Latin q and w, so without explicit font encoding change in the document they can't be rendered by T2A encoded TeX font, another problem with my hoped-for "no mark-up" approach, besides breaking kerning and not setting up hyphenation).

The \@uclclist contains more \cyr..., presumably from utf8enc.dfu (one does not see it in File List, but I guess because it is loaded in format since TL2018), so using it would mean assigning T2A default font encoding substitution wrongly to some letters. Which is not a problem if the document contains no such letters...

da svidania

2

The following code is very hacky but still it doesn't make you list all cyrillic commands explicitly. The idea is to take the list somewhere, and there's a uppercase-lowercace conversion list with all \cyr* commands. So looping over @uclclist we can call \DeclareTextSymbolDefault for all cyrillic macros (there are some others in the list, like \OE, \AE, but declaring the default encoding for them seems to be harmless).

\documentclass{article}

\usepackage[T2A,T1]{fontenc}

\makeatletter
\def\myloop#1{%
\ifx\relax#1
  \let\next\relax
\else
  \let\next\myloop
  \DeclareTextSymbolDefault{#1}{T2A}
\fi
\next}
\expandafter\myloop\@uclclist\relax
\makeatother

\begin{document}
До свидания! é, è, ç, \OE, \ae
\end{document}
  • thanks, I could add a check for the macro name to start with \cyr or \CYR. – user4686 Nov 16 '18 at 11:55
  • Right, I thought about that but decided to keep code simple at the moment. – Sergei Golovan Nov 16 '18 at 11:55
  • an alternative could be to input t2aenc.def with special temporary meaning given to the macros it uses, but this is yet more hacky and possibly error prone. I suspect I may in the end simply copy-paste from that file and do some regex search/replace to prepare my own package, but I wouldn't know how to handle accents. I could also simply prepare a list of all \cyr... and \CYR.. I see there and do a loop, with \@tfor e.g. At any rate, +1 for proposal. – user4686 Nov 16 '18 at 12:01
  • the \@uclclist will contain \cyrabhdze, (presumably from a declaration inside utf8enc.dfu), but it is in T2B and T2C, not in T2A. So it would be wrong to use this trick, except of course if one is sure the document will contain no such letters available in T2B or T2C or X2 but not in T2A encoding. Besides, \CYRpalochka does not appear in the list presumably because there is no difference for it between lowercase and uppercase. – user4686 Nov 16 '18 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy