From 70b329ebac62e7267e0c2dd9cb842d2cfa112d8b Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 15 Jun 2024 13:36:11 +0300 Subject: [PATCH] chore(packages): Improve error message when a font doesn't support math (#2070) --- packages/math/base-elements.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/math/base-elements.lua b/packages/math/base-elements.lua index df3ba44e1..aa2dfd590 100644 --- a/packages/math/base-elements.lua +++ b/packages/math/base-elements.lua @@ -115,11 +115,18 @@ local function retrieveMathTable (font) if not face then SU.error("Could not find requested font " .. font .. " or any suitable substitutes") end - local mathTable = ot.parseMath(hb.get_table(face, "MATH")) - local upem = ot.parseHead(hb.get_table(face, "head")).unitsPerEm - if mathTable == nil then - SU.error("You must use a math font for math rendering.") + local fontHasMathTable, rawMathTable, mathTableParsable, mathTable + fontHasMathTable, rawMathTable = pcall(hb.get_table, face, "MATH") + if fontHasMathTable then + mathTableParsable, mathTable = pcall(ot.parseMath, rawMathTable) + end + if not fontHasMathTable or not mathTableParsable then + SU.error(([[You must use a math font for math rendering. + + The math table in '%s' could not be %s. + ]]):format(face.filename, fontHasMathTable and "parsed" or "loaded")) end + local upem = ot.parseHead(hb.get_table(face, "head")).unitsPerEm local constants = {} for k, v in pairs(mathTable.mathConstants) do if type(v) == "table" then