Skip to content

Commit

Permalink
Improvement: Made compiling more secure and silent.
Browse files Browse the repository at this point in the history
  • Loading branch information
JelteF committed Jun 24, 2015
1 parent 092e86d commit 56d45f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ been moved an renamed.
also doesn't take a plt argument anymore. The plt module is now imported
when a `MatplotlibFigure` figure is instantiated.

- Compiling is more secure now and it doesn't show output unless an error occurs
or explicitly specified.

### Added
- Lots of documentation!!!!!
- A float environment base class.
Expand Down
18 changes: 14 additions & 4 deletions pylatex/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,18 @@ def dumps(self):
def generate_tex(self, filepath=''):
super().generate_tex(self.select_filepath(filepath))

def generate_pdf(self, filepath='', clean=True, compiler='pdflatex'):
def generate_pdf(self, filepath='', clean=True, compiler='pdflatex',
silent=True):
"""Generate a pdf file from the document.
:param filepath: the name of the file
:param clean: whether non-pdf files created by `pdflatex` must be
removed or not
:param silent: whether to hide compiler output
:type filepath: str
:type clean: bool
:type silent: bool
"""

filepath = self.select_filepath(filepath)
Expand All @@ -115,10 +118,17 @@ def generate_pdf(self, filepath='', clean=True, compiler='pdflatex'):

self.generate_tex(basename)

command = compiler + ' --interaction=nonstopmode --jobname="' + \
basename + '" "' + basename + '.tex"'
command = [compiler, '--interaction', 'nonstopmode',
'--jobname', basename, basename + '.tex']

subprocess.check_call(command, shell=True)
try:
output = subprocess.check_output(command)
except subprocess.CalledProcessError as e:
print(e.output.decode())
raise e
else:
if not silent:
print(output.decode())

if clean:
for ext in ['aux', 'log', 'out', 'tex']:
Expand Down

0 comments on commit 56d45f0

Please sign in to comment.