# FNC Conversion Components in TMS Analytics & Physics 3.3

Let’s begin with formula converters:

- TFNCFormula2PlainConverter – converts a formula to plain text.
- TFNCFormula2TeXConverter – converts a formula to TeX format.

The **TFNCFormula2PlainConverter **component has the following published properties:

**Formula (string)**– a formula to convert.**PlainFormula (string)**– the formula in plain text format (read-only).**Valid (boolean)**– the formula is valid for conversion (read-only).**Error (string)**– description of the error if occurred during conversion (read-only).

The component provides a very simple functionality: when the** ‘Formula’** property changes, the value is converted to plain text format and assigned to the **‘PlainFormula’** property.

What is the plain text format and when it could be useful? Plain text format just presents a formula as a string using special Unicode characters to make it closer to natural math notation. For example, the formula** ‘x^2’** can be written with the superscript symbol as **‘x2’**. In the following picture, an example of such conversion is presented.

Here we should note that not all formulae can be presented in this format. If a formula is not valid for the conversion, an error message will be shown with the ‘Error’ property.

On the FNC chart, we showed the formula of the fitted curve in the legend. Let’s use the converter and improve the design of the application. We just need to write a small piece of code:

procedure TForm1.ShowCurveLegend(const formula: string);

begin

FNCFormula2PlainConverter1.Formula:= formula;

TMSFNCChart1.Series[1].LegendText:= FNCFormula2PlainConverter1.PlainFormula;

end;

procedure TForm1.FNCApproxFunction1D1FormulaChanged(Sender: TObject; const formula: string);

begin

ShowCurveLegend(formula);

end;

When a formula of the approximated function is changed, we convert it to plain text format and show the formula on the chart. The resulting form is presented in the picture below.

As one can see, the formula of the fitted curve looks like a natural math expression, without superfluous symbols, like power operator** ‘^’** and indexing brackets** ‘[]’**. One more example of the curve, fitted with a Fourier series, is shown in the following picture.

We can use the same approach to present units of measurement in the form of natural physics notation with the **TFNCUnit2PlainConverter **component. An example of such conversion is shown in the picture below.

**TFNCFormula2TeXConverter**has similar functionality, but it converts formulae to TeX format. This format is not for human reading, so, we need a drawing library to display formulae in natural math notation. We’ll use the MathJax library, as described in this article, together with the

**TTMSFNCWebBrowser**component. Here is a simple code for converting a formula to TeX format and showing it in the browser component:

procedure TForm1.DrawFormula(const formula: string);

var

texf, htmlcode: string;

begin

FNCFormula2TeXConverter1.Formula:= formula;

texf:= FNCFormula2TeXConverter1.TeXFormula;

htmlcode:= GetTeXHTML(texf);

DrawTeXInBrowser(htmlcode);

end;

Thus, we have a simple application to display math formulae. An example of a formula drawing is shown in the picture below.