1

Coloring cyrillic comment does not work in LuaLaTeX.

How might I be able to resolve this issue?

MWE:

\documentclass{article}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=modern]{russian}
\setotherlanguage{english}
\defaultfontfeatures{Ligatures={TeX}}
\setmainfont{Times New Roman}
\newfontfamily{\cyrillicfont}{Times New Roman}
\setsansfont{Arial}
\newfontfamily{\cyrillicfontsf}{Arial}
\setmonofont{Courier New}
\newfontfamily\cyrillicfonttt[Script=Cyrillic]{Courier New}
\usepackage{xcolor}
%\definecolor{gray}{rgb}{0.4,0.4,0.4}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}
\usepackage{listings}
\lstloadlanguages{SQL}

\lstdefinelanguage{SQL}
{
    keywords={create, replace, table, primary, foreign, references, key, not, null, select, insert, update, where, from, as, into, values, set, delete, order, by, and, distinct, max, min, group, having, count, left, right, full, join, on, union, plan, collate, all, returns, procedure, begin, end, suspend, generator, to, or, each, execute, row, statement, active, trigger, for, before, after, is, if, then, new, old, gen_id, position, inactive, grant, revoke, with, option, public, domain, collation, character, translation, usage, cascade, restrict, sequence, increment, minvalue, maxvalue, start, function, default, nextval, currval},
    keywordstyle=\color{darkblue},
    ndkeywords={varchar, integer, smallint, char},
    ndkeywordstyle=\color{cyan},
    sensitive=false,
    morecomment=[l]--,
    morecomment=[s][\color{orange}]{/*}{*/},
    morestring=[d]',
    morestring=[d]",
    stringstyle=\color{purple}
}

\lstdefinestyle{listSQL}{
%   extendedchars=true,
%   extendedchars=\true,
    language=SQL,
    belowcaptionskip=5pt,
    xleftmargin=0.5cm,
    numbers=left,
    numberstyle=\small,
    frame=single,
    keepspaces=true,
    breaklines=true,
    breakatwhitespace=true,
    breakindent=0pt,
    emph={},
    emphstyle=\color{red},
    basicstyle=\ttfamily,
    columns=fullflexible,
    showstringspaces=false,
    commentstyle=\color{orange}\upshape}

\begin{filecontents*}[overwrite]{dbstart.txt}
    -- Create table sgroup
    create table sgroup (
    id integer not null,
    group_name varchar(40),
    primary key (id));  -- уникальный ключ id
    -- Создаем таблицу Студент
    create table student (
    id integer not null,
    id_group integer not null, -- поле для связи с таблицей Группа
    student_name varchar(40),
    last_name varchar(40),
    middle_name varchar(40),
    sex char(1),
    age smallint,
    primary key (id), -- уникальный ключ id
    foreign key (id_group) references sgroup (id)); -- определение связи с таблицей Группа
    -- Создаем таблицу Хобби
    create table hobby (
    id integer not null, -- уникальный ключ
    hobby_name varchar(100),
    primary key (id)); -- уникальный ключ id
    -- Создаем таблицу Студент-Хобби
    create table student_hobby (
    id_student integer not null, -- поле для связи с таблицей Студент
    id_hobby integer not null, -- поле для связи с таблицей Хобби
    primary key (id_student, id_hobby), -- уникальный ключ составной id_student, id_hobby
    foreign key (id_hobby) references hobby (id), -- определение связи с таблицей Хобби
    foreign key (id_student) references student (id)); -- определение связи с таблицей Студент
\end{filecontents*}

\begin{document}
    In string: \lstinline[style=listSQL] !select count(*) from sgroup; -- выборка! !
    \lstinputlisting[label=dbstart, style=listSQL]{dbstart.txt}
\end{document}

enter image description here

4

1 Answer 1

1

Use minted package.

Example with default settings:

\inputminted{SQL}{dbstart.txt}

minted

MWE

\documentclass{article}
\usepackage{xcolor}
%\definecolor{gray}{rgb}{0.4,0.4,0.4}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{cyan}{rgb}{0.0,0.6,0.6}
\usepackage{polyglossia}
\setdefaultlanguage[spelling=modern]{russian}
\setotherlanguage{english}
\defaultfontfeatures{Ligatures={TeX}}
\setmainfont{Times New Roman}
\newfontfamily{\cyrillicfont}{Times New Roman}
\setsansfont{Arial}
\newfontfamily{\cyrillicfontsf}{Arial}
\setmonofont{Courier New}
\newfontfamily\cyrillicfonttt[Script=Cyrillic]{Noto Sans Mono}
\usepackage{minted}

\usepackage{listings}
\lstset{escapebegin=\begin{russian},escapeend=\end{russian}}
\lstloadlanguages{SQL}

\lstdefinelanguage{SQL}
{
    keywords={create, replace, table, primary, foreign, references, key, not, null, select, insert, update, where, from, as, into, values, set, delete, order, by, and, distinct, max, min, group, having, count, left, right, full, join, on, union, plan, collate, all, returns, procedure, begin, end, suspend, generator, to, or, each, execute, row, statement, active, trigger, for, before, after, is, if, then, new, old, gen_id, position, inactive, grant, revoke, with, option, public, domain, collation, character, translation, usage, cascade, restrict, sequence, increment, minvalue, maxvalue, start, function, default, nextval, currval},
    keywordstyle=\color{darkblue},
    ndkeywords={varchar, integer, smallint, char},
    ndkeywordstyle=\color{cyan},
    sensitive=false,
    morecomment=[l]--,
    morecomment=[s][\color{orange}]{/*}{*/},
    morestring=[d]',
    morestring=[d]",
    stringstyle=\color{purple}
}

\lstdefinestyle{listSQL}{
%   extendedchars=true,
%   extendedchars=\true,
    language=SQL,
    belowcaptionskip=5pt,
    xleftmargin=0.5cm,
    numbers=left,
    numberstyle=\small,
    frame=single,
    keepspaces=true,
    breaklines=true,
    breakatwhitespace=true,
    breakindent=0pt,
    emph={},
    emphstyle=\color{red},
    basicstyle=\ttfamily,
    columns=fullflexible,
    showstringspaces=false,
    commentstyle=\color{orange}\upshape}

\begin{filecontents*}[overwrite]{dbstart.txt}
    -- Create table sgroup
    create table sgroup (
    id integer not null,
    group_name varchar(40),
    primary key (id));  -- уникальный ключ id
    -- Создаем таблицу Студент
    create table student (
    id integer not null,
    id_group integer not null, -- поле для связи с таблицей Группа
    student_name varchar(40),
    last_name varchar(40),
    middle_name varchar(40),
    sex char(1),
    age smallint,
    primary key (id), -- уникальный ключ id
    foreign key (id_group) references sgroup (id)); -- определение связи с таблицей Группа
    -- Создаем таблицу Хобби
    create table hobby (
    id integer not null, -- уникальный ключ
    hobby_name varchar(100),
    primary key (id)); -- уникальный ключ id
    -- Создаем таблицу Студент-Хобби
    create table student_hobby (
    id_student integer not null, -- поле для связи с таблицей Студент
    id_hobby integer not null, -- поле для связи с таблицей Хобби
    primary key (id_student, id_hobby), -- уникальный ключ составной id_student, id_hobby
    foreign key (id_hobby) references hobby (id), -- определение связи с таблицей Хобби
    foreign key (id_student) references student (id)); -- определение связи с таблицей Студент
\end{filecontents*}

\begin{document}
%    In string: \lstinline[style=listSQL] !select count(*) from sgroup; -- выборка! !
%    \lstinputlisting[label=dbstart, style=listSQL]{dbstart.txt}
%    
\inputminted{SQL}{dbstart.txt}.
            
\end{document}

There are many options and customisations possible.

For example, a random built-in style (algol) and breaklines option:

\usemintedstyle[SQL]{algol}
\inputminted[breaklines]{SQL}{dbstart.txt}.

algol style

3
  • I know about the minted package, but it requires external dependencies. It doesn't suit me. I liked the package: fvextra \VerbatimInput[frame=single, digits=left, break lines, breakafter=\space]{dbstart.txt }. He doesn't have a coloring book. Thanks, @Cicada.
    – Youra_P
    Commented Dec 7, 2022 at 16:37
  • tcolorbox could be an option.
    – Cicada
    Commented Dec 8, 2022 at 5:22
  • Thanks, @Cicada.
    – Youra_P
    Commented Dec 8, 2022 at 9:42

You must log in to answer this question.

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