5

I am using the fontenc package in order to write texts in either Serbian Latin script (OT1 encoding) or Serbian Cyrillic script (OT2 encoding). My objective is to typeset an appreciable quantity of body text by compiling a single LaTeX code and to produce the Serbian Latin output text or Serbian Cyrillic output text depending on the used fontenc encoding. However, this appears impossible as switching from one fontenc encoding to the other implies the use of different letter representations in the LaTeX code. For instance, letter ž (Latin) is identical to ж (Cyrillic). Yet, they must be differently encoded in OT1 and OT2 as \v{z} and zh, respectively. I have given two examples below in which the same sentence meaning "Perhaps Novak Djokovic can win a match against Nadal on clay" has the two outputs (Latin and Cyrillic), but their LaTeX codes are unfortunately different, and not universal as wanted. Any help would be more than welcome. Thanks in advance.

% Example_1
\documentclass{scrartcl}
\usepackage[OT1]{fontenc}
\usepackage[english,serbian]{babel}
\begin{document}
Mo\v{z}da Novak \DJ{}okovi\'{c} mo\v{z}e da osvoji me\v{c} protiv Nadala na \v{s}ljaci.
\end{document}
% Example_2
\documentclass{scrartcl}
\usepackage[OT2]{fontenc}
\usepackage[english,serbian]{babel}
\begin{document}
Mozhda Novak DJokovic1 mozhe da osvoji mech protiv Nadala na shljaci.
\end{document}
  • 2
    why OT1 and OT2? These are old encodings. Also why don't you input directly in utf8? – Ulrike Fischer Nov 13 at 8:58
  • Thank you @UlrikeFischer. A time ago, I used a Serbian Cyrillic keyboard to write the LaTeX code as an input. However, it was hard to manipulate this code (copy, paste, cut...) when switching from one editor to the other... – Savchenko Nov 13 at 9:39
3

For Serbian language the best option is to use the cmsrb package. You will also get the correct italic shape of Cyrillic italic letters.

\documentclass{article}
\usepackage{cmsrb}
\usepackage[OT2,T1]{fontenc} %better to use T1, but OT1 will also work
\usepackage[serbian]{babel}
\begin{document}

Mo\v{z}da Novak \DJ{}okovi\'{c} mo\v{z}e da osvoji me\v{c} protiv Nadala na \v{s}ljaci.

\textit{abc\v c\'cdd\v z\dj efghijklljmnnjoprs\v stuvz\v z}

\fontencoding{OT2}\selectfont

Mo\v{z}da Novak \DJ{}okovi\'{c} mo\v{z}e da osvoji me\v{c} protiv Nadala na \v{s}ljaci.

\textit{abc\v c\'cdd\v z\dj efghijklljmnnjoprs\v stuvz\v z}

\end{document}

cmsrb Example

This will also work with UTF-8 input.

  • This works too! Thank you so much @Урош! I have just had a look at your cmsrb package - great work indeed. I was wondering if your package could enable the use of the single LaTex code: " Mozhda Novak DJ{}okovic1 mozhe da osvoji mech protiv Nadala na shljaci." for producing the two outputs (Latin and Cyrilic) at the same time. Typing in this code seems faster. If this is achievable within the package, would you expect any issue with the syllable division rules? Many many thanks in advance. Cheers! – Savchenko Nov 13 at 13:23
  • 1
    @Savchenko Well, it is possible to create ligatures such as 'ch', 'dj' and so on for the some next version of the package. I have removed them on purpose because the default OT2 ligatures are very bad solution for the Serbian language. However, I've been thinking to add DY, ZX, CY, CX, DX, SX ligatures for Ђ, Ж, Ћ, Ч, Џ, Ш in the next package version. Also I thing this will make a much better hyphenation. This is possible to be done for the T1 encoding too, but I'm not sure that is a good idea. I'm preparing the new version, and I will think about the best solution. – Урош Nov 14 at 10:27
5

I suggest using UTF-8 input. The only problem is with “Dž” and “dž” that should be input \DZ and \dz respectively.

\documentclass{article}
\usepackage[OT2,OT1]{fontenc}
\usepackage[english,serbian]{babel}

\DeclareTextCompositeCommand{\v}{OT2}{C}{Ch}
\DeclareTextCompositeCommand{\v}{OT2}{c}{ch}
\DeclareTextCompositeCommand{\v}{OT2}{S}{Sh}
\DeclareTextCompositeCommand{\v}{OT2}{s}{sh}
\DeclareTextCompositeCommand{\v}{OT2}{Z}{Zh}
\DeclareTextCompositeCommand{\v}{OT2}{z}{zh}
\DeclareTextCompositeCommand{\'}{OT2}{C}{C1}
\DeclareTextCompositeCommand{\'}{OT2}{c}{c1}
\DeclareTextCommand{\DJ}{OT2}{Dj}
\DeclareTextCommand{\dj}{OT2}{dj}
\DeclareTextCommand{\DZ}{OT1}{Dž}
\DeclareTextCommand{\DZ}{OT2}{D2}
\DeclareTextCommand{\dz}{OT1}{dž}
\DeclareTextCommand{\dz}{OT2}{d2}

\makeatletter
\g@addto@macro\@uclclist{\dj\DJ\dz\DZ}
\makeatother

\begin{document}

Možda Novak Đoković može da osvoji meć protiv Nadala na šljaci.

{\footnotesize\MakeUppercase{Možda Novak Đoković može da osvoji meć protiv Nadala na šljaci.}\par}

A B C Č Ć D \DZ\ Đ E F G H I J K L Lj M N Nj O P R S Š T U V Z Ž

a b c č ć d \dz\ đ e f g h i j k l lj m n nj o p r s š t u v z ž

\MakeUppercase{a b c č ć d \dz\ đ e f g h i j k l lj m n nj o p r s š t u v z ž}

\bigskip

\fontencoding{OT2}\selectfont

Možda Novak Đoković može da osvoji meć protiv Nadala na šljaci.

{\footnotesize\MakeUppercase{Možda Novak Đoković može da osvoji meć protiv Nadala na šljaci.}\par}

A B V G D Đ E Ž Z I J K L Lj M N Nj O P R S T Ć U F H C Č \DZ\ Š

a b v g d đ e ž z i j k l lj m n nj o p r s t ć u f h c č \dz\ š

\MakeUppercase{a b v g d đ e ž z i j k l lj m n nj o p r s t ć u f h c č \dz\ š}

\end{document}

enter image description here

A proper solution would be to use XeLaTeX, though, see https://tex.stackexchange.com/a/44740/4427

  • Wow! The problem solved. Thank you greatly @egreg. It works perfectly well. – Savchenko Nov 13 at 10:34

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.