首先,抱歉,由于我的 MWE 大小,我不知道如何将其弄小。
我正在为我的课程开发某种问题库。我的目的是在 pdf 文档中显示一个练习,该练习将在共享点中供学生使用,然后,在课堂上进行讨论后,我可以将解决方案添加到 pdf 中。我的所有练习都一样。
首先,我有问题库:01_Question.tex
\usepackage{bm}
\usepackage{listings}
%\usepackage{minted}
\usepackage{color}
\usepackage[utf8]{inputenc}
\usepackage{amsmath} % for '\text' macro
\usepackage[shortlabels]{enumitem}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{shapes, arrows}
\addexercise
{S0101}
{Question description}
{Test of the exercise}
{Solution
% here I can use tkiz graphics also
}
\addexercise
{S0102}
{Question description}
{Test of the exercise}
{Solution}
然后我有一个问题管理器文件:listQuestionManager.tex
\usepackage{pgffor}
\usepackage{pdfpages}
\ExplSyntaxOn
\NewDocumentCommand{\addexercise}{m m m m}
{
\exercise_add:nnnn { #1 } { #2 } { #3 } { #4 }
}
\NewDocumentCommand{\Question}{m}
{
\exercise_question:n {#1}
}
\NewDocumentCommand{\Solution}{m}
{
\exercise_solution:n {#1}
}
\NewDocumentCommand{\Description}{m}
{
\exercise_description:n { #1 }
}
\NewDocumentCommand{\printexercises}{}
{
\exercise_print:
}
\prop_new:N \g_exercise_texts_prop
\seq_new:N \g_exercise_keys_seq
\cs_new_protected:Nn \exercise_add:nnnn
{
\seq_gput_right:Nn \g_exercise_keys_seq { #1 }
\prop_gput:Nnn \g_exercise_texts_prop { #1@desc } { #2 }
\prop_gput:Nnn \g_exercise_texts_prop { #1@text } { #3 }
\prop_gput:Nnn \g_exercise_texts_prop { #1@sol } { #4 }
}
\cs_new_protected:Nn \exercise_description:n
{
\prop_get:NnNT \g_exercise_texts_prop {#1@desc} \l_tmpa_tl
{ \tl_use:N \l_tmpa_tl }
}
\cs_new_protected:Nn \exercise_question:n
{
\prop_get:NnNT \g_exercise_texts_prop {#1@text} \l_tmpa_tl
{ \tl_use:N \l_tmpa_tl }
}
\cs_new_protected:Nn \exercise_solution:n
{
\prop_get:NnNT \g_exercise_texts_prop {#1@sol} \l_tmpa_tl
{ \tl_use:N \l_tmpa_tl }
}
\cs_new_protected:Nn \exercise_print:
{
\seq_map_function:NN \g_exercise_keys_seq \__exercise_print:n
}
\cs_new_protected:Nn \__exercise_print:n
{
\noindent
\textbf{\underline{Id\;Pregunta}:\;} { #1 }
\par
\noindent
\textbf{Description:\;} \exercise_description:n {#1}
\par
\noindent
\textbf{Enunciado:}
\\
\exercise_question:n {#1}
\par
\noindent
\textbf{Solucion:}
\\
\exercise_solution:n {#1}
\par
\addvspace{\topsep}
}
\cs_new_eq:NN \strcompare \str_if_eq:eeTF
\ExplSyntaxOff
\def\questionind{Q}
\def\solutionind{S}
\def\questsolind{QS}
\def\finalind{SXXX}
\input{01_Questions.tex}
最后,当我想在 pdf 中添加一些练习/解决方案时,我需要编译的是01_Practice.tex
:
\documentclass{article}
\input{listQuestionManager.tex}
% This is what I have to change to include question. e.g. "S0101/QS" S0101 is the id of the question, Q means "only question", QS means "Question + Solution"
\newcommand\iterable{
S0101/QS,
S0202/Q
SXXX/QS}
\begin{document}
\section*{Ejercicios}
\newcounter{int}
\foreach \n/\q in \iterable{
\strcompare{\n}{\finalind}
{
}{
\stepcounter{int}
\noindent
\textbf{\underline{Pregunta \theint}}
\vspace{8pt}
%https://tex.stackexchange.com/a/619633/300269
\\
\strcompare{\q}{\questionind}
{
\noindent
\textbf{Enunciado:}
\\
\noindent
\expandafter\Question\expandafter{\n}
}
\noindent
%\vspace{80pt}
\strcompare{\q}{\solutionind}
{
\noindent
\textbf{Solución:}
\\
\noindent
\expandafter\Solution\expandafter{\n}
}
\strcompare{\q}{\questsolind}
{
\noindent
\textbf{Enunciado:}
\\
\noindent
\expandafter\Question\expandafter{\n}
%\parskip=7pt
%\parskip=5pt
\vspace{10pt}
\noindent
\textbf{Solución:}
\\
\noindent
\expandafter\Solution\expandafter{\n}
}
\vspace{20pt}
}
%}
%
}
\end{document}
现在,我想在解决方案部分中使用代码块。所以我使用了这样的练习:
\addexercise
{SomeID}
{SomeDesc}
{Some Text}
{
\begin{lstlisting}
\end{lstlisting}
}
但失败了。我只在日志中看到这一点,但这并没有太大帮助:
! TeX capacity exceeded, sorry [input stack size=10000].
<inserted text>
\relax
l.90 }
If you really absolutely need more capacity,
you can ask a wizard to enlarge me.
Here is how much of TeX's memory you used:
18416 strings out of 475248
376809 string characters out of 5769538
1929785 words of memory out of 5000000
39628 multiletter control sequences out of 15000+600000
563130 words of font info for 55 fonts, out of 8000000 for 9000
1141 hyphenation exceptions out of 8191
10000i,8n,9995p,474b,859s stack positions out of 10000i,1000n,20000p,200000b,200000s
! ==> Fatal error occurred, no output PDF file produced!