Home

Awesome

libtexprintf & utftex

CI

The utftex program and underlying libtexprintf library provide tools to pretty print math in mono-space fonts, using a tex-like syntax. It produces UTF-8 encoded text. The program was inspired by asciiTeX, and the improved asciiTeX fork. However, utftex supports much more TeX syntax and contains extensive Unicode tables to map latex commands to Unicode symbols. Use libtexprintf/utftex to unlock the math capabilities of Unicode in mono-space text applications.

Note that how the equations look depends strongly on the font you use. Naturally, one needs a monospace font with good Unicode support for the symbols you use. A good monospace font for math is, for example,
JuliaMono.

libtexprintf

The core library to pretty print math in mono-space font. Use it to enable your c or c++ code to print out formatted math. The calls are modeled after the printf family to produce formatted output.

utftex

The utftex program uses libtexprinf to implement a command-line utility to format math. For example:

> utftex '\frac{\alpha}{\beta+x}'  

gives

 α   
───  
β+x  

The texprintf library provides a fairly full featured tex-like syntax with arrays, brackets, many symbols, and even font style (note that texprintf outputs UTF-8 and as such cannot change the fonts. However, Unicode does provide several font-styles like mathematical calligraphic style, or italic). For example:

> utftex -F mathnormal '\frac{1}{a+x}' 

gives

 1
───
𝑎+𝑥

It also supports some diacritical combining marks, to do things like

utftex '\vec x' 

to get

x⃗.

A bit more elaborate example is this small table of Laplace transforms:

> utftex '\begin{array}{|l|l|}  
\hline  
f(t) & \mathscr{L}[f(t)]=F(s) \\\hline  
1 & \frac{1}{s} \\\hline  
e^{at}f(t) & F(s-a) \\\hline  
\delta\left(t\right) & 1 \\\hline  
\delta\left(t-t_0\right) & e^{-st_0} \\\hline  
\int_0^t f(x)g(t-x)dx & F(s)G(s)\hline  
\end{array}'  

┌────────────────┬──────────────┐ 
│f(t)            │ 𝓛[f(t)]=F(s) │  
├────────────────┼──────────────┤  
│                │ 1            │  
│1               │ ─            │  
│                │ s            │  
├────────────────┼──────────────┤  
│ at             │              │  
│e  f(t)         │ F(s-a)       │  
├────────────────┼──────────────┤  
│δ(t)            │ 1            │  
├────────────────┼──────────────┤  
│                │  -st         │  
│                │     0        │  
│δ⎛t-t ⎞         │ e            │  
│ ⎝   0⎠         │              │  
├────────────────┼──────────────┤  
│ t              │              │  
│⌠               │              │  
│⎮  f(x)g(t-x)dx │ F(s)G(s)     │  
│⌡               │              │  
│ 0              │              │  
└────────────────┴──────────────┘  

Note that if the table borders do not properly align you are not viewing the table in monospace fonts.

utfstringinfo

Utility to analyze UTF-8 strings. The utfstringinfo program reads arguments or, if no arguments are provided, stdin and for every single character it finds it shows the UTF-8 byte sequence, the Unicode code-point and, if applicable, the utftex command that can be used to generate the symbol.

Software using libtexprintf/utftex

Several projects use libtexprintf or utftex. Some projects that I am aware of are (in arbitrary order):

Questions One Might Ask (QOMA)

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
 <alias>
   <family>monospace</family>
   <prefer>
     <family>MONO</family>
     <family>SYMBOLMONO</family>
   </prefer>
 </alias>
</fontconfig>