@@ -178,7 +178,7 @@ public void writePartOfDatabase(Writer writer, BibDatabaseContext bibDatabaseCon
178178 writePreamble (writer , bibDatabaseContext .getDatabase ().getPreamble ());
179179
180180 // Write strings if there are any.
181- writeStrings (writer , bibDatabaseContext .getDatabase ());
181+ writeStrings (writer , bibDatabaseContext .getDatabase (), preferences . isReformatFile () );
182182
183183 // Write database entries.
184184 List <BibEntry > sortedEntries = BibDatabaseWriter .getSortedEntries (bibDatabaseContext ,
@@ -198,7 +198,7 @@ public void writePartOfDatabase(Writer writer, BibDatabaseContext bibDatabaseCon
198198 entryType -> typesToWrite .put (entryType .getName (), entryType ));
199199 }
200200
201- bibtexEntryWriter .write (entry , writer , bibDatabaseContext .getMode ());
201+ bibtexEntryWriter .write (entry , writer , bibDatabaseContext .getMode (), preferences . isReformatFile () );
202202
203203 }
204204
@@ -324,13 +324,14 @@ private void writePreamble(Writer fw, String preamble) throws IOException {
324324 }
325325 }
326326
327- private void writeString (Writer fw , BibtexString bs , Map <String , BibtexString > remaining , int maxKeyLength )
327+ private void writeString (Writer fw , BibtexString bs , Map <String , BibtexString > remaining , int maxKeyLength ,
328+ Boolean reformatFile )
328329 throws IOException {
329330 // First remove this from the "remaining" list so it can't cause problem with circular refs:
330331 remaining .remove (bs .getName ());
331332
332333 //if the string has not been modified, write it back as it was
333- if (!bs .hasChanged ()) {
334+ if (!reformatFile && ! bs .hasChanged ()) {
334335 fw .write (bs .getParsedSerialization ());
335336 return ;
336337 }
@@ -351,7 +352,7 @@ private void writeString(Writer fw, BibtexString bs, Map<String, BibtexString> r
351352 Object referred = remaining .get (foundLabel .substring (1 , foundLabel .length () - 1 ));
352353 // If the label we found exists as a key in the "remaining" Map, we go on and write it now:
353354 if (referred != null ) {
354- writeString (fw , (BibtexString ) referred , remaining , maxKeyLength );
355+ writeString (fw , (BibtexString ) referred , remaining , maxKeyLength , reformatFile );
355356 }
356357 }
357358
@@ -384,9 +385,10 @@ private void writeString(Writer fw, BibtexString bs, Map<String, BibtexString> r
384385 *
385386 * @param fw The Writer to send the output to.
386387 * @param database The database whose strings we should write.
388+ * @param reformatFile
387389 * @throws IOException If anything goes wrong in writing.
388390 */
389- private void writeStrings (Writer fw , BibDatabase database ) throws IOException {
391+ private void writeStrings (Writer fw , BibDatabase database , Boolean reformatFile ) throws IOException {
390392 List <BibtexString > strings = database .getStringKeySet ().stream ().map (database ::getString ).collect (
391393 Collectors .toList ());
392394 strings .sort (new BibtexStringComparator (true ));
@@ -402,7 +404,7 @@ private void writeStrings(Writer fw, BibDatabase database) throws IOException {
402404 isFirstStringInType = true ;
403405 for (BibtexString bs : strings ) {
404406 if (remaining .containsKey (bs .getName ()) && (bs .getType () == t )) {
405- writeString (fw , bs , remaining , maxKeyLength );
407+ writeString (fw , bs , remaining , maxKeyLength , reformatFile );
406408 isFirstStringInType = false ;
407409 }
408410 }
0 commit comments