Syntax Reference
Tungsten uses a custom parser that supports a mix of standard LaTeX syntax and intuitive shorthand common in programming or handwritten math.
Variables and Constant## Quick Reference Cheatsheet
| Category | Input Example | Notes |
|---|---|---|
| Arithmetic | 1 + 2 * 3 | Standard order of operations applies |
| Exponents | x^2, e^{x+1} | Use {} to group complex exponents. |
| Fractions | \frac{a}{b}, a/b | Both LaTeX and inline division are supported. |
| Grouping | (a + b)c | Parentheses () define scope. |
| Functions | \sin(x), f(x), \ln x | Standard function calls. |
| Variables | x, vel, x1 | Must start with a letter. |
| Greek | \alpha, \beta, \pi | Standard LaTeX commands. |
| Matrices | \begin{pmatrix}...\end{pmatrix} | Supports p, b, and v matrix types. |
| Vectors | \vec{v}, \mathbf{v}, \begin{pmatrix}...\end{pmatrix} | Symbolic vector notation or as row or column matrix. |
| Derivatives | \frac{d}{dx} x^2, f', \dot{f} | Multiple notations for differentiation. |
| Integrals | \int_{0}^{\infty} e^{-x} dx | Definite and indefinite integrals. |
1. Variables and Constants
Tungsten uses strict tokenization rules to distinguish between variables, numbers, and commands.
Variable Naming
- Structure: Variable names must begin with a letter (A-Z, a-z).
- Alphanumeric: After the first letter, variables may contain digits or underscores.
- ✅ Valid:
x,y_2,velocity,Area51 - ❌ Invalid:
1x(starts with digit),_x(starts with underscore)
- ✅ Valid:
- Case Sensitivity:
xandXare treated as distinct variables.
Greek Letters
Tungsten recognizes standard LaTeX commands for Greek letters. These are treated as symbolic entities distinct from standard variables.
- Syntax:
\alpha,\beta,\Gamma,\omega, etc. - Usage: They can be used anywhere a variable is used:
2\pi,\sin(\theta).
Constants
Certain symbols are reserved or automatically recognized as mathematical constants depending on the backend:
\piorpie(Euler's number)\infty(Infinity)
2. Operators and Precedence
The parser adheres to standard mathematical precedence rules. When operators share the same precedence, associativity determines the order of evaluation.
| Precedence | Operator | Description | Associativity | Syntax Variants |
|---|---|---|---|---|
| 3 (Highest) | ^ | Exponentiation | Right | x^2, x^{y+1} |
| 2 | * | Multiplication | Left | *, \cdot, \times |
| 2 | / | Division | Left | /, \frac{num}{den} |
| 1 | + | Addition | Left | + |
| 1 | - | Subtraction | Left | - |
| 0 (Lowest) | = | Equality | None | =, ==, &= |
Important Notes on Operators:
- Right Associativity (
^):2^3^4is parsed as2^(3^4), not(2^3)^4. - Synonyms: The parser treats
\cdot(dot) and\times(cross) identically to*in scalar arithmetic contexts. However, in Linear Algebra contexts, they denote Dot Product and Cross Product respectively.
Implicit Multiplication
You can often omit the multiplication operator, just like in handwritten math. The parser infers multiplication in the following cases:
- Number + Variable:
2xbecomes2 * x - Variable + Variable:
x ybecomesx * y(Note:xyis parsed as a single variable named "xy". Use a space to separate them.) - Group + Variable:
(a+b)xbecomes(a+b) * x - Variable + Group:
x(x+1)becomesx * (x+1)unlessxis a known function name. - Number + Greek:
2\pibecomes2 * \pi - Function Chains:
\sin(x)\cos(y)becomes\sin(x) * \cos(y)
3. Functions and Grouping
Function Syntax
- Standard Calls:
name(arg1, arg2)- Example:
f(x),sin(x) - Built-in functions, evaluated function definitions, and names in
symbolic_functionsare recognized as calls. - The default symbolic names are
f,g,h, andr, so symbolic mathematics and plotting can use them without a formula. - Other names before parentheses mean multiplication. Configure
symbolic_functionsfor additional undefined symbolic functions; an empty list disables the default symbolic names. - Derivative notation locally identifies dependent functions, preserving initial conditions such as
y(0)in an ODE containingy'.
- Example:
- LaTeX Style Calls:
\command{arg}- Example:
\sqrt{x},\frac{1}{2}
- Example:
- Parenthesis-less Calls: For common log/trig functions, parentheses can sometimes be omitted if the argument is a single token.
\ln xis valid.\sin \thetais valid.\cos(x + 1)is valid
Session-local Function Definitions
Select f(x) = x^2 and run :TungstenEvaluate to define f. Then select f(5) and evaluate it to obtain 25.
You can also use := or select the definition and run :TungstenDefinePersistentVariable.
Definitions accept Latin identifier names and distinct Latin identifier parameters, for example difference(x,y) = x-y.
Both square(t) = t(t+1) and subsequent calls such as square(5) are supported; t(t+1) is multiplication.
Redefining a function replaces its previous formula. Function calls are expanded as AST expressions before evaluation by either backend, so Wolfram persistence is not required.
Definitions last for the current Neovim session and are cleared by :TungstenClearPersistentVars.
They currently support algebraic bodies, including built-in and other defined function calls.
Recursive definitions and bodies containing bound-variable calculus notation such as integrals or summations are rejected.
An equation such as f(5) = 25 is not a definition.
Modified Bessel Functions
Tungsten supports the modified Bessel functions of the first and second kinds using their conventional uppercase notation:
I_0(x)andI_{0}(x)denote the modified Bessel function of the first kind.K_0(x)andK_{0}(x)denote the modified Bessel function of the second kind.- The order may be symbolic or an arbitrary braced expression, for example
I_\nu(x),K_n(x), orI_{n+1}(x). - The argument must be parenthesized.
- Only uppercase
IandKare recognized as modified Bessel notation. - A bare expression such as
I_0remains an ordinary subscripted symbol; onlyI_0(...)is treated as a function call.
Internally these are represented as besseli(order, argument) and besselk(order, argument). Wolfram maps them to BesselI and BesselK, while the Python backend maps them to SymPy's besseli and besselk. Python plotting still requires SciPy for these special functions and will ask you to use the Wolfram plotting backend until SciPy support is added.
Grouping Symbols
- Parentheses
(): Used for standard mathematical grouping and function arguments. - Braces
{}: Used strictly for LaTeX command arguments (e.g.,x^{2},\frac{a}{b}). - Brackets
[]: Often used for defining lists or specific matrix notations, though()is preferred for arithmetic precedence.
4. Syntax Limitations and Edge Cases
To ensure the parser behaves predictably, certain inputs that might look "okay" to a human are strictly invalid.
1. Decimal Formatting
Numbers must have a leading digit before the decimal point.
- ✅ Correct:
0.5 - ❌ Incorrect:
.5(This will fail to parse as a number)
2. Whitespace and Implicit Multiplication
As noted in section 3, whitespace is semantically significant for variables.
xyVariable named "xy"x yMultiplicationx * y
3. LaTeX Environment Closure
All LaTeX environments must be perfectly balanced.
- ❌
\begin{pmatrix} 1 & 2(Missing end tag) - ❌
\frac{1}{2(Unmatched brace)
4. Argument Bracing
LaTeX commands like \frac and \sqrt expect arguments in braces {}.
- ✅
x^{10} - ⚠️
x^10(Parses as(x^1) * 0like it would in standard LaTeX) - ❌
\frac 1 2(Arguments must be braced:\frac{1}{2})
5. Multi-line Inputs
For systems of equations or similar you are able to use the standard LaTeX-construction of &= and \\. &= is parsed as = and \\ is parsed as beginning a new expression.
x + y &= 1 \\
x - y &= 2
You are also able to use semi-colons ; between expressions:
x + y = 1;
x - y = 2
Found syntax that should work but doesn't? The world of mathematical notation is vast. If you encounter valid mathematical notation that Tungsten fails to parse, please file a bug report or feature request.
