为什么我使用过滤模块时出现 [[ 输出文件丢失的情况

为什么我使用过滤模块时出现 [[ 输出文件丢失的情况

为什么我会收到此错误:[[输出文件丢失

 \setuppapersize[A4][A4]
\usemodule[filter]
\defineexternalfilter
  [python]
  [
    filtercommand={python \externalfilterinputfile \space > \externalfilteroutputfile},
    output={\externalfilterbasefile.tex},
   cache=yes,
   readcommand=\typefile,
   spacebefore=medium,
   spaceafter=medium, 
  ]


\starttext

% From Sympy doc
\startpython
from sympy import *
x = symbols('x')
a = Integral(cos(x)*exp(x), x)
Eq(a, a.doit())
\stoppython

\stoptext

使用 pythontex :

% arara: pdflatex
% arara: pythontex
% arara: pdflatex

\documentclass{article}
\usepackage{pythontex}

\begin{document}


pyconsole :

\begin{pyconsole}[][frame=single]
from sympy import *
x = symbols('x')
a = Integral(cos(x)*exp(x), x)
Eq(a, a.doit())
\end{pyconsole}



 sympyblock

\begin{sympyblock}
from sympy import *
x= symbols('x')
f = x**3 + cos(x)**5
g = Integral(f, x)
\end{sympyblock}

\[\sympy{g}=\sympy{g.doit()}\]

\end{document}

结果 :

输出

答案1

嗯,首先你需要print。其次,你到底需要输入什么?不是 Python 专家,但根据文档,(La)TeX 打印可用。仅出于说明目的,我定义了两个过滤器,因此请选择适合您需要的过滤器:

\usemodule[filter]
%It depends on your OS. In mine it's python3
\defineexternalfilter
    [pythontyping]
    [filtercommand={python3 \externalfilterinputfile \space > \externalfilteroutputfile},
    output={\externalfilterbasefile.tex},
    cache=yes,
    readcommand=\typefile,
    spacebefore=medium,
    spaceafter=medium]
%We copy settings to save typing
\defineexternalfilter[pythonformula][pythontyping]
%But instead of typing, we input a formula
\setupexternalfilter[pythonformula]
    [readcommand=\samplefile] %\input should also work
\startTEXpage
%This prints verbatim text
\startpythontyping
from sympy import *
x = symbols('x')
a = Integral(cos(x)*exp(x), x)
print(Eq(a, a.doit()))
\stoppythontyping

%This inputs a formula
\startformula
\startpythonformula
from sympy import *
x = symbols('x')
a = Integral(cos(x)*exp(x), x)
# print(Eq(a, a.doit()))
print(latex(Eq(a, a.doit())))
\stoppythonformula
\stopformula
\stopTEXpage

在此处输入图片描述

相关内容