가벼운 명령줄 라텍스 소프트웨어

가벼운 명령줄 라텍스 소프트웨어

저는 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를 지원하지 않으므로 커뮤니티를 위해 LaTeX를 확장하고 싶습니다.

또한 가벼운 명령줄 소프트웨어가 필요합니다(5MB 미만이 바람직합니다. 그렇지 않으면 다른 사람이 내 확장 프로그램을 다운로드하기 어려울 것입니다.)

답변1

클래스를 사용하여 프로그램 도구를 호출 standalone하여 컴파일하고 변환할 수 있습니다.pdflatexconvertimagemagick.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

추가 패키지를 로드하고 독립 실행형 옵션을 변경하기 위해 서문 코드를 편집할 수 있습니다(자세한 내용은 독립 실행형 설명서 참조). 스크립트가 작동하도록 하거나 더 강력하게 만드는 데 도움이 필요하면 알려주십시오.

관련 정보