diff --git a/README.rst b/README.rst index 32ed3e4..1947c20 100644 --- a/README.rst +++ b/README.rst @@ -51,12 +51,42 @@ Install Requirements packages: -* python > 3.6 +* python >= 3.9 * numpy * scipy>=0.19 -* matplotlib>=2.0 +* matplotlib>=3.6 * astropy +Optional LaTeX dependencies for enhanced plot rendering: + +* A LaTeX distribution (e.g., TeX Live, MiKTeX) +* dvipng (for PNG output) +* cm-super (Computer Modern fonts) + +**Installation instructions:** + +On Ubuntu/Debian: + +.. code-block:: bash + + sudo apt-get install texlive-latex-base texlive-fonts-recommended dvipng cm-super + +On macOS with Homebrew: + +.. code-block:: bash + + brew install --cask mactex + # dvipng and cm-super are included with MacTeX + +On macOS with MacPorts: + +.. code-block:: bash + + sudo port install texlive +full + +**Note:** LaTeX dependencies are optional. If not installed, ctaplot will automatically +fall back to matplotlib's default text rendering without LaTeX support. + We recommend the use of `anaconda `_ The package is available through pip: diff --git a/ctaplot/plots/style.py b/ctaplot/plots/style.py index a9cfe9d..3082bc0 100644 --- a/ctaplot/plots/style.py +++ b/ctaplot/plots/style.py @@ -1,18 +1,29 @@ import matplotlib as mpl from distutils.spawn import find_executable from contextlib import contextmanager +import logging from ..io.dataset import get +logger = logging.getLogger(__name__) + def check_latex(): """ - Check if a latex distribution is installed. + Check if a latex distribution is installed and has required packages. Returns ------- - bool: True if a LaTeX distribution could be found + bool: True if a LaTeX distribution with required packages could be found """ - return find_executable('latex') is not None + if not find_executable('latex'): + return False + + # Check if dvipng is available (needed for matplotlib LaTeX rendering) + if not find_executable('dvipng'): + logger.warning("LaTeX found but dvipng is missing. Install dvipng for full LaTeX support.") + return False + + return True @contextmanager @@ -36,8 +47,12 @@ def context(style='notebook'): """ style_path = get(f'ctaplot-{style}') with mpl.style.context(['seaborn-v0_8-deep', style_path]): - if not check_latex(): + latex_available = check_latex() + if not latex_available: mpl.rcParams['text.usetex'] = False + if style in ['slides', 'paper']: + logger.info(f"LaTeX not fully available. For enhanced {style} rendering, " + "install LaTeX with dvipng and cm-super packages.") yield @@ -55,7 +70,11 @@ def set_style(style='notebook'): style_path = get(f'ctaplot-{style}') mpl.pyplot.style.use(['seaborn-v0_8-deep', style_path]) - if not check_latex(): + latex_available = check_latex() + if not latex_available: mpl.rcParams['text.usetex'] = False + if style in ['slides', 'paper']: + logger.info(f"LaTeX not fully available. For enhanced {style} rendering, " + "install LaTeX with dvipng and cm-super packages.") diff --git a/environment.yml b/environment.yml index b2652b9..180c689 100644 --- a/environment.yml +++ b/environment.yml @@ -19,3 +19,6 @@ dependencies: - ipympl - tqdm - h5py + # Optional: LaTeX support for enhanced plot rendering + # Note: LaTeX dependencies may need to be installed separately + # See README for platform-specific installation instructions