sixelmath 0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sixelmath-0.1/LICENSE.txt +19 -0
- sixelmath-0.1/PKG-INFO +92 -0
- sixelmath-0.1/README.md +56 -0
- sixelmath-0.1/pyproject.toml +3 -0
- sixelmath-0.1/setup.cfg +51 -0
- sixelmath-0.1/sixelmath/__init__.py +4 -0
- sixelmath-0.1/sixelmath/__main__.py +37 -0
- sixelmath-0.1/sixelmath/latex.py +87 -0
- sixelmath-0.1/sixelmath/querycolor.py +100 -0
- sixelmath-0.1/sixelmath/sympysixel.py +28 -0
- sixelmath-0.1/sixelmath.egg-info/PKG-INFO +92 -0
- sixelmath-0.1/sixelmath.egg-info/SOURCES.txt +16 -0
- sixelmath-0.1/sixelmath.egg-info/dependency_links.txt +1 -0
- sixelmath-0.1/sixelmath.egg-info/entry_points.txt +2 -0
- sixelmath-0.1/sixelmath.egg-info/not-zip-safe +1 -0
- sixelmath-0.1/sixelmath.egg-info/requires.txt +5 -0
- sixelmath-0.1/sixelmath.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2026 Collin J. Delker
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
sixelmath-0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sixelmath
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Render LaTeX math and Sympy expressions to Sixel Terminal Graphics. Suuports any Math-enabled font, no LaTeX installation required.
|
|
5
|
+
Home-page: https://github.com/cdelker/sixelmath
|
|
6
|
+
Author: Collin J. Delker
|
|
7
|
+
Author-email: code@collindelker.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Documentation, https://github.com/cdelker/sixelmath
|
|
10
|
+
Project-URL: Source Code, https://github.com/cdelker/sixelmath
|
|
11
|
+
Keywords: LaTeX,math,sympy,sixel,terminal
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Intended Audience :: Education
|
|
23
|
+
Classifier: Intended Audience :: Science/Research
|
|
24
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
25
|
+
Classifier: Intended Audience :: Developers
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE.txt
|
|
30
|
+
Requires-Dist: ziamath>=0.13
|
|
31
|
+
Requires-Dist: latex2mathml
|
|
32
|
+
Requires-Dist: timg
|
|
33
|
+
Requires-Dist: cairosvg
|
|
34
|
+
Requires-Dist: Pillow
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# sixelmath
|
|
38
|
+
|
|
39
|
+
Render LaTeX Math expressions or Sympy objects in the terminal using sixel graphics.
|
|
40
|
+
Math rendering is done using [ziamath](https://ziamath.readthedocs.io), a pure-Python LaTeX math renderer that does not require a Latex installation.
|
|
41
|
+
Any math-enabled truetype/opentype font may be used; STIXTwoMath-Regular is included and used by default.
|
|
42
|
+
Also uses [cairosvg](https://pypi.org/project/CairoSVG/), [timg](https://pypi.org/project/timg/), and [Pillow](https://pypi.org/project/pillow/).
|
|
43
|
+
|
|
44
|
+
See list of sixel-supported terminal emulators [here](https://www.arewesixelyet.com).
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Command Line
|
|
50
|
+
|
|
51
|
+
Render a LaTeX expression:
|
|
52
|
+
|
|
53
|
+
sixelmath "\frac{1}{1+x}"
|
|
54
|
+
|
|
55
|
+
Options include:
|
|
56
|
+
|
|
57
|
+
* '-s': Font size in points
|
|
58
|
+
* '-f': Path to font file (must include MATH table)
|
|
59
|
+
* '-c': Color as a supported named color, or hex value such as `#FFFFFF`
|
|
60
|
+
* '-b': Background color as a supported named color, or hex value such as `#FFFFFF`
|
|
61
|
+
* '-m': Margin width in pixels
|
|
62
|
+
|
|
63
|
+
In POSIX environments, the font and background color are detected automatically if not manually specified.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Python
|
|
67
|
+
|
|
68
|
+
To render LaTeX from Python code:
|
|
69
|
+
|
|
70
|
+
from sixelmath import sixelmath
|
|
71
|
+
sixelmath(r'\frac{1}{1+x}')
|
|
72
|
+
|
|
73
|
+
Keyword arguments may be passed to `sixelmath` to change options:
|
|
74
|
+
|
|
75
|
+
* `color`: Font color. A named terminal color like 'white', or RGB hex color such as `#FFFFFF`
|
|
76
|
+
* `bgcolor`: Background color.
|
|
77
|
+
* `font`: Path to a TTF or OTF font file. Must contain a MATH table. STIXTwoMath-Regular is used by default.
|
|
78
|
+
* `fontsize`: Font size in pixels
|
|
79
|
+
* `margin`: Pixel margin around the euqation
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### Sympy
|
|
83
|
+
|
|
84
|
+
Import the `sixelmath.sympysixel` module to install a Sympy Printer that automatically displays Sympy expressions as sixel graphics.
|
|
85
|
+
|
|
86
|
+
import sympy
|
|
87
|
+
from sixelmath import sympysixel
|
|
88
|
+
sympy.sympify('A * exp(-x^2)')
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
To change display format, use `sixelmath.sixel_defaults`, with the same keyword arguments listed above for `sixelmath`.
|
|
92
|
+
The sixel printer may be turned off using `sympysixel.disable()` and turned on with `sympysixel.enable()`.
|
sixelmath-0.1/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# sixelmath
|
|
2
|
+
|
|
3
|
+
Render LaTeX Math expressions or Sympy objects in the terminal using sixel graphics.
|
|
4
|
+
Math rendering is done using [ziamath](https://ziamath.readthedocs.io), a pure-Python LaTeX math renderer that does not require a Latex installation.
|
|
5
|
+
Any math-enabled truetype/opentype font may be used; STIXTwoMath-Regular is included and used by default.
|
|
6
|
+
Also uses [cairosvg](https://pypi.org/project/CairoSVG/), [timg](https://pypi.org/project/timg/), and [Pillow](https://pypi.org/project/pillow/).
|
|
7
|
+
|
|
8
|
+
See list of sixel-supported terminal emulators [here](https://www.arewesixelyet.com).
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Command Line
|
|
14
|
+
|
|
15
|
+
Render a LaTeX expression:
|
|
16
|
+
|
|
17
|
+
sixelmath "\frac{1}{1+x}"
|
|
18
|
+
|
|
19
|
+
Options include:
|
|
20
|
+
|
|
21
|
+
* '-s': Font size in points
|
|
22
|
+
* '-f': Path to font file (must include MATH table)
|
|
23
|
+
* '-c': Color as a supported named color, or hex value such as `#FFFFFF`
|
|
24
|
+
* '-b': Background color as a supported named color, or hex value such as `#FFFFFF`
|
|
25
|
+
* '-m': Margin width in pixels
|
|
26
|
+
|
|
27
|
+
In POSIX environments, the font and background color are detected automatically if not manually specified.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Python
|
|
31
|
+
|
|
32
|
+
To render LaTeX from Python code:
|
|
33
|
+
|
|
34
|
+
from sixelmath import sixelmath
|
|
35
|
+
sixelmath(r'\frac{1}{1+x}')
|
|
36
|
+
|
|
37
|
+
Keyword arguments may be passed to `sixelmath` to change options:
|
|
38
|
+
|
|
39
|
+
* `color`: Font color. A named terminal color like 'white', or RGB hex color such as `#FFFFFF`
|
|
40
|
+
* `bgcolor`: Background color.
|
|
41
|
+
* `font`: Path to a TTF or OTF font file. Must contain a MATH table. STIXTwoMath-Regular is used by default.
|
|
42
|
+
* `fontsize`: Font size in pixels
|
|
43
|
+
* `margin`: Pixel margin around the euqation
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Sympy
|
|
47
|
+
|
|
48
|
+
Import the `sixelmath.sympysixel` module to install a Sympy Printer that automatically displays Sympy expressions as sixel graphics.
|
|
49
|
+
|
|
50
|
+
import sympy
|
|
51
|
+
from sixelmath import sympysixel
|
|
52
|
+
sympy.sympify('A * exp(-x^2)')
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
To change display format, use `sixelmath.sixel_defaults`, with the same keyword arguments listed above for `sixelmath`.
|
|
56
|
+
The sixel printer may be turned off using `sympysixel.disable()` and turned on with `sympysixel.enable()`.
|
sixelmath-0.1/setup.cfg
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[metadata]
|
|
2
|
+
name = sixelmath
|
|
3
|
+
version = attr: sixelmath.__version__
|
|
4
|
+
author = Collin J. Delker
|
|
5
|
+
author_email = code@collindelker.com
|
|
6
|
+
url = https://github.com/cdelker/sixelmath
|
|
7
|
+
description = Render LaTeX math and Sympy expressions to Sixel Terminal Graphics. Suuports any Math-enabled font, no LaTeX installation required.
|
|
8
|
+
long_description = file: README.md
|
|
9
|
+
long_description_content_type = text/markdown
|
|
10
|
+
keywords = LaTeX, math, sympy, sixel, terminal
|
|
11
|
+
license = MIT
|
|
12
|
+
project_urls =
|
|
13
|
+
Documentation = https://github.com/cdelker/sixelmath
|
|
14
|
+
Source Code = https://github.com/cdelker/sixelmath
|
|
15
|
+
classifiers =
|
|
16
|
+
Development Status :: 4 - Beta
|
|
17
|
+
Programming Language :: Python :: 3
|
|
18
|
+
Programming Language :: Python :: 3.9
|
|
19
|
+
Programming Language :: Python :: 3.10
|
|
20
|
+
Programming Language :: Python :: 3.11
|
|
21
|
+
Programming Language :: Python :: 3.12
|
|
22
|
+
Programming Language :: Python :: 3.13
|
|
23
|
+
Programming Language :: Python :: 3.14
|
|
24
|
+
License :: OSI Approved :: MIT License
|
|
25
|
+
Operating System :: OS Independent
|
|
26
|
+
Intended Audience :: Education
|
|
27
|
+
Intended Audience :: Science/Research
|
|
28
|
+
Intended Audience :: End Users/Desktop
|
|
29
|
+
Intended Audience :: Developers
|
|
30
|
+
Topic :: Scientific/Engineering :: Mathematics
|
|
31
|
+
|
|
32
|
+
[options]
|
|
33
|
+
packages = find:
|
|
34
|
+
zip_safe = False
|
|
35
|
+
python_requires = >= 3.9
|
|
36
|
+
include_package_data = True
|
|
37
|
+
install_requires =
|
|
38
|
+
ziamath>=0.13
|
|
39
|
+
latex2mathml
|
|
40
|
+
timg
|
|
41
|
+
cairosvg
|
|
42
|
+
Pillow
|
|
43
|
+
|
|
44
|
+
[options.entry_points]
|
|
45
|
+
console_scripts =
|
|
46
|
+
sixelmath = sixelmath.__main__:main
|
|
47
|
+
|
|
48
|
+
[egg_info]
|
|
49
|
+
tag_build =
|
|
50
|
+
tag_date = 0
|
|
51
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
''' Command-line program to print tex to sixel '''
|
|
2
|
+
import argparse
|
|
3
|
+
import pathlib
|
|
4
|
+
|
|
5
|
+
from sixelmath import sixelmath, sixel_defaults
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main():
|
|
9
|
+
parser = argparse.ArgumentParser(
|
|
10
|
+
description='Render LaTeX math in terminal using sixel graphics')
|
|
11
|
+
parser.add_argument(
|
|
12
|
+
'tex', type=str, default='',
|
|
13
|
+
help='LaTeX math expression')
|
|
14
|
+
parser.add_argument(
|
|
15
|
+
'-s', '--size', type=float, default=24,
|
|
16
|
+
help='Font size')
|
|
17
|
+
parser.add_argument(
|
|
18
|
+
'-f', '--font', type=pathlib.Path, default=None,
|
|
19
|
+
help='Path to TTF or OTF font with MATH tables')
|
|
20
|
+
parser.add_argument(
|
|
21
|
+
'-c', '--color', type=str, default=None,
|
|
22
|
+
help='Font color as named color or hex #RRGGBB')
|
|
23
|
+
parser.add_argument(
|
|
24
|
+
'-b', '--bgcolor', type=str, default=None,
|
|
25
|
+
help='Background color')
|
|
26
|
+
parser.add_argument(
|
|
27
|
+
'-m', '--margin', type=int, default=4,
|
|
28
|
+
help='Pixel margin surrounding equation')
|
|
29
|
+
|
|
30
|
+
args = parser.parse_args()
|
|
31
|
+
sixel_defaults(
|
|
32
|
+
font=args.font,
|
|
33
|
+
fontsize=args.size,
|
|
34
|
+
color=args.color,
|
|
35
|
+
bgcolor=args.bgcolor,
|
|
36
|
+
margin=args.margin)
|
|
37
|
+
sixelmath(args.tex)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
''' Render LaTeX math expressions as sixel graphics '''
|
|
2
|
+
import io
|
|
3
|
+
import os
|
|
4
|
+
from functools import partial
|
|
5
|
+
|
|
6
|
+
import cairosvg
|
|
7
|
+
import timg
|
|
8
|
+
import ziamath as zm
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _sixelmath(
|
|
12
|
+
tex,
|
|
13
|
+
fontsize,
|
|
14
|
+
font,
|
|
15
|
+
color,
|
|
16
|
+
bgcolor,
|
|
17
|
+
margin
|
|
18
|
+
):
|
|
19
|
+
''' Print LaTeX math expression to sixel
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
tex: LaTeX expression to render
|
|
23
|
+
fontsize: Font size in points
|
|
24
|
+
font: Path to font file with MATH table.
|
|
25
|
+
STIXTwoMath-Regular used by default.
|
|
26
|
+
color: Font color as named color or hex #RRGGBB
|
|
27
|
+
bgcolor: Background color
|
|
28
|
+
margin: Pixel margin around equation
|
|
29
|
+
'''
|
|
30
|
+
svg = zm.Latex(
|
|
31
|
+
tex,
|
|
32
|
+
font=font,
|
|
33
|
+
size=fontsize,
|
|
34
|
+
color=color,
|
|
35
|
+
margin=margin
|
|
36
|
+
).svg()
|
|
37
|
+
png = cairosvg.svg2png(svg, background_color=bgcolor)
|
|
38
|
+
renderer = timg.Renderer()
|
|
39
|
+
renderer.load_image_from_file(io.BytesIO(png))
|
|
40
|
+
renderer.render(timg.SixelMethod)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
sixelmath = partial(
|
|
44
|
+
_sixelmath, fontsize=24, font=None,
|
|
45
|
+
color='#fcfcfc', bgcolor='#232627',
|
|
46
|
+
margin=4)
|
|
47
|
+
sixelmath.__doc__ = _sixelmath.__doc__
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def sixel_defaults(
|
|
51
|
+
fontsize=None,
|
|
52
|
+
font=None,
|
|
53
|
+
color=None,
|
|
54
|
+
bgcolor=None,
|
|
55
|
+
margin=None
|
|
56
|
+
):
|
|
57
|
+
''' Set default parameters. Use None to leave unchanged.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
fontsize: Font size in points
|
|
61
|
+
font: Path to font file with MATH table
|
|
62
|
+
color: Font color as named color or hex #RRGGBB
|
|
63
|
+
bgcolor: Background color
|
|
64
|
+
margin: Pixel margin around equation
|
|
65
|
+
'''
|
|
66
|
+
if fontsize:
|
|
67
|
+
sixelmath.keywords['fontsize'] = fontsize
|
|
68
|
+
if font:
|
|
69
|
+
sixelmath.keywords['font'] = font
|
|
70
|
+
if color:
|
|
71
|
+
sixelmath.keywords['color'] = color
|
|
72
|
+
if bgcolor:
|
|
73
|
+
sixelmath.keywords['bgcolor'] = bgcolor
|
|
74
|
+
if margin is not None:
|
|
75
|
+
sixelmath.keywords['margin'] = margin
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if os.name == 'posix':
|
|
79
|
+
# Detect terminal foreground/background colors.
|
|
80
|
+
# Only works on POSIX, and may not supoprt all terminals.
|
|
81
|
+
from . import querycolor
|
|
82
|
+
fg = querycolor.get_default_fg()
|
|
83
|
+
bg = querycolor.get_default_bg()
|
|
84
|
+
if fg is not None:
|
|
85
|
+
sixel_defaults(color=fg)
|
|
86
|
+
if bg is not None:
|
|
87
|
+
sixel_defaults(bgcolor=bg)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
''' Determine terminal foreground and background colors
|
|
2
|
+
|
|
3
|
+
Source: https://jwodder.github.io/kbits/posts/term-fgbg/
|
|
4
|
+
John T. Wodder II, CC-BY-4.0
|
|
5
|
+
'''
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
from collections.abc import Iterator
|
|
8
|
+
from contextlib import contextmanager
|
|
9
|
+
from copy import deepcopy
|
|
10
|
+
import re
|
|
11
|
+
import sys
|
|
12
|
+
import termios
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def parse_color(color):
|
|
16
|
+
if color.startswith('rgb:'):
|
|
17
|
+
rgb = f'#{color[4:6]}{color[9:11]}{color[14:16]}'
|
|
18
|
+
else:
|
|
19
|
+
rgb = None
|
|
20
|
+
return rgb
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def get_default_fg() -> str:
|
|
24
|
+
"""
|
|
25
|
+
Query the attached terminal for the default foreground color and return the
|
|
26
|
+
color string from the response
|
|
27
|
+
|
|
28
|
+
:raises IOError: if stdin or stdout is not a terminal
|
|
29
|
+
:raises ValueError: if the reply from the terminal is malformed
|
|
30
|
+
"""
|
|
31
|
+
try:
|
|
32
|
+
color = osc_query(10)
|
|
33
|
+
except (ValueError, IOError):
|
|
34
|
+
return None
|
|
35
|
+
else:
|
|
36
|
+
return parse_color(color)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_default_bg() -> str:
|
|
40
|
+
"""
|
|
41
|
+
Query the attached terminal for the default background color and return the
|
|
42
|
+
color string from the response
|
|
43
|
+
|
|
44
|
+
:raises IOError: if stdin or stdout is not a terminal
|
|
45
|
+
:raises ValueError: if the reply from the terminal is malformed
|
|
46
|
+
"""
|
|
47
|
+
try:
|
|
48
|
+
color = osc_query(11)
|
|
49
|
+
except (ValueError, IOError):
|
|
50
|
+
return None
|
|
51
|
+
else:
|
|
52
|
+
return parse_color(color)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def osc_query(ps: int) -> str:
|
|
56
|
+
if sys.stdin.isatty() and sys.stdout.isatty():
|
|
57
|
+
with cbreak_noecho():
|
|
58
|
+
print(f"\x1b]{ps};?\x1b\\", end="", flush=True)
|
|
59
|
+
resp = b""
|
|
60
|
+
while not resp.endswith((b"\x1b\\", b"\x07")):
|
|
61
|
+
resp += sys.stdin.buffer.read(1)
|
|
62
|
+
s = resp.decode("utf-8", "surrogateescape")
|
|
63
|
+
if m := re.fullmatch(rf"\x1B\]{ps};(.+)(?:\x1B\\|\x07)", s):
|
|
64
|
+
return m[1]
|
|
65
|
+
else:
|
|
66
|
+
raise ValueError(s)
|
|
67
|
+
else:
|
|
68
|
+
raise IOError("not connected to a terminal")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
# File descriptor for standard input:
|
|
72
|
+
STDIN = 0
|
|
73
|
+
|
|
74
|
+
# Indices into the tuple returned by `tcgetattr()`:
|
|
75
|
+
LFLAG = 3
|
|
76
|
+
CC = 6
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@contextmanager
|
|
80
|
+
def cbreak_noecho() -> Iterator[None]:
|
|
81
|
+
"""
|
|
82
|
+
A context manager that configures the terminal on standard input to use
|
|
83
|
+
cbreak mode and to disable input echoing. The original terminal
|
|
84
|
+
configuration is restored on exit.
|
|
85
|
+
"""
|
|
86
|
+
orig = termios.tcgetattr(STDIN)
|
|
87
|
+
term = deepcopy(orig)
|
|
88
|
+
term[LFLAG] &= ~(termios.ICANON | termios.ECHO)
|
|
89
|
+
term[CC][termios.VMIN] = 1
|
|
90
|
+
term[CC][termios.VTIME] = 0
|
|
91
|
+
termios.tcsetattr(STDIN, termios.TCSANOW, term)
|
|
92
|
+
try:
|
|
93
|
+
yield
|
|
94
|
+
finally:
|
|
95
|
+
termios.tcsetattr(STDIN, termios.TCSANOW, orig)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
print("Foreground color:", get_default_fg())
|
|
100
|
+
print("Background color:", get_default_bg())
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
''' Import this module to install a sympy __repr__ using sixel graphics '''
|
|
2
|
+
import sympy
|
|
3
|
+
from sympy.printing.defaults import Printable
|
|
4
|
+
|
|
5
|
+
from .latex import sixelmath
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def sympysixel(sym):
|
|
9
|
+
''' Print Sympy expression to sixel '''
|
|
10
|
+
tex = sympy.latex(sym)
|
|
11
|
+
sixelmath(tex)
|
|
12
|
+
return ''
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
_default_repr = Printable.__repr__
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def disable():
|
|
19
|
+
''' Disable sympy sixel printer '''
|
|
20
|
+
Printable.__repr__ = _default_repr
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def enable():
|
|
24
|
+
''' Enable sympy sixel printer '''
|
|
25
|
+
Printable.__repr__ = sympysixel
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
enable()
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: sixelmath
|
|
3
|
+
Version: 0.1
|
|
4
|
+
Summary: Render LaTeX math and Sympy expressions to Sixel Terminal Graphics. Suuports any Math-enabled font, no LaTeX installation required.
|
|
5
|
+
Home-page: https://github.com/cdelker/sixelmath
|
|
6
|
+
Author: Collin J. Delker
|
|
7
|
+
Author-email: code@collindelker.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Documentation, https://github.com/cdelker/sixelmath
|
|
10
|
+
Project-URL: Source Code, https://github.com/cdelker/sixelmath
|
|
11
|
+
Keywords: LaTeX,math,sympy,sixel,terminal
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Intended Audience :: Education
|
|
23
|
+
Classifier: Intended Audience :: Science/Research
|
|
24
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
25
|
+
Classifier: Intended Audience :: Developers
|
|
26
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE.txt
|
|
30
|
+
Requires-Dist: ziamath>=0.13
|
|
31
|
+
Requires-Dist: latex2mathml
|
|
32
|
+
Requires-Dist: timg
|
|
33
|
+
Requires-Dist: cairosvg
|
|
34
|
+
Requires-Dist: Pillow
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# sixelmath
|
|
38
|
+
|
|
39
|
+
Render LaTeX Math expressions or Sympy objects in the terminal using sixel graphics.
|
|
40
|
+
Math rendering is done using [ziamath](https://ziamath.readthedocs.io), a pure-Python LaTeX math renderer that does not require a Latex installation.
|
|
41
|
+
Any math-enabled truetype/opentype font may be used; STIXTwoMath-Regular is included and used by default.
|
|
42
|
+
Also uses [cairosvg](https://pypi.org/project/CairoSVG/), [timg](https://pypi.org/project/timg/), and [Pillow](https://pypi.org/project/pillow/).
|
|
43
|
+
|
|
44
|
+
See list of sixel-supported terminal emulators [here](https://www.arewesixelyet.com).
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Usage
|
|
48
|
+
|
|
49
|
+
### Command Line
|
|
50
|
+
|
|
51
|
+
Render a LaTeX expression:
|
|
52
|
+
|
|
53
|
+
sixelmath "\frac{1}{1+x}"
|
|
54
|
+
|
|
55
|
+
Options include:
|
|
56
|
+
|
|
57
|
+
* '-s': Font size in points
|
|
58
|
+
* '-f': Path to font file (must include MATH table)
|
|
59
|
+
* '-c': Color as a supported named color, or hex value such as `#FFFFFF`
|
|
60
|
+
* '-b': Background color as a supported named color, or hex value such as `#FFFFFF`
|
|
61
|
+
* '-m': Margin width in pixels
|
|
62
|
+
|
|
63
|
+
In POSIX environments, the font and background color are detected automatically if not manually specified.
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Python
|
|
67
|
+
|
|
68
|
+
To render LaTeX from Python code:
|
|
69
|
+
|
|
70
|
+
from sixelmath import sixelmath
|
|
71
|
+
sixelmath(r'\frac{1}{1+x}')
|
|
72
|
+
|
|
73
|
+
Keyword arguments may be passed to `sixelmath` to change options:
|
|
74
|
+
|
|
75
|
+
* `color`: Font color. A named terminal color like 'white', or RGB hex color such as `#FFFFFF`
|
|
76
|
+
* `bgcolor`: Background color.
|
|
77
|
+
* `font`: Path to a TTF or OTF font file. Must contain a MATH table. STIXTwoMath-Regular is used by default.
|
|
78
|
+
* `fontsize`: Font size in pixels
|
|
79
|
+
* `margin`: Pixel margin around the euqation
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
### Sympy
|
|
83
|
+
|
|
84
|
+
Import the `sixelmath.sympysixel` module to install a Sympy Printer that automatically displays Sympy expressions as sixel graphics.
|
|
85
|
+
|
|
86
|
+
import sympy
|
|
87
|
+
from sixelmath import sympysixel
|
|
88
|
+
sympy.sympify('A * exp(-x^2)')
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
To change display format, use `sixelmath.sixel_defaults`, with the same keyword arguments listed above for `sixelmath`.
|
|
92
|
+
The sixel printer may be turned off using `sympysixel.disable()` and turned on with `sympysixel.enable()`.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
LICENSE.txt
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
setup.cfg
|
|
5
|
+
sixelmath/__init__.py
|
|
6
|
+
sixelmath/__main__.py
|
|
7
|
+
sixelmath/latex.py
|
|
8
|
+
sixelmath/querycolor.py
|
|
9
|
+
sixelmath/sympysixel.py
|
|
10
|
+
sixelmath.egg-info/PKG-INFO
|
|
11
|
+
sixelmath.egg-info/SOURCES.txt
|
|
12
|
+
sixelmath.egg-info/dependency_links.txt
|
|
13
|
+
sixelmath.egg-info/entry_points.txt
|
|
14
|
+
sixelmath.egg-info/not-zip-safe
|
|
15
|
+
sixelmath.egg-info/requires.txt
|
|
16
|
+
sixelmath.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
sixelmath
|