lstlistoflistings 填充的是 XeLaTeX 日志,而不是实际代码

lstlistoflistings 填充的是 XeLaTeX 日志,而不是实际代码

我在使用命令时遇到了困难,\lstlistings因为它没有生成lol包含列表的正确文件,但由于某种原因,它会填充 XeLaTeX 执行日志;反之亦然,XeLaTeX 日志的一部分会填充一些我认为应该在lol文件中的内容,例如

\defcounter {refsection}{0}\relax 
\contentsline {lstlisting}{\numberline {1.1}Struttura della funzione handler pe
r Lambda}{13}{lstlisting.1.1}%
) (main/2.aux
...

我的环境是由 Windows 10 上的 MiKTeX 20.12 + TeXStudio 3.0.4 组成的。

目前,我很难提供与我的问题相同的示例代码,因为我正在处理一个关于我的文档的相当大的项目;但是,如果您仍然需要一些代码,我可能会尝试安排一个显示相同不稳定行为的错误代码。我很抱歉。不过,下面是我的序言:

\pdfpagewidth
\paperwidth
\pdfpageheight
\paperheight

\usepackage[italian, british, american]{babel}
%\usepackage[useregional, showdow]{datetime2}

\usepackage{epsfig}
\usepackage{amsmath, amssymb}
\usepackage{amscd}
\usepackage{ifxetex}
\ifxetex
  \usepackage{fontspec}
  \usepackage{newpxtext, newpxmath} % Palatino font
\else
  \usepackage[T1]{fontenc}
  \usepackage[utf8]{inputenc} % necessary for listings package
  \usepackage[sc]{mathpazo}
  \linespread{1.05}
\fi
%\setmainfont{Palatino Linotype}
\setmonofont[Scale=0.88]{Fira Mono}
\usepackage[usenames, dvipsnames]{xcolor}
\usepackage{lettrine}

% chapter style
\usepackage{titlesec}
\titleformat{\chapter}[block]
  {\bfseries\Huge} % format
  {\thechapter.} % label
  {0.5ex} % sep
  {} % before-code
  [] % after-code

% headers and footers
\usepackage{fancyhdr}
\fancyhead{}
\fancyhead[LO,RE]{\rightmark}
%\fancyfoot{}
%\fancyfoot[LE,RO]{\thepage}
%\fancyfoot[LO,CE]{\chaptertitlename \thechapter}
%\fancyfoot[CO,RE]{FLY Graph}

\usepackage{svg}
%\svgsetup{
%  inkscape=true,
%  inkscapeexe="C:/Program Files/Inkscape"
%}
\svgpath{ {img/} }
\usepackage{graphicx}
\graphicspath{ {img/} }

\usepackage{wrapfig}
\usepackage{hologo}
\usepackage[document]{ragged2e}
\frenchspacing
\usepackage{geometry}
\geometry{a4paper, tmargin=3cm, bmargin=3cm, lmargin=3.5cm, rmargin=3.5cm}

% define a custom colour box
\usepackage[most]{tcolorbox}
\newtcolorbox{topic}[1]{
  colback=lightgray!60!white,
  colbacktitle=lightgray!60!white,
  colframe=lightgray!60!white,
  coltitle=black,
  sharp corners,
  grow to right by=-10mm,
  grow to left by=-10mm,
  boxrule=0pt,
  boxsep=0pt,
  breakable,
  bottom=5mm,
  halign=justify,
  halign title=center,
  toptitle=4mm,
  bottomtitle=2mm,
  fonttitle=\Large\bfseries,
  title=#1
}

%HYPERREF per uso con dvi
\usepackage[final, breaklinks, hidelinks]{hyperref}
\hypersetup{
  linkcolor = darkgray
}

% caption settings
\usepackage[margin=10pt, font=small, labelfont=bf]{caption}
\usepackage{subcaption}

% minitoc
%\usepackage{mtcoff}
\usepackage[italian]{minitoc}

\usepackage{rotating}
\usepackage{multirow}
\usepackage{picture}
\usepackage{amssymb}
%\textwidth16cm
%\textheight22cm
\headsep6mm

% Bibliography
\usepackage[
  backend = biber,
  bibencoding = utf8,
  style = alphabetic-verb,
  labelnumber,
  defernumbers = true,
%  sorting = none,
  block = par,
  backref = true%,
%  sortsets = true,
%  refsection = chapter,
%  refsegment = chapter
]{biblatex}
\defbibheading{bibliography}[\refname]{%
  \chapter*{#1}%
  \markboth{#1}{#1}%
}
\DefineBibliographyStrings{italian}{%
  backrefpage = {pag.}, % originally "cited on page"
  backrefpages = {pagg.} % originally "cited on pages"
}
%\usepackage{natbib}

\definecolor{light-gray}{gray}{0.95}

\usepackage{csquotes}
\usepackage{quoting}
\quotingsetup{font=small}

%pulisce tutte le pagine bianche di separazione
%\clearpage{\pagestyle{empty}\cleardoublepage
\makeindex

%INTERLINEA
\linespread{1.3}

\usepackage{algorithm2e}
\usepackage{algpseudocode}
\usepackage{lipsum}
\usepackage{setspace}
\usepackage{verbatim}
\usepackage{changepage}


\usepackage{listings}
\lstset{
  extendedchars = true,
  basicstyle = \small\ttfamily,
  keywordstyle = \bfseries,
  stringstyle = \ttfamily,
  commentstyle = \color{gray},
  breaklines = true,
  tabsize = 2,
  numbersep = 5pt,
  stepnumber = 5,
  numbers = left,
  numberstyle = \scriptsize,
  captionpos = b,
  frame = lines,
  aboveskip = 20pt,
  belowskip = 20pt,
  literate = {«}{\flqq}1 {»}{\frqq}1
}
\lstdefinestyle{bash}{
  language = bash,
  numbers = none,
  frame = single%,
%  keywordstyle = \bfseries\color{violet}%,
%  morekeywords = {python3, source, deactivate, cd, zip, aws},
%  otherkeywords = {~}
}
\lstdefinestyle{xml}{
  language = xml,
  commentstyle = \color{gray},
  moredelim = [s][\bfseries\color{blue}]{<}{>}
}
\lstdefinestyle{fly}{
  language = fly,
  keywordstyle = [1]\bfseries\color{violet},
  keywordstyle = [2]\bfseries\color{orange},
  commentstyle = \color{gray},
  stringstyle = \color{olive}
}
\lstdefinelanguage{fly}{
  morekeywords = {var, const, func, on, fly, in, then, thenall, println},
  otherkeywords = {!, ?},
  morekeywords = [2]{type},
  sensitive = false,
  morecomment = [l]{//},
  morestring = [b]"
}
\lstdefinestyle{java}{
  language = java,
  keywordstyle = \bfseries\color{violet},
  moredelim = [s][\itshape\color{blue}]{<}{>},
  commentstyle = \color{gray}
}
\lstdefinestyle{xtend}{
  language = java,
  morekeywords = {val, var},
  keywordstyle = \bfseries\color{violet},
  moredelim = [s][\color{darkgray}]{«}{»},
  moredelim = [s][\color{olive}]{'''}{'''},
  morecomment = [l]{«««},
  commentstyle = \color{gray}
}
\lstdefinestyle{python}{
  language = python,
  keywordstyle = [2]\bfseries\color{violet},
  keywordstyle = [1]\bfseries\color{blue},
  morekeywords = [2]{Boolean},
  morekeywords = [1]{self},% why tho
  commentstyle = \color{gray}
}

% Per generare il glossario e l'indice dei simboli
\usepackage[toc, acronym]{glossaries}
\glspatchtabularx
\setacronymstyle{long-sc-short}
\makeglossaries

\makeatletter
\usepackage[final]{pdfpages}

%\newcommand\frontmatter{%
%    \cleardoublepage
%  %\@mainmatterfalse
%  \pagenumbering{roman}}

%\newcommand\mainmatter{%
%    \cleardoublepage
% % \@mainmattertrue
%  \pagenumbering{arabic}}

%\newcommand\backmatter{%
%  \if@openright
%    \cleardoublepage
%  \else
%    \clearpage
%  \fi
% % \@mainmatterfalse
%   }

\newcommand{\paginavuota}{\newpage\null\thispagestyle{empty}\newpage\null\thispagestyle{empty}}

% pacchetto per massimizzare il logo sulla pagina frontespizio
\usepackage{eso-pic}

% tables
\usepackage{adjustbox}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{pdflscape}
\usepackage{array}
\usepackage{dcolumn}
\newcolumntype{d}[3]{D{.}{.}{#1}}
\newcolumntype{R}{>{\raggedleft\arraybackslash}X}%
\newcolumntype{L}{X<{\arraybackslash\raggedright}}%
\newcolumntype{M}{>{$}l<{$}}
\newcommand*{\thead}[1]{\multicolumn{1}{l}{\textbf{#1}}}

\usepackage{fontawesome5}
\usepackage{seqsplit}

% descrizione di un nuovo comando per centrare e massimizzare l'immagine
\newcommand \atpagecenter [1]{ %
\AddToShipoutPicture *{\AtPageCenter {%
\makebox (0 ,-50){\includegraphics %
%\makebox (0 ,100){\includegraphics %
[ width=0.8\paperwidth ]{#1}}}}}
%[ width=0.6\paperwidth ]{#1}}}}}

% comandi per i nomi di immagini, tabelle e listati
\newcommand \prtref [1]{%
%  \faParagraph \ \thepart \ \ref{#1}% TODO fix
  Parte \ref{#1}% TODO fix
}

\newcommand \chpref [1]{%
%  \faParagraph\ \chaptername\ \ref{#1}%
  \chaptername\ \ref{#1}%
}

\newcommand \secref [1]{%
%  \faParagraph\ \thesection\ \ref{#1}%
  \thesection\ \ref{#1}%
}

\newcommand \ssecref [1]{%
  \thesubsection\ \ref{#1}%
}

\newcommand \sssecref [1]{%
  \thesubsubsection\ \ref{#1}%
}

\newcommand \figref [1]{%
  \figurename\ \ref{#1}%
}

\newcommand \tabref [1]{%
  \tablename\ \ref{#1}%
}

\newcommand \lstref [1]{%
  \lstlistingname\ \ref{#1}%
}

%\renewcommand \eqref [1]{%
%  \faEqual \ \theequation \ \ref{#1}%
%}

% descrizione di un nuovo ambiente per le citazioni fuori corpo
\newenvironment{citazione}
  {\begin{quotation}\footnotesize}
  {\end{quotation}}


% abstract environment
\newenvironment{abstract}%
{\cleardoublepage\null \begin{center}%
    \bfseries \abstractname \end{center}}%
{\vfill\null}

% define bibliography environment to have two different styles
\DeclareFieldFormat{labelnumberwidth}{\mkbibbrackets{#1}}
\renewbibmacro*{cite}{%
  \printtext[bibhyperref]{%
    \printfield{labelprefix}%
    \ifkeyword{secondary}
    {\printfield{labelnumber}}
    {\printfield{labelalpha}%
      \printfield{extraalpha}}}}

\defbibenvironment{sitography}
{\list
  {\printtext[labelnumberwidth]{%
      \printfield{labelprefix}%
      \printfield{labelnumber}}}
  {\setlength{\labelwidth}{\labelnumberwidth}%
    \setlength{\leftmargin}{\labelwidth}%
    \setlength{\labelsep}{\biblabelsep}%
    \addtolength{\leftmargin}{\labelsep}%
    \setlength{\itemsep}{\bibitemsep}%
    \setlength{\parsep}{\bibparsep}}%
  \renewcommand*{\makelabel}[1]{\hss##1}}
{\endlist}
{\item}

以下是 MWE 生成错误的 .lol 文件:

% !TEX program = xelatex
% !TeX encoding = UTF-8
% !TeX spellcheck = en_GB
\documentclass[a4paper, 11pt, titlepage, oneside]{book}

\usepackage{packages} % this is given preamble

\begin{document}
  \selectlanguage{british}

  \frontmatter

  \justifying

  \mtcaddchapter[\contentsname]
  \dominitoc
  \noptcrule
  \tableofcontents
  \clearpage

  \mtcaddchapter[\listfigurename]
  \listoffigures
  \clearpage

  \mtcaddchapter[\listtablename]
  \listoftables
  \clearpage

  \renewcommand\lstlistingname{Listings}
  \mtcaddchapter[\lstlistingname]
  \lstlistoflistings
  \clearpage

  \mainmatter
  \adjustmtc
  \chapter{Introduction}
  \minitoc
  \mtcskip
  This is some sort of joke introduction, for demo purposes only.
  \begin{figure}[h!]
    \centering
    \includegraphics[demo]{}
    \caption{This is a fake image}
    \label{fig:fakeimage}
  \end{figure}

  \section{Some sort of section}
  \begin{table}
    \centering
    \begin{tabularx}{.5\textwidth}{c c}
      \toprule
      A & B \\
      \midrule
      1 & 2 \\
      3 & 4 \\
    \end{tabularx}
    \caption{A table}
    \label{tab:table}
  \end{table}

  \begin{lstlisting}[
    caption = {Sample listing},
    label = lst:sample
  ]
print("SUP DAWG")
  \end{lstlisting}

  \chapter{Conclusion}
  \minitoc
  \mtcskip
  Is this the real life? Or is this fantasy?

  \section{Look, I'm a section too!}
  \begin{lstlisting}[
    caption = {Another sample listing},
    label = lst:sample2
  ]
print("Fare well!")
  \end{lstlisting}

\end{document}

有人知道这个问题的大致原因吗?可能是由于我不知道的一些软件包冲突?

答案1

您会收到一个明显的错误:

! No room for a new \write.
\e@ch@ck ...message {No room for a new \string #4}
                                                  \fi \fi 
l.382   \lstlistoflistings

pdftex 和 xetex 只有 16 个文件写入寄存器(编号从 0 到 15),并且它们已经用完了。这意味着从那时起写入文件都是错误的,所有内容都会进入日志。

查看日志中的写入分配,你会发现

\w@pgf@writea=\write3    %pgf 
\tcb@out=\write4         %tcolorbox
\tcb@record@out=\write5  %tcolorbox
\tf@mtc=\write6          %minitoc
\blx@bcfout=\write7      %biblatex
\@indexfile=\write8      %index
\glswrite=\write9        %glossaries
\glo@main@file=\write10  %glossaries 
\glo@acronym@file=\write11  %glossaries
\@outlinefile=\write12   %hyperref 
\tf@toc=\write13         %toc
\tf@lof=\write14         %lof
\tf@lot=\write15         %lot

其中最容易避免的是词汇表,文档描述了许多不使用写入寄存器的编译选项。

对于 tcolorbox,我打开了一个问题:https://github.com/TFS/tcolorbox/issues/134

除此之外,您还可以尝试 morewrites 包,但它会大大减慢编译速度。

最简单的方法是切换到具有更多写入寄存器的 lualatex。

相关内容