如果我调用太多,列表就会失败 - 包 xkeyval:`LANGUAGE' 在系列 `lst' 中未定义

如果我调用太多,列表就会失败 - 包 xkeyval:`LANGUAGE' 在系列 `lst' 中未定义

我正在写一份文档,其中包含一些有关该listings包的定制内容:

  • lstjson通过以下方式定义的环境\lstnewenvironment
  • \restsection用作命令,但用以下命令\section包装节头:\lstinline
  • 一个\lstitem命令,它的作用与上面一样\item

该结构似乎有效,但随着文档的增长,它停止编译。错误是

Package xkeyval: `LANGUAGE' undefined in families `lst'

下面是一个(非)工作示例。奇怪的是,它似乎取决于我使用列表的次数:如果您删除足够多的\lstitems 或“某种字段”行,它将编译。

\documentclass[11pt,a4paper]{memoir}

\usepackage[english]{babel}
\usepackage{libertine}

\usepackage[hidelinks]{hyperref}
\usepackage[nameinlink]{cleveref}

\usepackage{listings}

\usepackage{fontspec}
\setmonofont{Consolas}

\usepackage{color}

\lstset{
  basicstyle=\small\ttfamily
}

\lstdefinelanguage{rest}
{
    morekeywords={GET,POST,CREATE,UPDATE,DELETE},
    keywordstyle=\color{red}
}

\newcommand{\restsection}[1]
    {
        \section{
            \texorpdfstring
                {\lstinline[language={rest}]|#1|}
                {#1}
        }
    }

\lstnewenvironment{lstjson}
    {\lstset{
        basicstyle=\small\ttfamily
    }}
    {}

\newcommand{\lstitem}[2]
    {
        \item \lstinline|#1| \\
            #2
    }

%end of preamble

\title{Non-Working Example}

\begin{document}

\frontmatter

\maketitle

\clearpage

\tableofcontents

\mainmatter

\chapter{Introduction}
\label{chp:Introduction}

This is the introduction.

%This section works
\restsection{POST /api/login}
\label{api:login}

Used to authenticate.

\subsection*{Payload}

\begin{lstjson}
{
  "username": String,
  "password": String
}      
\end{lstjson}

\subsection*{Response}

\begin{lstjson}
{
    stuff
}
\end{lstjson}

%This section does not work
\restsection{DataStructure}
\label{data:DataStructure}

\subsection*{Schema}

\begin{lstjson}
    {
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
        some kind of field
    }
\end{lstjson}

\subsection*{Description of fields}

\begin{itemize}
    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }

    \lstitem{stuff}{
        stuff
    }    
\end{itemize}

\end{document}

答案1

我通过评论收到了对提供的 mwe 的答复(感谢 daleif),但主文档中仍然出现问题。然而,我仍然必须将它们隔离到新的 mwe 中,因为文档现在由于解决方法而正常工作\clearpage。与此同时,我将用 daleif 的答复结束此篇。

LANGUAGE 是此处的关键提示。您是否尝试过将此添加到序言中:\nouppercaseheads\pagestyle{headings}回忆录中的默认标题是大写的,因此大写也会影响变量参数。关闭它们更容易,无论如何,我认为不再推荐使用大写标题。

相关内容