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

Set BIBINPUTS and BSTINPUTS environment variables when making PDF #676

Merged
merged 3 commits into from
Sep 16, 2017
Merged
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
17 changes: 13 additions & 4 deletions nbconvert/exporters/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ def __str__(self):
u = self.__unicode__()
return cast_bytes_py2(u)

def prepend_to_env_search_path(varname, value, envdict):
"""Add value to the environment variable varname in envdict

e.g. prepend_to_env_search_path('BIBINPUTS', '/home/sally/foo', os.environ)
"""
if not value:
return # Nothing to add

envdict[varname] = cast_bytes_py2(value) + os.pathsep + envdict.get(varname, '')

class PDFExporter(LatexExporter):
"""Writer designed to write to PDF files.
Expand Down Expand Up @@ -105,10 +114,10 @@ def run_command(self, command_list, filename, count, log_function):
if shell:
command = subprocess.list2cmdline(command)
env = os.environ.copy()
env['TEXINPUTS'] = os.pathsep.join([
cast_bytes_py2(self.texinputs),
env.get('TEXINPUTS', ''),
])
prepend_to_env_search_path('TEXINPUTS', self.texinputs, env)
prepend_to_env_search_path('BIBINPUTS', self.texinputs, env)
prepend_to_env_search_path('BSTINPUTS', self.texinputs, env)

with open(os.devnull, 'rb') as null:
stdout = subprocess.PIPE if not self.verbose else None
for index in range(count):
Expand Down