Skip to content

Commit

Permalink
Add checks to tex and pdfcrop
Browse files Browse the repository at this point in the history
  • Loading branch information
wesselb committed Apr 7, 2022
1 parent b10d0a9 commit d113e01
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions wbml/plot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import subprocess
from functools import wraps

import subprocess
import lab as B
import matplotlib.pyplot as plt
from plum import Dispatcher

from .warning import warn_upmodule

__all__ = ["patch", "tex", "tweak", "style", "pdfcrop"]

_dispatch = Dispatcher()
Expand Down Expand Up @@ -76,7 +78,13 @@ def patched_f(*args, **kw_args):

def tex():
"""Use TeX for rendering."""
plt.rcParams["text.usetex"] = True # Use TeX for rendering.
if subprocess.call("which latex", shell=True) == 0:
plt.rcParams["text.usetex"] = True # Use TeX for rendering.
else:
warn_upmodule(
"No LaTeX installation found, so LaTeX will not be used to render "
"`matplotlib` figures."
)


def tweak(
Expand Down Expand Up @@ -189,4 +197,10 @@ def pdfcrop(path):
Args:
path (str): Path of PDF.
"""
subprocess.call(["pdfcrop", path, path])
if subprocess.call("which pdfcrop", shell=True) == 0:
subprocess.call(["pdfcrop", path, path])
else:
warn_upmodule(
"External tool `pdfcrop` cannot be found. "
"Skipping the application of `pdfcrop`."
)

0 comments on commit d113e01

Please sign in to comment.