Skip to content

Commit

Permalink
fix up notebook utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
MridulS committed Feb 21, 2020
1 parent 908e179 commit 90d566d
Showing 1 changed file with 9 additions and 6 deletions.
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

0 comments on commit 90d566d

Please sign in to comment.