Creating a bibliography style

Hello Everyone,

preamble

This is a not yet polished guide on how I customized the bibliography style to show hyperlinks to the DOIs of articles, which I want for an article that I’m writing. I will continue to update it if I figure out something new, or if something is pointed out to me in the comments below. My hope is that, maybe, this can help someone, and perhaps together we can improve the TeXmacs help article on it to make it a bit easier for beginners.

I am not going to enter into the details of how to program the bibliography style with Scheme, but I am only giving a step by step guide on this specific example. This being said, you should be able to easily extend this for deeper and/or different bibliographies with some knowledge of BibTex and Scheme.

There is already some guidance on how to do this under Help->Scheme extensions->Writing TeXmacs bibliography files, but I still found myself to be pretty overwhelmed with this, and it took me pretty long to figure it out despite. Nonetheless, it is a good article and - if you are interested in/required to customize the bibliography style, I definitely recommend going through this. There is also this forum thread with additional discussion and info.

Guide

I think that it is a good idea to first chose a style that comes close to what you have in mind, as we will make a derivative of that one. In my case, tm-elsart-num since it orders the sources in the order that they appear in the text and cites numerically.


Once you have something that you like, we need the TEXMACS_PATH. On Linux, you can find it with echo $TEXMACS_PATH. This should also work on MacOS. I don’t know where it is on Windows (found it, thanks, will add it next week).

Once you have that, navigate to that path and go to progs>bibtex. You should see some scheme files like abbrv.scm, plain.scm, ieeetr.scm and others.

Copy the style that you want to modify and create a new file with a good name for your modified style (like julius-link-elsart-num.scm to make it easy to remember what your style is in the future).

Open the file in your text editor of choice. Use Replace (often ctrl+h) to replace elsart-num with the name of your style, which should be the same as the file name. Replace all occurrences in the document.

Now the top of the document should be something like this:

14: (texmacs-module (bibtex elsart-num)
15:  (:use (bibtex bib-utils) (bibtex plain)))

14: (texmacs-module (bibtex julius-link-elsart-num)
15:  (:use (bibtex bib-utils) (bibtex plain)))

If you scroll down a bit, you will see the definitions for the different parts in the bibtex bibliography. Something like (tm-define (bib-format-name x), etc.

So imagine you have the following entry in your bibliography:

@article{mitchison1996Actin-,
    number = {3},
    volume = {84},
    url = {http://dx.doi.org/10.1016/S0092-8674(00)81281-7},
    journal = {Cell},
    pages = {371–379},
    publisher = {Elsevier BV},
    author = {Mitchison, T.J and Cramer, L.P},
    year = {1996},
    title = {Actin-Based Cell Motility and Cell Locomotion},
    doi = {10.1016/s0092-8674(00)81281-7},
    month = {February},
    issn = {0092-8674},
}

Then this is where the formatting of the author name is defined. Since links aren’t used in this style, we will need to add our own.

Below the other tags, append the following (in my case at line 100):

;; Added function to format URL field
(define (bib-format-url x)
  (let* ((u (bib-field x "url")))
    (if (bib-null? u) "" `(concat "url: " ,u))))

Then add the url field to the article entry definition just below:

(tm-define (bib-format-article n x)
  (:mode bib-julius-link-elsart-num?)
  `(concat ,(bib-format-bibitem n x)
	   ,(bib-label (list-ref x 2))
	   ,(bib-new-block
	     (bib-new-sentence
	      `(,(bib-format-author x)
		,(bib-format-field-Locase x "title")
		,@(if (bib-empty? x "crossref")
		      `(,(bib-format-vol-num-pages x))
		      `((concat ,(bib-translate "in ")
				(cite ,(bib-field x "crossref")))
			,(bib-format-pages x)))
		,(bib-format-note x))))))

(tm-define (bib-format-article n x)
  (:mode bib-julius-link-elsart-num?)
  `(concat ,(bib-format-bibitem n x)
	   ,(bib-label (list-ref x 2))
	   ,(bib-new-block
	     (bib-new-sentence
	      `(,(bib-format-author x)
		,(bib-format-field-Locase x "title")
		,@(if (bib-empty? x "crossref")
		      `(,(bib-format-vol-num-pages x))
		      `((concat ,(bib-translate "in ")
				(cite ,(bib-field x "crossref")))
			,(bib-format-pages x)))
		,(bib-format-note x)
        ,(bib-format-url x))))))

Do like this for the other entry types that you want the urls to show up on.

Then finally, we need to add this to the file bib-utils.scm in the same folder as the style files:

76: (tm-define (bib-standard-styles)
77:  (list "tm-plain" "tm-abbrv" "tm-abstract" "tm-acm" "tm-alpha" "tm-elsart-num"
78:        "tm-ieeetr" "tm-siam" "tm-unsrt"))

76: (tm-define (bib-standard-styles)
77:  (list "tm-plain" "tm-abbrv" "tm-abstract" "tm-acm" "tm-alpha" "tm-elsart-num"
78:        "tm-ieeetr" "tm-siam" "tm-unsrt" "tm-julius-link-elsart-num"))

Take a deep breath and maybe a sip of your favorite beverage, this was all the coding that we needed to do.

If you have TeXmacs opened, then restart it now so that it can reload the bibliographies.
Then open the document and head down to the bibliography.
Click on the bibliography, click on the current style:
Screenshot%20from%202024-09-24%2000-09-08
And click on Other .... It will show a Pop-Up, where you can enter the name of your style, prefixed with “tm-”. For example, tm-julius-link-elsart-num. Then click on “ok”. Now rebuild the current buffer (either click on the button or do crtl+shift+R). The sources should now show up.

Did everything work out?

2 Likes

I will have more time to look at your post next week, this said: would you consider posting the same in TeXmacs blog at https://texmacs.github.io/notes/docs/main.html ?

Instructions on how to post are at https://github.com/texmacs/notes
Or you could send the post in TeXmacs format to @mgubi and he will publish it on the blog for you.

I think the blog and all TeXmacs users would benefit strongly from a how-to section.

Moreover posts in the forum slide away as new posts are published and so disappear from the awareness of users. There is a nice wiki how-to post which you can see only if you are not logged in, for example: usually the fact that it exists slips away from my mind. On the opposite, posts remain prominent on the blog.

This would not exclude publishing the same under a Wikipedia TeXmacs how-to wikibook (which yet needs to be started :slight_smile: )

1 Like

I wanted to collect some feedback before going further, since making changes is easier in the forum :wink:

Please give me some time to read the post and try the code :slight_smile:

1 Like

@schroedingers_possum I wrote you through the messaging system of the forum.

@pireddag thanks for the message
I rewrote a part of the preamble, I hope that this is a bit clearer than before.