本文整理汇总了Python中pylatex.Document.append方法的典型用法代码示例。如果您正苦于以下问题:Python Document.append方法的具体用法?Python Document.append怎么用?Python Document.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylatex.Document
的用法示例。
在下文中一共展示了Document.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_document
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def test_document():
geometry_options = {
"includeheadfoot": True,
"headheight": "12pt",
"headsep": "10pt",
"landscape": True
}
doc = Document(
default_filepath='default_filepath',
documentclass='article',
fontenc='T1',
inputenc='utf8',
lmodern=True,
data=None,
page_numbers=True,
indent=False,
document_options=["a4paper", "12pt"],
geometry_options=geometry_options
)
repr(doc)
doc.append('Some text.')
doc.change_page_style(style="empty")
doc.change_document_style(style="plain")
doc.add_color(name="lightgray", model="gray", description="0.6")
doc.add_color(name="abitless", model="gray", description="0.8")
doc.set_variable(name="myVar", value="1234")
doc.set_variable(name="myVar", value="1234")
doc.change_length(parameter=r"\headheight", value="0.5in")
doc.generate_tex(filepath='')
doc.generate_pdf(filepath='', clean=True)
示例2: arxiv_search
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [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: circuit_to_pdf_using_qcircuit_via_tex
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def circuit_to_pdf_using_qcircuit_via_tex(circuit: circuits.Circuit,
filepath: str,
pdf_kwargs=None,
qcircuit_kwargs=None,
clean_ext=('dvi', 'ps'),
documentclass='article'):
"""Compiles the QCircuit-based latex diagram of the given circuit.
Args:
circuit: The circuit to produce a pdf of.
filepath: Where to output the pdf.
pdf_kwargs: The arguments to pass to generate_pdf.
qcircuit_kwargs: The arguments to pass to
circuit_to_latex_using_qcircuit.
clean_ext: The file extensions to clean up after compilation. By
default, latexmk is used with the '-pdfps' flag, which produces
intermediary dvi and ps files.
documentclass: The documentclass of the latex file.
"""
pdf_kwargs = {'compiler': 'latexmk', 'compiler_args': ['-pdfps'],
**({} if pdf_kwargs is None else pdf_kwargs)}
qcircuit_kwargs = {} if qcircuit_kwargs is None else qcircuit_kwargs
tex = circuit_to_latex_using_qcircuit(circuit, **qcircuit_kwargs)
doc = Document(documentclass=documentclass, document_options='dvips')
doc.packages.append(Package('amsmath'))
doc.packages.append(Package('qcircuit'))
doc.append(NoEscape(tex))
doc.generate_pdf(filepath, **pdf_kwargs)
for ext in clean_ext:
try:
os.remove(filepath + '.' + ext)
except (OSError, IOError) as e:
if e.errno != errno.ENOENT:
raise
示例4: generate_info_report
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def generate_info_report():
"""
Generate a report with cover, status und last 2 lines in log for every test
"""
## Define the geometry for LaTeX files
geometry_options = {
"head": "40pt",
"margin": "0.5in",
"bottom": "0.6in",
"includeheadfoot": True
}
## Create the LaTeX object, a instance of Document Class
doc = Document(documentclass='article', geometry_options=geometry_options)
## Add cover
generate_cover2(doc)
doc.append(NewPage())
## Add status table
generate_status_tabel(doc)
doc.append(NewPage())
## Add last 2 lines in log.txt
for i in range(1, 4):
generate_info_list(doc, i)
doc.generate_pdf("RiMEA-Projekt Analyse", clean_tex=False)
示例5: test
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def test():
doc = Document("utils_escape_latex")
section = Section('Escape LaTeX characters test')
text = escape_latex('''\
& (ampersand)
% (percent)
$ (dollar)
# (number)
_ (underscore)
{ (left curly brace)
} (right curly brace)
~ (tilde)
^ (caret)
\\ (backslash)
--- (three minuses)
a\xA0a (non breaking space)
[ (left bracket)
] (right bracket)
''')
section.append(text)
doc.append(section)
doc.generate_pdf()
示例6: build_document
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
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
示例7: get_cv_doc
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def get_cv_doc(filename):
"""Returns a pylatex.Document instance pre-loaded with everything needed for my cv style."""
doc = Document(filename,
documentclass='article')
# Set Packages
doc.packages.append(Package('marginnote'))
doc.packages.append(UnsafeCommand('reversemarginpar'))
doc.packages.append(Package('graphicx'))
doc.packages.append(Package('classicthesis', options='nochapters'))
doc.packages.append(Package('currvita', options='LabelsAligned'))
doc.packages.append(Package('hyperref'))
doc.packages.append(UnsafeCommand('hypersetup', extra_arguments=r'colorlinks, breaklinks, urlcolor=Maroon, linkcolor=Maroon'))
doc.packages.append(UnsafeCommand('newlength', r'\datebox', ))
doc.packages.append(UnsafeCommand('settowidth', r'\datebox', extra_arguments='Tuebingen, Germany'))
doc.packages.append(UnsafeCommand('renewcommand', r'\cvheadingfont', extra_arguments=r'\LARGE\color{Maroon}'))
# Unchanged-ish (Extra line break at the end)
doc.packages.append(UnsafeCommand('newcommand', r'\SubHeading', options=1,
extra_arguments=r'\vspace{1em}\noindent\spacedlowsmallcaps{#1}\vspace{0.7em}\\'))
doc.packages.append(UnsafeCommand('newcommand', r'\Email', options=1,
extra_arguments=r'\href{mailto:#1}{#1}'))
# Unchanged
doc.packages.append(UnsafeCommand('newcommand', r'\MarginText', options=1, extra_arguments=r'\marginpar{\raggedleft\small#1}'))
# Unchanged
doc.packages.append(UnsafeCommand('newcommand', r'\Description', options=1,
extra_arguments=r'\hangindent=2em\hangafter=0\footnotesize{#1}\par\normalsize\vspace{1em}'))
doc.packages.append(UnsafeCommand('newcommand', r'\DescMarg', options=2,
extra_arguments=r'\noindent\hangindent=2em\hangafter=0 \parbox{\datebox}{\small} \MarginText{#1} #2 \vspace{0.3em}\\'))
##################
doc.packages.append(UnsafeCommand('newcommand', r'\HeaderOnly', options=2,
extra_arguments= r'\noindent\hangindent=2em\hangafter=0 \parbox{\datebox}{\small \textit{#1}}\hspace{1.5em} #2 \vspace{0.5em}\\'))
doc.packages.append(UnsafeCommand('newcommand', r'\EntryHeader', options=3,
extra_arguments=r'\noindent\hangindent=2em\hangafter=0 \parbox{\datebox}{\small \textit{#2}}\hspace{1.5em} \MarginText{#1} #3 \vspace{0.5em}'))
doc.packages.append(UnsafeCommand('newcommand', r'\NewEntry', options=4,
extra_arguments=r'\EntryHeader{#1}{#2}{#3}\\\Description{#4}'))
# Fill Document
doc.append(UnsafeCommand('thispagestyle', 'empty'))
doc.append(NoEscape(r'\raggedright'))
return doc
示例8: test
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def test():
doc = Document()
section = Section('Multirow Test')
figure = Figure()
image_filename = os.path.join(os.path.dirname(__file__),
'../examples/kitten.jpg')
figure.add_image(image_filename)
figure.add_caption('Whoooo an imagage of a pdf')
section.append(figure)
doc.append(section)
doc.generate_pdf()
示例9: _upload_problem
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def _upload_problem(self, problem):
"""Uploads a specified problem to imgur.
Returns:
A tuple (str, (int, int)), where str is the url, on imgur and
the tuples are the dimensions of the image (width, height).
Raises:
LatexParsingException : there was an issue parsing the document
"""
default_doc = []
# populate doc with the appropriate problem
for line in problem[0]:
# these first two statements are for wrapping the title around in a minipage which allows
# the problem to be generated on one page and doesn't invoke \newpage
if line == '\\begin{document}':
default_doc.append(NoEscape(line))
default_doc.append(NoEscape('\\begin{minipage}{\\textwidth}'))
elif line == '\\maketitle':
default_doc.append(NoEscape(line))
default_doc.append(NoEscape('\\end{minipage}'))
elif line == '\\end{itemize}':
for line2 in problem[1]:
default_doc.append(NoEscape(line2))
default_doc.append(NoEscape(line))
else:
default_doc.append(NoEscape(line))
doc_class_line = NoEscape(default_doc[0])
use_pkg_line = NoEscape(default_doc[1])
# skip twocolumn since it makes the problem look spread awfully
opts = filter(lambda pkg: pkg != 'twocolumn', doc_class_line[doc_class_line.find('[') + 1: doc_class_line.find(']')].split(','))
args = NoEscape(doc_class_line[doc_class_line.find('{') + 1: doc_class_line.find('}')])
doc = Document(documentclass=Command('documentclass', options=opts, arguments=args))
# load packages
doc.packages = [Package(i) for i in use_pkg_line[use_pkg_line.find('{') + 1: use_pkg_line.find('}')].split(',')]
# position right after \begin{document}
it = 4
while default_doc[it].strip() != '\end{document}':
doc.append(NoEscape(default_doc[it]))
it += 1
# fail safe for future problems which may not parse correctly
try:
doc.generate_pdf('default', compiler="pdflatex")
except:
raise LatexParsingException
# These are normal Linux commands that are used to convert the pdf
# file created by pylatex into a snippet
os.system("pdfcrop default.pdf")
os.system("pdftoppm default-crop.pdf|pnmtopng > default.png")
path = os.path.abspath('default.png')
uploaded_image = self._client.upload_image(path, title="LaTeX")
return uploaded_image.link, OnlineImage.get_local_image_info(path)
示例10: test
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def test():
doc = Document()
Subsection('Only a single string', data='Some words')
sec1 = Section('Only contains one subsection', data='Subsection')
sec2 = Section('Only a single italic command', data=Command('textit',
'Hey'))
sec2.append('something else that is not italic')
doc.append(sec1)
doc.append(sec2)
doc.generate_pdf()
示例11: test_document
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def test_document():
doc = Document(
default_filepath="default_filepath",
documentclass="article",
fontenc="T1",
inputenc="utf8",
lmodern=True,
data=None,
)
doc.append("Some text.")
doc.generate_tex(filepath="")
doc.generate_pdf(filepath="", clean=True)
示例12: test_document
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def test_document():
doc = Document(
default_filepath='default_filepath',
documentclass='article',
fontenc='T1',
inputenc='utf8',
lmodern=True,
data=None,
)
repr(doc)
doc.append('Some text.')
doc.generate_tex(filepath='')
doc.generate_pdf(filepath='', clean=True)
示例13: test_document
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [as 别名]
def test_document():
doc = Document(
default_filepath='default_filepath',
documentclass='article',
fontenc='T1',
inputenc='utf8',
author='',
title='',
date='',
data=None,
maketitle=False
)
doc.append('Some text.')
doc.generate_tex(filepath='')
doc.generate_pdf(filepath='', clean=True)
示例14: __init__
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [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
示例15: generate_eva_report
# 需要导入模块: from pylatex import Document [as 别名]
# 或者: from pylatex.Document import append [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)