Skip to content

Commit

Permalink
Fix issue with rowindent (ForNeVeR#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForNeVeR committed Aug 4, 2019
1 parent fed7257 commit 91a8b63
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
36 changes: 16 additions & 20 deletions src/WpfMath/TexFormulaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,14 @@ private Atom ProcessCommand(
/// <param name="matrixsource">The source to retrieve the 2D-Array of atoms from.</param>
private List<List<Atom>> GetMatrixData(TexFormula formula, SourceSpan matrixsource, bool allowEmptyCells = true, bool parseasArrays = false)
{
List<List<StringBuilder>> rowdata = new List<List<StringBuilder>>() { new List<StringBuilder>() { new StringBuilder() } };
// rowindent: how many characters the next row should skip for its sourcespan to start
var rowdata = new List<List<(StringBuilder builder, int rowindent)>>
{
new List<(StringBuilder, int)> {(new StringBuilder(), 0)}
};
int rows = 0;
int cols = 0;
//how many characters the next row should skip for its sourcespan to start
int rowindent = 0;

//to ensure multiple row separators aren't used
string rowseparationstyle = null;
for (int i = 0; i < matrixsource.ToString().Length; i++)
Expand All @@ -640,11 +643,10 @@ private List<List<Atom>> GetMatrixData(TexFormula formula, SourceSpan matrixsour
}
else
{
rowdata.Add(new List<StringBuilder>() { new StringBuilder() });
rowdata.Add(new List<(StringBuilder, int)> { (new StringBuilder(), 2) });
rows++;
cols = 0;
i++;
rowindent = 2;
rowseparationstyle = "slash";
}
}
Expand All @@ -663,11 +665,10 @@ private List<List<Atom>> GetMatrixData(TexFormula formula, SourceSpan matrixsour
}
else
{
rowdata.Add(new List<StringBuilder>() { new StringBuilder() });
rowdata.Add(new List<(StringBuilder, int)> {(new StringBuilder(), 3)});
rows++;
cols = 0;
i += 2;
rowindent = 3;
rowseparationstyle = "carriagereturn";
}

Expand All @@ -679,25 +680,25 @@ private List<List<Atom>> GetMatrixData(TexFormula formula, SourceSpan matrixsour
}
else if (curchar == '\\' && Char.IsSymbol(nextchar))
{
rowdata[rows][cols].Append(curchar.ToString() + nextchar.ToString());
rowdata[rows][cols].builder.Append($"{curchar}{nextchar}");
i++;
}
else if (curchar == leftGroupChar)
{
var nestedgroup = ReadGroup(matrixsource.ToString(), leftGroupChar, rightGroupChar, i);

rowdata[rows][cols].Append("{" + nestedgroup + "}");
rowdata[rows][cols].builder.Append("{" + nestedgroup + "}");
i += nestedgroup.Length + 1;
}
else if (curchar == '&')
{
//create a new column in the current row.
rowdata[rows].Add(new StringBuilder());
rowdata[rows].Add((new StringBuilder(), 1));
cols++;
}
else
{
rowdata[rows][cols].Append(curchar.ToString());
rowdata[rows][cols].builder.Append(curchar.ToString());
}
}

Expand All @@ -712,7 +713,8 @@ private List<List<Atom>> GetMatrixData(TexFormula formula, SourceSpan matrixsour
List<Atom> rowcellatoms = new List<Atom>();
for (int j = 0; j < rowitem.Count; j++)
{
var cellitem = rowdata[i][j];
var (cellitem, rowindent) = rowdata[i][j];
matrixsrcstart += rowindent;
if (cellitem.ToString().Trim().Length > 0 || cellitem.Length > 0)
{
var cellsource = matrixsource.Segment(matrixsrcstart, cellitem.Length);// new SourceSpan(cellitem, matrixsrcstart, cellitem.Length);
Expand Down Expand Up @@ -742,14 +744,8 @@ private List<List<Atom>> GetMatrixData(TexFormula formula, SourceSpan matrixsour
var cellsource = new SourceSpan(" ", 0, 1);
rowcellatoms.Add(new NullAtom(cellsource));
}
if (j < (rowitem.Count - 1))
{
matrixsrcstart += (cellitem.Length + 1);
}
else
{
matrixsrcstart += (cellitem.Length + rowindent + 1);
}

matrixsrcstart += cellitem.Length;
}

matrixcells.Add(rowcellatoms);
Expand Down
13 changes: 8 additions & 5 deletions src/WpfMath/WpfMath.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
<AssemblyVersion>0.6.0</AssemblyVersion>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Data/*"/>
<Resource Include="Fonts\cmex10.ttf"/>
<Resource Include="Fonts\cmmi10.ttf"/>
<Resource Include="Fonts\cmr10.ttf"/>
<Resource Include="Fonts\cmsy10.ttf"/>
<EmbeddedResource Include="Data/*" />
<Resource Include="Fonts\cmex10.ttf" />
<Resource Include="Fonts\cmmi10.ttf" />
<Resource Include="Fonts\cmr10.ttf" />
<Resource Include="Fonts\cmsy10.ttf" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
</ItemGroup>
</Project>

0 comments on commit 91a8b63

Please sign in to comment.