我正在编写一个 Latex 文件。但是当我尝试将以下代码添加到该文件时,它无法再编译:
\begin{lstlisting}[language=bash,caption={bash version}]
btcd --txindex --simnet --rpcuser=kek --rpcpass=kek
\end{lstlisting}
我收到这些错误:
Illegal parameter number in definition of \lst@insertargs.
<to be read again>
}
l.241 }
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
Illegal parameter number in definition of \lst@arg.
<to be read again>
}
l.241 }
You meant to type ## instead of #, right?
Or maybe a } was forgotten somewhere earlier, and things
are all screwed up? I'm going to assume that you meant ##.
Runaway argument?
! Paragraph ended before \lst@next was complete.
<to be read again>
\par
l.241 }
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
文件如下:
\documentclass[ngerman, openany]{scrbook}
\usepackage[utf8]{inputenc}
\input{../shared/expl-cfg}
\input{expl/switch-cfg}
\begin{document}
\ifthenelse{\boolean{isPresentation}}{
\chapter{Wirtschaft von Kryptowährungen}
}{
\chapter{Analyse}\label{sec:analyse}
\section{Struktur des Lightning Network}
insert something here
\section{Funktionsweise des Lightning Networks}
insert something here
\section{Implementierung eines Lightning Networks in einem privaten Blockchain}
insert something here
\begin{lstlisting}[language=bash,caption={bash version}]
btcd --txindex --simnet --rpcuser=kek --rpcpass=kek
\end{lstlisting}
}
\end{document}
这里是../shared/expl-cfg
:
\typeout{This is twp-cfg, the common configuration file (JHf)}
\makeatletter
\usepackage{ifthen}
\usepackage{iftex}
\usepackage{listings}
编辑:这是switch-cfg
文件。
\csname SwitchCfgLoaded\endcsname
\let\SwitchCfgLoaded\endinput
\newboolean{isBook}
\newboolean{isPresentation}
\makeatletter
\@ifclassloaded{scrbook}{
\setboolean{isBook}{true}
}{
\@ifclassloaded{beamer}{
\setboolean{isPresentation}{true}
}{}
}
\ifthenelse{\boolean{isBook}}{
}{
\let\frontmatter\relax
\let\mainmatter\relax
\let\backmatter\relax
\let\chapter\section
\let\section\subsection
\let\subsection\subsubsection
\ifthenelse{\boolean{isPresentation}}{
\AtBeginSubsection[]{
\begin{frame}<beamer|handout>%
\begin{block}{}
\insertsubsectionhead
\end{block}
\end{frame}
}{}
}{}
}
我该如何解决这个问题?使用时我遇到了同样的问题verbatim
。我使用 Overleaf 和 LuaLaTeX 作为编译器。
答案1
我相信您遇到了描述的 listings 包的问题这里和这里。这会阻止您在构造中使用列表\ifthenelse
。
但是,如果你恢复到普通的 TeX 样式条件,它确实有效:
\ifisPresentation%
\chapter{Wirtschaft von Kryptowährungen}
\else%
\chapter{Analyse}\label{sec:analyse}
\section{Struktur des Lightning Network}
insert something here
\section{Funktionsweise des Lightning Networks}
insert something here
\section{Implementierung eines Lightning Networks in einem privaten Blockchain}
insert something here
\begin{lstlisting}[language=bash,caption={bash version}]
btcd --txindex --simnet --rpcuser=kek --rpcpass=kek
\end{lstlisting}
\fi
\end{document}
其他可行的方法包括\listinline
:
\lstinline[language=bash,caption={bash version}]{btcd --txindex --simnet --rpcuser=kek --rpcpass=kek}
或者你可以将 bash 保存到单独的文件 ( bashcmd.sh
) 并使用:
\lstinputlisting[language=bash,caption={bash version}]{bashcmd.sh}
上面给出的链接中问题的答案中可能有其他解决方案。
以后,请不要将代码拆分成三个单独的文件,除非这样做没有理由来证明您的问题。您这样做只会让我们更难帮助您。