+-- Find any subscripts in the given word and typeset them
+function buffers.visualizers.lam.do_subscripts(word)
+ local match_mul = buffers.visualizers.lam.match_mul
+ base, sub = match_mul(res, submatches)
+ if sub then
+ word = base .. "\\low{" .. sub .. "}"
+ -- After a word has been used as a base, allow subscripts
+ -- without _, even for non-numbers.
+ if not bases[base] then
+ -- Register that we've added this base
+ bases[base] = true
+ -- Add a pattern for this base
+ submatches[#submatches+1] = "^(" .. base .. ")([%a%d,]+)$"
+ end
+ end
+ return word
+end
+
+function buffers.visualizers.lam.begin_of_buffer(type, name)
+ -- Initially allow subscripts using _ or just appending a number (later,
+ -- we will add extra patterns here.
+ submatches = {"^(.*)_([%a%d,]+)$", "^(.*[^%d])(%d+)$"}
+ -- This stores all the bases we've encountered so far (to prevent
+ -- duplicates). For each of them there will be a pattern in submatches
+ -- above.
+ bases = {}
+end
+