Hi,
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:
-
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)
-
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?)
`(concat
,(bib-format-bibitem n x)
,(bib-label (list-ref x 2))
,(bib-new-list-spc
`(,(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))
)
,brR
)) )
;;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?)
`(concat
,(bib-format-bibitem n x)
,(bib-label (list-ref x 2))
,(bib-new-list-spc
`(,(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
`(hlink
(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
)
)
) )