Skip to content
tlehmanPublic

About

Shell/REPL that renders LaTeX on terminals (looks best on kitty and Ghostty)

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

texsh

A LaTeX math shell for the terminal, with a small command language that operates on LaTeX expressions. LaTeX always lives inside $…$; a bare $…$ line renders it in place with shell flow like zsh or bash and math layout from opentui-math.

texsh> $x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$

           ╭────────
     -b ± √ b² - 4ac
x = ─────────────────
           2a

texsh> unicode $\mathbb{R}^n$
  ℝⁿ
  U+211D U+207F

texsh> unicode $\sum_{i=1}^{n} x_i^2 \leq \aleph_0$
  ∑ᵢ₌₁ⁿ xᵢ² ≤ ℵ₀

On Kitty-compatible terminals (Ghostty, Kitty, WezTerm) formulas also render as high-resolution MathJax graphics, with automatic Unicode-cell fallback everywhere else.

Requirements

  • Bun ≥ 1.3
  • A real terminal for the interactive shell (-c works in a pipe)

Install & run

bun install
bun start

Or:

bun index.ts

One-shot evaluation (prints to stdout, exit code 1 on error):

bun index.ts -c 'unicode $\mathbb{R}$'      # ℝ
bun index.ts -c '$e^{i\pi} + 1 = 0$'         # Unicode-cell rendering

The language

line    := command arg*
arg     := word | '$' latex '$' | '$$' latex '$$'
Input What happens
$…$ Render the expression (implicit render)
render $…$ Same, explicit: aliases r, show, tex
unicode $…$ Convert the expression to Unicode text and copy it to the clipboard: aliases u, uni
copy [$…$] Copy the last unicode result, or the given expression's Unicode form: aliases cp, c
help / ? Built-in command list
examples Sample lines to try
history Past inputs
mode auto|kitty|cells Switch graphics backend
clear / Ctrl+L Clear scrollback
exit / Ctrl+C Leave the shell
↑ / ↓ Previous / next command

Bare LaTeX without $…$ is a syntax error; the shell tells you what to wrap. Commands accept several $…$ arguments and handle each in turn.

unicode

unicode $…$ transliterates LaTeX into plain Unicode, using the Mathematical Alphanumeric Symbols block, the superscript/subscript blocks, and the usual operator code points:

LaTeX Unicode
\mathbb{R}, \mathbb{1} ℝ, 𝟙
\mathcal{L}, \mathfrak{g}, \mathbf{x}, \mathit{x} ℒ, 𝔤, 𝐱, 𝑥
\alpha, \Omega, \varepsilon, \aleph_0 α, Ω, ε, ℵ₀
x^2, a_{ij}, e^{-x}, A^\top, 90^\circ x², aᵢⱼ, e⁻ˣ, Aᵀ, 90°
\sum_{i=1}^{n}, \int_0^1 ∑ᵢ₌₁ⁿ, ∫₀¹
\frac{1}{2}, \frac{5}{4}, \sqrt[3]{x}, \binom{n}{k} ½, ⁵⁄₄, ∛x, (ⁿₖ)
\vec{v}, \hat{x}, \overline{AB}, \not\in v⃗, x̂, A̅B̅, ∉
\forall x \in \mathbb{R}, P \implies Q ∀x ∈ ℝ, P ⟹ Q
\begin{pmatrix} a & b \\ c & d \end{pmatrix} (a b; c d)

The result lands on your clipboard automatically (via pbcopy, wl-copy, xclip, or xsel when present, else OSC 52, which works over SSH in Ghostty, Kitty, WezTerm, and iTerm2). copy re-copies the last result, and dragging the mouse over any output copies the selection on release.

Spacing follows TeX's atom classes, so a+b=c comes out as a + b = c and \sin x as sin x. When Unicode has no form for something (a superscript π, a general fraction, a matrix) the command prints its best approximation and a ⚠ note saying what was approximated. Plain letters stay plain; use \mathit{x} for 𝑥.

Stack

License

MIT

About

Shell/REPL that renders LaTeX on terminals (looks best on kitty and Ghostty)

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages