列表 - 错误无法加载请求的样式

列表 - 错误无法加载请求的样式

我正在尝试为我的 javascript 代码片段创建一些样式。我的配置如下:

\documentclass[letterpaper, dvipsnames]{article}
\usepackage[utf8]{inputenc}
\usepackage{listings} % Package for adding javascript code with code highlighting
\usepackage[dvipsnames]{xcolor} % Package for adding colors
\definecolor{purple}{rgb}{0.65, 0.12, 0.82}
\definecolor{main-color}{rgb}{0.6627, 0.7176, 0.7764}
\definecolor{back-color}{rgb}{0.1686, 0.1686, 0.1686}

\lstdefinestyle{codeSection}
{
  language= JavaScript,
  basicstyle = {\ttfamily \color{main-color}},
  backgroundcolor = {\color{back-color}},
  commentstyle = {\color{OliveGreen}},
  stringstyle = {\color{green}},
  keywordstyle = {\color{orange}\bfseries},
  keywordstyle = [2]{\color{orange}},
  keywordstyle = [3]{\color{purple}},
  keywordstyle = [4]{\color{lime}},
  keywordstyle = [5]{\color{orange}},
  keywords = {typeof, new, true, false, function, return, null, switch, var, if, in, while, do, else, case, break, class, export, boolean, throw, implements, import, this, constructor, string, number, public, private, static, const, var, let, void},
  morekeywords = [2]{class, export, boolean, throw, implements, import, this, interface},
  morekeywords = [3]{Promise, Observable},
  morekeywords = [4]{console},
  otherkeywords = {;},
  comment = [l]{//},
  morecomment = [s]{/*}{*/},
  morestring = [b]',
  morestring = [b]",
  sensitive = false,
  breaklines = true,
  showstringspaces= false,
  showspaces= false,
  extendedchars= true
}

现在,当我尝试添加一些代码时,它会以正确的样式呈现,但它给了我错误:Could not load requested styling.代码插入如下所示:

\begin{document}
\begin{figure}[H]
\begin{lstlisting}[style=codeSection]
export interface FakeHttpResponse {
    code: string;
    message: string;
}

const scndPromise = new Promise<FakeHttpResponse>((resolve, reject) => {
    setTimeout(() => {
        resolve({
            code: '200',
            message: 'Promise kept!'
        });
    }, 10 * 1000);
});

console.log(scndPromise);
setTimeout(() => console.log(scndPromise), 10 * 1000);
\end{lstlisting}
\end{figure}
\end{document}

有人能帮我修复这个错误吗?

答案1

我通过以下配置修复了它:

\lstdefinelanguage{JavaScript}
{
  keywords = {typeof, new, true, false, function, return, null, switch, var, if, in, while, do, else, case, break, class, export, boolean, throw, implements, import, this, constructor, string, number, public, private, static, const, var, let, void},
  morekeywords = [2]{class, export, boolean, throw, implements, import, this, interface},
  morekeywords = [3]{Promise, Observable},
  morekeywords = [4]{log},
  otherkeywords = {;},
  comment = [l]{//},
  morecomment = [s]{/*}{*/},
  morestring = [b]',
  morestring = [b]",
}

\lstset
{
  language= JavaScript,
  commentstyle = {\color{OliveGreen}},
  stringstyle = {\color{green}},
  keywordstyle = {\color{orange}\bfseries},
  keywordstyle = [2]{\color{orange}},
  keywordstyle = [3]{\color{purple}},
  keywordstyle = [4]{\color{lime}},
  keywordstyle = [5]{\color{orange}},
  basicstyle = {\ttfamily \color{main-color}},
  backgroundcolor = {\color{back-color}},    
  sensitive = false,
  breaklines = true,
  showstringspaces= false,
  showspaces= false,
  extendedchars= true
}

相关内容