
간단한 예를 찾았습니다여기G. Poore가 답변했지만 제대로 작동하지 않습니다. PDF로의 출력은 다음과 같습니다
?? PythonTeX ??
?? PythonTeX ??
내가 뭔가를 놓치고 있는 걸까? 아래에서
.tex
,.py
,.pytxcode
및 내 파일을 찾을 수 있습니다.latexmkrc
.
파일 test.tex
은 다음과 같습니다
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[makestderr]{pythontex}
\newenvironment{pyconcodeblock}%
{\VerbatimEnvironment
\begin{VerbatimOut}{test.py}}%
{\end{VerbatimOut}%
\pyconc{exec(compile(open('test.py', 'rb').read(), 'test.py', 'exec'))}%
\inputpygments{python}{test.py}}
\begin{document}
\begin{pyconcodeblock}
import os
import sys
sys.path.append(os.getcwd())
def foo(x):
return 2*x
\end{pyconcodeblock}
\begin{pyconsole}
x = 10
foo(x)
\end{pyconsole}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
에서하비 머드, 내가 추가한 다음 항목을 찾았습니다 Latexmk
.
$pdflatex='pdflatex --shell-escape -interaction=nonstopmode %O %S
-file-line-error -synctex=1';
# This shows how to use the pythontex package with latexmk
# This version has a fudge on the latex and pdflatex commands that
# allows the pythontex custom dependency to work even when $out_dir
# is used to set the output directory. Without the fudge (done by
# trickery symbolic links) the custom dependency for using pythontex
# will not be detected.
add_cus_dep('pytxcode', 'tex', 0, 'pythontex');
sub pythontex {
# This subroutine is a fudge, because it from latexmk's point of
# view, it makes the main .tex file depend on the .pytxcode file.
# But it doesn't actually make the .tex file, but is used for its
# side effects in creating other files. The dependence is a way
# of triggering the rule to be run whenever the .pytxcode file
# changes, and to do this before running latex/pdflatex again.
return system("pythontex.py \"$_[0]\"") ;
}
$pdflatex = 'internal mylatex %R %Z pdflatex %O %S';
$latex = 'internal mylatex %R %Z latex %O %S';
sub mylatex {
my $root = shift;
my $dir_string = shift;
my $code = "$root.pytxcode";
my $result = "pythontex-files-$root";
if ($dir_string) {
warn "mylatex: Making symlinks to fool cus_dep creation\n";
unlink $code;
if (-l $result) {
unlink $result;
}
elsif (-d $result) {
unlink glob "$result/*";
rmdir $result;
}
symlink $dir_string.$code, $code;
if ( ! -e $dir_string.$result ) { mkdir $dir_string.$result; }
symlink $dir_string.$result, $result;
}
else {
foreach ($code, $result) { if (-l) { unlink; } }
}
return system @_;
}
파일 test.py
에는 다음이 포함됩니다.
import os
import sys
sys.path.append(os.getcwd())
def foo(x):
return 2*x
나는 또한 import os
, import sys
및 없이 시도했습니다 sys.path.append(os.getcwd())
. 그러면 다음이 test.pytxcode
포함됩니다.
=>PYTHONTEX#pycon#default#default#0#c#####22#
exec(compile(open('test.py', 'rb').read(), 'test.py', 'exec'))
=>PYTHONTEX#PYGpython#EXT:test.py#defaultverb#0#verbatim#####22#
=>PYTHONTEX#pycon#default#default#1#console#####24#
x = 10
foo(x)
=>PYTHONTEX:SETTINGS#
version=0.14
outputdir=pythontex-files-test
workingdir=.
workingdirset=false
gobble=none
rerun=default
hashdependencies=default
makestderr=true
stderrfilename=full
keeptemps=none
pyfuture=default
pyconfuture=none
pygments=true
pygglobal=:GLOBAL||
fvextfile=-1
pyconbanner=none
pyconfilename=stdin
depythontex=false
pygfamily=py|python|
pygfamily=pycon|pycon|
pygfamily=sympy|python|
pygfamily=sympycon|pycon|
pygfamily=pylab|python|
pygfamily=pylabcon|pycon|
pygfamily=PYGpython|python|
답변1
?? PythonTeX ??
PythonTeX가 또는 을 제공한다면 ??
이는 실행되지 않았음을 의미하므로 콘텐츠가 생성되지 않았습니다.
.latexmkrc
Windows에서는 작동하지 않았습니다 . 내 시스템 구성 return system("pythontex.py \"$_[0]\"") ;
에 맞게 줄을 변경해야 했습니다 . return system("pythontex \"$_[0]\"") ;
그 후에는 효과가 있었습니다.
Windows를 사용 중이라면 문제가 해결될 수 있습니다. 그렇지 않으면 출력을 읽고 latexmk
PythonTeX가 실행되지 않은 이유를 확인해야 합니다. 어느 쪽이든 .latexmkrc
.