diff --git a/luamml-pdf.sty b/luamml-pdf.sty index 7f1d751..0e2419d 100644 --- a/luamml-pdf.sty +++ b/luamml-pdf.sty @@ -77,6 +77,12 @@ \__luamml_pdf_showlists: } +\NewDocumentCommand \RegisterFamilyMapping {m m} { + \iow_log:x { + LUAMML_INSTRUCTION:REGISTER_MAPPING: \int_use:N #1 : #2 + } +} + \endinput \cs_new:Npn \__luamml_patch_package:nn #1 #2 { diff --git a/pdfmml-logreader.lua b/pdfmml-logreader.lua index 384345a..377f92d 100644 --- a/pdfmml-logreader.lua +++ b/pdfmml-logreader.lua @@ -14,11 +14,18 @@ local luamml_block = l.Cg('LUAMML_FORMULA_BEGIN:' * id * l.P'\n'^1 * l.Ct( local luamml_mark = l.Cg('LUAMML_MARK:' * id * ':' * l.Cs((1 - l.P'\n' + l.Cg('\n' * l.Cc'' - '\nLUAMML_MARK_END\n'))^0) * '\nLUAMML_MARK_END\n' * l.Cc'marks') +local luamml_instruction = l.Cg('LUAMML_INSTRUCTION:' * l.Cc(nil) * l.C((1 - l.P'\n')^0) * '\n' * l.Cc'instructions') + local function multi_table_set(t, key, value, table) - assert(t[table])[key] = value + table = t[table] + table[key or #table + 1] = value return t end -local log_file = l.Cf(l.Ct(l.Cg(l.Ct'', 'groups') * l.Cg(l.Ct'', 'marks')) * (luamml_block + luamml_mark + line)^0, multi_table_set) +local log_file = l.Cf(l.Ct(l.Cg(l.Ct'', 'groups') + * l.Cg(l.Ct'', 'marks') + * l.Cg(l.Ct'', 'instructions')) + * (luamml_block + luamml_mark + luamml_instruction + line)^0, + multi_table_set) return function(filename) local f diff --git a/pdfmml.lua b/pdfmml.lua index 58f509b..2b45dcb 100755 --- a/pdfmml.lua +++ b/pdfmml.lua @@ -4,10 +4,6 @@ local convert = require'luamml-convert' local mappings = require'luamml-legacy-mappings' local to_xml = require'luamml-xmlwriter' -convert.register_family(1, mappings.oml) -convert.register_family(2, mappings.oms) -convert.register_family(3, mappings.omx) - local parse_showlists = require'pdfmml-showlists' local parse_log = require'pdfmml-logreader' @@ -30,9 +26,23 @@ if #arg < 1 then If {outname} includes {}, then a separate file is written for every formula with {} replaced by the formula id.\n', arg[0])) os.exit(1) end -local math_lists = assert(parse_log(assert(try_extensions(arg[1], '.tml', '.log'), +local parsed = assert(parse_log(assert(try_extensions(arg[1], '.tml', '.log'), "Couldn't find input file."))) +for i, inst in ipairs(parsed.instructions) do + local _, _, family, mapping_name = inst:find'^REGISTER_MAPPING:([0-9]+):(.*)$' + if family then + local mapping = mappings[mapping_name] + if mapping then + convert.register_family(tonumber(family), mapping) + else + io.stderr:write(string.format('Unknown mapping %s ignored\n', mapping_name)) + end + else + io.stderr:write'Unknown instruction ignored\n' + end +end + local out_prefix, out_suffix, out_stream if not arg[2] or arg[2] == '-' then out_stream = io.stdout @@ -42,10 +52,10 @@ else out_stream = assert(io.open(arg[2], 'w')) end end -for i, block in ipairs(math_lists.groups) do +for i, block in ipairs(parsed.groups) do local stream = out_stream or assert(io.open(out_prefix .. tostring(i) .. out_suffix, 'w')) block = block[1] - local parsed = parse_showlists(block, nil, nil, math_lists.marks) + local parsed = parse_showlists(block, nil, nil, parsed.marks) local style = block.display and 0 or 2 stream:write( to_xml(convert.make_root(convert.process(parsed, style), style)), '\n' diff --git a/test_pdf.tex b/test_pdf.tex index 5d14c49..9b459f7 100644 --- a/test_pdf.tex +++ b/test_pdf.tex @@ -1,9 +1,9 @@ \documentclass{article} \usepackage{luamml-pdf} -% \RegisterFamilyMapping\symsymbols{oms} -% \RegisterFamilyMapping\symletters{oml} -% \RegisterFamilyMapping\symlargesymbols{omx} +\RegisterFamilyMapping\symsymbols{oms} +\RegisterFamilyMapping\symletters{oml} +\RegisterFamilyMapping\symlargesymbols{omx} \ExplSyntaxOn \cs_set_eq:NN \WriteoutFormula \luamml_pdf_write: