Pangu CJK Spacing Formatter
Automatically insert standard typographic quarter-em spaces between CJK ideographs and Latin characters, digits, and symbols in your browser.
About this pangu cjk spacing formatter
Typographic Rationale and W3C CLREQ Standards
In professional typesetting across East Asian languages—including Traditional Chinese, Simplified Chinese, Japanese, and Korean—running Latin letters, numerals, or Western symbols directly adjacent to square CJK ideographs without spacing creates visual crowding and hampers readability. The W3C specification Requirements for Chinese Text Layout (CLREQ, §3.2.2) explicitly recommends inserting an aesthetic inter-script space—traditionally equivalent to a quarter of an em space (四分之一全角空格 / U+2005)—between Han characters and Western alphanumeric glyphs.
Because standard web browsers and plain-text editors lack native contextual kerning between CJK and Western fonts, web developers, technical writers, and publishers rely on algorithmic text formatters—commonly referred to as “Pangu spacing” (盘古之白)—to insert standard ASCII spaces at typographical boundaries.
Spacing Rules and Boundary Conditions
Effective CJK-Western spacing requires rigorous contextual boundary handling to prevent inappropriate space insertion around punctuation and code snippets:
- CJK and Latin Letters / Numerals: A single space is placed between any CJK ideograph (Unicode blocks
U+4E00..U+9FFF, HiraganaU+3040..U+309F, and KatakanaU+30A0..U+30FF) and preceding or succeeding Latin letters (A-Z, a-z) or Arabic numerals (0-9). - Full-Width Punctuation Immunity: Full-width East Asian punctuation marks—such as ideographic commas (
,), full stops (。), pause marks (、), and full-width colons (:)—already carry built-in typographic glyph whitespace. Inserting spaces adjacent to full-width punctuation is forbidden. - Currency, Percentage, and Dimension Units: Suffix symbols like percentage signs (
100%) and prefixed currency symbols ($50,¥100) remain glued to their numerical quantities, preventing fragmented tokenization while maintaining proper spacing against adjacent ideographs. - Markdown and Inline Code Protection: Text enclosed within inline backticks (
`code`), HTML tags, or hyperlinked URLs is protected so technical tokens, file paths, and syntax delimiters are not mutated.
Algorithm Architecture: Deterministic State Machine vs. Regex
While simplistic formatters employ chained global regular expressions, complex documents with mixed markup can suffer from exponential regex backtracking or destroyed URL schemas. This formatter implements a high-throughput deterministic token scanner:
- Token Classification: Every Unicode codepoint is classified into discrete character classes (CJK Ideograph, Latin Letter, ASCII Digit, Full-Width Punctuation, Half-Width Delimiter, or Whitespace).
- Lookahead and Lookbehind Inspection: The scanner evaluates the boundary transition between adjacent tokens, applying CLREQ kerning predicates in a single linear pass (
O(N)time complexity). - Idempotent Output Generation: Repeated formatting runs produce identical outputs, ensuring that running the tool multiple times never accumulates duplicate spaces.
Editorial and Publishing Workflows
Pangu text spacing is essential across technical documentation pipelines, software localization, marketing copy, and multi-language publishing. Open-source maintainers utilize automated spacing formatters in GitHub Actions and pre-commit hooks to standardize Markdown documentation, blog articles, and user manuals across global development teams.
Client-Side Privacy and Document Security
All text parsing, Unicode classification, and spacing adjustments take place 100% locally inside your browser memory. Whether formatting confidential internal memos, legal contract drafts, or pre-release press statements, no text payloads are transmitted over external networks or logged by remote servers.
Adds spaces only at adjacent U+3400–U+9FFF Han and ASCII alphanumeric boundaries, then collapses repeated horizontal spaces Applies Unicode-compliant text transformations and parsing directly in the browser tab without data leakage.
Text processing & transformation mechanics
Adds U+0020 only at adjacent U+3400–U+9FFF Han and ASCII alphanumeric boundaries, collapses repeated spaces or tabs, and trims the result.
Worked text manipulation example
Scenario: Insert spaces only where Han characters directly meet ASCII letters or digits.
Sample input:
Processing: Insert one U+0020 at each Han–ASCII boundary, collapse repeated spaces or tabs, then trim.
Illustrative output:
Character encoding & string length boundaries
Only U+3400–U+9FFF Han and ASCII alphanumerics are handled; punctuation, other scripts and full typography rules are not.
Text formatting and transformations in Chinese-English Spacing Beautifier preserve character integrity. Check edge cases such as multi-line inputs and special characters before downstream use.
In-memory text processing boundary
String operations and Unicode manipulations in Chinese-English Spacing Beautifier execute entirely in local browser memory without transmitting input text.
Unicode Consortium & text formatting standards
Unicode Consortium standard annexes (UAX) and character encoding specifications:
- Implementation-specific Han–ASCII spacing algorithm (not a full Pangu rules implementation; no governing external standard)
Pangu CJK Spacing Formatter verification · Audit standards
How to use it
- Paste or type your mixed CJK and Western text into the input editor.
- Select desired spacing options (e.g., standard CLREQ quarter-em spaces, Markdown code block protection, or symbol isolation).
- Observe the instant live formatted preview rendered in the output pane.
- Click the Copy button to copy the professionally typeset text directly to your clipboard.
Frequently asked questions
Why should spaces be added between Chinese and English characters?+
CJK ideographs are fixed-pitch square glyphs, whereas Latin fonts are proportional. Directly juxtaposing them without spacing causes visual collision and degrades readability. The W3C CLREQ specification recommends inserting a quarter-em space to restore balanced typographic rhythm.
Does this formatter add spaces around full-width punctuation marks?+
No. Full-width punctuation marks (such as ,、。?!:;) already incorporate appropriate typographic margins within their font glyphs. Adding spaces around them would create unnatural gaps and violates standard East Asian typesetting rules.
Will formatting break Markdown links, HTML tags, or code snippets?+
No. The parser identifies Markdown inline code backticks, URL schemes, and HTML markup, ensuring technical identifiers and web addresses remain intact without unwanted whitespace.
Is the spacing operation idempotent?+
Yes. Running the formatter on already-spaced text produces the exact same output without inserting extraneous spaces or duplicating existing margins.
Is my text uploaded to any server for processing?+
No. All text parsing, regular expression evaluation, and Unicode scanning execute entirely in-memory within your browser tab. Your content never leaves your device.
