from fnmatch import translate from pylatex import Document, Section, Subsection, Command from pylatex.base_classes import Environment from docx import Document as docx_Document from pylatex.utils import NoEscape from pylatex.basic import NewLine from translate import Zh2En from pylatex.utils import italic, NoEscape deffill_document(doc): with doc.create(Section('A section')): doc.append('Some regular text and some ') doc.append(italic('italic text. ')) with doc.create(Subsection('A subsection')): doc.append('Also some crazy characters: $&#{}')
classABSTRACT(Environment): escape = False content_separator = "\n" if __name__ == '__main__': doc = Document(default_filepath='paper',documentclass='IEEEtran',document_options='journal',lmodern=False,textcomp=False) doc.preamble.append(Command('title', 'Translate to English using the YNMT natural language translation model')) doc.preamble.append(Command('author', '***, ***')) doc.append(NoEscape(r'\maketitle')) with doc.create(ABSTRACT()): abstract = docx_Document(r"./abstract.docx") for p in abstract.paragraphs: abstrach_zh = p.text abstrach_en = Zh2En(abstrach_zh) doc.append(abstrach_en) with doc.create(Section('Introduction')): introduction = docx_Document(r"./introduction.docx") for p in introduction.paragraphs: introduction_zh = p.text introduction_en = Zh2En(introduction_zh) doc.append(introduction_en) doc.append(NoEscape(r'\par')) doc.generate_pdf(clean_tex=False) doc.generate_tex()