ForHosting KIT · Developer Utilities

LaTeX escaper

In 10%_off, LaTeX would read the percent sign as the start of a comment and the underscore as a subscript; escaped as 10\%\_off, both print as written. The same goes for ampersands, dollar signs, braces and backslashes, and the escapes can be undone. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
Text
Cost is $5 & 10%_off
Calculation mode
Escape
You get
Result
Cost is \$5 \& 10\%\_off
Length
24
Specials
4

Pasting free text into a LaTeX document is a classic footgun: an ampersand ends a table cell, a percent starts a comment that swallows the rest of the line, a dollar opens math mode, an underscore starts a subscript, a hash collides with macro parameters, braces change grouping, a tilde becomes a non-breaking space, a caret starts a superscript, and a lone backslash begins a control sequence. This LaTeX escaper turns plain text into a safe fragment you can drop into paragraphs, captions, labels, and bibliography fields, and it reverses the same map when you need the original characters back. Escape mode rewrites every TeX special using portable text-mode sequences such as \&, \%, \$, \_, \#, \{, \}, \textbackslash{}, \textasciitilde{}, and \textasciicircum{}.

How LaTeX special-character escapes work in practice

LaTeX treats a small set of ASCII characters as syntax rather than printable glyphs. The backslash introduces control sequences, so a path like C:\Users must not appear raw in text mode. Ampersand is the column separator in tabular and align environments; percent starts a comment that hides everything until the end of the line; dollar toggles inline math; underscore and caret mark subscripts and superscripts; hash marks macro parameters; braces delimit groups; and tilde is an active character for non-breaking spaces.

When your pipeline injects user titles, product codes, file names, URLs, or CSV cells into a .tex template, any of those specials will change the meaning of the document or abort the compile. This capability walks the input character by character. In escape mode it replaces each special with a standard text-mode sequence: simple specials become a backslash plus the character (\&, \%, \$, \#, \_, \{, \}), while backslash, tilde, and caret use named forms with empty braces so the following letter is never absorbed into a control word.

In unescape mode it matches the longest known sequence first, restores the plain character, and rejects trailing backslashes, truncated \textbackslash{ fragments, incomplete \~ or \^ forms, and any other unrecognized escape so callers never receive silent corruption.

What you send and what you get back

Send a required string field named text and an optional mode field. Mode escape converts plain text into LaTeX-safe text stored in result. Mode unescape reverses known special-character sequences in text and returns the recovered plain string in result.

The response always echoes mode and the original text, and adds result, length of the result, and specials—the count of special characters rewritten in either direction—so UIs can show how much work was done. Classic checks include escaping a price line that contains dollars, ampersands, and percent signs; unescaping a fragment that uses \_ and \textbackslash{}; round-tripping braces and hash marks from a product SKU; and rejecting a string that ends with a bare backslash.

Wire the free browser form for quick checks and classroom demos, then call the identical contract from scripts when you generate reports, invoices, or batch papers.

Where a LaTeX escaper earns its keep

Document generators that merge CRM fields, survey answers, or spreadsheet cells into LaTeX templates must escape every free-text value before write-out, or a single ampersand in a company name will break the tabular and a percent in a discount label will comment out the rest of the row. Academic and publishing pipelines that build title pages, abstracts, and author lists from web forms need a reliable escape path so user-supplied samples remain valid TeX.

Support and localization teams paste log fragments or ticket subjects that already contain backslash escapes and need an unescape path that fails loudly on truncated sequences instead of inventing characters. Curriculum authors teaching TeX specials want one dedicated page for character escaping rather than burying the topic under a generic Base64 or HTML-entity tool, because search intent and the allowed escape set differ.

If you need HTML entities, URL percent-encoding, JavaScript string literals, or full document compilation, treat those as separate search intents and landings rather than overloading this LaTeX escaper page.

Safe free text in generated .tex files

Escape titles, captions, table cells, and bibliography fields before writing them into LaTeX templates so &, %, $, _, and \ never break the compile.

Round-trip product codes and SKUs

Escape and unescape SKUs and path-like strings that mix underscores, hashes, dollars, and backslashes for invoices and technical reports.

Which characters are escaped?

Backslash, ampersand, percent, dollar, underscore, hash, left and right braces, tilde, and caret. Those are the standard TeX specials that change document meaning in text mode.

Can I both escape and unescape?

Yes. Set mode to escape (default) to encode plain text, or mode to unescape to recover text from LaTeX special-character sequences.

Why is backslash written as \textbackslash{} instead of \\?

In LaTeX, \\ is a line break command, not a printable backslash. The named form \textbackslash{} is the portable text-mode way to show a backslash character.

What does it cost?

The browser tool is free and runs locally.

Why does the rest of my line vanish after a percent sign?

Because LaTeX treats the percent sign as the start of a comment and hides everything after it until the end of the line. Escaped as \%, it prints as a normal percent sign and the rest of the line stays visible.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/enc/latex-escape

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/enc/latex-escape \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"Cost is $5 & 10%_off"}'
{
  "text": "Cost is $5 & 10%_off"
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "enc.latex_escape",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Unescape mode understands those forms plus the short \~{} and \^{} variants, and fails immediately with invalid_input on trailing backslashes, incomplete named sequences, or unrecognized escapes instead of inventing half-decoded garbage.

How LaTeX special-character escapes work in practice

The path is pure string work with no network, no random seeds, and no wall-clock timestamps, so identical inputs always produce identical JSON. Pricing for successful API calls is the published base of $0.002 per item, and validation failures do not consume prepaid balance.

What you send and what you get back

When mode is omitted, escape is the default so a single payload still does useful work. Missing text, non-string objects that cannot be coerced, unsupported mode values, strings longer than the documented maximum, trailing backslashes, incomplete named forms such as a cut-off \textbackslash{, incomplete tilde or caret short forms, and unrecognized escape sequences all fail with invalid_input and a clear English message that names the position when possible. Validation failures do not consume prepaid balance. Successful API pricing is the published base of $0.002 per item.

Where a LaTeX escaper earns its keep

Because this capability is a pure parse engine, API pricing is the published base of $0.002 per successful item and failed validation does not consume balance.

Recover plain text from escaped fragments

Unescape LaTeX special-character sequences from templates, logs, and golden fixtures back to readable text, with hard failures on incomplete escapes.

What happens if an escape sequence is malformed?

Unescape fails with invalid_input, naming the position and the problem (for example a trailing backslash or incomplete \textbackslash{). Nothing is charged for validation failures.

Read the full KIT documentation →