Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 32 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.anaconda.com>`_

The package is available through pip:
Expand Down
29 changes: 24 additions & 5 deletions ctaplot/plots/style.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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


Expand All @@ -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.")


3 changes: 3 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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