Код Pycode внутри вопроса exsheet

Код Pycode внутри вопроса exsheet

Я хочу создать таблицу внутри вопроса (или решения) 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}

Редактировать

Если я заменю exsheets на xsim, это сработает в упражнении, но не сработает, если я заменяю его и в упражнении, и в среде решения:

\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}

Связанный контент