Skip to content

Commit

Permalink
Merge branch 'feature-snuggletex-integration' of github.com:deybis17/…
Browse files Browse the repository at this point in the history
…jabref into deybis17-feature-snuggletex-integration

# Conflicts:
#	build.gradle
#	src/main/java/module-info.java
#	src/main/resources/journals/journal-list.mv
#	src/main/resources/l10n/JabRef_en.properties
  • Loading branch information
koppor committed Sep 7, 2023
2 parents 29f5cae + 05adf55 commit 4fb512e
Show file tree
Hide file tree
Showing 7 changed files with 382 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We added support for multiple languages for exporting to and importing references from MS Office. [#9699](https://github.com/JabRef/jabref/issues/9699)
- We enabled scrolling in the groups list when dragging a group on another group. [#2869](https://github.com/JabRef/jabref/pull/2869)
- We added the option to automatically download online files when a new entry is created from an existing ID (e.g., DOI). The option can be disabled in the preferences under "Import and Export". [#9756](https://github.com/JabRef/jabref/issues/9756)
- We added an integrity check for more special characters. [#8712](https://github.com/JabRef/jabref/issues/8712)
- We added a new Integrity check for unescaped ampersands. [koppor#585](https://github.com/koppor/jabref/issues/585)
- We added support for parsing `$\backslash$` in file paths (as exported by Mendeley). [forum#3470](https://discourse.jabref.org/t/mendeley-bib-import-with-linked-files/3470)
- We added the possibility to automatically fetch entries when an ISBN is pasted on the main table. [#9864](https://github.com/JabRef/jabref/issues/9864)
Expand Down
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ dependencies {
exclude module: 'fastparse_2.13'
}

implementation "de.rototor.snuggletex:snuggletex:1.3.0"
implementation ("de.rototor.snuggletex:snuggletex-jeuclid:1.3.0") {
exclude group: "org.apache.xmlgraphics"
}

implementation group: 'com.microsoft.azure', name: 'applicationinsights-core', version: '2.4.1'
implementation (group: 'com.microsoft.azure', name: 'applicationinsights-logging-log4j2', version: '2.4.1') {
exclude module: "log4j-core"
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
requires jbibtex;
requires citeproc.java;

requires snuggletex.core;

requires org.apache.pdfbox;
requires org.apache.xmpbox;
requires com.ibm.icu;
Expand Down Expand Up @@ -141,5 +143,4 @@
requires org.antlr.antlr4.runtime;
requires org.libreoffice.uno;
requires de.saxsys.mvvmfx.validation;

}
3 changes: 2 additions & 1 deletion src/main/java/org/jabref/logic/integrity/IntegrityCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public IntegrityCheck(BibDatabaseContext bibDatabaseContext,
new EntryLinkChecker(bibDatabaseContext.getDatabase()),
new CitationKeyDeviationChecker(bibDatabaseContext, citationKeyPatternPreferences),
new CitationKeyDuplicationChecker(bibDatabaseContext.getDatabase()),
new AmpersandChecker()
new AmpersandChecker(),
new LatexIntegrityChecker()
));
if (bibDatabaseContext.isBiblatexMode()) {
entryCheckers.addAll(List.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.jabref.logic.integrity;

import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;

import org.jabref.logic.l10n.Localization;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.ac.ed.ph.snuggletex.ErrorCode;
import uk.ac.ed.ph.snuggletex.InputError;
import uk.ac.ed.ph.snuggletex.SnuggleEngine;
import uk.ac.ed.ph.snuggletex.SnuggleInput;
import uk.ac.ed.ph.snuggletex.SnuggleSession;
import uk.ac.ed.ph.snuggletex.definitions.CoreErrorCode;
import uk.ac.ed.ph.snuggletex.definitions.CoreErrorGroup;

public class LatexIntegrityChecker implements EntryChecker {

private static final Logger LOGGER = LoggerFactory.getLogger(SnuggleSession.class);
private static final SnuggleEngine ENGINE = new SnuggleEngine();
private static final SnuggleSession SESSION = ENGINE.createSession();
private static final ResourceBundle ERROR_MESSAGES = ENGINE.getPackages().get(0).getErrorMessageBundle();
private static final Set<ErrorCode> EXCLUDED_ERRORS = new HashSet<>();

static {
// Static configuration.
SESSION.getConfiguration().setFailingFast(true);

// '#' only allowed inside and command/environment definitions.
EXCLUDED_ERRORS.add(CoreErrorCode.TTEG04);
}

@Override
public List<IntegrityMessage> check(BibEntry entry) {
List<IntegrityMessage> results = new ArrayList<>();

for (Map.Entry<Field, String> field : entry.getFieldMap().entrySet()) {
SnuggleInput input = new SnuggleInput(field.getValue());
try {
SESSION.parseInput(input);
} catch (IOException e) {
LOGGER.error("Error at parsing", e);
}
if (!SESSION.getErrors().isEmpty()) {
// Retrieve the first error only because it is likely to be more meaningful.
// Displaying all (subsequent) faults may lead to confusion.
// We further get a slight performance benefit from failing fast (see static config in class header).
InputError error = SESSION.getErrors().get(0);
ErrorCode errorCode = error.getErrorCode();
// Exclude all DOM building errors as this functionality is not used.
// Further, exclude individual errors.
if (!errorCode.getErrorGroup().equals(CoreErrorGroup.TDE) && !EXCLUDED_ERRORS.contains(errorCode)) {
String jabrefMessageWrapper = errorMessageFormatHelper(errorCode, error.getArguments());
results.add(new IntegrityMessage(jabrefMessageWrapper, entry, field.getKey()));
}
}
SESSION.reset();
}
return results;
}

public static String errorMessageFormatHelper(ErrorCode snuggleTexErrorCode, Object... arguments) {
String snuggletexMessagePattern = LatexIntegrityChecker.ERROR_MESSAGES.getString(snuggleTexErrorCode.getName());
String snuggletexErrorMessage = MessageFormat.format(snuggletexMessagePattern, arguments);
return Localization.lang("LaTeX Parsing Error: %0", snuggletexErrorMessage);
}
}



1 change: 1 addition & 0 deletions src/main/resources/l10n/JabRef_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ changes\ all\ letters\ to\ lower\ case.=changes all letters to lower case.
CHANGES\ ALL\ LETTERS\ TO\ UPPER\ CASE.=CHANGES ALL LETTERS TO UPPER CASE.
Changes\ The\ First\ Letter\ Of\ All\ Words\ To\ Capital\ Case\ And\ The\ Remaining\ Letters\ To\ Lower\ Case.=Changes The First Letter Of All Words To Capital Case And The Remaining Letters To Lower Case.
Cleans\ up\ LaTeX\ code.=Cleans up LaTeX code.
LaTeX\ Parsing\ Error: %0\:=LaTeX Parsing Error: %0
Converts\ HTML\ code\ to\ LaTeX\ code.=Converts HTML code to LaTeX code.
HTML\ to\ Unicode=HTML to Unicode
Converts\ HTML\ code\ to\ Unicode.=Converts HTML code to Unicode.
Expand Down
Loading

0 comments on commit 4fb512e

Please sign in to comment.