我问过相似的东西之前,但该特定问题已得到解决(等待截至 2.3.19 18:12 GMT+1 的评论作为答案发布)。
我有一个 LaTeX 代码,它在特定行出现以下错误:
Incomplete \iffalse; all text was ignored after line 157.
Forbidden control sequence found while scanning text of \write.
在第 157 行
以下代码引发了错误(第 157 行y[ row[i] ] += ...
)\section{COO Kernel}
:
\documentclass[11pt,oneside,czech,american]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=4cm,bmargin=3cm,lmargin=3cm,rmargin=2cm,headheight=0.8cm,headsep=1cm,footskip=0.5cm}
\pagestyle{headings}
\setcounter{secnumdepth}{3}
\usepackage{url}
\usepackage{amsthm}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{setspace}
\usepackage{listings}
\usepackage{textcomp}
\usepackage{tikz}
\usetikzlibrary{plotmarks}
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{wrapfig}
\usepackage{xcolor}
\makeatletter
\newenvironment{lyxlist}[1]
{\begin{list}{}
{\settowidth{\labelwidth}{#1}
\setlength{\leftmargin}{\labelwidth}
\addtolength{\leftmargin}{\labelsep}
\renewcommand{\makelabel}[1]{##1\hfil}}}
{\end{list}}
\usepackage[varg]{txfonts}
\usepackage{indentfirst}
\clubpenalty=9500
\widowpenalty=9500
\hyphenation{CDFA HARDI HiPPIES IKEM InterTrack MEGIDDO MIMD MPFA DICOM ASCLEPIOS MedInria}
\newcommand{\UNASSIGNED}{\textcolor{red}{UNASSIGNED}}
\renewcommand{\vec}[1]{\boldsymbol{#1}}
\definecolor{light-gray}{gray}{0.95}
\newcommand{\code}[1]{\colorbox{light-gray}{\texttt{#1}}}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\definecolor{Darkgreen}{rgb}{0.0, 0.2, 0.13}
\lstset{
backgroundcolor=\color{lbcolor},
tabsize=4,
language=[GNU]C++,
basicstyle=\scriptsize,
upquote=true,
aboveskip={0.001\baselineskip},
columns=fixed,
showstringspaces=false,
extendedchars=false,
breaklines=true,
prebreak = \raisebox{0ex}[0ex][0ex]{\ensuremath{\hookleftarrow}},
frame=single,
numbers=left,
showtabs=false,
showspaces=false,
showstringspaces=false,
identifierstyle=\ttfamily,
keywordstyle=\color[rgb]{0,0,1},
commentstyle=\color[rgb]{0.026,0.112,0.095},
stringstyle=\color[rgb]{0.627,0.126,0.941},
numberstyle=\color[rgb]{0.205, 0.142, 0.73},
}
\lstset{
backgroundcolor=\color{lbcolor},
tabsize=4,
language=C++,
captionpos=b,
tabsize=3,
frame=lines,
numbers=left,
numberstyle=\tiny,
numbersep=5pt,
breaklines=true,
showstringspaces=false,
basicstyle=\footnotesize,
keywordstyle=\color[rgb]{0,0,1},
commentstyle=\color{Darkgreen},
stringstyle=\color{red},
}
\lstset{
morekeywords={__global__},
alsoletter={.},
morekeywords={blockDim.x},
morekeywords={blockIdx.x},
morekeywords={threadIdx.x}
}
\raggedbottom
\makeatother
\usepackage{babel}
\begin{document}
\tableofcontents{}
\chapter*{Implementation/Kernels of formats}
\addcontentsline{toc}{chapter}{Implementation/Kernels of formats}
\setcounter{chapter}{3}
\setcounter{section}{0}
\section{DIAG Kernel}
\begin{lstlisting}[caption= SpMV pseudocode using DIAG format for storing a matrix from \textit{Efficient sparse matrix-vector multiplication on CUDA} \cite{Bell-Garland}.]
__global__ void
spmv_dia_kernel ( const int num_rows,
const int num_cols,
const int num_diags,
const int * offsets,
const float * data,
const float * x,
float * y )
{
int row = blockDim.x * blockIdx.x + threadIdx.x;
if ( row < num_rows ){
float dot = 0;
for ( int n = 0; n < num_diags; n++ ){
int col = row + offsets[ n ];
float val = data[ num_rows * n + row ];
if ( col >= 0 && col < num_cols )
dot += val * x[ col ];
}
y[ row ] += dot;
}
}
\end{lstlisting}
\textcolor{red}{DO I DESCRIBE THE CODE?} according to my notes in
\textit{Efficient sparse matrix-vector multiplication on CUDA}
%\cite{Bell-Garland}.
\section{COO Kernel}
\begin{lstlisting}[caption= SpMV pseudocode using COO format for storing a matrix \cite{Parallel-Uppsala}.]
__global__ void
spmv_coo_kernel ( const int num_non_zero_elements,
const float * data,
const int * row,
const int * col,
const float * x,
float * y )
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if ( row < num_non_zero_elements )
y[ row[i] ] += data[i] * x[ col[i] ];
}
\end{lstlisting}
\begin{thebibliography}{1}
\bibitem{Bell-Garland}N Bell, M. Garland: \emph{Efficient sparse matrix-vector multiplication on CUDA}. NVIDIA Technical Report NVR-2008-004, NVIDIA Corporation, 1-32, 2008.
\bibitem{Parallel-Uppsala}D. Lukarski: \emph{Sparse Matrix-Vector Multiplication and Matrix Formats}. Parallel Algorithms for Scientific Computing, Uppsala University, 2013. \url{https://www.it.uu.se/education/phd_studies/phd_courses/pasc/lecture-1}
\end{thebibliography}
\end{document}
在这种情况下,罪魁祸首是\textcolor
和\textit
行,它们位于包装中的第一个 C++ 代码块之后lstlisting
和之前\section{COO Kernel}
。
如果这两行没有同时注释,那么编译器将抛出上述错误,但是,任何其他组合(在这三行中)只要不同时包含这两行,都可以正常编译。
有人知道可能是什么原因吗?
PS:该序言是一位教授创建的,作为所有学生使用的模板,我被告知不要对其进行改动。
答案1
问题在于捷克语选项。此语言使连字符处于活动状态。在您的示例中,列表中间有一个分页符。这意味着带有的标题是在Parallel-Uppsala
列表设置处于活动状态时写入的,然后连字符断开。
\shorthandoff{-}
您可以使用或\string-
在 cite 命令中使用来禁用活动连字符:
\documentclass[11pt,oneside,czech,american]{book}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=4cm,bmargin=3cm,lmargin=3cm,rmargin=2cm,headheight=0.8cm,headsep=1cm,footskip=0.5cm}
%\pagestyle{headings}
%\setcounter{secnumdepth}{3}
\usepackage{listings}
\usepackage{babel}
\begin{document}
blb
\vspace{0.8\textheight}
%\shorthandoff{-} %<--
\begin{lstlisting}[caption= SpMV pseudocode using COO format for storing a matrix \cite{Parallel\string-Uppsala}. %<-- or \string
]
__global__ void
spmv_coo_kernel ( const int num_non_zero_elements,
const float * data,
const int * row,
const int * col,
const float * x,
float * y )
{
int i = blockDim.x * blockIdx.x + threadIdx.x;
if ( row < num_non_zero_elements )
y[ row[i] ] += data[i] * x[ col[i] ];
}
\end{lstlisting}
\end{document}