Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

MicroTeX

> 数据库
Open source

A dynamic, cross-platform, and embeddable LaTeX rendering library

653 stars0 likes3 views
WebsiteGitHub

About

A dynamic, cross-platform, and embeddable LaTeX rendering library

It is a dynamic, cross-platform, and embeddable LaTeX rendering library. Its main purpose is to display mathematical formulas written in LaTeX. It can be embedded in applications on various platforms (Android, iOS, Windows, Linux GTK, Qt...). The following pictures demonstrate the application run in Ubuntu (using GTK) and Windows.

Here contains more demos you may want to take a look.

Build demo

First make sure you have a C++ compiler that supports C++ 17 standard. It uses CMake to build the demo, make sure you have it installed. Currently support Windows and Linux on PC, the version on Mac OS is in the plan, and you can find the Android version in here.

  • CygWin or MinGW is recommended to be installed on Windows, and Gdiplus is required.
  • GTKMM and GSVMM must be installed on Linux for a GTK build.
  • Qt development packages must be installed for a Qt installation.

After all the dependencies have been satisfied, run the following commands to build:

bash
cd your/project/dir
mkdir build
cd build
cmake ..
make -j32

After all the works have done, run the executable file LaTeX in the directory build to check the demo.

If you wish to build in Qt mode on your plaform add -DQT=ON to the cmake command above.

Headless mode

It supports to run with headless mode (no GUI) on Linux OS, check the scripts below to learn how to do this.

Batch mode:

bash
./LaTeX -headless \
    -samples=res/SAMPLES.tex \
    -outputdir=samples \
    -prefix=sample_ \
    # common options
    -textsize=14 \
    -foreground=black \
    -background=white \
    -padding=0 \
    -maxwidth=720

Single mode:

bash
./LaTeX -headless \
    "-input=\sqrt[3]{(x-y)^3}=x-y" \
    -output=an_example.svg
    # other options...

COMMON OPTIONS

  • -h: show usages and exit

  • -headless: tells the application to run with the headless mode, that converts the input LaTeX codes into SVG images

  • -textsize: config the font size (in point) to display formulas, the default is 20

  • -foreground: config the foreground color to display formulas; the value can be a color name or in the form of #AARRGGBB; default is black

  • -background: config the background color to display formulas; the value can be a color name or in the form of #AARRGGBB; default is transparent

  • -padding: config spaces to add to the SVG images, the default is 10

  • -maxwidth: config the max width of the graphics context, the default is 720 pixels; this option has weak limits on the SVG images, thus the width of the SVG image may be wider than the value defined by this option

BATCH MODE OPTIONS

The program will save the SVG images produced by the LaTeX codes that parsed from the given file (specified by the option '-samples') into the directory specified by the option '-outputdir'.

  • -outputdir: indicates the directory to save the SVG images

  • -samples: specifies the file that contains several LaTeX codes split by a line that consists of the character '%' only, the default is './res/SAMPLES.tex'; check this file to get more details

  • -prefix: specifies the prefix of the filename of the SVG images, the default is ''; for example if 2 pieces of code have given with the option '-prefix=a_', the filename of the SVG images will be 'a_0.svg' and 'a_1.svg'

SINGLE MODE OPTIONS

  • -input: the source code that is written in LaTeX

  • -output: indicates where to save the produced SVG image, only works if the option '-input' has given

NOTICE

If both '-outputdir' and '-input' are specified, the '-input' option wins. Run the command ./LaTeX -h to get helps.

Please read this section to learn more.

Compile-time options

The program can be built just fine using the default compilation options. However, if required, the options documented below can be used to omit some features (that can reduce the library size) and to check memory only.

HAVE_LOG

If HAVE_LOG is defined, the program will output some logs (e.g.: the symbols parse result, generated box tree and so on) during runtime to help us to find out if there're issues or bugs, the default is ON. The option will be disabled when building with release mode, you can set it to OFF manually to make double insurance. For example, when parsing the following LaTeX code with the option is defined:

tex
\sqrt[3]{(x-y)^3}=x-y

will produce the following box tree:

…

The number represents the depth of the tree node.

GRAPHICS_DEBUG

If this macro is defined, then the custom command \debug and \\undebug will be compiled, the default is ON. The program will draw some assisted information to help us to check if there're issues when draw formulas after run \debug, and \\undebug will close this feature. For example, parse the LaTeX code below:

…

will produce:

The red blocks represent the depth of the boxes, and these rectangles represent the boxes' bounds.

MEM_CHECK

Basically, the program implemented an empty graphics interface (check this file), all the other implementations will be ignored if the MEM_CHECK option is defined, the default is OFF. It is useful when using valgrind to detect memory leaks and memory misuse, make sure you have compiled it with the option -DCMAKE_BUILD_TYPE=Debug before using valgrind. The following script shows how to do memory check using valgrind.

bash
cmake 
    -DCMAKE_BUILD_TYPE=Debug \
    -DGRAPHICS_DEBUG=ON \
    -DMEM_CHECK=ON \
    -DHAVE_LOG=OFF ..
make -j32
valgrind --leak-check=full -v ./LaTeX

will produce:

…

Meson build manifest

You can also build the cairo version of cLaTeXMath with Meson:

bash
meson _build -DTARGET_DEMO=NONE # you can specify TARGET_DEMO=GTK if you want a GTK+ GUI to test cLaTeXMath, otherwise only the library (TARGET_DEVEL) will be built.
ninja -C _build
_build/clatexmath

Prebuilt packages

@sp1ritCS maintains more or less upto date packages of cLaTeXMath/cairo for Arch, CentOS, Debian, Fedora, Mageia, SLE, openSUSE & Ubuntu on the openSUSE Buildservice: home:sp1rit:notekit/clatexmath.

The binaries (built packages) are publicly (without SUSE univention account) available here: download.opensuse.org/repositories/home:/sp1rit:/notekit/. Install instructions can be found on openSUSE's software-o-o instance:

  • Arch (and SRPMs): software.opensuse.org//download.html?project=home:sp1rit:notekit&package=clatexmath
  • RPM (CentOS, Fedora, Mageia, SLE & openSUSE): software.opensuse.org//download.html?project=home:sp1rit:notekit&package=clatexmath-devel
  • DPKG (Debian, Raspbian & xUbuntu): software.opensuse.org//download.html?project=home:sp1rit:notekit&package=libclatexmath-dev

If you just want to use cLaTeXMath for your GTK/Cairo project, this may be best way to get started.

How to use

This section shows how to use this library to display mathematical formulas.

First, load the required resources at the very beginning:

cpp
#include "latex.h"

using namespace tex;

/**
 * Initialize the program with the default parameter (directory
 * path of the resources) value "res" to load required resources,
 * that may take a long time, you may call it from a background
 * thread.
 *
 * Also, you can use the code below to specifies your custom
 * resources directory:
 * 
 *      LaTex::init("your/resources/root/directory");
 */
LaTeX::init();

// After initialization, you could display your formulas now

You could set the point size (pixels per point) use the code below:

cpp
/** 
 * Set the point size; the default value is 1 that means
 * use 1 pixel to represent 1 point.
 */
TeXFormula::PIXELS_PER_POINT = 2;

Also, you could set the DPI (dots per inch) use the code below:

cpp
/**
 * For example, set the DPI-target to 74, the point size
 * will be 74/72
 */
TeXFormula::setDPITarget(74);

Write the code below to release resources before application exit, it is not necessary but is a good habit.

cpp
// ... some other code ...
// before application exit

LaTeX::release();

Display mathematical formulas

General mode:

…

Builder mode:

…

NOTICE

A style and text size are required to build a TeXRender, in another word, you must call method setStyle and setSize before method build has been called, otherwise an ex_invalid_state exception will be thrown. If the logical width has not set, the generated TeXRender may be wide enough to overflow into the graphics context.

Now you can draw the generated TeXRender (take Graphics2D_cairo that uses cairomm to implement the graphics (2D) context that run in Linux as an example):

cpp
// cairomm implementation
Graphics2D_cairo g2;
// draw the formula on the coordinate (10, 10) of the graphics context
r->draw(10, 10);
// IMPORTANT: remember to delete the generated TeXRender after there
// is no use on it.
delete r;

The code above will produce:

Implement the graphical interfaces

Basically, you need to implement all the interfaces declared in this file. There're 4 implementations list below, check it out before the start.

  • graphic_cairo: that uses cairomm and gtkmm to implement these interfaces that run in Linux, declared in here, and implemented here.

  • graphic_win32: is a Windows implementation that uses gdiplus to implement these interfaces, please check here and here.

  • And implementations on Android OS can be found at here.

  • And the empty implementations to perform memory check are defined in here.

The following sections illustrate these interfaces.

tex::Font

This interface represents a font (typeface). The program uses it to draw characters and layout boxes. The code below shows how to implement this interface with the name Font_impl.

…

tex::TextLayout

An alphabet contains several Unicode-blocks on a Basic Multilingual Plane (BMP), check here for more information.

For these characters in unregistered alphabets, the library uses tex::TextLayout to layout it. For example, parse the following LaTeX code:

tex
\int_{now}^{\infty} \text{努力}

The character "努" and "力" are under the Unicode-block CJK Unified Ideographs belongs to the alphabet CJK that has not registered with the program, it will use the implementation of the class tex::TextLayout to layout the text "努力" and calculate the layout bounds. The tex::TextLayout_cairo implementation (declared in here) demonstrates how to do this.

The LaTeX code above will produce:

The predefined Unicode-blocks are list below, check this file for more details.

name               code range
-----------------  ---------------
BASIC_LATIN        0x0020 ~ 0x007F
LATIN1_SUPPLEMENT  0x0080 ~ 0x00FF
CYRILLIC           0x0400 ~ 0x04FF
GREEK              0x0370 ~ 0x03FF
GREEK_EXTENDED     0x1f00 ~ 0x1FFF
UNKNOWN            0xFFFF ~ 0xFFFF

Write

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

C++androidcross-platformlatexmacros

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库