Verified Owner
Top Fields Constructors Methods
org.jabref.logic.preview

public final Class BstPreviewLayout

extends Object
implements PreviewLayout
Class Inheritance
All Implemented Interfaces
org.jabref.logic.preview.PreviewLayout
Annotations
@NullMarked
Imports
java.io.IOException, .InputStream, java.nio.charset.StandardCharsets, java.nio.file.Files, .Path, java.util.List, .Map, java.util.regex.Matcher, .Pattern, org.jabref.logic.bst.BstVM, org.jabref.logic.cleanup.ConvertToBibtexCleanup, org.jabref.logic.formatter.bibtexfields.RemoveNewlinesFormatter, org.jabref.logic.l10n.Localization, org.jabref.logic.layout.format.LatexToUnicodeFormatter, .RemoveLatexCommandsFormatter, .RemoveTilde, org.jabref.logic.openoffice.style.BstStyle, org.jabref.logic.util.StandardFileType, org.jabref.model.database.BibDatabaseContext, org.jabref.model.entry.BibEntry, org.jabref.model.entry.field.Field, org.jabref.model.strings.LatexToUnicodeAdapter, org.antlr.v4.runtime.misc.ParseCancellationException, org.jspecify.annotations.NullMarked, .Nullable, org.slf4j.Logger, .LoggerFactory

Field Summary

Modifier and TypeField and Description
private static final Pattern
private static final Pattern
BRACED_MATH_COMMAND_PATTERN

Matches a single LaTeX math command wrapped in the {{$...$}} form written by some exporters, e.g. {{$\Sigma$}}.

private @Nullable BstVM
private static final Pattern
private static final Pattern
private @Nullable String
private static final Pattern
private static final Pattern
private static final Pattern
private static final Pattern
private static final Logger
private static final Pattern
private final String
private final Path
private String
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
private
BstPreviewLayout(Path path, String source, @Nullable BstVM bstVM, @Nullable String error)

Private constructor used by of(BstStyle) for pre-built internal styles.

public

Method Summary

Modifier and TypeMethod and Description
private static void
convertBracedMathToUnicode(BibEntry entry)

Replaces {{$\Cmd$}} math expressions in all fields of the given entry by the corresponding Unicode character, wrapped in braces.

private static String
private static int
findBalancedGroupEnd(String input, int contentStart)

public String
public String
public Path
public String
public String
public String
public static boolean
isBstStyleFile(String styleFile)

Checks if the given style file is a BST file by checking the extension

private static boolean
isEscaped(String input, int index)

public static BstPreviewLayout
of(BstStyle style)

Creates a BstPreviewLayout for the given BstStyle, supporting both internal (classpath) and external (filesystem) styles.

private static String
private static String
private static int
skipWhitespace(String input, int startIndex)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BIBITEM_PATTERNback to summary
private static final Pattern BIBITEM_PATTERN
BRACED_MATH_COMMAND_PATTERNback to summary
private static final Pattern BRACED_MATH_COMMAND_PATTERN

Matches a single LaTeX math command wrapped in the {{$...$}} form written by some exporters, e.g. {{$\Sigma$}}. Group 1 is the command without its leading backslash (Sigma). Reads as: {{ $ \ (command) $ }}.

bstVMback to summary
private @Nullable BstVM bstVM
COMMENT_PATTERNback to summary
private static final Pattern COMMENT_PATTERN
EMPH_PATTERNback to summary
private static final Pattern EMPH_PATTERN
errorback to summary
private @Nullable String error
GROUP_BF_PATTERNback to summary
private static final Pattern GROUP_BF_PATTERN
GROUP_EM_PATTERNback to summary
private static final Pattern GROUP_EM_PATTERN
GROUP_IT_PATTERNback to summary
private static final Pattern GROUP_IT_PATTERN
LATEX_COMMAND_PATTERNback to summary
private static final Pattern LATEX_COMMAND_PATTERN
LOGGERback to summary
private static final Logger LOGGER
MULTIPLE_SPACES_PATTERNback to summary
private static final Pattern MULTIPLE_SPACES_PATTERN
nameback to summary
private final String name
pathback to summary
private final Path path
sourceback to summary
private String source
TEXTBF_PATTERNback to summary
private static final Pattern TEXTBF_PATTERN
TEXTIT_PATTERNback to summary
private static final Pattern TEXTIT_PATTERN

Constructor Detail

BstPreviewLayoutback to summary
private BstPreviewLayout(Path path, String source, @Nullable BstVM bstVM, @Nullable String error)

Private constructor used by of(BstStyle) for pre-built internal styles.

BstPreviewLayoutback to summary
public BstPreviewLayout(Path path)

Method Detail

convertBracedMathToUnicodeback to summary
private static void convertBracedMathToUnicode(BibEntry entry)

Replaces {{$\Cmd$}} math expressions in all fields of the given entry by the corresponding Unicode character, wrapped in braces. The entry is modified in place, so it has to be a copy.

The BST engine passes $...$ through unchanged, so without this step the raw math reaches the preview and is then stripped by RemoveLatexCommandsFormatter.

The braces around the result are required: they keep BstCaseChanger from lowercasing the symbol (Σ would become σ). This is also the reason BibEntry#getFieldLatexFree cannot be used here -- it resolves the LaTeX, but does not add the protecting braces.

Commands that cannot be resolved are kept as they are: LatexToUnicodeAdapter#format returns its (NFC-normalized) input if parsing fails, so replacing unconditionally would corrupt them.

convertInlineSmallCapsToHtmlback to summary
private static String convertInlineSmallCapsToHtml(String latex)
findBalancedGroupEndback to summary
private static int findBalancedGroupEnd(String input, int contentStart)
generatePreviewback to summary
public String generatePreview(BibEntry originalEntry, BibDatabaseContext databaseContext)

Implements org.jabref.logic.preview.PreviewLayout.generatePreview.

Annotations
@Override
getDisplayNameback to summary
public String getDisplayName()

Implements org.jabref.logic.preview.PreviewLayout.getDisplayName.

Annotations
@Override
getFilePathback to summary
public Path getFilePath()
getNameback to summary
public String getName()

Implements org.jabref.logic.preview.PreviewLayout.getName.

Annotations
@Override
getShortTitleback to summary
public String getShortTitle()

Implements org.jabref.logic.preview.PreviewLayout.getShortTitle.

Annotations
@Override
getTextback to summary
public String getText()

Implements org.jabref.logic.preview.PreviewLayout.getText.

Annotations
@Override
isBstStyleFileback to summary
public static boolean isBstStyleFile(String styleFile)

Checks if the given style file is a BST file by checking the extension

isEscapedback to summary
private static boolean isEscaped(String input, int index)
ofback to summary
public static BstPreviewLayout of(BstStyle style)

Creates a BstPreviewLayout for the given BstStyle, supporting both internal (classpath) and external (filesystem) styles.

replaceCommandWithBalancedArgumentback to summary
private static String replaceCommandWithBalancedArgument(String input, String command)
replaceLegacySwitchWithBalancedArgumentback to summary
private static String replaceLegacySwitchWithBalancedArgument(String input, String command)
skipWhitespaceback to summary
private static int skipWhitespace(String input, int startIndex)