Skip to content

Commit

Permalink
Fix conversion of "'n" and "\'{n}" from LaTeX to Unicode (#2464)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenhard authored and tobiasdiez committed Jan 15, 2017
1 parent 4a49adc commit bc633dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- Backslashes in content selectors are now correctly escaped. Fixes [#2426](https://github.com/JabRef/jabref/issues/2426).
- Non-ISO timestamp settings prevented the opening of the entry editor (see [#2447](https://github.com/JabRef/jabref/issues/2447))
- When pressing <kbd>Ctrl</kbd> + <kbd>F</kbd> and the searchbar is already focused the text will be selected.
- LaTeX symbols are now displayed as Unicode for the author column in the main table. Fixes [#2458](https://github.com/JabRef/jabref/issues/2458).
- LaTeX symbols are now displayed as Unicode for the author column in the main table. "'n" and "\'{n}" are parsed correctly. Fixes [#2458](https://github.com/JabRef/jabref/issues/2458).

### Removed

Expand Down
17 changes: 16 additions & 1 deletion src/main/java/net/sf/jabref/model/strings/LatexToUnicode.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public String format(String inField) {
|| StringUtil.SPECIAL_COMMAND_CHARS.contains(String.valueOf(c))) {
escaped = false;

// a single ' can also be a command
if('\'' == c){
incommand = true;
currentCommand = new StringBuilder();
}

if (!incommand) {
sb.append(c);
} else {
Expand All @@ -83,7 +89,7 @@ public String format(String inField) {
} else {
commandBody = field.substring(i, i + 1);
}
String result = CHARS.get(command + commandBody);
String result = fixCollidingCommand(CHARS.get(command + commandBody), c);

if (result == null) {
// Use combining accents if argument is single character or empty
Expand Down Expand Up @@ -206,4 +212,13 @@ public String format(String inField) {
return result;

}

private String fixCollidingCommand(String currentChar, Character bracket) {
// when stripping Latex, there is a collision between unicode characters 324 and 329. Hence, this needs to be checked
if (!("ʼn".equals(currentChar) && '{' == bracket)) {
return currentChar;
} else {
return "ń";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,10 @@ public void unknownCommandWithEmptyArgumentIsKept() {
public void testTildeN () {
assertEquals("Montaña", formatter.format("Monta\\~{n}a"));
}

@Test
public void testApostrophN () {
assertEquals("Maliński", formatter.format("Mali\\'{n}ski"));
assertEquals("Maliʼnski", formatter.format("Mali'nski"));
}
}

0 comments on commit bc633dc

Please sign in to comment.