GNU TeXmacsUser manualReferenceAboutEnglish
Editing databases

1.Overview

A database is edited as a TeXmacs document whose body is a list of db-entry tags (see The Scheme database layers). There are three kinds of such documents:

Database views

the virtual document tmfs://db/kind/file shows the result of a query on the user database of the given kind. Saving it stores the modified entries back into the database. This is what Data\(\rightarrow\)Open bibliography and Data\(\rightarrow\)Open AI agents open.

Ordinary files

any document with the style database-bib (for instance a .bib file opened through the tmbib format) can be edited with the same tools. Its entries are not in the database, but can be imported into it.

Local bibliographies

the virtual document tmfs://biblio/prefix/file shows the bibliographic entries attached to a document (see Bibliographies).

All the database UI is only reachable when the preference "database tool" is on: the Data menu (both in the menu bar and in the compact main menu) is guarded by with-database-tool? in

texmacs/menus/main-menu.scm

, and many actions test supports-db?. The modules are loaded lazily from

init-texmacs.scm

(lazy-menu, lazy-define, lazy-tmfs-handler and lazy-keyboard).

2.Styles and modes

The package database (file

styles/test/database.ts

) defines the rendering of db-entry, db-folded-entry, db-pretty-entry, db-field, db-field-optional, db-field-alternative, db-pretty and db-result, and the variable db-kind. The styles database-bib and database-ai-agents use this package and set db-kind; database-bib moreover defines the markup for names in author fields (name-von, name-jr, name-sep) and for the raw BibTEX constructs that may occur in a converted .bib file (bib-comment, bib-preamble, bib-string, …). For a database kind kind, db-get-style returns the style name database-kind.

The modes are defined in

kernel/texmacs/tm-modes.scm

and in the kind modules:

in-database?

the style has the variable database-style, i.e. uses the database package;

in-bib?

the style is database-bib;

in-bib-names?

moreover inside an author or editor field (

bib-menu.scm

);

in-ai-agents?

the style is database-ai-agents (

ai-agents-menu.scm

).

In these modes

db-menu.scm

replaces the Insert menu and the mode icons by database specific ones (new entry of each type of the kind, import or confirmation of entries), and adds Focus menus to insert and remove fields.

3.The tmfs://db handler

db-tmfs.scm

registers the handlers for the db class of tmfs URLs. The name part of the URL is parsed by name->query: leading components of the form var=val are query parameters, the next component is the kind and the rest is a file name. The file name is only used for the title (global yields “My bibliographic database”); the documents always show (user-database kind).

(tmfs-load-handler (db name) …)
(showing a database)

Builds the query from the parameters of the URL and the per-document preferences returned by db-get-current-query (search, order, direction, limit, present, stored as preferences named param,url by db-set-query-preference). The search string is split at commas into :match constraints (words of less than two characters are ignored), a "type" constraint restricts the results to the types of the kind, and each order attribute gives an :order constraint. The resulting entries are presented as db-entry, db-folded-entry or db-pretty-entry depending on the present parameter, in a document with style database-kind.

(tmfs-save-handler (db name doc) …)
(saving)

Calls db-confirm-entries-in on the document, which commits all complete entries (see below).

The toolbar of

db-menu.scm

(db-toolbar, shown at the bottom of the window by db-show-toolbar for tmfs://db buffers) edits the query preferences and reverts the buffer. Hence changing the search string or the order simply reloads the virtual document.

4.Editing entries

4.1.Creating and completing entries

(make-db-entry type) inserts a new entry after the current paragraph, with a fresh identifier from db-create-id, meta fields contributor (the default user), modus ("manual") and date, and calls db-complete-fields, which uses the format of the type in db-format-table to add empty mandatory fields (db-field), alternatives (db-field-alternative) and optional fields (db-field-optional). The cursor is placed in the name of the entry.

The keyboard handlers of

db-edit.scm

implement a “fill out the form” interaction through kbd-enter:

In author and editor fields of bibliographic entries,

bib-kbd.scm

adds shortcuts: a comma or “and” starts a new name (name-sep), ↩ converts a plain list A. Einstein and N. Bohr into structured names with name markup for the last names, and Insert\(\rightarrow\)Particle or Insert\(\rightarrow\)Title suffix insert name-von and name-jr.

4.2.Confirming and removing entries

An entry of a database view is committed to the database when it is confirmed, either explicitly (⌥↩, kbd-alternate-enter, or the confirmation icon), or when the buffer is saved. confirm-entry computes the new entry with entry->assoc-list and calls db-update-entry with extra fields contributor and modus ("manual") and with time stamps. If the entry changed, it gets a new identifier, which is written back into the document together with the new meta fields. Before committing, detach-buffer-entries gives fresh identifiers to entries which occur several times in the buffer with the same identifier (for instance after copy and paste), so that the copies become independent entries.

Structured deletion of an entry (⌥⌫, ⌥⌦, structured-remove-horizontal) removes it from the database (remove-entry) and from the document. Removal only sets the expiration date of the lines, so an entry can be recovered with with-time.

In an ordinary document (not a database view), Insert\(\rightarrow\)Import entry and Insert\(\rightarrow\)Import selected entries import the entries into the user database of the kind, through db-import-this-entry and db-import-selection, which are redefined by the bibliographic kind.

5.Searching and choosing entries

db-widgets.scm

implements a search dialogue:

(open-db-chooser db kind name call-back)
(choose an entry)

Opens a dialogue (or a side tool if side tools are enabled) with an input field and a result area. Each keystroke schedules, after 200 ms of inactivity, a query ((:completes text) ("type" …)) limited to 20 results on db. The results are pretty-printed with db-pretty in the auxiliary buffer tmfs://aux/db-search-results; clicking a result (db-confirm-result) calls call-back with the name of the entry. Queries and loaded entries are cached for the life of the dialogue. The result areas can be resized.

For bibliographies, open-bib-chooser opens this dialogue on (bib-database). It is used by the focus search tool inside citations (focus-open-search-tool in

bib-menu.scm

, Focus\(\rightarrow\)Search references) and by the alternate tab key (kbd-alternate-tab, which calls kbd-alternate-variant) in a citation, while ⇥ (kbd-variant in

bib-kbd.scm

) completes the citation key with index-get-name-completions. For the kind "bib", the dialogue also lists the matching references of Zotero after those of the database, puts the source of each reference before it, and names its sources in a line above the input field (see Citations from Zotero).

When the database tool is off, ⇥ in a citation completes keys from the .bib file of the document (citekey-completions in

bibtex/bib-complete.scm

) and from Zotero, and the same dialogue is opened on the marker :bib-file instead of a database (zotero-open-search-tool, through the definitions of focus-can-search? and focus-open-search-tool for citations in

generic-edit.scm

): db-search-results then lists the entries of the .bib file of the bibliography, and those of Zotero.

5.1.Pretty printing

The "Pretty" presentation and the search results use the function (db-pretty l kind fm), which is the identity by default. For bibliographies (

bib-manage.scm

) it converts the entries to BibTEX entries and formats them with the internal siam style, turning each item into (db-result name text). In a database view, db-pretty-entry calls the secure Scheme function ext-db-pretty-entry through extern, which caches the result per kind (

db-markup.scm

); clicking the key of a pretty entry (db-pretty-notify) turns it back into an editable db-entry.

6.Other dialogues

Identities

(open-identities) edit the users of users-master.tmdb; the pseudo and full name of the default user are used as contributor of new entries.

Preferences

(open-db-preferences) currently only contain the preference "auto bib import", which controls the automatic importation of bibliographies attached to documents.

Storage

(Data\(\rightarrow\)Storage) selects the file used as the user database of the current kind (use-database).

Import and export

(Data\(\rightarrow\)Import, Data\(\rightarrow\)Export) are dispatched through db-import-select, db-export-select, db-import-file and db-export-file, which do nothing by default in

db-convert.scm

and are redefined in the mode in-bib? by

bib-manage.scm

. Recently used files are remembered with learn-interactive (db-recent-imports, db-recent-exports).

7.Pitfalls

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".