#! /usr/bin/python3 # Last edited on 2026-09-09 11:45:01 by stolfi # To be included in python progs. import sys, os, re from sys import stderr as err from math import inf, sqrt, nan, isnan, isfinite from error_funcs import arg_error, file_line_error, prog_error def name_for_tex_macro(name): # Converts an string {name} to a camel-case string # suitable to include in the name of TeX macros. E.g., # "starps-fu-wc3b-DAIIN-par.ivt" -> "StarpsFuWcCbDAIINParIvp". # The {name} should contain only letters, digits, or [-,.]. # Digits are replaced by uppercase letters [A-J]. assert not re.match(r"[^-,.a-zA-Z0-9]", name), "invalid char" # Map digits to letters A-J: table = str.maketrans('0123456789', 'ABCDEFGHIJ') name = name.translate(table) # Split at '-' and '.', capitalize each segment: els = re.split(r"[-,.]", name) txels = [] for el in els: txel = el[0].upper() + el[1:] txels.append(txel) txname = "".join(txels) return txname # ----------------------------------------------------------------------