ForNeVeR / xaml-math

A collection of .NET libraries for rendering mathematical formulae using the LaTeX typesetting style, for the WPF and Avalonia XAML-based frameworks
MIT License
634 stars 100 forks source link

Suggested solution #484 #485

Open Thor181 opened 4 months ago

ForNeVeR commented 4 months ago

Your current solution yields the following result for a simple matrix \matrix{x & y \\ z & y}: image

As you can see, y is lifted.

I would prefer something like this: image (with better following the vertical free space, though)

This view has been achieved using the following patch (apply on top of your current changes):

Index: src/XamlMath.Shared/Atoms/MatrixAtom.cs
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/XamlMath.Shared/Atoms/MatrixAtom.cs b/src/XamlMath.Shared/Atoms/MatrixAtom.cs
--- a/src/XamlMath.Shared/Atoms/MatrixAtom.cs   (revision Staged)
+++ b/src/XamlMath.Shared/Atoms/MatrixAtom.cs   (date 1710274735726)
@@ -56,33 +56,25 @@
         foreach (var row in cells)
         {
             var rowContainer = new HorizontalBox();
-            var rowHeight = row.Length > 0 ? row.Max(cell => cell.TotalHeight) : 0.0;
+            var rowHeight = row.Length > 0 ? row.Max(cell => cell.Height) : 0.0;

             for (var j = 0; j < columnCount; ++j)
             {
                 var cell = row[j];
                 var columnWidth = columnWidths[j];

-                var vFreeSpace = rowHeight - cell.TotalHeight;
+                var vFreeSpace = rowHeight - cell.Height;
                 var tbGap = (VerticalPadding + vFreeSpace) / 2;

                 var cellContainer = new VerticalBox();
+                var depth = cell.Depth;

-                if (cell.TotalHeight <= 0.54)
-                {
-                    cellContainer.Add(new StrutBox(0.0, vFreeSpace, 0.0, 0.0));
-                    cellContainer.Add(cell);
-                    cellContainer.Add(new StrutBox(0.0, VerticalPadding / 2, 0.0, 0.0));
-                }
-                else
-                {
-                    cellContainer.Add(new StrutBox(0.0, tbGap, 0.0, 0.0));
-                    cellContainer.Add(cell);
-                    cellContainer.Add(new StrutBox(0.0, tbGap, 0.0, 0.0));
-                }
+                cellContainer.Add(new StrutBox(0.0, tbGap, 0.0, 0.0));
+                cellContainer.Add(cell);
+                cellContainer.Add(new StrutBox(0.0, tbGap - depth, 0.0, 0.0));

-                cellContainer.Height = cellContainer.TotalHeight;
-                cellContainer.Depth = 0;
+                cellContainer.Height = cell.Height;
+                cellContainer.Depth = cell.Depth;

                 var hFreeSpace = columnWidth - cell.TotalWidth;
                 var (lGap, rGap) = GetLeftRightGap(hFreeSpace, j);

Could you please investigate this patch and try applying it?