Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix conversion of "'n" and "\'{n}" from LaTeX to Unicode #2464

Merged
merged 1 commit into from
Jan 15, 2017
Merged
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
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"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one assert per tests pls...... 😢

}
}