軽量なコマンドラインLaTeXソフトウェア

軽量なコマンドラインLaTeXソフトウェア

私は LaTeX の初心者ですが、次のような数式を書くためだけに Open Office に LaTeX を実装したいと考えています。http://www.hostmath.com/そうすれば、パッケージなしで数式を直接記述し、それを Windows 用の png 画像に変換できます。(そのソフトウェアが Linux/Mac をサポートしていれば良いのですが)

のように:

xyz.exe -convert "\oint \frac-b \pm \sqrt{b^2 - 4ac}}{2a}, \space \forall a,b,c \in \mathbb{N}, \text{xyz text} dr" C:/temp/latex/001.png

OpenOffice は LaTeX をサポートしていないので、コミュニティのために拡張できれば幸いです。

また、軽量のコマンドライン ソフトウェアも必要です (5 MB 未満が望ましい。そうでないと、他のユーザーが私の拡張機能をダウンロードすることが困難になります)。

答え1

standaloneクラスを使用してプログラムのツールpdflatexを呼び出して、一気にコンパイルして方程式に変換することも可能です(convertimagemagick.pngこの答え要約についてはこちらをご覧ください。

コマンドラインウィジェットを作成するために必要なのは、正しいプリアンブルを含む最小限のドキュメントに標準入力を挿入する短いスクリプトだけです。これはほとんどの言語で可能なはずですが、私は構文に慣れているので python (3) を使用しました。次のファイルでtextopng.py:

#!/usr/bin/env python
import sys, os, subprocess
# Tested with Python 3.7.2 (4.20.10-arch1-1-ARCH)
# Requires imagemagick
# Name of .tex created (.png will have same name up to the extension)
tex_file = 'outf.tex'
# Preamble code - add additional \usepackage{} calls to this string
# Note: The size option of convert may be useful e.g. size=640
preamble = r'\documentclass[convert={density=900,outext=.png},preview,border=1pt]{standalone}\usepackage{amsmath}'
# Place input in inline math environment
equation = r'\(' + sys.argv[1] + r'\)'
# Construct our mini latex document
latex_string =  preamble + '\n' + r'\begin{document}' + equation + r'\end{document}'
# Write to tex_file
with open(tex_file, 'w') as f:
    f.write(latex_string)
try:
    # Compile .tex with pdflatex. -shell-escape parameter required for convert option of standalone class to work
    proc = subprocess.run(["pdflatex", "-shell-escape", tex_file], capture_output=True, text=True,stdin=subprocess.DEVNULL, timeout=3)
    if proc.stderr != '':
        # Print any error
        print('Process error:\n{}'.format(proc.stderr))
    if proc.stdout != '':
        # Print standard output from pdflatex
        print('Process output:\n{}'.format(proc.stdout))
# Timeout for process currently set to 3 seconds
except subprocess.TimeoutExpired:
    print('pdflatex process timed out.')

例えば、

python3 textopng.py  "x=\frac{y^2}{32}"

を生産した.png

出力png

追加のパッケージをロードし、スタンドアロン オプションを変更するには、プリアンブル コードを編集する必要があります (詳細については、スタンドアロンのドキュメントを参照してください)。スクリプトを動作させたり、より堅牢にしたりするためにサポートが必要な場合は、お知らせください。

関連情報