verybadcat / CSharpMath

LaTeX. in C#. (ported from the wonderful iosMath project).
MIT License
380 stars 61 forks source link

API Redesign #58

Open Happypig375 opened 5 years ago

Happypig375 commented 5 years ago

Is your feature request related to a problem? Please describe. Currently, the APIs for CSharpMath are not intuitive at all. For example, to convert MathList->TeX, one has to call MathListBuilder.MathListToString which is a static method (not easy to discover), and its name doesn't imply anything about the result being a TeX string at all.

Describe the solution you'd like

  1. Streamline the use of CSharpMath APIs.

    SkiaSharp.SKCanvas canvas = …;
    "\\frac{1}{2}"
    .TeXToMathAtoms()
    .ToDisplay()
    .ToOutput(canvas);
  2. Replace mutable global variables with settings objects. e.g. CSharpMath.Atoms.MathAtoms contain multiple dictionaries that act as hidden dependencies. They should be made obvious.

  3. Reduce legacy boilerplate code from iosMath. e.g. Why do some math atoms have their respective interfaces? It's not like MathAtoms will have alternate implementations, they are just data containers. If they are to be extended, they can be inherited. e.g. Reduce boilerplate folders. They scare new contributors. Most folders in CSharpMath/ contain few files anyway. e.g. Remove CSharpMath.Enumerations.MathAtomType. Use pattern matching on types instead.

  4. Simplify the NuGet chain. It's not obvious what CSharpMath.Rendering does based on its name. CSharpMath, CSharpMath.Editor and CSharpMath.Rendering should be merged into one. Typography should be integrated directly into CSharpMath because

.NET font reader library name Can read math layout info for glyphs?
NRasterizer :x:
SixLabors.Fonts :x:
SharpFont :x:
Typography :heavy_check_mark:
Source: https://github.com/Jolg42/awesome-typography#c-2

It's not like there is or will be any other implementations for font reading of math fonts.

Describe alternatives you've considered Continuing the current API and result in a degraded user experience.

Difficulty: How difficult would it be? (Trivial, Very Easy, Easy, Moderate, Hard, Very Hard, Tedious, Backbreaking) Very hard. A lot of time will be needed to achieve this.

Additional context

57

Smurf-IV commented 5 years ago

Please can you keep the "Core" of the CSharpMath, out of the need for "Rendering and editor" as this allows it to be used for other frameworks, i.e. Services only.

charlesroddie commented 5 years ago

What are these services and how would CSharpMath be used without rendering?

Smurf-IV commented 5 years ago

@charlesroddie

Happypig375 commented 5 years ago

Other frameworks can still be used. image

Happypig375 commented 5 years ago

Editing capabilities will be baked into MathAtoms.

charlesroddie commented 5 years ago

Streamline the use of CSharpMath APIs.

Very good but not sure about the example. I don't think that we should add extension methods to string! If you are creating object B from A then B.FromA(a:A) is often better because usually A can be defined without reference to B but not vice versa.

Replace mutable global variables with settings objects.

Sounds good.

Reduce legacy boilerplate code from iosMath.

Great.

Simplify the NuGet chain. It's not obvious what CSharpMath.Rendering does based on its name. CSharpMath, CSharpMath.Editor and CSharpMath.Rendering should be merged into one. Typography should be integrated directly into CSharpMath because

That's not a significant problem for users. If the projects have a natural structure where later projects naturally depend on earlier ones, then having things in separate projects enforces that ordering, unlike C# code in the same project. I don't know if this is the case with the current CSharpMath projects though.

Happypig375 commented 4 years ago

An update since the original post:

  1. Streamline the use of CSharpMath APIs: Better solved by documentation as in https://github.com/verybadcat/CSharpMath#major-processes-of-drawing-latex. Extension methods would result in pollution as noted by @charlesroddie.
  2. Replace mutable global variables with settings objects: To do. This is required to support \def, \DeclareMathOperator etc.
  3. Reduce legacy boilerplate code from iosMath: Already done as part of the 0.4 update.
  4. Simplify the NuGet chain: Not a good idea as noted by @charlesroddie.

New items:

  1. Merge the entirety of CSharpMath.Rendering.Text into CSharpMath.Atom. In LaTeX, \text enables text-mode inside math-mode. With a separate implementation of CSharpMath.Rendering.Text, this is impossible. It is also undesirable to maintain two LaTeX parsers and two LaTeX trees at the same time. Moreover, this results in difference functionality between CSharpMath.Atom and CSharpMath.Rendering.Text, e.g. CSharpMath.Atom supports \colorbox while CSharpMath.Rendering.Text supports \fontsize, when such functionality should be present on both implementations. With #143, the same parser can be reused for both math-mode and text-mode with swappable command dictionaries.

An open question is whether to support (MathList->Text LaTeX) on top of (MathList->Math LaTeX). Math LaTeX seems enough for everyday use.

The remaining items will be done as "Parser refactor (part 2)", blocked on #143.

Happypig375 commented 4 years ago

Note for implementing display math inside text: as seen in http://www.dfcd.net/articles/latex/latex.html, we can add a center environment that helps the implementation.