Skip to content

Fix IEEE preview does not display month #3983

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

Merged
merged 9 commits into from
May 2, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ private void writeText(String text, int startPos, int endPos) {

private void writeStringLabel(String text, int startPos, int endPos,
boolean first, boolean last) {
putIn((first ? "" : " # ") + text.substring(startPos, endPos)
+ (last ? "" : " # "));
putIn((first ? "{" : " # ") + text.substring(startPos, endPos)
Copy link
Member

Choose a reason for hiding this comment

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

Can you please explain the reason for this change. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method were create only for "#%s#" forma I guess. The output should be "{%s}" to have this result for month

month = {mon}

not this

month = mon

check this on #3239

Copy link
Member

Choose a reason for hiding this comment

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

Mhh, I'm pretty sure that month = jan is the correct form and not month = {jan}. Maybe @koppor can clarify this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here what happen if you did not add {}.
image

as you can see the return of 2005 is in side {} but the return of month isnt it.

the method executed to return year = {2005}
https://github.com/DevSiroukane/jabref/blob/67387113513ce9529e08b62ffc430d13e24f0b4b/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java#L157

the method executed to return month = mon when month field is in this forma "#%s#".
https://github.com/DevSiroukane/jabref/blob/67387113513ce9529e08b62ffc430d13e24f0b4b/src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java#L163

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we know that bibTeX forma should be

key = {value}

u can add a debug instruction here LatexFieldFormatter.java#L166

System.out.println(stringBuilder);

and see the out put after each change in any field. You will find that only month output is wrong if we miss the {} that I add on

LatexFieldFormatter.java#writeStringLabel(String text, int startPos, int endPos, boolean first, boolean last)

Copy link
Member

Choose a reason for hiding this comment

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

@DevSiroukane You are confusing it here. If it's #month# it should be displayed without braces in the source. So the entry editor part was already correct.
Only when it's month -> {month}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Siedlerchr are you sure that month should not be between {} on source tab?

because I try to use generate entry using DOI (ex: 10.1109/TSG.2014.2346511) and the out put is this on source tab:

@Article{Rahbari-Asr2014,
  author    = {Navid Rahbari-Asr and Unnati Ojha and Ziang Zhang and Mo-Yuen Chow},
  title     = {Incremental Welfare Consensus Algorithm for Cooperative Distributed Generation/Demand Response in Smart Grid},
  journal   = {{IEEE} Transactions on Smart Grid},
  year      = {2014},
  volume    = {5},
  number    = {6},
  pages     = {2836--2845},
  month     = {nov},
  doi       = {10.1109/tsg.2014.2346511},
  publisher = {Institute of Electrical and Electronics Engineers ({IEEE})},
}

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the month does not need be in braces. Its a feature of bibtex called "Bibtex Strings", see e.g. http://www.bibtex.org/Format/.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Siedlerchr I think I should let source tab month appear as before

month = mon

I will remove the change as you said @tobiasdiez

+ (last ? "}" : " # "));
}

private void putIn(String s) {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/logic/citationstyle/CSLAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import de.undercouch.citeproc.bibtex.BibTeXConverter;
import de.undercouch.citeproc.csl.CSLItemData;
import de.undercouch.citeproc.output.Bibliography;
import org.jabref.model.entry.FieldName;
import org.jbibtex.BibTeXEntry;
import org.jbibtex.DigitStringValue;
import org.jbibtex.Key;
Expand Down Expand Up @@ -84,6 +85,14 @@ private static class JabRefItemDataProvider implements ItemDataProvider {
* Converts the {@link BibEntry} into {@link CSLItemData}.
*/
private static CSLItemData bibEntryToCSLItemData(BibEntry bibEntry) {

// create a copy of bibEntry
Copy link
Member

Choose a reason for hiding this comment

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

This comment states the same as it is done in the code. So please "Remove Superfluous Comments" Java by Comparison.

You can also describe, why a clone is generated!

Copy link
Contributor Author

@DevSiroukane DevSiroukane Apr 28, 2018

Choose a reason for hiding this comment

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

Is this a good comment?

/**
 * Converts the {@link BibEntry} into {@link CSLItemData}.
 *
 * Clone bibEntry to make a save changes,
 * change month field from JabRefFormat <code>#mon#</> to ShortName <code>mon</code>
 * because CSL does not support JabRefFormat.
 */

Clone was generated because bibEntry is shared with many objects. So, to be sure that non of this objects may have issue after changing month field. I create a copy to change on it.

bibEntry = (BibEntry) bibEntry.clone();
// change month field from "#mon#" to "mon"
if((bibEntry.getFieldMap().get(FieldName.MONTH) != null) && !bibEntry.getFieldMap().get(FieldName.MONTH).isEmpty()){
Copy link
Member

Choose a reason for hiding this comment

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

I would actually move this in the loop below. Has the advantage that you don't need to clone the entry.
And then you could try it using this way:

  if (FieldName.MONTH.equals(key)) {
                    bibEntry.getMonth().map(Month::getShortName).ifPresent(value -> bibTeXEntry.addField(new Key(key), new DigitStringValue(value)));
                }

Copy link
Member

Choose a reason for hiding this comment

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

Can you test if this works?

Copy link
Member

Choose a reason for hiding this comment

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

Or add LatexFieldFormatter fieldFormatter = new LatexFieldFormatter(...) in front of the for loop and then add .map(fieldFormatter ::format). In this way, we also support custom bibtex strings (and not only the predefined ones for the month field).

Copy link
Member

Choose a reason for hiding this comment

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

Does not work, as LatexFieldFormatter a) needs preferences object b) has only a two argument format method and does not implment the interface

Copy link
Member

Choose a reason for hiding this comment

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

ok, but it works "with obvious modifications" 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Siedlerchr I try ur suggestion but it didnt work.
I can also prefer your solution but instead of making this instruction inside if block

bibEntry.getMonth().map(Month::getShortName).ifPresent(value -> bibTeXEntry.addField(new Key(key), new DigitStringValue(value)));

I will keep the instruction that I made.

bibEntry.getFieldMap().put(FieldName.MONTH, bibEntry.getMonth().get().getShortName());

What do you think?

bibEntry.getFieldMap().put(FieldName.MONTH, bibEntry.getMonth().get().getShortName());
}

String citeKey = bibEntry.getCiteKeyOptional().orElse("");
BibTeXEntry bibTeXEntry = new BibTeXEntry(new Key(bibEntry.getType()), new Key(citeKey));

Expand Down