jabref icon indicating copy to clipboard operation
jabref copied to clipboard

Special field markers and modifiers

Open NeymanDmitry opened this issue 1 year ago • 16 comments

When forming a link or filename, constructs like "veryshorttitle" are sometimes required, but sometimes this type of marker is required for another field, such as [MAINTITLE] or [user_title] etc.

It might be better to use something like modifiers :veryshorttitle, :shorttitle, etc., for any field, rather than just field markers for title, authors, and editors only.

NeymanDmitry avatar Jun 10 '24 16:06 NeymanDmitry

Hello :-)

I am not sure, but I assume the fieldmarkers are hardcoded and only provided for the most used fields. Please correct me, but I believe it is possible to achieve similar functionality than field markers by using Regular Expressions and modifiers. For example, :regex("pattern", "replacement") is your swiss army knive for all types of patterns and in your case specifically, :truncateN might be fitting replacement for [veryshorttitle], which is basically a simple :truncate1. See the section about modifiers in the documentation: https://docs.jabref.org/setup/citationkeypatterns#modifiers. Modifiers can be used with most field names. Also have a look at the regex documentation: https://docs.jabref.org/setup/citationkeypatterns#regular-expressions-regex

ThiloteE avatar Jun 10 '24 19:06 ThiloteE

For example, a construct like [title:truncate1] will only display the first letter of the corresponding token field, but what if I need to display only the first significant word or three words as "shorttitle"!?

Let there be two books published in the same year with the main title or the title of the series as “Elements of Mathematics” by Nicolas Bourbaki and the usual titles: 1) Functions of a Real Variable; 2) General Topology. When referring to such books, for clarity, you can create the citationkey in the form ("Bourbaki_2004_Elements_Functions" and "Bourbaki_2004_Elements_General").

In the example above, you can use the "verishorttitle" marker to display the first word of the title (Functions or General), but which construct will help you display the first word of the main title or custom title (not including the function words like the, with, etc)?

I'm not sure but an army knife won't work here!

NeymanDmitry avatar Jun 11 '24 12:06 NeymanDmitry

Please provide bibtex/biblatex source data, then I will play around with it. main title and user_title are not official bibtex/biblatex fields, but a custom field, right?

ThiloteE avatar Jun 11 '24 12:06 ThiloteE

Yes these are custom fields!

About the sources. For example, let them be like this:

@Book{Bamford_1972_Comprehensive_Reaction_V_7_EN,
  language         = {english},
  maintitle        = {Comprehensive Chemical Kinetics},
  title            = {Reaction of Metallic Salts and Complexes, and Oranometallic Compounds},
  volume           = {7},
  year             = {1972},
  editor           = {Bamford, C. H. and Tipper, C. F. H.},
}

@Book{Bamford_1972_Comprehensive_Reactions_V_6_EN,
  language         = {english},
  maintitle        = {Comprehensive Chemical Kinetics},
  title            = {Reactions of Non-Metallic Inorganic Compounds},
  volume           = {6},
  year             = {1972},
  editor           = {Bamford, C. H. and Tipper, C. F. H.},
}

@Book{Bamford_1972_Comprehensive_Decomposition_V_5_EN,
  language         = {english},
  maintitle        = {Comprehensive Chemical Kinetics},
  title            = {Decomposition and Isomerization of Organic Compounds},
  volume           = {5},
  year             = {1972},
  editor           = {Bamford, C. H. and Tipper, C. F. H.},
}

NeymanDmitry avatar Jun 12 '24 06:06 NeymanDmitry

You are right. I haven't found a regex (yet?) that can truncate well, under the condition that content of maintitle is variable and not fixed.

  1. "maintitle" is not a custom field. It is an optional field for "book" entries in biblatex. I haven't checked for bibtex.
  2. Under "Files > preferences > linked files > linked file name conventions > file name format pattern", I tried to use [auth.etal:regex("\\."," & "):regex("\\& etal","et al.")][Organization] ([date]) [MAINTITLE:regex("^\w\b\w\b\w\b.*$", "^\w\b\w\b\w$"] with following entry:
@book{Bamford_1972_Comprehensive_Reaction_V_7_EN,
language = {english},
maintitle = {Comprehensive Chemical Kinetics Are Wonderful Riddles},
title = {Reaction of Metallic Salts and Complexes, and Oranometallic Compounds},
volume = {7},
year = {1972},
editor = {Bamford, C. H. and Tipper, C. F. H.},
}

I test by pressing ALT + F8 (which is Quality > Clean up entries"). image

Expected outcome: Bamford & Tipper (1972) Comprehensive Chemical Kinetics 👍 Actual outcome: Bamford & Tipper (1972) Comprehensive Chemical Kinetics Are Wonderful Riddles ❌

I think there is an inherent limitation of the :regex("pattern", "replacement") modifier. For example, given the following file name format pattern: [auth.etal:regex("\\."," & "):regex("\\& etal","et al.")][Organization] ([date]) [MAINTITLE:regex("Comprehensive Chemical Kinetics Are Wonderful Riddle", "Comprehense Cinetics")]

Expected outcome: Bamford & Tipper (1972) Comprehense Cineticss 👍 Actual outcome: Bamford & Tipper (1972) Comprehense Cineticss 👍

ThiloteE avatar Jun 12 '24 11:06 ThiloteE

TL;DR: Looks like this has to be fixed in JabRef code.

I think, as you suggested, if it is possible, then extending some generic field markers like shorttitle or veryshorttitle to other or even all fields is a good idea.

ThiloteE avatar Jun 12 '24 11:06 ThiloteE

Hello can i take this issue ? I am a first time contributor

Mtjpp avatar Oct 07 '24 17:10 Mtjpp

Sure :-) 👍

ThiloteE avatar Oct 07 '24 18:10 ThiloteE

Welcome to the vibrant world of open-source development with JabRef!

Newcomers, we're excited to have you on board. Start by exploring our Contributing guidelines, and don't forget to check out our workspace setup guidelines to get started smoothly.

In case you encounter failing tests during development, please check our developer FAQs!

Having any questions or issues? Feel free to ask here on GitHub. Need help setting up your local workspace? Join the conversation on JabRef's Gitter chat. And don't hesitate to open a (draft) pull request early on to show the direction it is heading towards. This way, you will receive valuable feedback.

Happy coding! 🚀

github-actions[bot] avatar Oct 07 '24 18:10 github-actions[bot]

Hello i know it is not issue related but I am really struggling to clone the repository. I am always met with this error: RPC failed; curl 92 HTTP/2 stream 0 was not closed cleanly. I have tried all the recommended stuff from StackOverflow and I have tried ssh nothing helps so I am just wondering if anyone has any experience solving this ? Thank you

Mtjpp avatar Oct 12 '24 16:10 Mtjpp

@Mtjpp Such questions are better asked in our gitter chat: Try reducing the fetch depths while cloning: git clone --recurse-submodules --depth 10 https://github.com/JabRef/jabref.git JabRef

Siedlerchr avatar Oct 12 '24 18:10 Siedlerchr

Let there be two books published in the same year with the main title or the title of the series as “Elements of Mathematics” by Nicolas Bourbaki and the usual titles: 1) Functions of a Real Variable; 2) General Topology. When referring to such books, for clarity, you can create the citationkey in the form ("Bourbaki_2004_Elements_Functions" and "Bourbaki_2004_Elements_General").

Just to understand:

maintitle Elements of Mathematics plus title Functions of a Real Variable should be mapped to Elements_Funtions

and

maintitle Elements of Mathematics plus title General Topology should be mapped to Elements_General.


It might be better to use something like modifiers :veryshorttitle, :shorttitle, etc., for any field, rather than just field markers for title, authors, and editors only.

Just for the record: Our modifiers are listed at https://github.com/JabRef/user-documentation/blob/main/en/finding-sorting-and-cleaning-entries/saveactions.md#save-actions-as-modifiers.

koppor avatar Oct 14 '24 18:10 koppor

The issue is about the special field markers https://docs.jabref.org/setup/citationkeypatterns#special-field-markers

Siedlerchr avatar Oct 14 '24 18:10 Siedlerchr

The issue is about the special field markers https://docs.jabref.org/setup/citationkeypatterns#special-field-markers

And that :veryshorttitle can be used.

  • [USER_CUSTOM_TITLE_FIELD:veryshorttitle]
  • [USER_CUSTOM_TITLE_FIELD:shorttitle]
  • [USER_CUSTOM_TITLE_FIELD:camel]
  • [USER_CUSTOM_TITLE_FIELD:camelN]
  • [USER_CUSTOM_TITLE_FIELD:nameIni5] (all functions of auth/edtr should work here - only that name is used as prefix)

Meaning: Add new modifiers: https://docs.jabref.org/setup/citationkeypatterns#modifiers

koppor avatar Oct 14 '24 23:10 koppor

@NeymanDmitry I went into the code and got more claritiy, how things work. With https://github.com/JabRef/jabref/pull/11967, the escaping is more easiy.

This should be the pattern you are looking for:

[edtr]_[YEAR]_[MAINTITLE:regex("(\w+).*", "$1")]_[TITLE:regex("(\w+).*", "$1")]_V_[VOLUME]_[LANGUAGE:regex("english", "EN"):regex("french", "FR")]

The first "magic ingredient" is $1 backreferencing to th first group in the RegEx. The second "magic ingredient" is to use \w+ as first group. Also not the space * after that.

koppor avatar Oct 15 '24 00:10 koppor

Implementation notes:

  • one can see all methods which could be sued for name... at https://github.com/JabRef/jabref/blob/60ef28ae5be23ed35cb82824eb40e12b63c01a9f/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java#L351.
  • to hock into the modifiers, one needs to hock in around https://github.com/JabRef/jabref/blob/60ef28ae5be23ed35cb82824eb40e12b63c01a9f/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java#L586. I think, it is another check for modifier. Check if the modifier is known (the list is somehow at https://github.com/JabRef/jabref/issues/11367#issuecomment-2412533435). If yes: execute the modifier (parse the current resultingLabel into an AuthorList (using org.jabref.model.entry.AuthorList#parse) and then pass it to the methods. -- What I mean, hook before https://github.com/JabRef/jabref/blob/60ef28ae5be23ed35cb82824eb40e12b63c01a9f/src/main/java/org/jabref/logic/citationkeypattern/BracketedPattern.java#L589.

koppor avatar Oct 15 '24 00:10 koppor

Fixed by https://github.com/JabRef/jabref/pull/12067

koppor avatar Nov 28 '24 20:11 koppor