列表中的其他关键字

列表中的其他关键字

我有以下代码,我试图在其中添加SUCH THAT关键字。根据我的lstset,这应该排版为粗体,但事实并非如此。我不明白为什么,并希望得到建议。

\documentclass{article}
\usepackage{listings}

\lstset{
    language=SQL,
    basicstyle=\small\ttfamily,
    keywordstyle=\textbf,
    showspaces=false,
    showstringspaces=false, 
    deletekeywords={DOMAIN}, 
    morekeywords={*,IF,DEFINE,OPTIONS, SERVER, MENTIONS, IN, CONTAINS, ANCHOR,for,REFERENCES,DETERMINES}, mathescape=true,
    literate={SUCH\ THAT}{\bfseries SUCH\ THAT}{9}
}

\begin{document}
    \begin{lstlisting}
    FROM Relation SUCH THAT domain-condition
    \end{lstlisting}
\end{document}

答案1

\documentclass[a4paper,12pt]{article}

\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{color}

\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{ltgray}{rgb}{0.5,0.5,0.5}

\usepackage{listings}
\lstset{%
    backgroundcolor=\color{white},
    basicstyle=\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    commentstyle=\color{dkgreen},
    deletekeywords={...},
    escapeinside={\%*}{*)},
    extendedchars=true,
    frame=single,
    keepspaces=true,
    keywordstyle=\color{blue},
    language=SQL,
    morekeywords={*,modify,MODIFY,...},
    numbers=left,
    numbersep=15pt,
    numberstyle=\tiny,
    rulecolor=\color{ltgray},
    showspaces=false,
    showstringspaces=false, 
    showtabs=false,
    stepnumber=1,
    tabsize=4,
    title=\lstname
}

\begin{document}

\begin{lstlisting}[language=sql]
ALTER TABLE country
    MODIFY capital SET NOT NULL;
-- There is no MODIFY CONSTRAINT, so first remove than create anew:
ALTER TABLE country
    DROP CONSTRAINT country_capital_fkey;
ALTER TABLE country
    ADD CONSTRAINT country_capital_fkey FOREIGN KEY (capital) REFERENCES city(id) ON DELETE CASCADE;
\end{lstlisting}

\end{document}

在此处输入图片描述

答案2

你的打字机字体没有粗体版本。例如,使用 luximono 就可以正常工作:

\documentclass{article}
\usepackage{listings}
\usepackage[T1]{fontenc}
\usepackage{luximono}
\lstset{
    language=SQL,
    basicstyle=\small\ttfamily,
    keywordstyle=\textbf,
    showspaces=false,
    showstringspaces=false,
    deletekeywords={DOMAIN},
    morekeywords={*,IF,DEFINE,OPTIONS, SERVER, MENTIONS, IN, CONTAINS, ANCHOR,for,REFERENCES,DETERMINES}, mathescape=true,
    literate={SUCH\ THAT}{\bfseries SUCH\ THAT}{9}
}

\begin{document}
    \begin{lstlisting}
    FROM Relation SUCH THAT domain-condition
    \end{lstlisting}
\end{document}

在此处输入图片描述

相关内容