0.21.4 • Published 8 months ago

@artcompiler/translatex v0.21.4

Weekly downloads
-
License
MIT
Repository
-
Last release
8 months ago

TransLaTeX

A library for translating LaTeX

DESCRIPTION

This module implements a LaTeX translator using translation rules written in L120.

BUILD

$ make

This command will run ESLint linter and Jest tests.

INSTALLING

$ npm i './translatex'

where ./translatex refers to the directory that contains this repo.

CALLING

import {TransLaTeX} from '@artcompiler/translatex'
const str = TransLaTeX.translate(rules, '-1+2');
console.log(str);  // (negative (number one)) plus (number two)

where rules is a rules object created using L120. For example: https://gc.acx.ac/item?id=3LgCjBbX9u0

A rules object is the DATA JSON obtained by clicking the DATA link in the navigation bar at the top of the Graffiticode browser window. Here is a sample: https://gc.acx.ac/data?id=3LgCjBbX9u0

NUMBER FORMATTING

TransLaTeX supports Excel-like number formatting using the $fmt expander. This allows you to format numbers with different currency symbols, thousands separators, and decimal places.

Format String Syntax

The format string uses Excel-like patterns:

  • # - Optional digit
  • 0 - Required digit
  • , - Thousands separator (position determines separator type)
  • . - Decimal separator (position determines separator type)
  • Currency symbols: $, , ¥, £, , , ¢
  • _ prefix for suffix placement (e.g., _$ puts $ at the end)
Examples
// US Dollar format with comma thousands separator
const rules = {
  rules: { "?": ["$fmt{%1,$#,##0.00}"] }
};
TransLaTeX.translate(rules, "1234.56");  // "$1,234.56"

// European format with dot thousands, comma decimal
const rules = {
  rules: { "?": ["$fmt{%1,€#.##0,00}"] }
};
TransLaTeX.translate(rules, "1234.56");  // "€1.234,56"

// Japanese Yen (no decimals)
const rules = {
  rules: { "?": ["$fmt{%1,¥#,##0}"] }
};
TransLaTeX.translate(rules, "1234.56");  // "¥1,235"

// Currency suffix
const rules = {
  rules: { "?": ["$fmt{%1,#,##0.00_$}"] }
};
TransLaTeX.translate(rules, "1234.56");  // "1,234.56$"

// French format with space thousands separator
const rules = {
  rules: { "?": ["$fmt{%1,€# ##0,00}"] }
};
TransLaTeX.translate(rules, "1234567.89");  // "€1 234 567,89"

// International format with space separator
const rules = {
  rules: { "?": ["$fmt{%1,# ##0.00_$}"] }
};
TransLaTeX.translate(rules, "1234567.89");  // "1 234 567.89$"

// US Dollar with space separator (no decimals)
const rules = {
  rules: { "?": ["$fmt{%1,$# ##0}"] }
};
TransLaTeX.translate(rules, "12345.67");  // "$12 346"
Environment-Based Formatting

The $fmt expander can also get formatting instructions from the environment, which enables per-cell formatting in spreadsheet applications:

// Cell-based formatting (typical Graffiticode usage)
const formatRules = {
  rules: {
    "\\type{number}": ["$fmt"],
    "?": ["%1"]
  }
};

const options = {
  allowInterval: true,
  RHS: false,
  env: { format: "Currency" },  // Format from cell
  ...formatRules
};

TransLaTeX.translate(options, "1500.75", (err, val) => {
  console.log(val);  // "$1,500.75"
});

// Integration example (formatCellValue pattern)
const formatCellValue = ({ env, name }) => {
  const { val, format } = env.cells[name] || {};
  if (format && val.length > 0) {
    const options = {
      allowInterval: true,
      RHS: false,
      env: { format },
      ...formatRules
    };
    TransLaTeX.translate(options, val, (err, result) => {
      return result;  // Formatted value
    });
  }
  return val;  // Unformatted value
};
Supported Currency Symbols
  • $ - US Dollar
  • - Euro
  • ¥ - Japanese Yen
  • £ - British Pound
  • - Indian Rupee
  • - Russian Ruble
  • ¢ - Cent
Thousands Separators
  • Comma (,) - Used in US, UK: 1,234.56
  • Dot (.) - Used in Europe: 1.234,56
  • Space () - Used in France, Germany, Russia, International: 1 234 567,89

The separator behavior is determined by the pattern:

  • #,##0.00 = comma thousands, dot decimal (US/UK)
  • #.##0,00 = dot thousands, comma decimal (European)
  • # ##0,00 = space thousands, comma decimal (French/International)
  • # ##0.00 = space thousands, dot decimal (Canadian/Scientific)
Countries Using Space Separators

Space as thousands separator is used in:

  • France - €1 234 567,89
  • Germany - 1 234 567,50 €
  • Russia - ₽1 234 567,89
  • Poland, Czech Republic, Slovakia - 1 234 567,89
  • Nordic countries (Sweden, Norway, Finland) - 1 234 567,89
  • Scientific/International documents - Following ISO 31-0 standard
0.21.0

8 months ago

0.20.1

8 months ago

0.19.8

11 months ago

0.20.0

8 months ago

0.19.0

1 year ago

0.18.1

1 year ago

0.19.1

1 year ago

0.18.2

1 year ago

0.19.2

1 year ago

0.19.3

1 year ago

0.19.4

1 year ago

0.19.5

1 year ago

0.19.6

1 year ago

0.19.7

11 months ago

0.16.0

1 year ago

0.17.0

1 year ago

0.16.1

1 year ago

0.18.0

1 year ago

0.17.1

1 year ago

0.21.4

8 months ago

0.21.3

8 months ago

0.21.2

8 months ago

0.21.1

8 months ago

0.20.2

8 months ago

0.9.0

4 years ago

0.7.4

4 years ago

0.7.3

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago