latex
This commit is contained in:
parent
efedab186d
commit
e769f831c7
BIN
2302.02948.tar
Normal file
BIN
2302.02948.tar
Normal file
Binary file not shown.
@ -238,3 +238,6 @@ def Latex英文纠错(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_p
|
||||
yield from update_ui(chatbot=chatbot, history=history) # 刷新界面
|
||||
return
|
||||
yield from 多文件润色(file_manifest, project_folder, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, language='en', mode='proofread')
|
||||
|
||||
|
||||
|
||||
|
41
crazy_functions/Latex输出PDF结果.py
Normal file
41
crazy_functions/Latex输出PDF结果.py
Normal file
@ -0,0 +1,41 @@
|
||||
from toolbox import update_ui, trimmed_format_exc
|
||||
from toolbox import CatchException, report_execption, write_results_to_file, zip_folder
|
||||
import glob
|
||||
|
||||
def 编译Latex(main_tex, work_folder):
|
||||
import os
|
||||
current_dir = os.getcwd()
|
||||
os.chdir(work_folder);
|
||||
main_file = os.path.basename(main_tex)
|
||||
assert main_file.endswith('.tex')
|
||||
main_file = main_file[:-4]
|
||||
os.system(f'pdflatex {main_file}.tex')
|
||||
os.system(f'bibtex {main_file}.aux')
|
||||
os.system(f'pdflatex {main_file}.tex')
|
||||
os.system(f'pdflatex {main_file}.tex')
|
||||
os.chdir(current_dir)
|
||||
pdf_output = os.path.join(work_folder, f'{main_file}.pdf')
|
||||
|
||||
assert os.path.exists(pdf_output)
|
||||
return pdf_output
|
||||
|
||||
def Latex预处理(tar_file):
|
||||
from toolbox import extract_archive
|
||||
import shutil
|
||||
work_folder = 'private_upload/latex_workshop_temp'
|
||||
try:
|
||||
shutil.rmtree(work_folder)
|
||||
except:
|
||||
pass
|
||||
res = extract_archive(tar_file, dest_dir=work_folder)
|
||||
for texf in glob.glob('private_upload/latex_workshop_temp/*.tex'):
|
||||
with open(texf, 'r', encoding='utf8') as f:
|
||||
file_content = f.read()
|
||||
if r'\documentclass' in file_content:
|
||||
return texf, work_folder
|
||||
else:
|
||||
continue
|
||||
raise RuntimeError('无法找到一个主Tex文件(包含documentclass关键字)')
|
||||
|
||||
|
||||
|
@ -179,6 +179,16 @@ def test_Langchain知识库读取():
|
||||
for cookies, cb, hist, msg in silence_stdout(读取知识库作答)(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
|
||||
cli_printer.print(cb) # print(cb)
|
||||
|
||||
def test_Latex():
|
||||
from crazy_functions.Latex输出PDF结果 import Latex预处理, 编译Latex
|
||||
txt = "2302.02948.tar"
|
||||
print(txt)
|
||||
main_tex, work_folder = Latex预处理(txt)
|
||||
print('main tex:', main_tex)
|
||||
res = 编译Latex(main_tex, work_folder)
|
||||
# for cookies, cb, hist, msg in silence_stdout(编译Latex)(txt, llm_kwargs, plugin_kwargs, chatbot, history, system_prompt, web_port):
|
||||
# cli_printer.print(cb) # print(cb)
|
||||
|
||||
|
||||
|
||||
# test_解析一个Python项目()
|
||||
@ -192,8 +202,8 @@ def test_Langchain知识库读取():
|
||||
# test_联网回答问题()
|
||||
# test_解析ipynb文件()
|
||||
# test_数学动画生成manim()
|
||||
test_Langchain知识库()
|
||||
# test_Langchain知识库()
|
||||
# test_Langchain知识库读取()
|
||||
|
||||
test_Latex()
|
||||
input("程序完成,回车退出。")
|
||||
print("退出。")
|
Loading…
x
Reference in New Issue
Block a user