[main]Notes on TeXmacs

New list types

How to define new list types in TeXmacs.

The TeXmacs manual, in Section 11.4.4, and the Jolly Writer suggest that the macro new-list can be used to define new list types.

Quoting from the manual

The std-list d.t.d. also provides a macro new-list to define new lists. Its syntax is <new-list|name|item-render|item-transform>, where name is the name of the new list environment, item-render an (inline) macro for rendering the item and item-transform an additional transformation which is applied on the item text. For instance, the enumerate-roman environment is defined by

<new-list|enumerate-roman|aligned-dot-item|<macro|x|<number|x|roman>>>

As user bpascal40 observed in the forum, this is not enough for obtaining a new list type that works like the default itemize environment. If one has defined a list type by, exempli gratia,

<new-list|itemize-perso|aligned-dot-item|<macro|x|>>

then generating a list in the hybrid mode as will generate the itemize-perso environment but won't add the first item to it; moreover pressing Return while in the list environment won't add an item to the list.

In order to get an itemize-perso list to behave like a default itemize list we need two more instructions for TeXmacs.

We get a hint for the first instruction by examining the menu item InsertItemizeDefault; a search with ack inside the progs subdirectory of the TeXmacs installation directory shows that the menu item executes the Scheme command (make-tmlist 'itemize); the file where the menu is defined is text/text-menu.scm.

We need then to add a menu entry for itemize-perso and we do it through the following code in my-init-texmacs.scm:

(menu-bind itemize-menu
  (former)
  ---
  ("Perso" (make-tmlist 'itemize-perso)))

Executing the new menu entry that appears (InsertItemizePerso) generates a new list with a first item, like the following:

Note. The current HTML export filter can only export faithfully itemize environments, so we are substituting images for our custom itemization lists; a PDF export is faithful. We plan to write another post on HTML export of custom lists.

If we press Return inside this list no new item appears. We need one more piece of code, the declaration

(define-group itemize-tag
  itemize itemize-minus itemize-dot itemize-arrow itemize-perso)

The writer of this blog post does not understand how the declaration works, only the following that was explained by user mgubi in the forum: the declaration instructs TeXmacs to treat the group of tags in the same way.

Following this hint and looking inside the TeXmacs code one notices (without entering into the details of the code) that kbd-enter is defined inside lists (with a (:require (list-context? t)) declaration) as (make-item) (see the code in progs/text/text-edit.scm).

In fact after calling the define-group declaration above the itemize-perso list works nicely; after executing the menu entry InsertItemizePerso and pressing Return we get the following list with two items (again substituting an image for the HTML export of the list):

As a conclusion, to define a new list one should, in addition to executing the new-list macro, put in one's own my-init-texmacs.scm the following code (here, again, using the itemize-perso example)

(menu-bind itemize-menu
  (former)
  ---
  ("Perso" (make-tmlist 'itemize-perso)))

(define-group itemize-tag
  itemize itemize-minus itemize-dot itemize-arrow itemize-perso)