Did you know that you can define your own functions in Text Blaze? A function is a reusable action that does something, mainly transforming existing values in some way.

Text Blaze already has a bunch of functions pre-configured. Personally I really like text string functions, like **contains** or **concat**. Math functions are really useful as well, like **round**, **remainder**, or **random**.

All of these functions work with the formula command and are formatted as *functionname(thing_to_do_the_function_to)* as follows:

Contains: {=contains("This is my text", "text")}

Concat: {=concat("First string ","and ","second string")}

Round: {=round(12.6)}

Remainder: {=remainder(5,3)}

Random: {=random()}

Being able to define your own function is helpful if you have some sort of math equation you need to do frequently, or if you're changing text in a set way regularly. Creating your own functions, especially for math, lets you create snippets that are essentially your own quick calculators.

To define your own function, you'll use assignment mode and the format of x -> do_something_to_x. Full details are here in our documentation.

By defining these custom functions, I can call the function within my snippet when I need to do what the function does, instead of writing out its formula every single time. Here's some examples of custom functions that I've created that can be used as calculators:

**Converting celsius temperature to farenheit**

Defining my function: {farenheit=x -> (x*(9/5))+32}

*Using my function with a form field as the input:*

Enter temperature in Celsius {formtext: default=100; name=celsius}

That temperature is {=farenheit(celsius)} in Farenheit

**Converting inches to centimeters**

Defining my function: {cm=x -> x*2.54}

*Using my function*

Enter the number of inches: {formtext: default=12; name=inches}

{=inches} inches is {=cm(inches)} centimeters

**Calculating kPa from PSI**

Defining my function: {kPa=x -> concat((x*6.9),"kPa")}

*Using my function*

Enter the tire's PSI: {formtext: default=110; name=PSI}

Result: {=kPa(PSI)}

Text functions are less likely to be used as calculators, but they can still be defined if you plan to manipulate text in complex ways repeatedly in a snippet.

Defining my function: {wonkify=x -> concat(x, " & ", reverse(upper(x)))}

*Using my function:*

Enter text to wonkify: {formtext: name=regular}

Here's the wonkified version: {=wonkify(regular)}