Blog Options


<< January 2019 >>



Most Recent Post  |  Next Post  |  Previous Post  |  Index List

Drawing math formulae generated with TMS Analytics & Physics library


Monday, January 07, 2019

TMS Analytics & Physics developing library contains many algorithms for manipulating with symbolic math expressions. For example, it is able to evaluate symbolic derivatives of complicated expressions, approximate functions with symbolic, user-defined basis and so on. The result of any such manipulation is another symbolic expression. Many efforts in last versions has been spent for simplifying result expressions. The expression simplification required for presenting the result in shorted and readable form. For example, the derivative of ‘y^(x+1)’ by ‘x’ can be formally written as ‘(x+1)*y^(x+1-1)’ and this is correct answer, but after simplification it would be simpler for reading – ‘(x+1)*y^x’.

Nevertheless, all symbolic algorithms manipulate with math expressions, presented as plain Unicode strings. The main reason for this is providing simple interface for using math formulae inside Delphi programs. Presenting math expressions as plain strings requires using special syntax for different math structures. For example, power expression written with power operator ‘x^y’, vector expression written with brackets ‘[x y z]’ and so on. Such syntax is not ‘natural’ for math formula notation and so, result expressions are not suitable for ‘human reading’.

New version 2.7 of TMS Analytics and Physics pack contains new tools to convert symbolic expressions, generated with the library, to TeX format ( This format is widely used for creating scientific articles and documents. There are many free tools for drawing math formula, presented in TeX format in desktop and Web applications, converting documents to PDF or DOC format and so on.

Let us consider as symbolic expressions, generated with the library, can be drawn with Web browser as math formulae. First, we need to convert the expression to the TeX format. Here is an example of code for converting expressions:

  f, texf: string;
  converter: TAnalyticsConverter;
  f:= 'A*sin(n*x)+B/2*e^(m*y)';
  converter:= TAnalyticsTeXConverter.Create;
    texf:= converter.Convert(f);
  except on E: Exception do
    // Show exception message...

  // Using formula in TeX format...
In the code above an instance of the TAnalyticsTeXConverter class created. This class has the Convert method for converting symbolic expressions to the TeX format. For the expression, result string in TeX format is the following:


Expression in TeX format can be then drawn in Web browser using, for example, MathJax CDN service ( For doing this we can generate a file with the following HTML code:
<!DOCTYPE html>
    <script type="text/javascript" src=""></script>
    <title> TMS Analytics & Physics 2.7 </title>
    $$ XXX $$

where XXX must be replaced with the TeX formula. Launching browser for the generated HTML file the formula will be drawn. For the formula above, we get:

The converter to TeX format supports all formulae, satisfying the syntax of the library. All types of expressions can be converted and rendered, including implicit derivative operators, special functions and operators (sum, square root and so on).

There are some other examples of complicated formula, rendered in Web browser with the described approach.

- Implicit derivative expression:

- Expression with indexed data:

- Matrix/vector expression:

- Special function/operator expression:

As can be seen from the pictures above, all rendered formulae presented in natural math format and are easy to read and understand. Thus, all symbolic results, evaluated with the library, can be shown to the user as math formulae.

The version 2.7 is already available. Source code of the example application can be downloaded from here.

Bruno Fierens


This blog post has received 6 comments. Add a comment.

Most Recent Post  |  Next Post  |  Previous Post  |  Index List