Skip to content

Commit

Permalink
Closes #145
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainhalle committed Mar 31, 2021
1 parent ace6a5a commit 3d77030
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,22 @@ protected AnnotatedString replaceInlineEquations(AnnotatedString as_out, int lin
{
Match m = null;
Position p = Position.ZERO;
// Do it one last time for equations at the beginning of a line
m = as_out.find("^\\$.*?[^\\\\]\\$", p);
if (m != null)
{
p = m.getPosition();
String s_from = m.getMatch();
String s_to = "X";
String s_inside = s_from.substring(1, s_from.length() - 1);
if (s_inside.matches("[\\dA-Za-z\\.,]+"))
{
s_to = s_inside;
}
as_out = as_out.replaceAll(Pattern.quote(s_from), s_to);
}
m = null;
p = Position.ZERO;
do
{
m = as_out.find("[^\\\\]\\$.*?[^\\\\]\\$", p);
Expand All @@ -413,20 +429,6 @@ protected AnnotatedString replaceInlineEquations(AnnotatedString as_out, int lin
as_out = as_out.replaceAll(Pattern.quote(s_from), s_to);
p = p.moveBy(1); // To ensure progress
} while (m != null);
// Do it one last time for equations at the beginning of a line
m = as_out.find("^\\$.*?[^\\\\]\\$", p);
if (m != null)
{
p = m.getPosition();
String s_from = m.getMatch();
String s_to = "X";
String s_inside = s_from.substring(1, s_from.length() - 1);
if (s_inside.matches("[\\dA-Za-z\\.,]+"))
{
s_to = s_inside;
}
as_out = as_out.replaceAll(Pattern.quote(s_from), s_to);
}
return as_out;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ public void testRemoveMathMarkup5() throws TextCleanerException
assertEquals("Hello X world", as.toString());
}

@Test
public void testRemoveMathMarkup6() throws TextCleanerException
{
LatexCleaner detexer = new LatexCleaner().setIgnoreBeforeDocument(false);
AnnotatedString as = detexer.clean(AnnotatedString.read(new Scanner("Consider the following: Let" + CRLF + "$x=7$ and blahblah $y=5$ in the above.")));
assertEquals("Consider the following: Let" + CRLF + "X and blahblah X in the above.", as.toString());
}

@Test
public void testRemoveEnvironments1() throws TextCleanerException
{
Expand Down

0 comments on commit 3d77030

Please sign in to comment.