JabRef / jabref

Graphical Java application for managing BibTeX and biblatex (.bib) databases
https://devdocs.jabref.org
MIT License
3.53k stars 2.47k forks source link

Special field markers and modifiers #11367

Open NeymanDmitry opened 2 months ago

NeymanDmitry commented 2 months ago

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.

ThiloteE commented 2 months ago

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

NeymanDmitry commented 2 months ago

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!

ThiloteE commented 2 months ago

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?

NeymanDmitry commented 2 months ago

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.}, }

ThiloteE commented 2 months ago

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 commented 2 months ago

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.