我本质上想做这样的事情。
\documentclass{scrartcl}
\usepackage{fontspec}
\usepackage[gobble=auto]{pythontex}
\usepackage{ifthen}
\begin{document}
\newboolean{tex_bool}
\begin{pycode}
py_bool = 3 == 4
set_cmd = r'\setboolean{tex_bool}{true}' if py_bool else r'\setboolean{tex_bool}{false}'
print(set_cmd)
\end{pycode}
The boolean was
\ifthenelse{\boolean{tex_bool}}{%
true
}{%
false
}
\end{document}
然而,这种方法行不通,至少不可靠。
我认为我应该在这里指定扩展的顺序。但我不知道该怎么做。有办法吗?
答案1
用于\pyc
打印。
\documentclass{scrartcl}
\usepackage{fontspec}
\usepackage[gobble=auto]{pythontex}
\usepackage{ifthen}
\begin{document}
\newboolean{tex_bool}
\begin{pycode}
py_bool = 3 == 3
set_cmd = r'\setboolean{tex_bool}{true}' if py_bool else r'\setboolean{tex_bool}{false}'
\end{pycode}
\pyc{print(set_cmd)}
The boolean was
\ifthenelse{\boolean{tex_bool}}{%
true
}{%
false
}
\end{document}