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}

편집하다

exsheet를 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}

관련 정보