Metadata-Version: 2.4
Name: scifont
Version: 0.1.3
Summary: Force publication-quality, editable fonts in Matplotlib figures.
Home-page: https://github.com/studentiz/scifont
Author: studentiz
Author-email: studentiz <studentiz@live.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/studentiz/scifont
Project-URL: Repository, https://github.com/studentiz/scifont
Project-URL: Issues, https://github.com/studentiz/scifont/issues
Keywords: matplotlib,fonts,scientific,publication,visualization
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Topic :: Scientific/Engineering :: Visualization
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: matplotlib>=3.3.0
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# scifont

**Professional, Reproducible, and Editable Figures for Scientific Publishing.**

`scifont` is a lightweight Python library designed to solve the two most persistent headaches in scientific visualization with Matplotlib:
1.  **Missing Fonts in Docker/Linux**: "Arial" or "Times New Roman" are often missing in CI/CD environments or Linux servers, causing plots to fallback to default fonts.
2.  **Non-Editable Text**: Default Matplotlib settings often export text as paths (shapes), making it impossible to correct typos or adjust formatting in Adobe Illustrator or Inkscape.

## 🚀 Key Features

*   **Smart Font Selection**: Automatically prioritizes system fonts (Arial, Helvetica, Times New Roman) when available. Falls back to bundled open-source fonts (Arimo, Tinos) only when system fonts are missing. This ensures optimal performance and user preference while maintaining compatibility.
*   **Bundled Open-Source Fonts**: We ship with **Arimo** and **Tinos** (Apache 2.0 Licensed). These are **metric-compatible** alternatives to Arial and Times New Roman. They are legally safe to distribute and use anywhere.
*   **Metric-Compatible**: Arimo has the exact same character widths and spacing as Arial. Tinos matches Times New Roman. Your layout will remain identical to the proprietary versions.
*   **Editable Vector Graphics**: Automatically configures Matplotlib to export PDFs as `Type 42` objects and SVGs as `<text>` tags. Text remains editable in downstream vector software.
*   **Journal Presets**: One-line configuration for **Nature**, **Science**, **Cell**, and **IEEE** standards.

## 📦 Installation

```bash
pip install scifont
```

*(Or if installing from source)*
```bash
git clone https://github.com/studentiz/scifont.git
cd scifont
pip install .
```

## ⚡ Quick Start

Simply import `scifont` and select your target journal style at the start of your script.

```python
import matplotlib.pyplot as plt
import scifont

# 1. Apply style (e.g., 'nature' for Life Sciences, 'ieee' for Engineering)
scifont.use('nature')

# 2. Plot as usual
plt.figure(figsize=(4, 3))
plt.plot([1, 2, 3], [4, 5, 6], label='Data')

# The font will be Arial/Helvetica if available, otherwise Arimo (Arial-compatible)
plt.title("Editable Text in Nature Style")
plt.xlabel("Time (s)")
plt.ylabel("Velocity (m/s)")
plt.legend()

# 3. Save
# The output PDF/SVG will have editable text!
plt.tight_layout()
plt.savefig("figure.pdf")
plt.savefig("figure.svg")
```

## 📖 Supported Journal Styles

`scifont` adjusts font families, sizes, and line widths according to specific journal guidelines (2025 standards).

| Style Argument | Target Font Family | Primary Font (if available) | Fallback Font | Base Font Size | Target Journals |
| :--- | :--- | :--- | :--- | :--- | :--- |
| `'nature'` | Sans-serif | **Arial/Helvetica** | **Arimo** (matches Arial) | 7 pt | *Nature, Nature Comms, Scientific Reports* |
| `'cell'` | Sans-serif | **Arial/Helvetica** | **Arimo** (matches Arial) | 8 pt | *Cell, Molecular Cell, Neuron* |
| `'science'`| Sans-serif | **Arial/Helvetica** | **Arimo** (matches Arial) | 9 pt | *Science, Science Advances* |
| `'ieee'` | Serif | **Times New Roman/Times** | **Tinos** (matches Times New Roman) | 8 pt | *IEEE Transactions, Phys. Rev. Lett.* |

*Note: You can override any setting (e.g., font size) using standard `plt.rcParams` after calling `scifont.use()`.*

## 🛡️ Smart Font Selection & Legal Compliance

**Font Selection Strategy:**
`scifont` intelligently selects fonts based on availability:
1. **System Fonts First**: If Arial, Helvetica, or Times New Roman are available on your system, they will be used automatically. This provides the best performance and respects user preferences.
2. **Automatic Fallback**: If system fonts are missing (common in Docker/Linux environments), `scifont` automatically falls back to bundled open-source fonts (Arimo/Tinos).

**Why Bundle Open-Source Fonts?**
Many researchers are unaware that **Arial** and **Times New Roman** are proprietary fonts owned by Monotype.
1.  **Distribution**: It is illegal to bundle `arial.ttf` inside a Python package and distribute it without a costly license.
2.  **Reproducibility**: Reliance on system fonts alone leads to inconsistencies. A plot rendered on macOS (with Arial) looks different on Ubuntu (without Arial).

**Our Solution:**
We bundle **Arimo** and **Tinos**, developed by Steve Matteson for Google, as fallback fonts.
*   **License**: **Apache License 2.0**. You can use, bundle, and distribute them freely.
*   **Compatibility**: They are designed to be **Metric-Compatible** with Arial and Times New Roman. This means if you replace Arial with Arimo, the text takes up the *exact same space*. No line breaks will change; no labels will be cut off.

## 🔧 Editable Text (Vector Graphics)

By default, `scifont.use()` applies the following hidden Matplotlib settings to ensure compatibility with Adobe Illustrator, CorelDRAW, and Inkscape:

```python
plt.rcParams['pdf.fonttype'] = 42  # Embbed TrueType fonts (editable)
plt.rcParams['ps.fonttype'] = 42
plt.rcParams['svg.fonttype'] = 'none' # Do not convert text to path
```

## License

The `scifont` code is distributed under the **MIT License**.
The bundled fonts (Arimo and Tinos) are distributed under the **Apache License, Version 2.0**.
