A free program from Microsoft that provides developers with the tools, resources, and sandbox environments needed to build solutions for Microsoft 365.
Word Interop: EQ fields keep reverting Greek letters to default font even after setting Name/NameOther/NameAscii
I’m converting OMML (OMath) to EQ fields in a Word add-in (C#, .NET Framework 4.7.2, Word Interop). The issue: Greek letters inside the EQ field always fall back to the document’s default font (e.g., SimSun), even though I set all font slots (Name, NameAscii, NameOther, NameBi, NameFarEast). Latin letters respect the target font.
Environment:
• .NET Framework 4.7.2, C# 7.3
• Microsoft.Office.Interop.Word
• Target font example: “Tims New Roman” (user setting EquationFontName)
What I see in logs:
• EQ code after normalization: A=πr\s\up(2)α
• Debug warning (Name comes fallback, NameOther is set):
Minimal code (simplified):
string fieldCode = ConvertOMathToEq(omath);
fieldCode = NormalizeUnicodeMathCharacters(fieldCode);
var field = doc.Fields.Add(insertRange, Word.WdFieldType.wdFieldFormula, fieldCode, false);
string fontName = _settings?.EquationFontName ?? "Times New Roman";
field.ShowCodes = true;
ApplyFieldRangeFontFamily(field.Code, fontName);
// tried also: field.Update(); ApplyFieldRangeFontFamily(field.Result, fontName);
ApplyScriptFomratToField(field, scriptReduction); // only shrinks super/subscripts
field.ShowCodes = false;
private static void ApplyFieldRangeFontFamily(Word.Range range, string fontName)
{
range.Font.Name = fontName;
range.Font.NameAscii = fontName;
range.Font.NameOther = fontName;
// tried setting NameFarEast = fontName too; no change
range.Font.NameBi = fontName;
Debug.WriteLine($"expected: {fontName}, actual: {range.Font.Name}, NameOther: {range.Font.NameOther}");
}
What I’ve already tried / know:
- Toggle ShowCodes true → set fonts → ShowCodes false; also tried Update then set Result fonts. Still falls back.
- I map math alphanumeric Unicode to regular Greek (U+03B1, etc.) to avoid Cambria Math dependency.
- NameOther/NameAscii/NameBi are set; Name is empty when read back; final rendering still uses default font for Greek.
- Applying the same ApplyFontFamily to a normal text range works (Greek uses target font). Only EQ fields misbehave.
- Manually selecting the field result in Word UI and changing font forces Greek to the target font. Doing it via code fails.
Questions:
• Is there a reliable way to force Greek letters inside EQ fields to use the specified Latin font (e.g., Trebuchet MS) without fallback?
• Is there a required order (ShowCodes/Update) to make the font stick on Code/Result?
• Do EQ fields have a hidden font priority for non-ASCII? Must NameFarEast/NameOther be combined in a specific way?
• Any sample code or official guidance to ensure Greek in EQ fields obeys the specified font?
Thanks for any insights. I can provide more logs/tests if needed.