5

I have recently encountered weird problem. Following code:

\documentclass[14pt, a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{fontspec}
\usepackage[english, serbianc]{babel}
\usepackage{polyglossia}
\setmainlanguage[Script=Cyrillic]{serbian}
\setotherlanguage{english}
\setmainfont{XCharter}

\begin{document}

    \begin{serbian}
        \begin{abstract}
            Чича Ђорђе жваће шљиве. Његова кћи Љиља меша џем. \textsc{АаБбВвГгДд}.
        \end{abstract}

        \section{Чича Ђорђе: \textsc{АаБбВвГгДд}.}
        Чича Ђорђе: \textsc{АаБбВвГгДд}.
    \end{serbian}

    \begin{english}
        \section{\foreignlanguage{serbian}{Чича Ђорђе: \textsc{АаБбВвГгДд}.}}
        Чича Ђорђе: \textsc{АаБбВвГгДд}.
    \end{english}

\end{document}

renders this result:

enter image description here

As you can see I'm using XChapter that have rich Cyrillic support, however, it's small caps does not work neither within serbian language environment, nor inside abstract, section names, chapter names etc. What is funny is that small caps do work inside body text inside english language environment. I tested with other fonts with good Cyrillic small caps support and same problem happens.

Does anybody have an idea what the problem might be and how can I make XeTex render XChapter small caps correctly within serbian language environment and in abstract body, section names, chapter names, etc.?

4
  • Welcome to TeX.SE!
    – Mensch
    Oct 23, 2021 at 21:49
  • 1
    You shouldn't load fontenc, but it's a minor problem. A more relevant issue is loading both babel and polyglossia: don't. However, the problem seems to be with polyglossia, because with babel the small caps letters are correctly found.
    – egreg
    Oct 23, 2021 at 21:53
  • 1
    @egreg Thanks! It appears that turning off polyglossia functionality solved this issue as all seems to be correctly rendered. If you wish please post as answer so I can accept it. Oct 23, 2021 at 22:02
  • I’ve improved my answer so you can get Serbian lowercase letters plus small caps in either babel or polyglossia.
    – Davislor
    Oct 24, 2021 at 16:49

3 Answers 3

3

It seems an issue with polyglossia. By the way, you shouldn't load both it and babel, because they fight each other.

Also, don't load fontenc when using XeLaTeX or LuaLaTeX.

\documentclass[a4paper]{article}
\usepackage{fontspec}

\usepackage[english,serbianc]{babel}

\setmainfont{XCharter}

\begin{document}

\begin{abstract}
Чича Ђорђе жваће шљиве. Његова кћи Љиља меша џем. \textsc{АаБбВвГгДд}.
\end{abstract}

\section{Чича Ђорђе: \textsc{АаБбВвГгДд}.}

Чича Ђорђе: \textsc{АаБбВвГгДд}.

\begin{otherlanguage}{english}
\section{\foreignlanguage{serbian}{Чича Ђорђе: \textsc{АаБбВвГгДд}.}}
\textsc{AbcDef}\textbf{\textsc{AbcDef}}
\end{otherlanguage}

\end{document}

enter image description here

You can also use polyglossia, if preferred, but in this case you need to help the package by defining a \serbianfont family (maybe also \serbianfontsf and \serbianfonttt).

\documentclass[a4paper]{article}
\usepackage{polyglossia}
\usepackage{fontspec}

\setmainlanguage[script=Cyrillic]{serbian}
\setotherlanguage{english}

\setmainfont{XCharter}
\newfontfamily{\serbianfont}{XCharter}

\begin{document}

\begin{abstract}
Чича Ђорђе жваће шљиве. Његова кћи Љиља меша џем. \textsc{АаБбВвГгДд}.
\end{abstract}

\section{Чича Ђорђе: \textsc{АаБбВвГгДд}.}
        Чича Ђорђе: \textsc{АаБбВвГгДд}.

\begin{otherlanguage}{english}
\section{\foreignlanguage{serbian}{Чича Ђорђе: \textsc{АаБбВвГгДд}.}}
\textsc{AbcDef}\textbf{\textsc{AbcDef}}
\end{otherlanguage}

\end{document}
3
  • It’s actually because they used the Babel command \foreignlanguage{serbian}{,,,}, but loaded Babel with the language serbianc, not serbian. So, the language is not being changed, and XCharter has special small-caps features for Cyrillic.
    – Davislor
    Oct 23, 2021 at 22:27
  • @Davislor That's not the source of the problem.
    – egreg
    Oct 24, 2021 at 9:07
  • Thanks. I went back and solved the second problem.
    – Davislor
    Oct 24, 2021 at 16:49
2

First, you’re attempting to mix the incompatible packages polyglossia, fontenc and babel. You want to choose either babel with a legacy 8-bit encoding, babel with Unicode, or Polyglossia.

You are only getting this problem with the text within \foreignlanguage{serbian}{...} because you told Babel that you were using the language serbianc, not serbian. You’re mixing up babel and polyglossia here. As a result, the language is not being changed, so the script is still set to Latin.

When you fix that error, you have another problem: XCharter disables small caps for Language=Serbian. However, if you set Language=Default, you get a Russian instead of Serbian б. You want to set Language=Default only on the small caps font, and the solution to that turns out to be, for babel:

\documentclass[14pt, a4paper]{article}
\usepackage[english, serbianc]{babel}
\usepackage{fontspec}

\defaultfontfeatures[XCharter]{
  UprightFont = *-Roman,
  UprightFeatures = {SmallCapsFont=*-Roman},
  BoldFont = *-Bold,
  BoldFeatures = {SmallCapsFont=*-Bold},
  ItalicFont = *-Italic,
  SlantedFont = *-Slanted,
  SlantedFeatures = {SmallCapsFont=*-Slanted},
  BoldItalicFont = *-BoldItalic,
  BoldSlantedFont = *-BoldSlanted,
  BoldSlantedFeatures = {SmallCapsFont=*-BoldSlanted},
  SmallCapsFeatures={Letters=SmallCaps},
  Extension = .otf}

% XCharter 1.221 has liga for English but not Serbian, and a language feature
% for Serbian but not English.
\babelfont{rm}
          {XCharter}
\babelfont[english]{rm}
          [Ligatures=Common, Language=Default]{XCharter}
\babelfont[serbianc]{rm}
          [Script=Cyrillic,
           Language=Serbian,
           SmallCapsFeatures={Script=Cyrillic, Language=Default, Letters=SmallCaps}
          ]{XCharter}

\babeltags{serbian=serbianc} % Enable \begin{serbian}, etc.
\babeltags{english=english}

\begin{document}

    \begin{serbian}
        \begin{abstract}
            Чича Ђорђе жваће шљиве. Његова кћи Љиља меша џем. АаБбВвГгДд \textsc{АаБбВвГгДд}.
        \end{abstract}

        \section{АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.}
        АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.
    \end{serbian}

    \begin{english}
        \section{АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.}
        АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.
        \textsc{English AaBbCc}
    \end{english}

\end{document}

XCharter sample

This correctly gets you your Serbian lowercase letters, along with small caps. The equivalent for Polyglossia is:

\documentclass[14pt, a4paper]{article}
\usepackage{polyglossia}

\setdefaultlanguage{serbian}
\setotherlanguage{english}

\defaultfontfeatures[XCharter]{
  UprightFont = *-Roman,
  UprightFeatures = {SmallCapsFont=*-Roman},
  BoldFont = *-Bold,
  BoldFeatures = {SmallCapsFont=*-Bold},
  ItalicFont = *-Italic,
  SlantedFont = *-Slanted,
  SlantedFeatures = {SmallCapsFont=*-Slanted},
  BoldItalicFont = *-BoldItalic,
  BoldSlantedFont = *-BoldSlanted,
  BoldSlantedFeatures = {SmallCapsFont=*-BoldSlanted},
  SmallCapsFeatures={Letters=SmallCaps},
  Extension = .otf}

% XCharter 1.221 has liga for English but not Serbian, and a language feature
% for Serbian but not English.
\setmainfont[Ligatures=Common, Language=Default]{XCharter}
\newfontfamily\serbianfont{XCharter}[
  Script=Cyrillic,
  Language=Serbian,
  SmallCapsFeatures={Script=Cyrillic, Language=Default, Letters=SmallCaps}]

\begin{document}

    \begin{serbian}
        \begin{abstract}
            Чича Ђорђе жваће шљиве. Његова кћи Љиља меша џем. АаБбВвГгДд \textsc{АаБбВвГгДд}.
        \end{abstract}

        \section{АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.}
        АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.
    \end{serbian}

    \begin{english}
        \section{АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.}
        АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.
        \textsc{English AaBbCc}
    \end{english}

\end{document}

Another alternative that saves you from language tagging is:

\documentclass[14pt, a4paper]{article}
\usepackage[nil]{babel}
\usepackage{fontspec}

\babelprovide[import=sr-Cyrl, onchar=fonts ids, main]{serbian}
\babelprovide[import=en, onchar=fonts ids]{english}

\defaultfontfeatures[XCharter]{
  UprightFont = *-Roman,
  UprightFeatures = {SmallCapsFont=*-Roman},
  BoldFont = *-Bold,
  BoldFeatures = {SmallCapsFont=*-Bold},
  ItalicFont = *-Italic,
  SlantedFont = *-Slanted,
  SlantedFeatures = {SmallCapsFont=*-Slanted},
  BoldItalicFont = *-BoldItalic,
  BoldSlantedFont = *-BoldSlanted,
  BoldSlantedFeatures = {SmallCapsFont=*-BoldSlanted},
  SmallCapsFeatures={Letters=SmallCaps},
  Extension = .otf}

% XCharter 1.221 has liga for English but not Serbian, and a language feature
% for Serbian but not English.
\babelfont{rm}
          {XCharter}
\babelfont[english]{rm}
          [Ligatures=Common, Language=Default]{XCharter}
\babelfont[serbian]{rm}
          [Script=Cyrillic,
           Language=Serbian,
           SmallCapsFeatures={Script=Cyrillic, Language=Default, Letters=SmallCaps}
          ]{XCharter}

\babeltags{serbian=serbian} % Enable \begin{serbian}, etc.
\babeltags{english=english}

\begin{document}

      \begin{abstract}
          Чича Ђорђе жваће шљиве. Његова кћи Љиља меша џем. АаБбВвГгДд \textsc{АаБбВвГгДд}.
      \end{abstract}

      \section{АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.}
        АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}. ffi

    \begin{english}
        \section{АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.}
        АаБбВвГгДд Чича Ђорђе: \textsc{АаБбВвГгДд}.
        \textsc{English AaBbCc} ffi
    \end{english}

\end{document}

XCharter sample

This automatically detects whether you are typing in Latin or Cyrillic, and selects the language, font features and hyphenation patterns appropriately, without tags. It requires LuaLaTeX, but there is also a way to do the same in XeLaTeX.

1

The problem can be reduced to the following

\documentclass{article}

\usepackage{fontspec}
\setmainfont{XCharter}[Script=Cyrillic,]
\setsansfont{XCharter}[Script=Cyrillic,Language=Serbian]

\begin{document}
АаБбВвГгДд \textsc{АаБбВвГгДд}.
 
\sffamily 
 
АаБбВвГгДд \textsc{АаБбВвГгДд}. 

\end{document}

enter image description here

As you can see adding both the cyrillic script and the serbian language disables the small caps.

The documentation of polyglossia doesn't really say how to avoid that the Language feature is used, but the following seems to work:

\documentclass{article}

\usepackage{fontspec}
\usepackage{polyglossia}

\setmainlanguage[script=Cyrillic]{serbian}
\SetLanguageKeys{serbian}{language=Default}

\setmainfont{XCharter}

\begin{document}
АаБбВвГгДд \textsc{АаБбВвГгДд}.
\end{document}
2
  • Thanks for providing this workaround for polyglossia. Tested few examples and all other features like hyphenation and sectioning work as well. Oct 24, 2021 at 15:33
  • Never mind, I found how to turn off Language=Serbian for small caps only.
    – Davislor
    Oct 24, 2021 at 16:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.