About bibliography in TeXmacs

I tried to incorporate bibliographic info in a tm file. However, I see that eprints are not treated well. For example:


  author       = {Wassenberg, Jan and Sanders, Peter},
  title        = {Faster Radix Sort via Virtual Memory and Write-Combining},
  date         = {2010-08-17},
  version      = 1,
  eprinttype   = {arxiv},
  eprintclass  = {cs.DS},
  eprint       = {1008.2849v1},

with test.tm:



  For a reference, see <cite|wassenberg>.

      <bibitem*|WS><label|bib-wassenberg>Jan Wassenberg<localize| and >Peter
      Sanders. <newblock>Faster radix sort via virtual memory and




The date, version, eprint identifier and the eprint classification are not shown. I wonder how to customize the bibliographic import to include these properly.

The processing of bibliography is defined in the scheme files you find in TeXmacs/progs/bibtex/, for example look at plain.scm which defines the plain style. Alternatively you can use bibliography styles which do not start with tm- in which case I think TeXmacs will use the external bibtex program to process the bibliography and you can then customise his behaviour much like you do in TeX.

bibtex is obsolete and it does not seem easy to use biblatex instead (which needs a different preprocessing than bibtex). It seems a bit difficult to customize these scheme files.

1 Like

I’m not sure why you claim that bibtex is obsolete. Anyway. Can you explain me what is the output you expect. From example from biblatex?

Also: in Help->Scheme extensions->Writing TeXmacs bibliography files you find some more information on how the user can customise bibliography files. Does not look difficult and one can learn how to do it progressively and report here so other users can join the effort and help. TeXmacs is a collaborative efforts of many people which use their spare time to (try to) build better tools for technical writing. A small help from each of us can bring the community to grow and flourish.


Sorry, maybe my post was not very clear. I expect an output which contains date and eprint info. In the example that I obtained, the output might contain something like arXiv:1008.2849v1.

I want to refer to Package documentation of biblatex, section 3.13.7, serving as a “standard reference” instead of my personal opinions.

Thanks for that. I thought that it might be possible to automatically translate biblatex rules into TeXmacs. After having viewed https://github.com/plk/biblatex/blob/dev/tex/latex/biblatex/biblatex.def, seemingly one can only translate them by hand.

Has anyone succeeded in creating a modified bibliography style? I tried following the help ( Help->Scheme extensions->Writing TeXmacs bibliography files), but failed.

I put an example.scm file in the $TEXMACS_PATH/progs/bibtex directory, with the contents given in that help document. If I then select the tm-example style in TeXmacs and refresh, I get an error message from bibtex.

EDIT: found it, you also need to add “tm-example” to (bib-standard-styles), defined in progs/bibtex/bib-utils.scm

1 Like

I run something like

(tm-define (bib-standard-styles)
        (append (former) '("tm-example"))

in an init file when I want to add a new bibliography style. I wrote one for my own publication list, I might put it in tm-forge soon.



I’m using a different approach that avoids modifying TeXmacs program directory and works with TeXmacs User HOME so it is update stable. It consists of two steps:

  1. Place the bibliography style file e.g. PSTplain.scm with your modifications in your (TexMacs User Home)/progs/bibtex directory. This file needs to contain the initialisation and overloads as discussed in the manual (see example below)

  2. Activate the style file in your TeXmacs document:
    a) insert a bibliography into your document if you haven’t already
    b) place the cursor before the first source item in the bibliography so that the TeXmacs property menu line shows ‘Bibliography’ and its attributes as file name and style button
    c) Press style button, choose other and enter tm-PSTplain into the dialog box. The style button should update to PSTplain .

Example for PSTplain.scm with online type for ePrints with arXiv and DOI references

My apologies for adding a bunch of code here, but this is the simplest way for me and I hope it is helpful. This code adds the online reference type that Zotero + BetterBibLaTex provide for eprints e.g. arXiv or DOI sources. It also demonstrates the mechanism how to add new reference types by overloading bib-format-misc.
Also note that the bibliography will include producing active <hlink> links.

;; MODULE      : PSTplain.scm
;; DESCRIPTION : plain style for BibTeX files additions by PST
;; COPYRIGHT   : (C) 2021  PST
;; How to use it:
;; Place this file in $HOME/progs/bibtex ($HOME is the TeXmacs User Home),
;; and activate it in your TeXmacs file as follows: Insert a bibliography into
;; your file. Place the cursor before the first source so that the TeXmacs property
;; menu line shows 'Bibliography' and its attributes as file name and style. Press
;; the style button, choose 'other' and enter tm-PSTplain .
;; See comments below on how to extend to citation source types that plain.scm 
;; doesn't know (e.g. 'online'). 
;; Overloading of formating routines works as described in the manual by just
;; providing an overload with same name here (see e.g. bib-format-article below). 
;; This software falls under the GNU general public license version 3 or later.
;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.

(texmacs-module (bibtex PSTplain)
  (:use (bibtex bib-utils) (bibtex plain)))

;;This file is just adding to the standard teXmacs plain.scm by overloading some
;;citation source formating functions (see TeXmacs Help->Scheme Extensions->Write Bibliography Styles)
(bib-define-style "PSTplain" "plain")

;;In order to extend the citation formats that plain.scm understands without having to modify
;;teXmacs installation files (which would be lost on an update) I overload the
;;bib-format-misc function that plain.scm calls for unknown formats (see bib-format-entry in plain.scm).
;;Note that in the event that plain.scm is updated to handle a new format type the format function
;;provided for this type in this file will still be called as it will overload the one in plain.scm
(tm-define (bib-format-misc n x)
  (:mode bib-PSTplain?)
  (with doctype (list-ref x 1)  
	(cond ;;see multi-branch in bib-format-entry in plain.scm 	
	  ;;deal with 'online' citation source format as generated by toolchain Zotero->BetterBibLaTex-export
	  ((equal? doctype "online") (bib-format-online n x))
	  ;;add further additional doctypes xxxxx HERE that bib-format-entry does not handle
	  ;;and provide a formating routine bib-format-xxxxx for it:
	  ;;((equal? doctype "xxxxx") (bib-format-xxxxx n x))
	  ;;handle unknown citation formats: 
	  (else (bib-format-unknown n x))

;;Deal with unknown citation format type:
;;output error message into the citation
;;tbd: output warning to TeXmacs warnings list dialog  
(tm-define (bib-format-unknown n x)
  (:mode bib-PSTplain?)  
     ,(bib-format-bibitem n x)
     ,(bib-label (list-ref x 2))
       `(,(bib-new-block (bib-format-author x))
	     ,(bib-new-block (bib-format-field-Locase x "title"))
		 "!!UNKNOWN CITATION TYPE '" ,(list-ref x 1) "' !! Add it in $HOME/progs/bibtex/PSTplain.scm!!"
		 ,(if (bib-empty? x "date")
		       "(date missing!)" ;;warn if no date given
		       `(concat "(" ,(bib-format-field x "date") ")") ;;bib-format-dateX outputs "", so not used.
	     ,(bib-new-block (bib-format-field x "note"))
	    ) ;end `( 
)   )

;;PST 2021-12-01 Extended bib-format-date:
;;Changed behaviour if 'year' is empty to use 'date',
;;and put delimiters brL and brR around the date (set to "" if not wanted)
;;Do not overload bib-format-date as it has additional arguments!
(tm-define (bib-format-dateX x brL brR)
  ;;(:mode bib-PSTplain?)
  (let* ((y (bib-field x "year"))
		 (m (bib-field x "month")))
	`(concat ,brL	 
			 ,(if (bib-null? y)
			     (bib-field x "date") ;;return 'date' if 'year' is empty! tbd: better formating!
				 (if (bib-null? m) y `(concat ,m " " ,y))
))   )  

;;PST 2021-12-01 Added for "online" doctype for online sources from arXiv etc.
;;as generated by the tool chain Zotero->better BibLaTex Export->Texmacs bibtex Import
(tm-define (bib-format-online n x)
  (:mode bib-PSTplain?)
     ,(bib-format-bibitem n x)
     ,(bib-label (list-ref x 2))
       `(,(bib-new-block (bib-format-author x))
	     ,(bib-new-block (bib-format-field-Locase x "title"))
		 ,(bib-format-earchiv x) ;;format the arXiv, doi, url etc online reference
		 ,(if (bib-empty? x "primaryclass")
		       "" ;;if no primary class given
		       `(concat "[" ,(bib-format-field x "primaryclass") "]") ;; e.g. quant-ph
		 ,(bib-format-dateX x "(" ")" )		  
	 "." ;terminates the citation by .
	 ,(bib-new-block (bib-format-field x "note")) ;adds the note and terminates by . if any

;;format an e-archiv format like arXiv, DOI etc.
;;Returns <hlink|describing text|URL> object instead of string
;;(see e.g. bib-label how to do insert teXmacs primitives)
(tm-define (bib-format-earchiv x)
   (with url (cadr (bib-field x "url")) ;;(bib-field x "url") returns <slink|url>, so take cadr to get url
	 (if (bib-empty? x "archiveprefix") 
	     ;;no archive named, so check if DOI or URL 
		 (if (bib-empty? x "doi") 
		 	 ;;if no DOI fall back to raw URL
			 `(concat ,(bib-format-field x "url") ;;(bib-field x "url") returns <slink|url>, so that is a link
					  " accessed " 
					 ,(bib-format-field x "urldate"))
		     ;;handle DOI:
			 `(hlink (concat "DOI:" ,(bib-format-field x "doi")) ,url)
	     ;;archiveprefix is given, so assume that eprint is also given
		     (concat ,(bib-format-field-preserve-case x "archiveprefix") ":"
			         ,(bib-format-field x "eprint") ;; ref within archive
				     ,(if (bib-empty? x "version") 
					       "" ;;no version provided
					       `(concat "v" ,(bib-format-field x "version"))
			 ,url ;;2.nd arg for hlink
)  )

Hi, I run this style but get an error. Does one need to add “tm-example” to (bib-standard-styles) , defined in progs/bibtex/bib-utils.scm as @jeroen commented?

Can you describe what is the error in question?

Thanks, @mgubi for joining in.
Here is a short explanation, I created PSTplain.scm style by copying the above code.
I saved that file in the folder with the address C:\Program Files (x86)\TeXmacs\progs\bibtex
The file is not visible in the style dropdown, under bibliography and I use the option to add other file, in the dialog I write PSTplain.scm and update the document. On update, I get this error, no description at all.

I have an idea of what the issue may be. TeXmacs issues commands that might not be interpreted by Windows; in these commands appears an environment variable expressed as $TEXMACS_HOME_PATH and I think Windows does not interpret it. But I may be wrong.

I saw the error message by running TeXmacs from cmd with the following batch file—please ignore the comments and adapt the path of the output file to a path that fits you.



REM Prevent wrong 64-bit JVM from being picked up:

rem 2024-03-18 commentare la riga seguente e mettere un underscore a Test_TeXmacs rende possibile l'esecuzione di questo script (please ignore the comments and adapt the path of the output file to one that fits for you)

rem SET TEXMACS_HOME_PATH="C:\Users\admin\Dati\Test\Test TeXmacs home dir"

cd "C:\Program Files (x86)\TeXmacs\bin"

rem dir

if exist "texmacs.exe" (echo texmacs exists)

if not exist "texmacs.exe" (echo texmacs does not exists)

start /b /wait "" "texmacs.exe" > "C:\Users\admin\Dati\Test\Test_TeXmacs\launch_texmacs.txt" 2>&1

if not %errorlevel% == 0 exit /b

else echo %errorlevel%

I think TeXmacs runs the function bibtex_run (string bib, string style, url bib_file, tree bib_t) in src/Plugins/Bibtex/bibtex.cpp (please see TeXmacs sources on github).

I hope that even if what I wrote here is wrong, it might help someone else to figure out what happens.

I am mixing things. My message refers to using BibTeX styles on Windows. But maybe there is still some useful information.

HI @pireddag

When I run your script TeXmacs starts and this is output I get in the txt file:

  1. TeXmacs] std-warning, Couldn’t concretize tuple (concat, etc, papersize)
  2. TeXmacs] With linked TrueType support
  3. running init-zotexmacs

Are you running BibTeX under Linux?
Can I send you my file and .my bib file and Vancouver .bst so you can try to compile it?

Please send and I will try. I am going to write you my email in a private message here in the forum----I do not want to write it publicly.