stx2any — definitions for DocBook XML

This file is copyright © 2004,2005,2006 by Panu Kalliokoski and released under the license in ../LICENSE

Note that the definitions won't look right in the target output format, because they contain target markup.

Definitions for DocBook XML.

XML requires well-formed paragraphs, so we have our own paragraph system here. We put a paragraph inside most everything just to be sure. Here are the macros to keep the result well-formed.

define(`w_paragraph', `w_closedefine(`@w_para_open',t)')
define(`w_open', `w_paragraph`'undefine(`@w_para_flag')')
define(`w_close',
`ifelse(defn(`@w_para_open'),t,)'dnl
`define(`@w_para_open',)')
w_close must be called before emitting any block-level tag. w_open will open a paragraph, no matter what. w_softopen marks that if there is text forthcoming, it must be in its own paragraph.

DocBook has its own sectioning system — very structured but poorly corresponding to traditional typography. (In some ways, a section is a unit, in others, it is not. For example, a document usually makes sensible reading if you take away headings, but not always when you remove some section.)

The macros here are linked to headings: headings produce sections. But we need to hook closing of sections somewhere. This is done at the template.

define(`@w_sectlev', 0)
define(`w_set_sect_level',
`ifelse(eval(`$1>'defn(`@w_sectlev')),1,
  `define(`@w_sectlev',incr(defn(`@w_sectlev')))'dnl
`w_closew_set_sect_level(`$1')',
  eval(`$1<'defn(`@w_sectlev')),1,
  `w_closew_softopen`'define(`@w_sectlev',
    decr(defn(`@w_sectlev')))w_set_sect_level(`$1')')')
define(`w_headline',
`w_set_sect_level(decr(`$1'))'dnl
`w_set_sect_level(`$1')$2w_softopen')

Block system environments.

w_define_env(-,`w_close',`w_closew_softopen')
w_define_env(#,`w_close',`w_closew_softopen')
w_define_env(i,`w_closew_open',`w_close')
w_define_env(q,`w_close
w_open',`w_close
w_softopen') w_define_env(:, `w_closepushdef(`@w_varitem_open',)', `w_close`'w_close_varitempopdef(`@w_varitem_open')w_softopen') define(`w_defnterm', `w_open_varitem$1') w_define_env(t, `define(`w_pending_block_hook', `w_closew_open')', `ifelse(defn(`w_pending_block_hook'),, `w_closew_close_varitem', `define(`w_pending_block_hook',)')') define(`w_open_varitem', `ifelse(defn(`@w_varitem_open'),,`w_close')'dnl `define(`@w_varitem_open',t)') define(`w_close_varitem', `ifelse(defn(`@w_varitem_open'),t,`w_closew_softopen`'')'dnl `define(`@w_varitem_open',)')

Other environments.

w_define_env(litblock,`w_close',`w_closew_softopen')
w_define_env(footnote,`',`')
w_define_env(compactlist,
`w_closew_open',
`w_closew_softopen')
w_define_env(center,
`w_closew_open',
`w_closew_softopen')
w_define_env(abstract,
`w_close`'w_begdiv(ingr)w_open',
`w_closew_enddiv(ingr)w_softopen')
w_define_env(comment, `')
w_define_env(citation,
`w_close
$*w_open', `w_close
w_softopen') w_define_env(`w_float_n', `w_close
w_softopen', `w_caption(`$1') w_close
w_softopen')

There is no real way to put line breaks into documents in DocBook. We should wrap the whole paragraph in literal layout, but we can't do that at this stage, and there might be non-hard line breaks in the same paragraph. Let's just settle for this ugly hack:

define(`w_linebr', w_nl)

Emphasis.

define(`w_literal', `$1')
define(`w_emph', `$1')
define(`w_techemph', `$1')
define(`w_strong', `$1')
define(`w_quotation', `$1')

Other inlines.

define(`w_link', `$2')
define(`w_url', `$1')
define(`w_img',
`'
`'
`$2'
`')
define(`w_label', `'dnl
`ifdef(`w_symmetric_crossrefs',`$2',`$2')')
define(`w_refer',
`ifdef(`w_symmetric_crossrefs',`')'dnl
`$2')

Tables.

define(`w_make_tablespec',
`ifelse(`$*',,,`'dnl
`w_make_tablespec(shift($@))')')
w_define_env(w_table,
`pushdef(`w_caption', `$1')'dnl
`w_closew_make_tablespec($@)w_nl',
`w_closepopdef(`w_caption')w_softopen`'')
w_define_env(w_row, `w_close', `w_close')
w_define_env(w_cell, `w_close', `w_close')
define(`w_table_rule',) dnl TODO?

Admonitions.

w_define_env(`admonition',
`w_close`'ifelse(w_standard_admonition(`$1'),t,`<`$1'>',``$1':')w_open',
`w_close`'ifelse(w_standard_admonition(`$1'),t,`',`')w_softopen')
define(`w_standard_admonition',
`ifelse(index(`Note,Tip,Caution,Warning,Important',`$1'),-1,,t)')

Special and quoted characters.

define(`w_lt', `<')
define(`w_gt', `>')
define(`w_amp', `&')
define(`w_emdash', `—')
define(`w_endash', `–')
define(`w_ellipsis', `…')
define(`w_copyrightsign', `©')
define(`w_trademarksign', `™')
define(`w_larrow', `←')
define(`w_rarrow', `→')