Math expressions

Get math expressions solved in numeric fields, texts, and arrow labels.

The editor solves the calculations you write:

  • Text and labels: write a calculation, then type = and Space. The result appears after it: 12*3= becomes 12*3= 36.
  • Numeric fields: type a calculation and confirm it: 360/3 becomes 120.

The result is an ordinary value: it doesn't update when you change the numbers later.

Where expressions work

In numeric fields

A calculation typed into a field becomes the field's value.

  • Operation: type an expression in any numeric field, such as the ones of the Attributes panel, then confirm it or leave the field.
  • Result: the field takes the result, rounded to the precision of the field and kept within its range. If the expression cannot be solved, the field goes back to its previous value.
  • Tip: write numbers without units, with a point for decimals. A field that shows a unit also accepts that unit at the end, such as 90/2° in an angle field. Calculations also work in animation block timings, the Timeline panel, and Animation settings.

Entering 360/3 in the W field:

The expression 360/3 entered in the rectangle's width field, outlined in orange

After confirming, W is 120:

The rectangle's width field shows the calculated value 120

In text and labels

A result written into the text, right after its expression.

  • Operation: while you edit the text of a shape, such as a text, a rich text block, or the label of a shape or arrow, type an expression, then = and Space.
  • Needs: in rich text, the = at the end of a paragraph, outside code blocks. Code editors and frame names don't solve expressions, and tables use their own formulas.
  • Result: the result is written after the =: 12*3= 36. If nothing before the = can be solved, the space is typed as usual.
  • Tip: to recalculate after changing the numbers, select the old result and press Space. Only the selected number is replaced.

Expressions also work while you edit an item of a Text Sequence, on the board or in the Attributes panel.

Text calculations showing 12 × 3 = 36, 100 / 3 = 33.333, and sqrt(144) = 12

In measuring arrow labels

An arrow can show its own length or angle as its label. Typing a new value or a calculation in that label changes the arrow to match.

  • Operation: edit the label of an arrow, type a value or an expression, and confirm it.
  • Needs: an arrow whose Label source is Distance or Angle, not Custom.
  • Result: the measured distance or angle changes to the result, within the arrow's Decimals and measuring limits. Shapes attached to the arrow can move or be resized with it. A ° in what you type is ignored.

Which part of the text is calculated

In texts, labels, and rich text, only the calculation at the end of what you're typing counts:

  • One line at a time: the calculation starts at the beginning of the line. In rich text, put each calculation in its own paragraph.
  • Several on one line: separate them with ;. In 2*3= 6; 4*5=, only 4*5 is calculated.
  • Words before it: words in front of the calculation are skipped. In Width 12*3=, the editor calculates 12*3.

In numeric fields and measuring arrow labels, everything you type is the calculation.

What you can write

Calculations use math.js, so you can write ordinary math. The most common operations:

OperationExampleResult
Add and subtract12+3-510
Multiply and divide12*3, 100/436, 25
Powers2^101024
Parentheses(2+3)*420
Square rootsqrt(144)12
Rounding to decimalsround(3.14159, 2)3.14
Trigonometrysin(pi/2), sin(90 deg)1
Constantspi, e3.142, 2.718
  • Symbols: ×, ÷, and π work too. Use a point for decimals.
  • Results: only finite numbers are used. A calculation that gives a unit, a matrix, or text is ignored. Results in text use up to three decimals, so 100/3 gives 33.333. Measuring labels use their Decimals setting.
  • Everything else: see the math.js lists of functions and constants.

Tables are different

Cells of a table use spreadsheet formulas instead: they start with =, take cell references, and offer functions such as SUM. See Formulas.