Python と pandoc を使用していくつかの html を latex に変換しようとしていますが、いくつかの問題に悩まされています。
私のpythonスクリプトをpandocと通信するために、私が使用しているファイルにsubprocess.Popen
リダイレクトstdout
して、ラテックステンプレートに含めるために保存しています。
古典的な実装方法を使用する場合Popen
from subprocess import Popen, PIPE, STDOUT
filedesc = open('myfile.tex','w')
args = ['pandoc', '-f', 'html', '-t', 'latex']
p = Popen(args, stdout=PIPE, stdin=PIPE, stderr=STDOUT)
outp, err = p.communicate(input=html)
filedesc.write(outp)
あるべきではない追加の新しい行を含む行を取得します。
> \textbf{M. John Harrison} (Rugby, Warckwickshire, 1945) は同時代の
>
>イギリスの作家。
これは (不思議なことに?) フstdout=PIPE
ァイル記述子を変更することで簡単に解決できます。
from subprocess import Popen, PIPE, STDOUT
filedesc = open('myfile.tex','w')
args = ['pandoc', '-f', 'html', '-t', 'latex']
p = Popen(args, stdout=filedesc, stdin=PIPE, stderr=STDOUT)
outp, err = p.communicate(input=html)
# not needed
# filedesc.write(outp)
しかし、文字列バッファーを使用したい場合、stdout パラメーターとして使用できないため、同じ問題が発生します。
Popen/pandocがこれを行うのを止める方法について何か考えはありますか?
ありがとう!