exsheet問題中的Pycode代碼

exsheet問題中的Pycode代碼

我想在 exsheets 問題(或解決方案)內建立一個表(使用在其外部的另一個 pycode 環境中定義的資料)。但這行不通。我做錯了什麼以及如何讓它發揮作用?

這是一個最小的例子:

\documentclass{article}

\usepackage{exsheets}
\usepackage[gobble=auto]{pythontex}

\usepackage{siunitx}
\sisetup{
  round-mode=places,
  round-precision=1
}

\begin{document}

\begin{pycode}[mySession]
X = [1,2,3]
Y = [4,5,6]
k = len(X)
\end{pycode}

\begin{question}
A question with a table:

% The following code doesn't work

% \begin{pycode}[mySession]
% print(r'''\begin{tabular}{c*{%s}{|c}}''' %k)
% print(r'''$X$''')
% for x in X:
%     print(r'''& \num{%s}''' %x)
% print(r'''\\\hline''')
% print(r'''$Y$''')
% for y in Y:
%     print(r'''& \num{%s}''' %y)
% print(r'''\end{tabular}''')
% \end{pycode}

\end{question}

Table outside of the question environment:

\begin{pycode}[mySession]
print(r'''\begin{tabular}{c*{%s}{|c}}''' %k)
print(r'''$X$''')
for x in X:
    print(r'''& \num{%s}''' %x)
print(r'''\\\hline''')
print(r'''$Y$''')
for y in Y:
    print(r'''& \num{%s}''' %y)
print(r'''\end{tabular}''')
\end{pycode}
\end{document}

編輯

如果我用 xsim 取代 exsheets,它可以在練習中工作,但如果我在練習和解決方案環境中都有它,則不會:

\documentclass{article}

\usepackage{xsim}
\usepackage[gobble=auto]{pythontex}

\usepackage{siunitx}
\sisetup{
  round-mode=places,
  round-precision=1
}

\begin{document}

\begin{pycode}[mySession]
X = [1,2,3]
Y = [4,5,6]
k = len(X)
\end{pycode}

\begin{exercise}
A exercise with a table:

\begin{pycode}[mySession]
print(r'''\begin{tabular}{c*{%s}{|c}}''' %k)
print(r'''$X$''')
for x in X:
    print(r'''& \num{%s}''' %x)
print(r'''\\\hline''')
print(r'''$Y$''')
for y in Y:
    print(r'''& \num{%s}''' %y)
print(r'''\end{tabular}''')
\end{pycode}

\end{exercise}

\begin{solution}
\begin{pycode}[mySession]
print(r'''\begin{tabular}{c*{%s}{|c}}''' %k)
print(r'''$X$''')
for x in X:
    print(r'''& \num{%s}''' %x)
print(r'''\\\hline''')
print(r'''$Y$''')
for y in Y:
    print(r'''& \num{%s}''' %y)
print(r'''\end{tabular}''')
\end{pycode}

\end{solution}

\printsolutions
\end{document}

答案1

exsheets軟體包已過時,並已正式更換為該軟體包xsim

您需要替換\begin{question}\begin{exercise}

相關內容