problsoln 和 listings 包兼容性问题

problsoln 和 listings 包兼容性问题

我正在尝试使用 probsoln 和 listings 包进行计算机科学练习,但当问题放在单独的文件中时,这些包似乎不兼容。如能得到任何帮助,我将不胜感激。

在文件中定义问题:

\documentclass{report}
\usepackage{probsoln,listings}

\begin{document}
\begin{onlyproblem}[fragile]
\lstset{language=Pascal}
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write('Case insensitive');
WritE('Pascal keywords.');
\end{lstlisting}
\end{onlyproblem}
\end{document}

运行良好,但是当我将问题和主文档分开时,代码就无法编译。

例如,编译 testPsLstLoad.tex

\documentclass{report}
\usepackage{probsoln,listings}

\begin{document}
\loadallproblems{testProblem}
\useproblem{program}
\end{document}

使用 testProblem.tex

\begin{defproblem}{program}
  \begin{onlyproblem}[fragile]
\lstset{language=Pascal}
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write('Case insensitive');
WritE('Pascal keywords.');
\end{lstlisting}
  \end{onlyproblem}
\end{defproblem}

给出:

pdflatex testPsLstLoad.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./testPsLstLoad.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-08-07>
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/report.cls
Document Class: report 2019/12/20 v1.4l Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2020/texmf-dist/tex/latex/probsoln/probsoln.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2020/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2020/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/local/texlive/2020/texmf-dist/tex/generic/xkeyval/keyval.tex)))))
(/usr/local/texlive/2020/texmf-dist/tex/latex/listings/listings.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/listings/lstmisc.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/listings/listings.cfg))
(/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def)
(./testPsLstLoad.aux) (./testProblem.tex) (./testPsLstLoad.vrb
(/usr/local/texlive/2020/texmf-dist/tex/latex/listings/lstlang1.sty)

Package Listings Warning: Text dropped after begin of listing on input line 1.

)

! LaTeX Error: \begin{lstlisting} on input line 1 ended by \end{onlyproblem}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.6 \useproblem{program}
                        
? 

谢谢,乔恩

答案1

我知道,所以请你原谅...:)

我认为我发现了 listings 和 probsoln 之间的另一个不兼容性

我使用模板“橙皮书”,列表中我有“TeX 容量超出,抱歉 [参数堆栈大小=10000]”。

没有我的文档就能完美编译...

\usepackage{bbding} \usepackage{amsmath} \usepackage{probsoln} \usepackage{enumitem}%,hyperref} \usepackage{nccmath} % 用于 ceqn 中心方程在对齐标签内 \usepackage{pdfpages} \usepackage{caption} \usepackage{multicol} % 多列文本 \usepackage{wrapfig} % 用于多列中的表格和图形 \usepackage{multirow} % 用于表格 \usepackage{epigraph} \usepackage{longtable} %\usepackage{listings}

此致

相关内容