本文整理汇总了Python中pylatex.Document.create方法的典型用法代码示例。如果您正苦于以下问题:Python Document.create方法的具体用法?Python Document.create怎么用?Python Document.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylatex.Document
的用法示例。
在下文中一共展示了Document.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def test():
doc = Document("multirow_cm")
with doc.create(Section('Multirow Test')):
with doc.create(Subsection('Multicol')):
# we need to keep track of the object here
with doc.create(Tabular('|c|c|')) as table1:
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()
with doc.create(Subsection('Multirow')):
with doc.create(Tabular('|c|c|c|')) as table2:
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()
doc.generate_pdf()
示例2: arxiv_search
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def arxiv_search(search_query):
url = 'http://export.arxiv.org/api/query?search_query=all:' + \
search_query + '&start=0&max_results=5'
data = urllib.request.urlopen(url).read()
soup = bs(data, features='xml')
title_array = []
summary_array = []
for i in soup.findAll('title'):
title_array.append(i)
for i in soup.findAll('summary'):
summary_array.append(i)
doc = Document()
doc.packages.append(
Package(
'geometry',
options=[
'tmargin=1cm',
'lmargin=1cm',
'rmargin=1cm']))
with doc.create(Section('Search results for \"' + search_query + '\"')):
for i in range(1, 5):
doc.append(Subsection(italic(title_array[i].string)))
doc.append(summary_array[i].string)
doc.generate_pdf()
示例3: generate_hr_tex
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def generate_hr_tex(G, matchings, output_dir, stats_filename):
"""
print statistics for the resident proposing stable,
max-cardinality popular, and popular amongst max-cardinality
matchings as a tex file
:param G: graph
:param matchings: information about the matchings
"""
# create a tex file with the statistics
doc = Document('table')
# M_s = matching_algos.stable_matching_hospital_residents(graph.copy_graph(G))
# add details about the graph, |A|, |B|, and # of edges
n1, n2, m = len(G.A), len(G.B), sum(len(G.E[r]) for r in G.A)
with doc.create(Subsection('graph details')):
with doc.create(Tabular('|c|c|')) as table:
table.add_hline()
table.add_row('n1', n1)
table.add_hline()
table.add_row('n2', n1)
table.add_hline()
table.add_row('m', m)
table.add_hline()
with doc.create(Subsection('general statistics')):
with doc.create(Tabular('|c|c|c|c|')) as table:
table.add_hline()
table.add_row(('description', 'size', 'bp', 'bp ratio'))
for desc in matchings:
M = matchings[desc]
sig = signature(G, M)
msize = matching_utils.matching_size(G, M)
bp = matching_utils.unstable_pairs(G, M)
table.add_hline()
table.add_row((desc, msize, len(bp), len(bp)/(m - msize)))
table.add_hline()
# statistics w.r.t. set A
stats_for_partition(G, matchings, doc)
# statistics w.r.t. set B
# stats_for_partition(G, matchings, doc, False)
stats_abs_path = os.path.join(output_dir, stats_filename)
doc.generate_pdf(filepath=stats_abs_path, clean_tex='False')
doc.generate_tex(filepath=stats_abs_path)
示例4: doit
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def doit(outfile = 'summary', ndim=3, action=True):
if action == False:
print(outfile, ndim)
return
if ndim == 3:
resfile = '05aperture_results_3d.txt'
statfile = '3d_cluster_statistics.txt'
elif ndim == 2:
resfile = '05aperture_results_2d.txt'
statfile = 'cluster_statistics.txt'
# generate blank LaTeX doc
geometry_options = {"tmargin": "1cm", "lmargin": "2cm"}
doc = Document(geometry_options=geometry_options)
# insert some introductory material
dirname = os.getcwd()
doc.append('Clustering output, found in')
doc.append(dirname)
# get the K-means section of results table and insert into the document
with doc.create(Section('K-means results')):
tmptex, ncl_list = get_stats(resfile, 'kmeans', oldcols_results, newcols_results, None, None)
doc.append(tmptex)
doc.append(NewPage())
# add the individual K-means runs
add_sections_to_doc(ncl_list, 'kmeans', doc, statfile, ndim)
# now the intro material for meanshift
# get the results table and insert into the document
with doc.create(Section('Meanshift results')):
tmptex, ncl_list = get_stats(resfile, 'meanshift', oldcols_res_ms, newcols_res_ms, None, None)
doc.append(tmptex)
doc.append(NewPage())
# add the individual meanshift runs
add_sections_to_doc(ncl_list, 'meanshift', doc, statfile, ndim)
# turn the LaTex into a PDF
doc.generate_tex(filepath=outfile)
doc.generate_pdf(outfile, clean_tex=False)
# all done!
return
示例5: main
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def main(fname, width, *args, **kwargs):
doc = Document(fname)
doc.packages.append(Package('geometry', options=['left=2cm', 'right=2cm']))
doc.append('Introduction.')
with doc.create(Section('I am a section')):
doc.append('Take a look at this beautiful plot:')
with doc.create(Figure(position='htbp')) as plot:
plot.add_plot(width=NoEscape(width), *args, **kwargs)
plot.add_caption('I am a caption.')
doc.append('Created using matplotlib.')
doc.append('Conclusion.')
doc.generate_pdf()
示例6: genenerate_tabus
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def genenerate_tabus():
geometry_options = {
"landscape": True,
"margin": "1.5in",
"headheight": "20pt",
"headsep": "10pt",
"includeheadfoot": True
}
doc = Document(page_numbers=True, geometry_options=geometry_options)
# Generate data table with 'tight' columns
fmt = "X[r] X[r] X[r] X[r] X[r] X[r]"
with doc.create(LongTabu(fmt, spread="0pt")) as data_table:
header_row1 = ["Prov", "Num", "CurBal", "IntPay", "Total", "IntR"]
data_table.add_row(header_row1, mapper=[bold])
data_table.add_hline()
data_table.add_empty_row()
data_table.end_table_header()
data_table.add_row(["Prov", "Num", "CurBal", "IntPay", "Total",
"IntR"])
row = ["PA", "9", "$100", "%10", "$1000", "Test"]
for i in range(40):
data_table.add_row(row)
with doc.create(Center()) as centered:
with centered.create(Tabu("X[r] X[r]", spread="1in")) as data_table:
header_row1 = ["X", "Y"]
data_table.add_row(header_row1, mapper=[bold])
data_table.add_hline()
row = [randint(0, 1000), randint(0, 1000)]
for i in range(4):
data_table.add_row(row)
with doc.create(Center()) as centered:
with centered.create(Tabu("X[r] X[r]", to="4in")) as data_table:
header_row1 = ["X", "Y"]
data_table.add_row(header_row1, mapper=[bold])
data_table.add_hline()
row = [randint(0, 1000), randint(0, 1000)]
for i in range(4):
data_table.add_row(row)
doc.generate_pdf("tabus", clean_tex=False)
示例7: __init__
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
class TrainingDocumentWriter:
def __init__(self, title):
self.title = title
self.doc = Document(title)
self.doc.packages.append(Package('geometry', options=['a4paper', 'top=2cm', 'bottom=2.5cm', 'left=2cm', 'right=2cm']))
self.doc.packages.append(Package('titlesec', options=['sf']))
self.doc.packages.append(Package('lmodern'))
self.doc.append(Command('sffamily'))
return
def append_plot(self, pyplot, caption=''):
with self.doc.create(Plt(position='htbp')) as plot:
plot.add_plot(pyplot, width=ur'\textwidth')
if caption!='':
plot.add_caption(caption)
return
def append_section(self, section_title='', content=''):
with self.doc.create(Section(section_title)):
if content!='':
self.doc.append(content)
return
def generate_pdf(self,filename=u'', clean=True, compiler='pdflatex'):
#This is a workaround to save the generated pdf in a different directory (not in working dir)
cur_path = os.getcwd()
dirlist = filename.split('/')
os.chdir(os.path.dirname(filename)) #cd to specified directory
#Remove possible existing file extension (.pdf)
if '.' in filename:
self.doc.generate_pdf(dirlist[len(dirlist)-1].split('.')[0])
else:
self.doc.generate_pdf(dirlist[len(dirlist)-1])
os.chdir(cur_path) #cd to original working directory
return
示例8: generate_heuristic_tex
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def generate_heuristic_tex(G, matchings, output_dir, stats_filename):
"""
print statistics for the hospital proposing heuristic as a tex file
:param G: graph
:param matchings: information about the matchings
"""
# create a tex file with the statistics
doc = Document('table')
# add details about the graph, |A|, |B|, and # of edges
n1, n2, m = len(G.A), len(G.B), sum(len(G.E[r]) for r in G.A)
with doc.create(Subsection('graph details')):
with doc.create(Tabular('|c|c|')) as table:
table.add_hline()
table.add_row('n1', n1)
table.add_hline()
table.add_row('n2', n1)
table.add_hline()
table.add_row('m', m)
table.add_hline()
M_s = matching_algos.stable_matching_hospital_residents(graph.copy_graph(G))
with doc.create(Subsection('Size statistics')):
with doc.create(Tabular('|c|c|c|c|c|c|c|')) as table:
table.add_hline()
table.add_row(('description', 'size', 'bp', 'bp ratio', 'block-R',
'rank-1', 'deficiency'))
for desc in matchings:
M = matchings[desc]
sig = signature(G, M)
bp = matching_utils.unstable_pairs(G, M)
msize = matching_utils.matching_size(G, M)
table.add_hline()
table.add_row((desc, msize, len(bp), len(bp)/(m - msize),
len(blocking_residents(bp)),
sum_ranks(sig, (1,)), #sum_ranks(sig, (1, 2, 3)),
total_deficiency(G, M_s)))
table.add_hline()
stats_abs_path = os.path.join(output_dir, stats_filename)
doc.generate_pdf(filepath=stats_abs_path, clean_tex='False')
doc.generate_tex(filepath=stats_abs_path)
示例9: createSimpleTable
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def createSimpleTable(tableColumns,d,filename):
doc = Document()
with doc.create(Table('|c|c|c|c|c|c|c|c|c|')) as table:
for row in d:
row[0]=row[0].replace('_','\_')
row[0]="\\textbf{"+row[0]+"}"
table.add_hline()
table.add_row(tuple(row))
table.add_hline()
a = open(filename, 'wr')
table.dump(a)
示例10: show_pdf
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def show_pdf(filename):
"""
Compiles a simple tex document that the matplotlib2tikz-generated figure 'filename' is embedded
in. Displays pdf.
:param filename | Name of input tex snippet (without extension)
"""
from pylatex import Document, Figure, Command, Package
document = Document()
document.packages.append(Package('pgfplots'))
with document.create(Figure(placement='ht')) as fig:
fig.append(Command("centering"))
fig.append(Command("input", "../figures/{}.tex".format(filename)))
fig.add_caption("Test printing.")
document.generate_pdf(clean=True, clean_tex=True)
from subprocess import call
call(['evince', "../figures/default_filepath.pdf"])
示例11: generate_eva_report
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def generate_eva_report():
"""
Generate a report which contains the evacution time for every test
"""
geometry_options = {
"head": "40pt",
"margin": "0.5in",
"bottom": "0.6in",
"includeheadfoot": True
}
doc = Document(geometry_options=geometry_options)
## Define style of report
reportStyle = PageStyle("reportStyle")
with reportStyle.create(Head("R")) as left_header:
with left_header.create(MiniPage(width=NoEscape(r"0.49\textwidth"),
pos='c', align='l')) as title_wrapper:
title_wrapper.append(LargeText(bold("RiMEA-Projekt")))
title_wrapper.append(LineBreak())
title_wrapper.append(MediumText(bold("Anlyse")))
doc.preamble.append(reportStyle)
## Apply Pagestyle
doc.change_document_style("reportStyle")
## Create table
with doc.create(LongTabu("X[c] X[c]",
row_height=1.5)) as report_table:
report_table.add_row(["Test",
"evacuation time(s)"],
mapper=bold)
report_table.add_hline()
## Write the results of 3 tests in table
for i in range(1,4):
report_table.add_row(i, get_evac_time(i)[0])
doc.append(NewPage())
doc.generate_pdf("RiMEA-Projekt Evacution Analyse", clean_tex=False)
示例12: generate_labels
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def generate_labels():
geometry_options = {"margin": "0.5in"}
doc = Document(geometry_options=geometry_options)
doc.change_document_style("empty")
for i in range(10):
with doc.create(MiniPage(width=r"0.5\textwidth")):
doc.append("Vladimir Gorovikov")
doc.append("\n")
doc.append("Company Name")
doc.append("\n")
doc.append("Somewhere, City")
doc.append("\n")
doc.append("Country")
if (i % 2) == 1:
doc.append(VerticalSpace("20pt"))
doc.append(LineBreak())
doc.generate_pdf("minipage", clean_tex=False)
示例13: generate_header
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def generate_header():
geometry_options = {"margin": "0.7in"}
doc = Document(geometry_options=geometry_options)
# Add document header
header = PageStyle("header")
# Create left header
with header.create(Head("L")):
header.append("Page date: ")
header.append(LineBreak())
header.append("R3")
# Create center header
with header.create(Head("C")):
header.append("Company")
# Create right header
with header.create(Head("R")):
header.append(simple_page_number())
# Create left footer
with header.create(Foot("L")):
header.append("Left Footer")
# Create center footer
with header.create(Foot("C")):
header.append("Center Footer")
# Create right footer
with header.create(Foot("R")):
header.append("Right Footer")
doc.preamble.append(header)
doc.change_document_style("header")
# Add Heading
with doc.create(MiniPage(align='c')):
doc.append(LargeText(bold("Title")))
doc.append(LineBreak())
doc.append(MediumText(bold("As at:")))
doc.generate_pdf("header", clean_tex=False)
示例14: len
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
#Table header
table_format = 'llllllll'
#Elements we want to put in the table
idces_table = (dz.reducDf.frame_tag.isin(dz.observation_dict['objects'] + dz.observation_dict['Standard_stars'] + ['flat', 'arc'])) & (dz.reducDf.file_location.str.contains('/raw_fits/'))
file_names = dz.reducDf[idces_table].sort_values(['RUN']).file_name.values
file_folders = dz.reducDf[idces_table].sort_values(['RUN']).file_location.values
RA_values = dz.reducDf[idces_table].sort_values(['RUN']).RA.values
DEC_values = dz.reducDf[idces_table].sort_values(['RUN']).DEC.values
UT = dz.reducDf[idces_table].sort_values(['RUN']).UT.values
objects = dz.reducDf[idces_table].sort_values(['RUN']).frame_tag.values
color = dz.reducDf[idces_table].sort_values(['RUN']).ISIARM.values
valid_values = dz.reducDf[idces_table].sort_values(['RUN']).valid_file.values
#Fill the table
with doc.create(Tabular(table_format)) as table:
#Adding the header
headers = ['Object', 'Frame', 'Arm', 'UT', 'RA', 'DEC', 'Flat Blue', 'Flat Red']
row_values = [None] * len(headers)
table.add_row(headers, escape=False)
table.add_hline()
for i in range(len(file_names)):
#Get the righ match if it is a target
if objects[i] in (dz.observation_dict['Standard_stars'] + dz.observation_dict['objects']):
blue_object = matched_frames['{codename}_{arm_color}_{calib_file}_bySeparation'.format(codename = objects[i], arm_color = 'Blue', calib_file = 'flat')]
red_object = matched_frames['{codename}_{arm_color}_{calib_file}_bySeparation'.format(codename = objects[i], arm_color = 'Red', calib_file = 'flat')]
match = [blue_object, red_object]
示例15: generate_unique
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import create [as 别名]
def generate_unique():
geometry_options = {
"head": "40pt",
"margin": "0.5in",
"bottom": "0.6in",
"includeheadfoot": True
}
doc = Document(geometry_options=geometry_options)
# Generating first page style
first_page = PageStyle("firstpage")
# Header image
with first_page.create(Head("L")) as header_left:
with header_left.create(MiniPage(width=NoEscape(r"0.49\textwidth"),
pos='c')) as logo_wrapper:
logo_file = os.path.join(os.path.dirname(__file__),
'sample-logo.png')
logo_wrapper.append(StandAloneGraphic(image_options="width=120px",
filename=logo_file))
# Add document title
with first_page.create(Head("R")) as right_header:
with right_header.create(MiniPage(width=NoEscape(r"0.49\textwidth"),
pos='c', align='r')) as title_wrapper:
title_wrapper.append(LargeText(bold("Bank Account Statement")))
title_wrapper.append(LineBreak())
title_wrapper.append(MediumText(bold("Date")))
# Add footer
with first_page.create(Foot("C")) as footer:
message = "Important message please read"
with footer.create(Tabularx(
"X X X X",
arguments=NoEscape(r"\textwidth"))) as footer_table:
footer_table.add_row(
[MultiColumn(4, align='l', data=TextColor("blue", message))])
footer_table.add_hline(color="blue")
footer_table.add_empty_row()
branch_address = MiniPage(
width=NoEscape(r"0.25\textwidth"),
pos='t')
branch_address.append("960 - 22nd street east")
branch_address.append("\n")
branch_address.append("Saskatoon, SK")
document_details = MiniPage(width=NoEscape(r"0.25\textwidth"),
pos='t', align='r')
document_details.append("1000")
document_details.append(LineBreak())
document_details.append(simple_page_number())
footer_table.add_row([branch_address, branch_address,
branch_address, document_details])
doc.preamble.append(first_page)
# End first page style
# Add customer information
with doc.create(Tabu("X[l] X[r]")) as first_page_table:
customer = MiniPage(width=NoEscape(r"0.49\textwidth"), pos='h')
customer.append("Verna Volcano")
customer.append("\n")
customer.append("For some Person")
customer.append("\n")
customer.append("Address1")
customer.append("\n")
customer.append("Address2")
customer.append("\n")
customer.append("Address3")
# Add branch information
branch = MiniPage(width=NoEscape(r"0.49\textwidth"), pos='t!',
align='r')
branch.append("Branch no.")
branch.append(LineBreak())
branch.append(bold("1181..."))
branch.append(LineBreak())
branch.append(bold("TIB Cheque"))
first_page_table.add_row([customer, branch])
first_page_table.add_empty_row()
doc.change_document_style("firstpage")
doc.add_color(name="lightgray", model="gray", description="0.80")
# Add statement table
with doc.create(LongTabu("X[l] X[2l] X[r] X[r] X[r]",
row_height=1.5)) as data_table:
data_table.add_row(["date",
"description",
"debits($)",
"credits($)",
"balance($)"],
mapper=bold,
color="lightgray")
data_table.add_empty_row()
data_table.add_hline()
#.........这里部分代码省略.........