How to Set Up Double Pinyin (双拼) Schemes in the Wanxiang Rime Input Method
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 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– Contains conversion tables for every supported layout (小鹤, 微软, 搜狗, 智能 ABC, 紫光, 国标, 万象, 自然码). Each block definesxformandderiverules that map full-pinyin codes to double-pinyin codes.wanxiang.schema.yaml– The main schema file. Itsspeller/algebrasection points towanxiang_algebra:/base/全拼by default, but accepts patches to swap in any double-pinyin base.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 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 (line 80) triggers set_schema.lua, which writes the following patch to custom/wanxiang.custom.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:
- Open or create
custom/wanxiang.custom.yamlin your Rime user directory (e.g.,~/.config/ibus/rime/custom/). - Add the following content:
# wanxiang.custom.yaml - Make 小鹤双拼 the default
patch:
speller/algebra:
__patch:
- wanxiang_algebra:/base/小鹤双拼
- 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:
- Locate an existing block (e.g.,
小鹤双拼:) inwanxiang_algebra.yaml. - Duplicate it, rename it (e.g.,
mysp:), and modify thexformrules:
mysp:
__append:
- xform/^z$/v/
- xform/^c$/i/
# ... additional custom mappings ...
- Reference your new block in
custom/wanxiang.custom.yaml:
patch:
speller/algebra:
__patch:
- wanxiang_algebra:/base/mysp
- 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:
["/mysp"] = "mysp",
Summary
- Core mechanism: Double pinyin conversion lives in
wanxiang_algebra.yamlas algebra rules that transform full-pinyin input. - Instant switching: Use slash commands (
/flypy,/mspy, etc.) handled bylua/set_schema.luato write temporary patches. - Permanent setup: Edit
custom/wanxiang.custom.yamlto patchspeller/algebrawith your preferred base reference. - Customization: Add new layouts by creating blocks in
wanxiang_algebra.yamland referencing them via the patch system.
Frequently Asked Questions
What file controls the double pinyin conversion rules?
The file 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 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 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 to reference wanxiang_algebra:/base/全拼 instead of a double-pinyin base. Deploy the schema to apply the change.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →