列表中的西里尔字符

列表中的西里尔字符

我尝试在源代码块中写一些西里尔文:

\begin{lstlisting}[caption={asdfa},label={lst:tokens},language=SQL]
SELECT 
(SELECT COUNT(*) 
FROM cards
WHERE description ILIKE '%#НОМЕР#%') AS PhoneNumber,
(SELECT COUNT(*) 
FROM cards
WHERE description ILIKE '%#ГОС.НОМЕР#%') AS LicensePlateNumber
\end{lstlisting}

样式设置如下:

\lstset{
    language=SQL,frame=ltrb,framesep=5pt,basicstyle=\normalsize,
    keywordstyle=\ttfamily\color{OliveGreen},
    identifierstyle=\ttfamily\color{CadetBlue}\bfseries, 
    commentstyle=\color{Brown},
    stringstyle=\ttfamily,
    showstringspaces=true,
    escapeinside={<--}{-->},
    extendedchars=\true,
    literate={а}{\cyra}1
    {б}{{\selectfont\char225}}1
    {в}{{\selectfont\char226}}1
    {г}{{\selectfont\char227}}1
    {д}{{\selectfont\char228}}1
    {е}{{\selectfont\char229}}1
    {ё}{{\"e}}1
    {ж}{{\selectfont\char230}}1
    {з}{{\selectfont\char231}}1
    {и}{{\selectfont\char232}}1
    ...
    }

西里尔文字符均未显示。我尝试将西里尔文括在罕见字符中(在评论中列出混合英语和俄语符号),但也没有用。使用extendedchars=true代替\true(为什么 utf8 不允许在列表中使用西里尔字母,而 utf8x 却允许?) 没有帮助。我找到了建议使用mintex(第一个链接),但我必须创建一个列表。

我一开始也导入了以下内容:

\usepackage[utf8]{inputenc}
\usepackage[russian, english]{babel}

使用polyglossia俄语作为附加语言也无帮助。

我怎样才能使这个东西能够与西里尔符号一起工作?

编辑:以下是导入的内容:

\documentclass[a4paper,12pt]{report}
\usepackage{graphicx}
\graphicspath{pics/}
\usepackage[a4paper,top=25mm,bottom=25mm]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyfoot{}
\fancyfoot[R]{\thepage}
\fancypagestyle{plain}{}
\usepackage[nottoc]{tocbibind}
\usepackage[utf8]{inputenc}
\usepackage[russian, english]{babel}
\usepackage{url}
\usepackage{xurl}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{float}
\usepackage{wrapfig}
\usepackage{indentfirst}
\usepackage{mathtools}
\usepackage{hyperref}
\usepackage{enumitem}
\usepackage[acronym,automake]{glossaries}
\usepackage{xcolor,listings}
\usepackage{fontspec}
\usepackage[T2A]{fontenc}
\setmonofont{Courier New}
\input{common/lststyles}

此后,不再应用任何包。

编辑2:这个示例代码可以工作,尽管方式有点奇怪:

\lstdefinestyle{code-style-sql}{
    belowcaptionskip=1\baselineskip,
    xleftmargin=\parindent,
    identifierstyle=\color{blue},
    language=SQL,                % the language of the code
    backgroundcolor=\color{backgray},       % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}; should come as last argument  
    commentstyle=\color{codegray},        % comment style
    keywordstyle=\color{codeblue}\bfseries,    % keyword style
    numberstyle=\tiny\color{codegray},      % the style that is used for the line-numbers
    stringstyle=\color{codeblue},        % string literal style
    basicstyle=\small\ttfamily\footnotesize,  % Размер и тип шрифта, the size of the fonts that are used for the code
    breakatwhitespace=false,               % sets if automatic breaks should only happen at whitespace
    breaklines=true,                  % Перенос строк, the size of the fonts that are used for the code       
    captionpos=lt,                          % sets the caption-position to bottom               
    keepspaces=true,                % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)             
    numbers=left,                          % where to put the line-numbers; possible values are (none, left, right)
    numbersep=5pt,                     % how far the line-numbers are from the code       
    stepnumber=1,                          % the step between two line-numbers. If it's 1, each line will be numbered
    showspaces=false,           % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'   
    showstringspaces=false,    % underline spaces within strings only    
    showtabs=false,             % show tabs within strings adding particular underscores     
    tabsize=2,          % Размер табуляции, sets default tabsize to 2 spaces
    %  frame=single,               % Рамка, adds a frame around the code
    %  frame=TB,
    literate={--}{{-{}-}}2,     % Корректно отображать двойной дефис
    literate={---}{{-{}-{}-}}3,  % Корректно отображать тройной дефис
    escapeinside={<--}{-->}
}
\lstset{style=code-style-sql}

它将西里尔文本移至左撇号并将符号留在右侧:'ГОСНОМЕР%#.#%'而不是'%#ГОС.НОМЕР#%'

答案1

您可以使用 XeLaTeX,但必须手动添加对基本(俄语)西里尔字母的支持。

\documentclass{article}
\usepackage[a4paper,top=25mm,bottom=25mm]{geometry}
\usepackage[russian,english]{babel}
\usepackage{fontspec}
\usepackage{listings}
\usepackage[dvipsnames]{xcolor}

% a main font that supports Cyrillic; use your preferred one
\setmainfont{NewCM10}[
  Extension=.otf,
  UprightFont=*-Regular,
  ItalicFont=*-Italic,
  BoldFont=*-Bold,
  BoldItalicFont=*-BoldItalic,
]
\setmonofont{Courier New}

\lstset{
  language=SQL,
  frame=ltrb,
  framesep=5pt,
  basicstyle=\normalsize,
  keywordstyle=\ttfamily\color{OliveGreen},
  identifierstyle=\ttfamily\color{CadetBlue}\bfseries, 
  commentstyle=\color{Brown},
  stringstyle=\ttfamily,
  showstringspaces=true,
  escapeinside={<--}{-->},
}

\makeatletter % see https://tex.stackexchange.com/a/320345
\lst@InputCatcodes
\def\lst@DefEC{%
 \lst@CCECUse \lst@ProcessLetter
  ^^80^^81^^82^^83^^84^^85^^86^^87^^88^^89^^8a^^8b^^8c^^8d^^8e^^8f%
  ^^90^^91^^92^^93^^94^^95^^96^^97^^98^^99^^9a^^9b^^9c^^9d^^9e^^9f%
  ^^a0^^a1^^a2^^a3^^a4^^a5^^a6^^a7^^a8^^a9^^aa^^ab^^ac^^ad^^ae^^af%
  ^^b0^^b1^^b2^^b3^^b4^^b5^^b6^^b7^^b8^^b9^^ba^^bb^^bc^^bd^^be^^bf%
  ^^c0^^c1^^c2^^c3^^c4^^c5^^c6^^c7^^c8^^c9^^ca^^cb^^cc^^cd^^ce^^cf%
  ^^d0^^d1^^d2^^d3^^d4^^d5^^d6^^d7^^d8^^d9^^da^^db^^dc^^dd^^de^^df%
  ^^e0^^e1^^e2^^e3^^e4^^e5^^e6^^e7^^e8^^e9^^ea^^eb^^ec^^ed^^ee^^ef%
  ^^f0^^f1^^f2^^f3^^f4^^f5^^f6^^f7^^f8^^f9^^fa^^fb^^fc^^fd^^fe^^ff%
  ^^^^20ac^^^^0153^^^^0152%
  % Basic Cyrillic alphabet coverage
  ^^^^0410^^^^0411^^^^0412^^^^0413^^^^0414^^^^0415^^^^0416^^^^0417%
  ^^^^0418^^^^0419^^^^041a^^^^041b^^^^041c^^^^041d^^^^041e^^^^041f%
  ^^^^0420^^^^0421^^^^0422^^^^0423^^^^0424^^^^0425^^^^0426^^^^0427%
  ^^^^0428^^^^0429^^^^042a^^^^042b^^^^042c^^^^042d^^^^042e^^^^042f%
  ^^^^0430^^^^0431^^^^0432^^^^0433^^^^0434^^^^0435^^^^0436^^^^0437%
  ^^^^0438^^^^0439^^^^043a^^^^043b^^^^043c^^^^043d^^^^043e^^^^043f%
  ^^^^0440^^^^0441^^^^0442^^^^0443^^^^0444^^^^0445^^^^0446^^^^0447%
  ^^^^0448^^^^0449^^^^044a^^^^044b^^^^044c^^^^044d^^^^044e^^^^044f%
  ^^^^0401^^^^0451%
  %%%
  ^^00}
\lst@RestoreCatcodes
\makeatother


\begin{document}

\begin{lstlisting}[caption={asdfa},label={lst:tokens},language=SQL]
SELECT 
(SELECT COUNT(*) 
FROM cards
WHERE description ILIKE '%#НОМЕР#%') AS PhoneNumber,
(SELECT COUNT(*) 
FROM cards
WHERE description ILIKE '%#ГОС.НОМЕР#%') AS LicensePlateNumber
\end{lstlisting}

\end{document}

请注意,您不应该加载inputencfontenc

在此处输入图片描述

答案2

从 XeTeX 切换到 pdfLaTeX 可以解决问题。

相关内容