NanoMichael / MicroTeX

A dynamic, cross-platform, and embeddable LaTeX rendering library
MIT License
399 stars 66 forks source link

NthRoot CreateBox is not created as epxected with visually identical #135

Closed Godricly closed 1 year ago

Godricly commented 1 year ago
  1. The Sqrt Atom was created here by calling NthRoot constructor with base and root Atom.

https://github.com/NanoMichael/MicroTeX/blob/master/src/core/macro_impl.h#L300

inline macro(sqrt) {
  if (args[2].empty()) return sptrOf<NthRoot>(Formula(tp, args[1], false)._root, nullptr);
  return sptrOf<NthRoot>(
    Formula(tp, args[1], false)._root,
    Formula(tp, args[2], false)._root
  );
}
  1. when root atom is a nullptr, the root atom is replaced by an EmptyAtom. https://github.com/NanoMichael/MicroTeX/blob/master/src/atom/atom_impl.h#L702

    NthRoot(const sptr<Atom>& base, const sptr<Atom>& root) {
    _base = base == nullptr ? sptrOf<EmptyAtom>() : base;
    _root = root == nullptr ? sptrOf<EmptyAtom>() : root;
    }
  2. The square-root case is not skipped properly Since root atom will never be nullptr. The square root is rendered through codes behind this line with a different structure.. https://github.com/NanoMichael/MicroTeX/blob/master/src/atom/atom_impl.cpp#L232

    // simple square-root
    if (_root == nullptr) return squareRoot;
NanoMichael commented 1 year ago

May you give an example to demonstrate how it is rendered?

BTW, the master branch is going to deprecate, you may want to take a look at the branch openmath, and any PR is appreciated.

Godricly commented 1 year ago

The rendered images are identical, but the structure are different.

Godricly commented 1 year ago

BTW, whats difference between the openmath branch and the master branch? My purpose is to synthesis characters for downstream formula recognition task, the visible location of a character is crucial for me.

NanoMichael commented 1 year ago

The openmath is a refactor of the master, and with Unicode-math functionality. You can use different fonts to render your formulas on the openmath branch, which is impossible on the master branch. The render result should be identical on both branches if you use the Latin-modern-math font.