def build_document(transcript): """ Processes a Transcript object to build a LaTeX document. """ # Open temporary file doc = Document(documentclass='scrartcl', title=transcript.title, subtitle=transcript.school, author=transcript.student, date=transcript.date.strftime('%d %B %Y'), temporary=True) doc.packages.append(Package('geometry', option='margin=1.0in')) doc.preamble.append( Command('renewcommand', argument=['\\familydefault', '\\sfdefault'])) doc.append(Command('maketitle')) # Iterate through each transcript section for t_section in transcript.sections: # Create new section s = Section(escape_latex(t_section.title)) # Add content to section for s_line in t_section.content: s_line = '\t'.join(s_line) s.append(escape_latex(s_line) + ' \\\n') # Add subsections to section for t_subsection in t_section.subsections: ss = Subsection(escape_latex(t_subsection.title)) num_cols = max(len(l) for l in t_subsection.content) ss_table = Table(' l ' * num_cols) # Add content to subsection for ss_line in t_subsection.content: ss_line = '\t'.join(ss_line) if ss_line.startswith('Course Topic'): ss_table.append('&') ss_table.add_multicolumn(num_cols - 1, 'l', escape_latex(ss_line)) ss_table.append(r'\\') elif not ss_line[:3].isupper() and not ss_line.startswith( 'Test'): ss_table.add_multicolumn(num_cols, 'l', escape_latex(ss_line)) ss_table.append(r'\\') else: if ss_line.startswith('TERM'): ss_table.add_hline() filled = escape_latex(ss_line).split('\t') filled += (num_cols - len(filled)) * [''] ss_table.add_row(filled) ss.append(ss_table) s.append(ss) doc.append(s) doc.generate_pdf(clean=True) return doc
def build_document(transcript): """ Processes a Transcript object to build a LaTeX document. """ # Open temporary file doc = Document(documentclass='scrartcl', title=transcript.title, subtitle=transcript.school, author=transcript.student, date=transcript.date.strftime('%d %B %Y'), temporary=True) doc.packages.append(Package('geometry', option='margin=1.0in')) doc.preamble.append(Command('renewcommand', argument=['\\familydefault', '\\sfdefault'])) doc.append(Command('maketitle')) # Iterate through each transcript section for t_section in transcript.sections: # Create new section s = Section(escape_latex(t_section.title)) # Add content to section for s_line in t_section.content: s_line = '\t'.join(s_line) s.append(escape_latex(s_line) + ' \\\n') # Add subsections to section for t_subsection in t_section.subsections: ss = Subsection(escape_latex(t_subsection.title)) num_cols = max(len(l) for l in t_subsection.content) ss_table = Table(' l ' * num_cols) # Add content to subsection for ss_line in t_subsection.content: ss_line = '\t'.join(ss_line) if ss_line.startswith('Course Topic'): ss_table.append('&') ss_table.add_multicolumn(num_cols-1, 'l', escape_latex(ss_line)) ss_table.append(r'\\') elif not ss_line[:3].isupper() and not ss_line.startswith('Test'): ss_table.add_multicolumn(num_cols, 'l', escape_latex(ss_line)) ss_table.append(r'\\') else: if ss_line.startswith('TERM'): ss_table.add_hline() filled = escape_latex(ss_line).split('\t') filled += (num_cols - len(filled)) * [''] ss_table.add_row(filled) ss.append(ss_table) s.append(ss) doc.append(s) doc.generate_pdf(clean=True) return doc
Subsection, Table, MultiColumn, MultiRow ) doc = Document("multirow") section = Section('Multirow Test') test1 = Subsection('MultiColumn') test2 = Subsection('MultiRow') test3 = Subsection('MultiColumn and MultiRow') test4 = Subsection('Vext01') table1 = Table('|c|c|c|c|') table1.add_hline() table1.add_row((MultiColumn(4, '|c|', 'Multicolumn'),)) table1.add_hline() table1.add_row((1, 2, 3, 4)) table1.add_hline() table1.add_row((5, 6, 7, 8)) table1.add_hline() row_cells = ('9', MultiColumn(3, '|c|', 'Multicolumn not on left')) table1.add_row(row_cells) table1.add_hline() table2 = Table('|c|c|c|') table2.add_hline() table2.add_row((MultiRow(3, '*', 'Multirow'), 1, 2)) table2.add_hline(2, 3) table2.add_row(('', 3, 4))
import numpy as np from pylatex import Document, Section, Subsection, Table, Math from pylatex.numpy import Matrix from pylatex.utils import italic doc = Document() section = Section('Yaay the first section, it can even be ' + italic('italic')) section.append('Some regular text') math = Subsection('Math', data=[Math(data=['2*3', '=', 6])]) section.append(math) table = Table('rc|cl') table.add_hline() table.add_row((1, 2, 3, 4)) table.add_hline(1, 2) table.add_empty_row() table.add_row((4, 5, 6, 7)) table = Subsection('Table of something', data=[table]) section.append(table) a = np.array([[100, 10, 20]]).T M = np.matrix([[2, 3, 4], [0, 0, 1], [0, 0, 2]]) math = Math(data=[Matrix(M), Matrix(a), '=', Matrix(M*a)])
import numpy as np from pylatex import Document, Section, Subsection, Table, Math, TikZ, Axis, \ Plot from pylatex.numpy import Matrix from pylatex.utils import italic doc = Document(filename="multirow") section = Section('Multirow Test') test1 = Subsection('Multicol') test2 = Subsection('Multirow') table1 = Table('|c|c|') table1.add_hline() table1.add_multicolumn(2, '|c|', 'Multicol') table1.add_hline() table1.add_row((1, 2)) table1.add_hline() table1.add_row((3, 4)) table1.add_hline() table2 = Table('|cc|c|c|') table2.add_hline() table2.add_multirow(2, '*', 'Multirow', cells=((1, 2), (3, 4))) table2.add_hline() test1.append(table1) test2.append(table2)
from pylatex import Document, Section, Subsection, Table, Math, TikZ, Axis, \ Plot from pylatex.numpy import Matrix from pylatex.utils import italic doc = Document() section = Section('Yaay the first section, it can even be ' + italic('italic')) section.append('Some regular text') math = Subsection('Math that is incorrect', data=[Math(data=['2*3', '=', 9])]) section.append(math) table = Table('rc|cl') table.add_hline() table.add_row((1, 2, 3, 4)) table.add_hline(1, 2) table.add_empty_row() table.add_row((4, 5, 6, 7)) table = Subsection('Table of something', data=[table]) section.append(table) a = np.array([[100, 10, 20]]).T M = np.matrix([[2, 3, 4], [0, 0, 1], [0, 0, 2]]) math = Math(data=[Matrix(M), Matrix(a), '=', Matrix(M*a)])
#!/usr/bin/python from pylatex import Document, Section, Subsection, Table doc = Document(filename="multirow") section = Section('Multirow Test') test1 = Subsection('Multicol') test2 = Subsection('Multirow') table1 = Table('|c|c|') table1.add_hline() table1.add_multicolumn(2, '|c|', 'Multicol') table1.add_hline() table1.add_row((1, 2)) table1.add_hline() table1.add_row((3, 4)) table1.add_hline() table2 = Table('|c|c|c|') table2.add_hline() table2.add_multirow(3, '*', 'Multirow', cells=((1, 2), (3, 4), (5, 6))) table2.add_hline() table2.add_multirow(3, '*', 'Multirow2') table2.add_hline() test1.append(table1) test2.append(table2) section.append(test1) section.append(test2)
doc.append('Some text.') doc.generate_tex(filename='') doc.generate_pdf(filename='', clean=True) # SectionBase s = Section(title='', numbering=True, data=None) # Math m = Math(data=None, inline=False) # Table t = Table(table_spec='|c|c|', data=None, pos=None, table_type='tabular') t.add_hline(start=None, end=None) t.add_row(cells=(1, 2), escape=False) t.add_multicolumn(size=2, align='|c|', content='Multicol', cells=None, escape=False) t.add_multirow(size=3, align='*', content='Multirow', hlines=True, cells=None, escape=False) # Command c = Command('documentclass', arguments=None, options=None, packages=None) # Figure f = Figure(data=None, position=None)
doc.append('Some text.') doc.generate_tex(filename='') doc.generate_pdf(filename='', clean=True) # SectionBase s = Section(title='', numbering=True, data=None) # Math m = Math(data=None, inline=False) # Table t = Table(table_spec='|c|c|', data=None, pos=None, table_type='tabular') t.add_hline(start=None, end=None) t.add_row(cells=(1, 2), escape=False) t.add_multicolumn(size=2, align='|c|', content='Multicol', cells=None, escape=False) t.add_multirow(size=3, align='*', content='Multirow', hlines=True, cells=None, escape=False) # Command c = Command(command='documentclass', arguments=None, options=None, packages=None) # Figure f = Figure(data=None, position=None)
import numpy as np from pylatex import Document, Section, Subsection, Table, Math, TikZ, Axis, Plot from pylatex.numpy import Matrix from pylatex.utils import italic doc = Document() section = Section('Yaay the first section, it can even be ' + italic('italic')) section.append('Some regular text') math = Subsection('Math that is incorrect', data=[Math(data=['2*3', '=', 9])]) section.append(math) table = Table('rc|cl') table.add_hline() table.add_row((1, 2, 3, 4)) table.add_hline(1, 2) table.add_empty_row() table.add_row((4, 5, 6, 7)) table = Subsection('Table of something', data=[table]) section.append(table) a = np.array([[100, 10, 20]]).T M = np.matrix([[2, 3, 4], [0, 0, 1], [0, 0, 2]]) math = Math(data=[Matrix(M), Matrix(a), '=', Matrix(M*a)])
from pylatex import Document, Section, Subsection, Table, Math, TikZ, Axis, \ Plot from pylatex.numpy import Matrix from pylatex.utils import italic doc = Document() section = Section('Yaay the first section, it can even be ' + italic('italic')) section.append('Some regular text') math = Subsection('Math that is incorrect', data=[Math(data=['2*3', '=', 9])]) section.append(math) table = Table('rc|cl') table.add_hline() table.add_row((1, 2, 3, 4)) table.add_hline(1, 2) table.add_empty_row() table.add_row((4, 5, 6, 7)) table = Subsection('Table of something', data=[table]) section.append(table) a = np.array([[100, 10, 20]]).T M = np.matrix([[2, 3, 4], [0, 0, 1], [0, 0, 2]]) math = Math(data=[Matrix(M), Matrix(a), '=', Matrix(M * a)]) equation = Subsection('Matrix equation', data=[math])