UnicodeIt

repository·main·Indexed 43 days ago

https://github.com/svenkreiss/unicodeit

A utility for converting LaTeX mathematical and symbolic tags into their corresponding Unicode characters. Available as a Python library (v0.7.5), a JavaScript/TypeScript package, and a macOS Automator integration.

Tokens
1.1K
Snippets
5
Records
6
Agent score
6%

What's inside UnicodeIt

  1. Install and use UnicodeIt in JavaScript / TypeScript

    main

    To use UnicodeIt in a JavaScript or TypeScript environment, install it via npm:

    npm install unicodeit --save-dev

    Use the replace method to convert LaTeX tags to Unicode:

    var unicodeit = require('unicodeit');
    console.log(unicodeit.replace('\alpha'));
    var unicodeit = require('unicodeit');
    console.log(unicodeit.replace('\alpha'));
  2. Create a Mac Automator Quick Action for UnicodeIt

    main

    You can create a macOS Quick Action (Service) to convert selected text to Unicode using a keyboard shortcut.

    Setup Steps

    1. Open Automator and create a new Quick Action (or Service).
    2. Set the defaults at the top to: Service receives *selected text* in *any application*.
    3. Check the box: output replaces selected text.
    4. Add the Run Shell Script action.
    5. In the dropdown, select pass in: as arguments.
    6. Enter the following command (ensure your Python interpreter has unicodeit installed): /usr/local/bin/python3 -m unicodeit.cli $1

    Assign a Keyboard Shortcut

    1. Go to System Preferences → Keyboard → Shortcuts → Services → Text.
    2. Find your new action (e.g., UnicodeItAction).
    3. Assign a shortcut, such as Command+Option+Shift U.
  3. Install and use UnicodeIt in Python

    main

    You can use UnicodeIt in Python projects to convert LaTeX tags to Unicode characters.

    To install the package, use pip:

    pip install unicodeit

    CLI Usage

    Run the conversion directly from your terminal using the module CLI:

    python -m unicodeit.cli \alpha

    Programmatic Usage

    Import unicodeit and use the replace function to convert strings containing LaTeX tags:

    import unicodeit
    print(unicodeit.replace('\alpha'))
    pip install unicodeit
    python -m unicodeit.cli \alpha
  4. UnicodeIt LaTeX to Unicode conversion examples

    main

    UnicodeIt supports a wide variety of LaTeX tags. Common examples include:

    LaTeXUnicode
    \alphaα
    \betaβ
    \infty∞
    \int∫
    \sum∑
    \partial∂
    \to→
    \mathcal{H}ℋ
    \mathbb{R}ℝ
    \dot{x}ẋ
    \ddot{x}ẍ
    A^6A⁶
    m_0m₀
    \sfrac{3}{5}⅗
    \alpha α, \beta β, \infty ∞       e^+ e⁺, \mu^- μ⁻               \exists ∃, \nexists ∄
    \int ∫, \sum ∑, \partial ∂        \to →, p\bar{p} pp̅             \mathcal{H} ℋ, \mathbb{R} ℝ
    \slash{\partial} ∂̸                \underline{x} x̲                \phone ☎, \checkmark ✓
    \dot{x} ẋ, \ddot{x} ẍ             A^6 A⁶, m_0 m₀                 \Im ℑ, \Re ℜ, \hbar ℏ
    \gamma γ, \Gamma Γ                \~{O} Õ                        \perp ⊥, \parallel ∥
    \sfrac{3}{5} ⅗                    \therefore ∴, \because ∵       \subset ⊂, \supset ⊃
  5. Convert LaTeX to Unicode using replace()

    main

    The primary entry point for the unicodeit JavaScript/TypeScript library is the replace function. Use this function to convert LaTeX mathematical expressions into their Unicode equivalents within a string.

    import { replace } from 'unicodeit';
    
    const latexString = '$\alpha + \beta = \gamma$';
    const unicodeString = replace(latexString);
    // Result: 'α + β = γ'
  6. Run unicodeit from the command line

    main

    You can use the unicodeit CLI to replace Unicode characters in strings passed as command-line arguments. The CLI accepts one or more strings and outputs the processed strings separated by spaces.

    Each argument provided to the CLI is processed individually by the replace function.

    # Example usage (assuming unicodeit is installed and in your PATH)
    unicodeit "Hello ℌello" "Unicodeit 🚀"