GNU TeXmacsUser manualReferenceAboutEnglish
Adding converters

New data formats and converters between them are declared using the macros define-format and converter, which are defined in

kernel/texmacs/tm-convert.scm

. TeXmacs maintains a graph of all declared converters and automatically combines them when no direct converter exists between two formats. Formats which can be converted from or into TeXmacs automatically appear in the File\(\rightarrow\)Import and File\(\rightarrow\)Export menus. Typical examples of declarations can be found in the files convert/*/init-*.scm, such as

convert/html/init-html.scm

. The internals of the LaTeX converters are described in the section on conversions.

Formats

Each format fm gives rise to several representations, which are distinguished by suffixes: fm-file (a URL), fm-document (a string with the complete document), fm-snippet (a string with a document fragment) and fm-stree (a parsed Scheme tree). For TeXmacs itself, the relevant formats are texmacs-file, texmacs-document, texmacs-snippet, texmacs-stree and texmacs-tree.

(define-format name option …)
(declare a new data format)

Declare a new format name, together with converters between name-file and name-document. The following options are supported:

(:name string)

The name of the format as it appears in menus.

(:suffix suffix …)

The file suffixes of the format; the first one is the default suffix.

(:recognize pred?)

A predicate on strings which recognizes documents in this format (used when the suffix does not determine the format). With the variant :must-recognize, a matching suffix is not sufficient: files which are not recognized by the predicate are opened as verbatim text.

(:hidden)

Do not show the format in menus.

Other options (such as :option, which occurs in some format declarations) are currently ignored by define-format; options should be attached to converters instead.

Converters
(converter from to option …)
(declare a converter)

Declare a converter from the format from to the format to (both given as symbols or strings with the suffixes mentioned above). The following options are supported:

(:function fun)

The conversion is done by applying fun to the input.

(:function-with-options fun)

fun takes a second argument: an association list of conversion options.

(:shell prog arg …)

The conversion is done by an external program prog. The special arguments from and to are replaced by the names of the input and output files. The converter is removed if prog cannot be found in the path.

(:require cond)

The converter is only defined if cond evaluates to true. This option (possibly preceded by :penalty) must come first. It allows for alternative implementations of the same converter depending on the availability of external tools: the last valid declaration is retained. Notice that cond is evaluated when the converter declaration is expanded, that is, when the module is loaded.

(:penalty x)

The cost of the converter (by default \(1.0\)), which is used when searching for the cheapest chain of converters.

(:option name default)

Declare an option of the converter, which is stored as a user preference name with the given default value and passed to the converter function in the option list.

For instance:

(define-format blablah
  (:name "Blablah")
  (:suffix "bla"))

(converter blablah-file latex-file
  (:require (url-exists-in-path? "bla2tex"))
  (:shell "bla2tex" from ">" to))
Using converters
(convert what from to option …)
(convert data)

Convert what from the format from to the format to, using the cheapest chain of declared converters. Returns #f if no such chain exists. For instance, (convert "<b>x</b>" "html-snippet" "texmacs-stree") parses a piece of Html. The variant (convert-to-file what from to dest) writes the result to the file dest.

(converter-search from to)

(converters-from from …)

(converters-to to …)
(inspect the converter graph)

Return the cheapest chain of formats leading from from to to (or #f), resp. the lists of formats which can be reached from, or converted to, the given formats.

(format-from-suffix suffix)

(format-get-name fm)

(format-default-suffix fm)
(information about formats)

Determine the format corresponding to a file suffix, the name of a format as shown in menus, resp. the default suffix of a format.

(lazy-format module format-1 …)
(lazy declaration of formats)

Promise that module defines formats and converters. This is how the initialization files declare the formats, as in (lazy-format (prog prog-format) scheme) in

init-texmacs.scm

: the module is loaded when the editor has been idle during two seconds, or as soon as information about formats or converters is needed. The names of the formats after module are only informative.

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".