verybadcat/CSharpMath

MathListToString: What is a correct way to handle placeholder ?

Closed this issue · 3 comments

Since 82317faf commit 2 test for CSharpMath.Editor.Tests.MathKeyboardTests are broken:

TestName Inputs Expected Actual
AtomInput [Power, Power, Power] □^{□^{□^■}} \square ^{\square ^{\square ^■}}
SubscriptWorksAtBeginningOfLine [Subscript] □_■ \square _■

Handler for this case was counted separately:

var command = MathAtoms.LatexSymbolNameForAtom((MathAtom)atom);
if (command == null) {
  if (atom is Extension.I_ExtensionAtom ext)
    builder.Append(Extension._MathListDestructor.MathAtomToString(ext));
  else
    builder.Append(aNucleus);
} else {
  builder.Append(@"\" + command + " ");
}

Now command isn't null but square, so the check doesn't apply here.

I'm not sure what will be the best way to handle it:

  • Check special cases before requesting LatexSymbolNameForAtom?
  • Don't change the code but adjust tests ?

Ideally the command should be returned. E.g. \sin instead of \mathrm{sin}. Therefore, the items to change are probably the tests.

Great. What about next part of the code:

if (atom is Extension.I_ExtensionAtom ext)
    builder.Append(Extension._MathListDestructor.MathAtomToString(ext));

Is there are any cases when it isn't redundant / obsolete?

It was intended to separate the iosMath-derived parts from CSharpMath-specific parts. However, since iosMath doesn't get much development, it would make sense to simplify the type hierarchy. The only type to change is RaiseBox.