# How to Set Up Double Pinyin (双拼) Schemes in the Wanxiang Rime Input Method

> Easily set up double pinyin schemes in Rime's Wanxiang input method. Activate layouts with slash commands or personalize by editing custom yaml files for a smoother typing experience.

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

---

**You can activate any standard double pinyin layout instantly by typing a slash command (e.g., `/flypy` for 小鹤双拼) or make it permanent by editing [`custom/wanxiang.custom.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/custom/wanxiang.custom.yaml) to reference the desired algebra rules.**

The Wanxiang input method for Rime ships with a full-pinyin core that transforms into various double pinyin schemes through **speller algebra**. This article explains how to set up double pinyin (双拼) schemes in the `amzxyz/rime_wanxiang` repository using the built-in patch system and Lua commands.

## How Double Pinyin Transformation Works

Wanxiang implements double pinyin through three coordinated components:

- **[`wanxiang_algebra.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_algebra.yaml)** – Contains conversion tables for every supported layout (小鹤, 微软, 搜狗, 智能 ABC, 紫光, 国标, 万象, 自然码). Each block defines `xform` and `derive` rules that map full-pinyin codes to double-pinyin codes.
- **[`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml)** – The main schema file. Its `speller/algebra` section points to `wanxiang_algebra:/base/全拼` by default, but accepts patches to swap in any double-pinyin base.
- **[`lua/set_schema.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/lua/set_schema.lua)** – A Lua translator that listens for slash commands (e.g., `/flypy`, `/mspy`) and writes the appropriate patch to your user directory.

When you invoke a command, [`set_schema.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/set_schema.lua) creates a patch file that replaces the base algebra reference, causing Rime to use the double-pinyin conversion table instead of full-pinyin.

## Switching Double Pinyin Schemes On-the-Fly

To change layouts without editing configuration files, type one of these commands while the input method is active:

| Command | Layout | Algebra Reference |
|---------|--------|-------------------|
| `/flypy` | 小鹤双拼 | `wanxiang_algebra:/base/小鹤双拼` |
| `/mspy` | 微软双拼 | `wanxiang_algebra:/base/微软双拼` |
| `/sogou` | 搜狗双拼 | `wanxiang_algebra:/base/搜狗双拼` |
| `/ziguang` | 紫光双拼 | `wanxiang_algebra:/base/紫光双拼` |
| `/gbpy` | 国标双拼 | `wanxiang_algebra:/base/国标双拼` |
| `/wxsp` | 万象双拼 | `wanxiang_algebra:/base/万象双拼` |
| `/zrm` | 自然码双拼 | `wanxiang_algebra:/base/自然码双拼` |
| `/pinyin` | 全拼 (reset) | `wanxiang_algebra:/base/全拼` |

The `lua_translator@*set_schema` entry in [`wanxiang.schema.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang.schema.yaml) (line 80) triggers [`set_schema.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/set_schema.lua), which writes the following patch to [`custom/wanxiang.custom.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/custom/wanxiang.custom.yaml):

```yaml
patch:
  speller/algebra:
    __patch:
      - wanxiang_algebra:/base/小鹤双拼

```

After the file is written, **deploy the schema** (press *Deploy* or restart Rime). The transformation rules take effect immediately.

## Setting a Default Double Pinyin Layout

To make a specific layout the default instead of full-pinyin, create a persistent patch:

1. Open or create [`custom/wanxiang.custom.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/custom/wanxiang.custom.yaml) in your Rime user directory (e.g., `~/.config/ibus/rime/custom/`).
2. Add the following content:

```yaml

# wanxiang.custom.yaml - Make 小鹤双拼 the default

patch:
  speller/algebra:
    __patch:
      - wanxiang_algebra:/base/小鹤双拼

```

3. Deploy the schema once.

Rime merges this patch with the main schema on startup. The `__patch` directive replaces the default `speller/algebra` entry, so the double-pinyin rules load automatically without requiring slash commands.

## Creating Custom Double Pinyin Layouts

You can define proprietary layouts by extending [`wanxiang_algebra.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_algebra.yaml):

1. Locate an existing block (e.g., `小鹤双拼:`) in [`wanxiang_algebra.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_algebra.yaml).
2. Duplicate it, rename it (e.g., `mysp:`), and modify the `xform` rules:

```yaml
mysp:
  __append:
    - xform/^z$/v/
    - xform/^c$/i/
    # ... additional custom mappings ...

```

3. Reference your new block in [`custom/wanxiang.custom.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/custom/wanxiang.custom.yaml):

```yaml
patch:
  speller/algebra:
    __patch:
      - wanxiang_algebra:/base/mysp

```

4. Deploy the schema.

If you want a dedicated slash command for your custom layout, add an entry to the `schema_map` table in [`lua/set_schema.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/lua/set_schema.lua):

```lua
["/mysp"] = "mysp",

```

## Summary

- **Core mechanism**: Double pinyin conversion lives in [`wanxiang_algebra.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_algebra.yaml) as algebra rules that transform full-pinyin input.
- **Instant switching**: Use slash commands (`/flypy`, `/mspy`, etc.) handled by [`lua/set_schema.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/lua/set_schema.lua) to write temporary patches.
- **Permanent setup**: Edit [`custom/wanxiang.custom.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/custom/wanxiang.custom.yaml) to patch `speller/algebra` with your preferred base reference.
- **Customization**: Add new layouts by creating blocks in [`wanxiang_algebra.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_algebra.yaml) and referencing them via the patch system.

## Frequently Asked Questions

### What file controls the double pinyin conversion rules?

The file [`wanxiang_algebra.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/wanxiang_algebra.yaml) in the repository root contains all conversion tables. Each supported scheme (小鹤, 微软, etc.) has a named block defining `xform` and `derive` rules that map full-pinyin syllables to double-pinyin keys.

### Why do I need to deploy after running a slash command?

The [`set_schema.lua`](https://github.com/amzxyz/rime_wanxiang/blob/main/set_schema.lua) script writes a patch file to disk, but Rime only loads configuration changes during the **deploy** phase. Deploying recompiles the schema with the new `speller/algebra` reference, activating the selected double-pinyin layout.

### Can I use double pinyin without the slash commands?

Yes. Instead of using `/flypy` or `/mspy`, manually create [`custom/wanxiang.custom.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/custom/wanxiang.custom.yaml) with a `patch:` section that sets `speller/algebra` to reference your chosen base (e.g., `wanxiang_algebra:/base/小鹤双拼`). This makes the layout active by default whenever Rime starts.

### How do I revert to full pinyin after switching to double pinyin?

Type `/pinyin` while the input method is active, or change your [`custom/wanxiang.custom.yaml`](https://github.com/amzxyz/rime_wanxiang/blob/main/custom/wanxiang.custom.yaml) to reference `wanxiang_algebra:/base/全拼` instead of a double-pinyin base. Deploy the schema to apply the change.