Skip to content

Commit

Permalink
Fix textStyles commands
Browse files Browse the repository at this point in the history
  • Loading branch information
rstm-sf authored and ForNeVeR committed Oct 19, 2019
1 parent 69a3d9c commit b31b833
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 7 deletions.
8 changes: 8 additions & 0 deletions src/WpfMath.Tests/BoxTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,11 @@ let wideItemInMatrixBox() =
[<Fact>]
let emptyColorbox(): unit =
verifyBox @"\colorbox{red}{}"

[<Fact>]
let emptyMathrm(): unit =
verifyBox @"\mathrm{}"

[<Fact>]
let emptyCommandText(): unit =
verifyBox @"\text{}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Children": [],
"Source": {
"Start": 1,
"End": 7,
"Length": 6,
"Source": "\\text{}"
},
"Foreground": null,
"Background": null,
"TotalHeight": 0.0,
"TotalWidth": 0.0,
"Italic": 0.0,
"Width": 0.0,
"Height": 0.0,
"Depth": 0.0,
"Shift": 0.0
}
18 changes: 18 additions & 0 deletions src/WpfMath.Tests/TestResults/BoxTests.emptyMathrm.approved.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"Children": [],
"Source": {
"Start": 1,
"End": 9,
"Length": 8,
"Source": "\\mathrm{}"
},
"Foreground": null,
"Background": null,
"TotalHeight": 0.0,
"TotalWidth": 0.0,
"Italic": 0.0,
"Width": 0.0,
"Height": 0.0,
"Depth": 0.0,
"Shift": 0.0
}
16 changes: 9 additions & 7 deletions src/WpfMath/TexFormulaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,15 @@ private void ProcessEscapeSequence(TexFormula formula,
// Text style was found.
SkipWhiteSpace(value, ref position);

var styledFormula = command == TexUtilities.TextStyleName
? ConvertRawText(ReadElement(value, ref position), command)
: Parse(ReadElement(value, ref position), command, environment.CreateChildEnvironment());

var atom = AttachScripts(formula, value, ref position, styledFormula.RootAtom, true, environment);
var source = new SourceSpan(formulaSource.Source, formulaSource.Start, position);
formula.Add(atom, source);
var remainingString = ReadElement(value, ref position);
var remaining = command == TexUtilities.TextStyleName
? ConvertRawText(remainingString, command)
: Parse(remainingString, command, environment.CreateChildEnvironment());

var source = value.Segment(start, position - start);
var styledAtom = new StyledAtom(source, remaining.RootAtom, null, null);
var commandAtom = AttachScripts(formula, value, ref position, styledAtom, true, environment);
formula.Add(commandAtom, source);
}
else if (embeddedCommands.Contains(command)
|| environment.AvailableCommands.ContainsKey(command)
Expand Down

0 comments on commit b31b833

Please sign in to comment.