0

I'm trying to output some code along with translated comments but the listing does not respect indentation and line breaks if first symbol in a line is Cyrillic:

\documentclass{book}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}
\usepackage{fontspec}
\usepackage{listings}

\setmonofont{Courier New}

\lstnewenvironment{codesample} {\lstset{basicstyle=\ttfamily,columns=fullflexible,keepspaces=true, backgroundcolor=\color{Cerulean}}}{}

\begin{document} \begin{codesample} Message: Welcome to Kyiv \end{codesample} \begin{codesample} Message: Ласкаво просимо до Києва \end{codesample} \begin{codesample} Повідомлення: Welcome to Kyiv \end{codesample} \begin{codesample} Повідомлення: Ласкаво просимо до Києва \end{codesample} \end{document}

enter image description here

Yola
  • 481
  • 1
    if you want to use chars above 256 you will have to declare them to listings first: https://tex.stackexchange.com/questions/25391/the-listings-package-and-utf-8/25396#25396 – Ulrike Fischer Dec 28 '20 at 13:52
  • @UlrikeFischer thank you, this helps. – Yola Dec 28 '20 at 14:31

1 Answers1

0

As per answer by Ulrike Fisher one needs to declare utf-8 characters to listing packages. Here is a declaration which works for Ukrainian.

\makeatletter
\lst@InputCatcodes
\def\lst@DefEC{%
    \lst@CCECUse \lst@ProcessLetter
    ^^^^0410^^^^0411^^^^0412^^^^0413^^^^0490^^^^0414^^^^0415^^^^0404% А Б В Г Ґ Д Е Є
    ^^^^0416^^^^0417^^^^0418^^^^0406^^^^0407^^^^0419^^^^041a^^^^041b% Ж З И І Ї Й К Л
    ^^^^041c^^^^041d^^^^041e^^^^041f^^^^0420^^^^0421^^^^0422^^^^0423% М Н О П Р С Т У
    ^^^^0424^^^^0425^^^^0426^^^^0427^^^^0428^^^^0429^^^^042c^^^^042e% Ф Х Ц Ч Ш Щ Ь Ю
    ^^^^042f% Я
    ^^^^0430^^^^0431^^^^0432^^^^0433^^^^0491^^^^0434^^^^0435^^^^0454% а б в г ґ д е є
    ^^^^0436^^^^0437^^^^0438^^^^0456^^^^0457^^^^0439^^^^043a^^^^043b% ж з и і ї й к л
    ^^^^043c^^^^043d^^^^043e^^^^043f^^^^0440^^^^0441^^^^0442^^^^0443% м н о п р с т у
    ^^^^0444^^^^0445^^^^0446^^^^0447^^^^0448^^^^0449^^^^044c^^^^044e% ф х ц ч ш щ ь ю
    ^^^^044f% я
    ^^00}
\lst@RestoreCatcodes
\makeatother
Yola
  • 481