9

I am trying to compile an old document, created about three years ago. Then it worked fine with pdflatex and TL2019 or TL2020 (I'm not sure which one). Now with pdflatex and TL2022 I get errors:

! LaTeX Error: Command \tg already defined.
               Or name \end... illegal, see p.192 of the manual.

and the same for \arctg and \cosec commands.

I isolated the problem (or so I think), and it arises when I put together babel with Spanish (as main language) and Russian, and amsmath. I suppose the problem is that both languages are defining the same macros and somehow that produces the errors, but I have no idea how to prevent them.

My M(non)WE is:

\documentclass{article}

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

\begin{document}
\tableofcontents
\section{Una sección}
En cirílico \foreignlanguage{russian}{Лев Семёнович Понтр\'{я}гин},
y en alfabeto occidental Lev Semënovi\v{c} Pontrâ\'{g}in.
\end{document}

Remark. It works if I remove any of these items:

  • amsmath package.
  • main option for Spanish.
  • Russian language (and the cyrillic text).

I also changed the loading order of the packages, but to no avail.

4
  • 1
    For the same reason, one cannot use chemformula with a few language modules that define \ch for the hyperbolic cosine and offer no way to prevent this.
    – egreg
    Commented Jan 26, 2023 at 9:15
  • @egreg, so there is no way to work with both languages with a recent LaTeX distribution? :O Commented Jan 26, 2023 at 9:21
  • I guess that this is something that Javier Bezos should sort out. However, if you just need to typeset some words in Russian, you can remove russian from the options to babel and add \babelprovide{russian}. By the way, the accent over g is wrong.
    – egreg
    Commented Jan 26, 2023 at 10:03
  • @egreg, indeed, I only need a couple or Russian names, but this way the cyrillic doesn't show Commented Jan 26, 2023 at 10:11

2 Answers 2

8

This is a bug that has been hidden for a couple of decades.

Both the Spanish and Russian modules for babel want to define “local” math operators, because of tradition.

In the past, with your setup, the Spanish definitions would silently override the Russian ones, but recently russianb.ldf replaced

\def\tg{\mathop{\operator@font tg}\nolimits}

with

\AtBeginDocument{%
  \@ifpackageloaded{amsopn}
  {%
    [...]
    \DeclareMathOperator{\tg}{tg}%
    [...]
  }{%
    [...]
    \DeclareRobustCommand\tg{\mathop{\operator@font tg}\nolimits}%
    [...]
  }

which would be a good thing (contrary to what the module for Spanish does, ignoring whether amsmath is loaded or not), provided no other language module defines \tg. Unfortunately, spanish.ldf does.

While Spanish offers a (not really friendly) way to disable the “language local” operators, Russian doesn't.1 In my opinion both should bind the definitions in \extras<language>: it would be quite strange to get “lím” in a Russian part of the document, for instance.

Is there a way out? I can see none for general bilingual typesetting. But if you just need russian for typesetting some words in Russian (names, for instance), you can avoid loading all of russian.ldf and just ask for basic support.

\documentclass{article}

\usepackage[T2A,T1]{fontenc}
\usepackage[main=spanish]{babel}
\babelprovide{russian}
\usepackage{amsmath}


\begin{document}

\tableofcontents
\section{Una sección}
En cirílico \foreignlanguage{russian}{Лев Семёнович Понтр\'{я}гин},
y en alfabeto occidental Lev Semënovi\v{c} Pontrâgin.
\end{document}

enter image description here

An interim workaround if you're tied to Debian based TeX Live:

\documentclass{article}

\usepackage[T2A,T1]{fontenc}
\usepackage[main=spanish]{babel}
\babelprovide{russian}
\usepackage{amsmath}

\newcommand{\rus}[1]{{%
  \fontencoding{T2A}\selectfont\foreignlanguage{russian}{#1}%
}}


\begin{document}

\tableofcontents
\section{Una sección}
En cirílico \rus{Лев Семёнович Понтр\'{я}гин},
y en alfabeto occidental Lev Semënovi\v{c} Pontrâgin.
\end{document}

Footnote.
1 In order to disable the Spanish style operators one can do

\makeatletter\let\es@operators\relax\makeatother

but this isn't helpful in the case at hand, because it removes everything about Spanish style math operators. If the document had Russian as main language, this would work, but the converse fails and there's no real way to make Russian and Spanish style operators to coexist in one and the same document. Currently no way to make a bilingual document, actually.

13
  • This is just what I need but I'm still getting errors: Command \CYRL unavailable in encoding T1. ...�в Семёнович Понтрягин} and many others like this. Perhaps I need a more recent update? Commented Jan 26, 2023 at 10:46
  • @JuanCastaño Yes, you need to update to TeX Live 2022.
    – egreg
    Commented Jan 26, 2023 at 10:58
  • This is what I have: This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) Commented Jan 26, 2023 at 10:59
  • @JuanCastaño I added a workaround for your situation.
    – egreg
    Commented Jan 26, 2023 at 11:02
  • 1
    @JavierBezos I fixed the “wrong” claim, but the bulk of the matter remains unsolved.
    – egreg
    Commented Jan 26, 2023 at 17:19
5

As a complement to @egreg’s answer [edit: which has some inaccuracies], and if you want the changes in spanish, here is a workaround. It first saves and disables the redefinitions done by spanish with the first implicit \selectlanguage{spanish}, and then, after russian has defined \tg, it enables them and selects spanish again. This minimal example prints “lím tg lim tg lím tg”.

\documentclass{article}

\usepackage[T2A, T1]{fontenc}
\usepackage[russian,spanish]{babel}

\let\savemathspanish\mathspanish
\let\mathspanish\relax
\AtBeginDocument{%
  \let\mathspanish\savemathspanish
  \selectlanguage{spanish}}

\usepackage{amsmath}

\begin{document}

$\lim\tg$ \foreignlanguage{russian}{$\lim\tg$} $\lim\tg$ 

\end{document}
1
  • +1, It works perfectly. Gracias, Javier!!! Commented Jan 30, 2023 at 14:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .