Pycode-Code in Exsheet-Frage

Pycode-Code in Exsheet-Frage

Ich möchte eine Tabelle innerhalb einer Exsheets-Frage (oder -Lösung) erstellen (mit Daten, die außerhalb davon in einer anderen Pycode-Umgebung definiert sind). Aber das funktioniert nicht. Was habe ich falsch gemacht und wie kann ich es zum Laufen bringen?

Hier ist ein Minimalbeispiel:

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

Bearbeiten

Wenn ich Exsheets durch xsim ersetze, funktioniert es innerhalb einer Übung, aber nicht, wenn ich es sowohl innerhalb der Übung als auch in der Lösungsumgebung habe:

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

Antwort1

Das exsheetsPaket ist veraltet und wurde offiziell durch das Paket ersetzt xsim.

Sie müssen ersetzen \begin{question}durch\begin{exercise}

verwandte Informationen