return nil
end
+function buffers.visualizers.lam.begin_of_buffer()
+ -- 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
+
+function buffers.visualizers.lam.end_of_buffer()
+ -- Reset submatches and bases, since flush_line can be called without
+ -- begin / end_of_buffer for \type.
+ buffers.visualizers.lam.begin_of_buffer()
+ bases = nil
+end
+
+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 bases and 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.flush_line(str,nested)
local result, state = { }, 0
local finish, change = buffers.finish_state, buffers.change_state
local take_symbol = buffers.visualizers.lam.take_symbol
local take_word = buffers.visualizers.lam.take_word
- local match_mul = buffers.visualizers.lam.match_mul
+ local do_subscripts = buffers.visualizers.lam.do_subscripts
-- Set the colorscheme, which is used by finish_state and change_state
buffers.currentcolors = buffers.visualizers.lam.colors
-
while str ~= "" do
local found = false
local word, symbol
-- Make all keywords bold
word = "{\\bold " .. word .. "}"
else
- -- Allow subscripts using _ or just appending a number.
- base, sub = match_mul(res, {"^(.*)_([%a%d,]+)$", "^(.*[^%d])(%d*)$"})
- if sub then
- word = base .. "\\low{" .. sub .. "}"
- end
+ -- Process any subscripts in the word
+ word = do_subscripts(word)
end
else
-- The next token is not a word, it must be a symbol
buffers.flush_result(result,nested)
end
+-- Call end_of_buffer once to set up submatches (since \type doesn't call
+-- begin_of_buffer / end_of_buffer).
+buffers.visualizers.lam.end_of_buffer()
+
-- vim: set sw=4 sts=4 expandtab ai: