generate_label

generate_label(arg, unique_id=False)

Generate formatted label text for use with show_eqn.

This function processes label inputs and returns formatted label strings that include the configured prefix and suffix. It supports multiple input types through singledispatch.

Parameters

Name Type Description Default
arg Any Label input. Can be: - str: Single label string - dict: Dictionary mapping keys to label strings - list: Converted to string representation, then labeled required
unique_id bool If True, generate a unique hash-based ID instead of using the provided label text. Defaults to False. False

Returns

Name Type Description
Any Formatted label(s) with prefix and suffix applied:
Any - str input returns formatted str
Any - dict input returns dict with formatted values
Any - list input returns formatted str (converted via str())

Examples

from keecas import symbols, generate_label

# String label
generate_label("my-label")  # Returns: 'eq-my-label'
'eq-my-label'
# Dict label with subscripted symbols
F, A_load = symbols(r"F, A_{load}")
labels = {F: "force", A_load: "area"}
generate_label(labels)  # Returns: {F: 'eq-force', A_{load}: 'eq-area'}
{F: 'eq-force', A_{load}: 'eq-area'}
# List label (converted to string)
generate_label(["item1", "item2"])  # Returns: "eq-['item1', 'item2']"
"eq-['item1', 'item2']"
# Unique ID generation
label = generate_label("key", unique_id=True)
label.startswith("eq-")  # Returns: True
True

See Also

Notes

  • Labels are formatted with config.latex.eq_prefix and config.latex.eq_suffix
  • Callable labels should be passed directly to show_eqn, not to generate_label
  • Unique IDs are deterministic hash-based identifiers