Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Auto detect text files and perform LF normalization
* text=auto

# Ensure shell scripts always use LF
*.sh text eol=lf

# Ensure Windows scripts always use CRLF
*.bat text eol=crlf
*.cmd text eol=crlf
*.ps1 text eol=crlf
58 changes: 29 additions & 29 deletions CSharpMath.Avalonia.Example/MainView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Styling;
namespace CSharpMath.Avalonia.Example {
public class MainView : UserControl {
public MainView() {
InitializeComponent();
var light = this.Find<RadioButton>("lightThemeRbn")!;
var dark = this.Find<RadioButton>("darkThemeRbn")!;
if ((string)Application.Current!.ActualThemeVariant.Key == "Dark")
dark.IsChecked = true;
else light.IsChecked = true;
light.IsCheckedChanged += (sender, e) => {
Application.Current!.RequestedThemeVariant =
light.IsChecked == true ? ThemeVariant.Light : ThemeVariant.Dark;
};
dark.IsCheckedChanged += (sender, e) => {
Application.Current!.RequestedThemeVariant =
dark.IsChecked == false ? ThemeVariant.Light : ThemeVariant.Dark;
};
}
private void InitializeComponent() {
AvaloniaXamlLoader.Load(this);
}
}
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Styling;

namespace CSharpMath.Avalonia.Example {
public class MainView : UserControl {
public MainView() {
InitializeComponent();

var light = this.Find<RadioButton>("lightThemeRbn")!;
var dark = this.Find<RadioButton>("darkThemeRbn")!;
if ((string)Application.Current!.ActualThemeVariant.Key == "Dark")
dark.IsChecked = true;
else light.IsChecked = true;
light.IsCheckedChanged += (sender, e) => {
Application.Current!.RequestedThemeVariant =
light.IsChecked == true ? ThemeVariant.Light : ThemeVariant.Dark;
};
dark.IsCheckedChanged += (sender, e) => {
Application.Current!.RequestedThemeVariant =
dark.IsChecked == false ? ThemeVariant.Light : ThemeVariant.Dark;
};
}

private void InitializeComponent() {
AvaloniaXamlLoader.Load(this);
}
}
}
16 changes: 8 additions & 8 deletions CSharpMath.Evaluation.Tests/CSharpMath.Evaluation.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--The Xunit auto-generated namespace should not overwrite CSharpMath.Evaluation-->
<RootNamespace>CSharpMath.EvaluationTests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../CSharpMath.Evaluation/CSharpMath.Evaluation.csproj" />
</ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!--The Xunit auto-generated namespace should not overwrite CSharpMath.Evaluation-->
<RootNamespace>CSharpMath.EvaluationTests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../CSharpMath.Evaluation/CSharpMath.Evaluation.csproj" />
</ItemGroup>
</Project>
2,110 changes: 1,055 additions & 1,055 deletions CSharpMath.Evaluation.Tests/EvaluationTests.cs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions CSharpMath.Xaml.Tests.NuGet/CSharpMath.Xaml.Tests.NuGet.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="CSharpMath.Avalonia" Version="0.5.0-alpha4" />
<PackageReference Include="Avalonia.Skia" Version="0.10.0" />
</ItemGroup>
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="CSharpMath.Avalonia" Version="0.5.0-alpha4" />
<PackageReference Include="Avalonia.Skia" Version="0.10.0" />
</ItemGroup>
</Project>
50 changes: 25 additions & 25 deletions CSharpMath.Xaml.Tests.NuGet/Test.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
namespace CSharpMath.Xaml.Tests.NuGet {
using Avalonia;
public class Program {
static string File(string platform, [System.Runtime.CompilerServices.CallerFilePath] string thisDir = "") =>
System.IO.Path.Combine(thisDir, "..", $"Test.{platform}.png");
[Xunit.Fact]
public void TestImage() {
// TODO: old versions of SkiaSharp fail to initialize on arm64 macOS since they only have x64 native libraries
//global::Avalonia.Skia.SkiaPlatform.Initialize();
// TODO: Update to use MAUI package
//using (var forms = System.IO.File.OpenWrite(File(nameof(Forms))))
// new Forms.MathView { LaTeX = "1", FontSize = 50 }.Painter.DrawAsStream()?.CopyTo(forms);
// TODO: Fix Avalonia package issue complaining about missing Avalonia.Visual reference.
//using (var avalonia = System.IO.File.OpenWrite(File(nameof(Avalonia))))
// new Avalonia.MathView { LaTeX = "1", FontSize = 50 }.Painter.DrawAsPng(avalonia);
var expected = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform
(System.Runtime.InteropServices.OSPlatform.Windows) ? 344 : 292;
//using (var forms = System.IO.File.OpenRead(File(nameof(Forms))))
// Xunit.Assert.Equal(expected, forms.Length);
//using (var avalonia = System.IO.File.OpenRead(File(nameof(Avalonia))))
// Xunit.Assert.Equal(expected, avalonia.Length);
}
}
namespace CSharpMath.Xaml.Tests.NuGet {
using Avalonia;
public class Program {
static string File(string platform, [System.Runtime.CompilerServices.CallerFilePath] string thisDir = "") =>
System.IO.Path.Combine(thisDir, "..", $"Test.{platform}.png");
[Xunit.Fact]
public void TestImage() {
// TODO: old versions of SkiaSharp fail to initialize on arm64 macOS since they only have x64 native libraries
//global::Avalonia.Skia.SkiaPlatform.Initialize();

// TODO: Update to use MAUI package
//using (var forms = System.IO.File.OpenWrite(File(nameof(Forms))))
// new Forms.MathView { LaTeX = "1", FontSize = 50 }.Painter.DrawAsStream()?.CopyTo(forms);
// TODO: Fix Avalonia package issue complaining about missing Avalonia.Visual reference.
//using (var avalonia = System.IO.File.OpenWrite(File(nameof(Avalonia))))
// new Avalonia.MathView { LaTeX = "1", FontSize = 50 }.Painter.DrawAsPng(avalonia);

var expected = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform
(System.Runtime.InteropServices.OSPlatform.Windows) ? 344 : 292;
//using (var forms = System.IO.File.OpenRead(File(nameof(Forms))))
// Xunit.Assert.Equal(expected, forms.Length);
//using (var avalonia = System.IO.File.OpenRead(File(nameof(Avalonia))))
// Xunit.Assert.Equal(expected, avalonia.Length);
}
}
}
48 changes: 24 additions & 24 deletions CSharpMath/Atom/Atoms/Accent.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
using System.Text;
namespace CSharpMath.Atom.Atoms {
/// <summary>An accented atom</summary>
public sealed class Accent : MathAtom, IMathListContainer {
public MathList InnerList { get; } = new MathList();
System.Collections.Generic.IEnumerable<MathList> IMathListContainer.InnerLists =>
new[] { InnerList };
public Accent(string value, MathList? innerList = null) : base(value) =>
InnerList = innerList ?? new MathList();
public override string DebugString =>
new StringBuilder(@"\accent")
.AppendInBracesOrLiteralNull(Nucleus)
.AppendInBracesOrLiteralNull(InnerList?.DebugString)
.ToString();
public new Accent Clone(bool finalize) => (Accent)base.Clone(finalize);
protected override MathAtom CloneInside(bool finalize) =>
new Accent(Nucleus, InnerList.Clone(finalize));
public override bool ScriptsAllowed => true;
public bool EqualsAccent(Accent other) =>
EqualsAtom(other) && InnerList.NullCheckingStructuralEquality(other?.InnerList);
public override bool Equals(object obj) => obj is Accent a ? EqualsAccent(a) : false;
public override int GetHashCode() => (base.GetHashCode(), InnerList).GetHashCode();
}
using System.Text;

namespace CSharpMath.Atom.Atoms {
/// <summary>An accented atom</summary>
public sealed class Accent : MathAtom, IMathListContainer {
public MathList InnerList { get; } = new MathList();
System.Collections.Generic.IEnumerable<MathList> IMathListContainer.InnerLists =>
new[] { InnerList };
public Accent(string value, MathList? innerList = null) : base(value) =>
InnerList = innerList ?? new MathList();
public override string DebugString =>
new StringBuilder(@"\accent")
.AppendInBracesOrLiteralNull(Nucleus)
.AppendInBracesOrLiteralNull(InnerList?.DebugString)
.ToString();
public new Accent Clone(bool finalize) => (Accent)base.Clone(finalize);
protected override MathAtom CloneInside(bool finalize) =>
new Accent(Nucleus, InnerList.Clone(finalize));
public override bool ScriptsAllowed => true;
public bool EqualsAccent(Accent other) =>
EqualsAtom(other) && InnerList.NullCheckingStructuralEquality(other?.InnerList);
public override bool Equals(object obj) => obj is Accent a ? EqualsAccent(a) : false;
public override int GetHashCode() => (base.GetHashCode(), InnerList).GetHashCode();
}
}
42 changes: 21 additions & 21 deletions CSharpMath/Atom/Atoms/ColorBox.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using System.Drawing;
using System.Text;
namespace CSharpMath.Atom.Atoms {
public sealed class ColorBox : MathAtom, IMathListContainer {
public Color Color { get; set; }
public MathList InnerList { get; }
System.Collections.Generic.IEnumerable<MathList> IMathListContainer.InnerLists =>
new[] { InnerList };
public ColorBox(Color color, MathList innerList) : base(string.Empty) =>
(Color, InnerList) = (color, innerList);
public override string DebugString =>
new StringBuilder(@"\colorbox")
.AppendInBracesOrLiteralNull(Color.ToString())
.AppendInBracesOrLiteralNull(InnerList.DebugString).ToString();
public override bool ScriptsAllowed => false;
public new ColorBox Clone(bool finalize) => (ColorBox)base.Clone(finalize);
protected override MathAtom CloneInside(bool finalize) =>
new ColorBox(Color, InnerList.Clone(finalize));
public override int GetHashCode() => (base.GetHashCode(), Color, InnerList).GetHashCode();
}
using System.Drawing;
using System.Text;

namespace CSharpMath.Atom.Atoms {
public sealed class ColorBox : MathAtom, IMathListContainer {
public Color Color { get; set; }
public MathList InnerList { get; }
System.Collections.Generic.IEnumerable<MathList> IMathListContainer.InnerLists =>
new[] { InnerList };
public ColorBox(Color color, MathList innerList) : base(string.Empty) =>
(Color, InnerList) = (color, innerList);
public override string DebugString =>
new StringBuilder(@"\colorbox")
.AppendInBracesOrLiteralNull(Color.ToString())
.AppendInBracesOrLiteralNull(InnerList.DebugString).ToString();
public override bool ScriptsAllowed => false;
public new ColorBox Clone(bool finalize) => (ColorBox)base.Clone(finalize);
protected override MathAtom CloneInside(bool finalize) =>
new ColorBox(Color, InnerList.Clone(finalize));
public override int GetHashCode() => (base.GetHashCode(), Color, InnerList).GetHashCode();
}
}
70 changes: 35 additions & 35 deletions CSharpMath/Atom/Atoms/Fraction.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
using System.Text;
namespace CSharpMath.Atom.Atoms {
public sealed class Fraction : MathAtom, IMathListContainer {
public MathList Numerator { get; }
public MathList Denominator { get; }
System.Collections.Generic.IEnumerable<MathList> IMathListContainer.InnerLists =>
new[] { Numerator, Denominator };
public Boundary LeftDelimiter { get; set; }
public Boundary RightDelimiter { get; set; }
/// <summary>In this context, a "rule" is a fraction line.</summary>
public bool HasRule { get; }
public Fraction(MathList numerator, MathList denominator, bool hasRule = true) =>
(Numerator, Denominator, HasRule) = (numerator, denominator, hasRule);
public override bool ScriptsAllowed => true;
public new Fraction Clone(bool finalize) => (Fraction)base.Clone(finalize);
protected override MathAtom CloneInside(bool finalize) =>
using System.Text;

namespace CSharpMath.Atom.Atoms {
public sealed class Fraction : MathAtom, IMathListContainer {
public MathList Numerator { get; }
public MathList Denominator { get; }
System.Collections.Generic.IEnumerable<MathList> IMathListContainer.InnerLists =>
new[] { Numerator, Denominator };
public Boundary LeftDelimiter { get; set; }
public Boundary RightDelimiter { get; set; }
/// <summary>In this context, a "rule" is a fraction line.</summary>
public bool HasRule { get; }
public Fraction(MathList numerator, MathList denominator, bool hasRule = true) =>
(Numerator, Denominator, HasRule) = (numerator, denominator, hasRule);
public override bool ScriptsAllowed => true;
public new Fraction Clone(bool finalize) => (Fraction)base.Clone(finalize);
protected override MathAtom CloneInside(bool finalize) =>
new Fraction(Numerator.Clone(finalize), Denominator.Clone(finalize), HasRule) {
LeftDelimiter = LeftDelimiter,
RightDelimiter = RightDelimiter
};
public override string DebugString =>
new StringBuilder(HasRule ? @"\frac" : @"\atop")
.AppendInBracketsOrNothing(LeftDelimiter.Nucleus)
.AppendInBracketsOrNothing(RightDelimiter.Nucleus)
.AppendInBracesOrEmptyBraces(Numerator?.DebugString)
.AppendInBracesOrEmptyBraces(Denominator?.DebugString)
.AppendDebugStringOfScripts(this).ToString();
public override bool Equals(object obj) => obj is Fraction f && EqualsFraction(f);
public bool EqualsFraction(Fraction other) =>
EqualsAtom(other)
&& Numerator.NullCheckingStructuralEquality(other.Numerator)
&& Denominator.NullCheckingStructuralEquality(other.Denominator)
&& LeftDelimiter == other.LeftDelimiter
&& RightDelimiter == other.RightDelimiter;
public override int GetHashCode() =>
(base.GetHashCode(), Numerator, Denominator, LeftDelimiter, RightDelimiter).GetHashCode();
}
};
public override string DebugString =>
new StringBuilder(HasRule ? @"\frac" : @"\atop")
.AppendInBracketsOrNothing(LeftDelimiter.Nucleus)
.AppendInBracketsOrNothing(RightDelimiter.Nucleus)
.AppendInBracesOrEmptyBraces(Numerator?.DebugString)
.AppendInBracesOrEmptyBraces(Denominator?.DebugString)
.AppendDebugStringOfScripts(this).ToString();
public override bool Equals(object obj) => obj is Fraction f && EqualsFraction(f);
public bool EqualsFraction(Fraction other) =>
EqualsAtom(other)
&& Numerator.NullCheckingStructuralEquality(other.Numerator)
&& Denominator.NullCheckingStructuralEquality(other.Denominator)
&& LeftDelimiter == other.LeftDelimiter
&& RightDelimiter == other.RightDelimiter;
public override int GetHashCode() =>
(base.GetHashCode(), Numerator, Denominator, LeftDelimiter, RightDelimiter).GetHashCode();
}
}
62 changes: 31 additions & 31 deletions CSharpMath/Atom/Atoms/Inner.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
using System.Text;
namespace CSharpMath.Atom.Atoms {
/// <summary>An inner atom, i.e. embedded math list</summary>
public sealed class Inner : MathAtom, IMathListContainer {
public Inner(Boundary left, MathList innerList, Boundary right) =>
(LeftBoundary, InnerList, RightBoundary) = (left, innerList, right);
public MathList InnerList { get; }
public Boundary LeftBoundary { get; }
public Boundary RightBoundary { get; }
System.Collections.Generic.IEnumerable<MathList> IMathListContainer.InnerLists =>
new[] { InnerList };
public override bool ScriptsAllowed => true;
public new Inner Clone(bool finalize) => (Inner)base.Clone(finalize);
protected override MathAtom CloneInside(bool finalize) =>
new Inner(LeftBoundary, InnerList.Clone(finalize), RightBoundary);
public bool EqualsInner(Inner otherInner) =>
EqualsAtom(otherInner)
&& InnerList.NullCheckingStructuralEquality(otherInner.InnerList)
&& LeftBoundary.NullCheckingStructuralEquality(otherInner.LeftBoundary)
&& RightBoundary.NullCheckingStructuralEquality(otherInner.RightBoundary);
public override bool Equals(object obj) => obj is Inner i ? EqualsInner(i) : false;
public override int GetHashCode() =>
(base.GetHashCode(), InnerList, LeftBoundary, RightBoundary).GetHashCode();
public override string DebugString =>
new StringBuilder(@"\inner")
.AppendInBracesOrEmptyBraces(LeftBoundary.Nucleus)
.AppendInBracesOrLiteralNull(InnerList.DebugString)
.AppendInBracesOrEmptyBraces(RightBoundary.Nucleus)
.AppendDebugStringOfScripts(this).ToString();
}
using System.Text;

namespace CSharpMath.Atom.Atoms {
/// <summary>An inner atom, i.e. embedded math list</summary>
public sealed class Inner : MathAtom, IMathListContainer {
public Inner(Boundary left, MathList innerList, Boundary right) =>
(LeftBoundary, InnerList, RightBoundary) = (left, innerList, right);
public MathList InnerList { get; }
public Boundary LeftBoundary { get; }
public Boundary RightBoundary { get; }
System.Collections.Generic.IEnumerable<MathList> IMathListContainer.InnerLists =>
new[] { InnerList };
public override bool ScriptsAllowed => true;
public new Inner Clone(bool finalize) => (Inner)base.Clone(finalize);
protected override MathAtom CloneInside(bool finalize) =>
new Inner(LeftBoundary, InnerList.Clone(finalize), RightBoundary);
public bool EqualsInner(Inner otherInner) =>
EqualsAtom(otherInner)
&& InnerList.NullCheckingStructuralEquality(otherInner.InnerList)
&& LeftBoundary.NullCheckingStructuralEquality(otherInner.LeftBoundary)
&& RightBoundary.NullCheckingStructuralEquality(otherInner.RightBoundary);
public override bool Equals(object obj) => obj is Inner i ? EqualsInner(i) : false;
public override int GetHashCode() =>
(base.GetHashCode(), InnerList, LeftBoundary, RightBoundary).GetHashCode();
public override string DebugString =>
new StringBuilder(@"\inner")
.AppendInBracesOrEmptyBraces(LeftBoundary.Nucleus)
.AppendInBracesOrLiteralNull(InnerList.DebugString)
.AppendInBracesOrEmptyBraces(RightBoundary.Nucleus)
.AppendDebugStringOfScripts(this).ToString();
}
}
Loading