# How to Enable and Use the Calculator Functionality in Rime Wanxiang

> **The Rime Wanxiang calculator is enabled by default via the `super_calculator` Lua translator triggered by the `V` key, allowing you to perform mathematical operations, unit conversions, and equation solving directly in your i...

- Repository: [amzxyz/rime_wanxiang](https://github.com/amzxyz/rime_wanxiang)
- Tags: 
- Published: 2026-02-24

---

**The Rime Wanxiang calculator is enabled by default via the `super_calculator` Lua translator triggered by the `V` key, allowing you to perform mathematical operations, unit conversions, and equation solving directly in your input method.**

The **calculator functionality** in the [rime_wanxiang](https://github.com/amzxyz/rime_wanxiang) input method schema transforms your Rime IME into a powerful computational tool. By leveraging a dedicated Lua translator, you can execute complex calculations without leaving your typing workflow. This guide explains how the feature is implemented in the source code and how to use its extensive mathematical capabilities.

## Architecture of the Wanxiang Calculator

The calculator is implemented as a **Lua translator** named `super_calculator` that intercepts specific input patterns and returns computed results as candidates. The architecture consists of four core components defined in the schema and Lua files:

- **Recognizer Pattern** – Defined in [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml) at line 44 as `calculator: "^V.*$"`, this regex detects any input starting with the trigger key `V` and routes it to the calculator translator.
- **Translator Registration** – At line 84 of [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml), the entry `lua_translator@*super_calculator` loads the Lua script for all matched inputs.
- **Lua Implementation** – The file [`lua/super_calculator.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/lua/super_calculator.lua) contains the `calc_methods` table (lines 18–102) that maps command keywords to mathematical functions, and the `T.init(env)` function (lines 6–12) that reads the configurable trigger character from the schema.
- **Result Formatting** – The `format_number_for_display` function (lines 24–38) ensures results display with appropriate significant digits and removes trailing zeros.

## Enabling the Calculator in Your Schema

The calculator is active out-of-the-box in both [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml) and [`wanxiang_t9.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_t9.schema.yaml). To verify or manually enable the **calculator functionality** in a custom schema, ensure these two configuration blocks exist:

1. **Add the recognizer pattern** in your schema file:

```yaml
recognizer:
  patterns:
    calculator: "^V.*$"

```

2. **Register the Lua translator** in the `engine/translators` section:

```yaml
engine:
  translators:
    - lua_translator@*super_calculator

```

After modifying the schema, reload Rime by pressing **Ctrl + `** (backtick) or restarting your IME to apply changes.

## Using the Calculator

To invoke the calculator, type the trigger key **`V`** (uppercase) followed by a command keyword or raw mathematical expression. The translator evaluates the input and returns the result as a candidate in the composition window.

### Basic Arithmetic and Statistics

You can perform standard arithmetic or use statistical shortcuts defined in the `calc_methods` table:

```text
V2+2                    → 4
V(12-5)/7               → 1
V3*7                    → 21
Vavg 4 8 15 16 23       → 13.2
Vvar 1 2 3 4 5          → 2

```

The `avg` command calculates the average of space-separated numbers, while `var` computes variance.

### Equation Solving

Solve polynomial equations using dedicated command keys:

```text
Vyyec 1 -3 2            → x₁=1, x₂=2
Vyyyc 1 -2 1 0          → x₁=x₂=x₃=0 (cubic)
Vyyyc 1 0 -4 0          → x₁=2, x₂=-2, x₃=0

```

The `yyec` command handles quadratic equations, and `yyyc` extends to cubic and quartic equations.

### Unit and Base Conversions

Convert between measurement units and number bases:

```text
Vdwhs 100 "kg" "lb"     → 220.462262185 (kilograms to pounds)
Vjzzh 255 10 2          → 11111111 (decimal to binary)
Vjzzh "ff" 16 10        → 255 (hexadecimal to decimal)
Vjzzh 15 10 2           → 1111 (decimal to binary)

```

The `dwhs` command performs unit conversions, while `jzzh` handles base conversions between radix 2 and 36.

### Geometry and Trigonometry

Calculate geometric properties and trigonometric values:

```text
Vzdbx 6 2               → 6.928203230275 (regular hexagon area)
Vsin 0.5                → 0.479425538604
Vdeg 1.0472             → 60.0000000000 (radians to degrees)
Vcesd 0 0 1 0 0 1       → standard & general circle equation

```

Arguments for trigonometric functions are interpreted in radians unless converted with `deg`.

## Customizing Calculator Commands

To extend the calculator with custom operations, modify [`lua/super_calculator.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/lua/super_calculator.lua):

1. Implement your function in the script.
2. Register it in the `calc_methods` table with a short key (e.g., `"mycmd"`).
3. Optionally add a description to the `methods_desc` table for documentation.
4. Reload Rime to activate the new command immediately under the `V` prefix.

## Summary

- The calculator is enabled via the `calculator: "^V.*$"` recognizer pattern and `lua_translator@*super_calculator` in [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml).
- The trigger key `V` is configurable through the schema and extracted dynamically by `T.init(env)` in [`super_calculator.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/super_calculator.lua).
- Supported operations include arithmetic, statistics, equation solving, unit conversion, base conversion, and geometry through the `calc_methods` table.
- Results are formatted by `format_number_for_display` to ensure readable output with appropriate precision.
- Press **Enter** to commit a result, or **Ctrl+Shift+Enter** to insert it without committing for chained calculations.

## Frequently Asked Questions

### Is the calculator enabled by default in Rime Wanxiang?

Yes. The default [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml) and [`wanxiang_t9.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_t9.schema.yaml) files ship with the recognizer pattern at line 44 and the Lua translator registration at line 84 already configured, so the functionality is available immediately after installing the schema.

### Can I change the trigger key from V to something else?

Yes. Modify the `calculator` pattern in your schema's `recognizer/patterns` section (e.g., change `^V.*$` to `^=.*$` to use the equals sign). The `T.init(env)` function in [`super_calculator.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/super_calculator.lua) automatically extracts the new trigger character from this pattern at runtime.

### How do I insert the result without committing the text?

Press **Ctrl+Shift+Enter** when the calculator result is highlighted. This inserts the computed value into your document without committing the original `V` command text, allowing you to continue typing or chain multiple calculations.

### Where can I find the list of supported calculator commands?

All available commands are defined as keys in the `calc_methods` table within [`lua/super_calculator.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/lua/super_calculator.lua) (lines 18–102). The header comments in this file (lines 23–63) also provide a quick reference list of shortcut commands such as `cb` (sum of cubes), `xsqz` (ceiling), and `mod` (modulus).