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

fix up notebook utilities #537

Merged
merged 1 commit into from
Feb 21, 2020
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
15 changes: 9 additions & 6 deletions HARK/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,7 @@ def test_latex_installation(pf):
os.system('apt-get update')
os.system('apt-get install texlive texlive-latex-extra texlive-xetex dvipng')
latexExists=True
return True
else:
raise ImportError('Please install a full distribution of LaTeX on your computer then rerun. \n \
A full distribution means textlive, texlive-latex-extras, texlive-xetex, dvipng, and ghostscript')
Expand All @@ -1358,7 +1359,7 @@ def in_ipynb():
return False


def setup_latex_env_notebook(pf):
def setup_latex_env_notebook(pf, latexExists):
""" This is needed for use of the latex_envs notebook extension
which allows the use of environments in Markdown.

Expand All @@ -1367,13 +1368,15 @@ def setup_latex_env_notebook(pf):
pf: str (platform)
output of determine_platform()
"""
if test_latex_installation(pf):
import os
from matplotlib import rc
import matplotlib.pyplot as plt
plt.rc('font', family='serif')
plt.rc('text', usetex=latexExists)
if latexExists:
latex_preamble = r'\usepackage{amsmath}\usepackage{amsfonts}\usepackage[T1]{fontenc}'
import os
from os import path
import matplotlib.pyplot as plt
latexdefs_path = os.getcwd()+'/latexdefs.tex'
if path.isfile(latexdefs_path):
if os.path.isfile(latexdefs_path):
latex_preamble = latex_preamble+r'\input{'+latexdefs_path+r'}'
else: # the required latex_envs package needs this file to exist even if it is empty
from pathlib import Path
Expand Down