Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional parameters to render_html and render_latex to export to files #38

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions stargazer/stargazer.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,22 @@ def append_notes(self, append):
self.notes_append = append

# Begin HTML render functions
def render_html(self):
def render_html(self, out=None):
""" Renders Stargazer object as HTML.

Args:
out: File to write HTML to (optional).
"""
html = ''
html += self.generate_header_html()
html += self.generate_body_html()
html += self.generate_footer_html()

if out is not None:
with open(out, "w") as f:
f.write(html)


return html

def generate_header_html(self):
Expand Down Expand Up @@ -416,12 +426,24 @@ def generate_additional_notes_html(self):
return notes_text

# Begin LaTeX render functions
def render_latex(self, only_tabular=False, insert_empty_rows=False):
def render_latex(self, only_tabular=False, insert_empty_rows=False, out=None):
""" Renders Stargazer object as LaTeX.

Args:
only_tabular: Whether the header and footer should be omitted.
Defaults to False.
insert_empty_rows: Whether to insert empty rows between variables.
Defaults to False.
out: File to write tex to (optional).
"""
latex = ''
latex += self.generate_header_latex(only_tabular=only_tabular)
latex += self.generate_body_latex(insert_empty_rows=insert_empty_rows)
latex += self.generate_footer_latex(only_tabular=only_tabular)

if out is not None:
with open(out, "w") as f:
f.write(latex)
return latex

def generate_header_latex(self, only_tabular=False):
Expand Down