开源软件名称(OpenSource Name):NanoMichael/MicroTeX开源软件地址(OpenSource Url):https://github.com/NanoMichael/MicroTeX开源编程语言(OpenSource Language):C++ 93.5%开源软件介绍(OpenSource Introduction):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 demoFirst make sure you have a C++ compiler that supports
After all the dependencies have been satisfied, run the following commands to build: cd your/project/dir
mkdir build
cd build
cmake ..
make -j32 After all the works have done, run the executable file If you wish to build in Qt mode on your plaform add Headless modeIt supports to run with headless mode (no GUI) on Linux OS, check the scripts below to learn how to do this. Batch mode: ./LaTeX -headless \
-samples=res/SAMPLES.tex \
-outputdir=samples \
-prefix=sample_ \
# common options
-textsize=14 \
-foreground=black \
-background=white \
-padding=0 \
-maxwidth=720 Single mode: ./LaTeX -headless \
"-input=\sqrt[3]{(x-y)^3}=x-y" \
-output=an_example.svg
# other options... COMMON OPTIONS
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'.
SINGLE MODE OPTIONS
Please read this section to learn more. Compile-time optionsThe 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_LOGIf 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: \sqrt[3]{(x-y)^3}=x-y will produce the following box tree:
The number represents the depth of the tree node. GRAPHICS_DEBUGIf this macro is defined, then the custom command \debug
\newcolumntype{s}{>{\color{#1234B6}}c}
\begin{array}{|c|c|c|s|}
\hline
\rowcolor{Tan}\multicolumn{4}{|c|}{\textcolor{white}{\bold{\text{Table Head}}}}\\
\hline
\text{Matrix}&\multicolumn{2}{|c|}{\text{Multicolumns}}&\text{Font size commands}\\
\hline
\begin{pmatrix}
\alpha_{11}&\cdots&\alpha_{1n}\\
\hdotsfor{3}\\
\alpha_{n1}&\cdots&\alpha_{nn}
\end{pmatrix}
&\large \text{Left}&\cellcolor{#00bde5}\small \textcolor{white}{\text{\bold{Right}}}
&\small \text{small Small}\\
\hline
\multicolumn{4}{|c|}{\text{Table Foot}}\\
\hline
\end{array} will produce: The red blocks represent the depth of the boxes, and these rectangles represent the boxes' bounds. MEM_CHECKBasically, the program implemented an empty graphics interface (check this file), all the other implementations will be ignored if the 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 manifestYou can also build the cairo version of cLaTeXMath with Meson: 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:
If you just want to use cLaTeXMath for your GTK/Cairo project, this may be best way to get started. How to useThis section shows how to use this library to display mathematical formulas. First, load the required resources at the very beginning: #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: /**
* 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: /**
* 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. // ... some other code ...
// before application exit
LaTeX::release(); Display mathematical formulasGeneral mode: // ... initialization ...
/**
* The LaTeX code to parse.
*
* The program uses wide string to represent UTF characters, you
* could use the code below to convert a string with UTF-8 encoding
* to a wide string:
*
* wstring wstr = utf82wide("A string with UTF-8 encoding.");
*/
wstring code = L"\\int_{now}^{+\\infty} \\text{Keep trying}";
// Convert the code to a paintable object (TeXRender)
auto r = LaTeX::parse(
code, // LaTeX code to parse
720, // logical width of the graphics context (in pixel)
20, // font size (in point)
10, // space between 2 lines (in pixel)
BLACK // foreground color
); Builder mode: wstring code = L"\\int_{now}^{+\\infty} \\text{Keep trying}";
TeXFormula formula;
TeXRenderBuilder builder;
formula.setLaTeX(code);
auto r = builder
// environment style, see TeXConstants (defined in common.h) to
// get more details
.setStyle(STYLE_DISPLAY)
// text size (in point)
.setSize(20)
// the logical width and the alignment of the graphics context
.setWidth(UnitType::pixel, 720, Alignment::left)
// set if the logical width of the graphics context specified
// above is the max width to display the formula, the formula
// will be centered if set to true; you must call this method
// after 'setWidth' has called, otherwise an ex_invalid_state
// exception will be thrown
.setIsMaxWidth(false)
// space between 2 lines
.setLineSpace(UnitType::pixel, 10)
.setForground(tex::BLACK)
// convert the formula to a paintable object (TeXRender)
.build(formula);
Now you can draw the generated // 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 interfacesBasically, you need to implement all the interfaces declared in this file. There're 4 implementations list below, check it out before the start.
The following sections illustrate these interfaces. tex::FontThis 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 #include "graphic/graphic.h"
namespace tex {
class Font_impl : public tex::Font {
public:
Font_impl(const string& file, float size) {
// load platform-specific font from given file and size
}
Font_impl(const string& name, int style, float size) {
// create platform-specific font with given name, style
// and size
}
// ... implementations of the other methods ...
};
/**
* IMPORTANT: do not forget to implement the 2 static methods below,
* it is the factory methods to create a new font.
*/
Font* Font::create(const string& file, float size) {
return new Font_impl(file, size);
}
sptr<Font> Font::_create(const string& name, int style, float size) {
return sptrOf<Font_impl>(name, style, size);
}
} // namespace tex tex::TextLayoutAn 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 \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 The LaTeX code above will produce: The predefined Unicode-blocks are list below, check this file for more details.
Write the code below to register a new alphabet with the program: class NewAlphabetRegistration : public AlphabetRegistration {
private:
vector<UnicodeBlock> _blocks;
public:
NewAlphabetRegistration(const vector<UnicodeBlock>& blocks)
:_blocks(blocks) {}
const vector<UnicodeBlock>& getUnicodeBlock() const override {
return _blocks;
}
const string getPackage() const override {
// the root directory path of the font-mapping and
// symbols-mapping for this alphabet
}
const string getTeXFontFile() const override {
// language settings (a xml file) for this alphabet
}
};
// ... some other code ...
// Define a new Unicode-block
auto newBlock = UnicodeBlock::define(
newAlphabetCodePointStart,
newAlphabetCodePointEnd);
// Register the new alphabet
DefaultTeXFont::registerAlphabet(new NewAlphabetRegistration({newBlock}); tex::Graphics2DThis interface defines a 2D graphics context, all the TeX drawing operations will on it. It declares various basic 2D graphics operations, including affine transformations and meta graphical operations. The class Custom commands and symbols\debug and \undebugAs mentioned above, the command \fatalIfCmdConflictThis command takes a boolean argument to determine whether to raise an error that when defining a new command but it has defined already or redefining a command but it has not defined. The default value is true. The script below shows how to use it. \fatalIfCmdConflict{true}
% define a new command with the name R
\newcommand{\R}{\mathbb{R}}
\R
% here will cause the program throws an error
% use \fatalIfCmdConflict{false} to disable it
\newcommand{\R}{\mathcal{R}} \breakEverywhereThis command takes a boolean argument, the predefined value is false. Its functionality is hard to describe, an example worths thousands of words, the examples below show the difference between when it set to true and false. \text{What is real? How do you define ‘real’? If you're talking about what you can feel, what you can smell, what you can taste and see, then ‘real’ is simply electrical signals interpreted by your brain. \bold{\text{― Morpheus The Matrix}}} When with And with
\TeX and \AndroidTeXThe logo and the logo of the Android version are produced by the command \TeX \\
\AndroidTeX Custom symbolsThere're 4 custom symbols in the script below: AB \varparallel CD
AB \nvarparallel CD
AB \varparalleleq CD
\parallelogram ABCD that will produce: TODO
LicenseExcluding the fonts and xml resources (under the directory
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论