<!DOCTYPE style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN"
[
<!-- Table styles by Anders Berglund as borrowed from Jon Bosak's
     db63.dsl stylesheet plus modifications                          -->
<!ENTITY table.dsl SYSTEM "table.dsl">

]>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; MODULE:    "Extreme 2000" Stylesheet Main Module
;; VERSION:   1.0
;; DATE:      February 10, 2000
;;
;; MULBERRY INTERNAL VERSION CONTROL:
;; $Id: paper.dsl,v 1.3 2000-03-06 18:46:36-04 tkg Exp tkg $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SYSTEM:    Extreme
;;
;; PURPOSE:   This is the main module of the DSSSL stylesheet
;;            used for "Extreme 2000" papers.
;;            Based on previous "Markup Technologies" stylesheet.
;;
;; CONTAINS:  1) Structure of this stylesheet
;;            2) How to modify this stylesheet
;;            3) Variables overridden on command line
;;            4) External procedure definitions
;;            5) External characteristic definitions
;;            6) Unit declarations
;;            7) Variable definitions
;;            8) Style definitions
;;            9) Common function definitions
;;            10) Initial values for inherited characteristics
;;            11) Element construction rules
;;            12) External module references
;;
;; PACKAGES REQUIRED:
;;            1) table.dsl -- Table module
;;
;; ORIGINAL CREATION DATE:
;;            February 2000
;;
;; CREATED BY:
;;            Mulberry Technologies, Inc.
;;            17 West Jefferson Street, Suite 207
;;            Rockville, MD  20850
;;            Phone:  301/315-9631
;;            Fax:    301/315-8285
;;            email:  info@mulberrytech.com
;;            WWW:    http://www.mulberrytech.com
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 1. Structure of this Stylesheet
;;
;; This stylesheet begins with extensive comments on how to modify the
;; stylesheet followed by the element construction rules that tell the
;; DSSSL engine what to do for the elements in your document.  That is
;; then followed by declarations of parameterization variables,
;; styles, procedures, and references to external modules.  All
;; sections of this stylesheet are numbered for ease of navigation.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 2. HOW TO MODIFY THIS STYLESHEET
;;
;; This stylesheet has been highly parameterized, and the definitions
;; of the parameterizaton variables have been grouped in section 7 of
;; this stylesheet.  All parameterization variable names start and end
;; with "%" (e.g., "%footer-font-size%") to make it easier to
;; distinguish them from built-in functions and variables.
;;
;; If you modify any of the parameterization variables, be sure to
;; preserve the "type" of the variable.  That is, change a variable
;; with a string value to a different string; a length to a length,
;; etc.  If you do not, you are likely to cause an error.
;;
;; The "types" of the variables are:
;;
;;    "string"     A string value
;;    9pt          A length
;;    4pi          A length
;;    8.5in        A length
;;    'bold        A symbol (There is generally a limited list of
;;                           symbols which you can use for a given
;;                           characteristic)
;;    #f           A boolean
;;    #t           A boolean. (The only allowed values are #t and #f)
;;    %block-sep%  Another parameterization variable

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 3. Boolean variables to be overridden from the Jade command line
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; blind is set to #f by default; use -V blind to set it to true
(define blind #f)

;; Setting A4 to #t causes the page size to be changed to A4 (210mm by
;; 297mm)
(define A4 #f)

;; Setting recto-verso to #t causes the page header and footer to
;; change between recto and verso pages
(define recto-verso #f)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 4. External procedure definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; These allow us to use procedures built into Jade but not part of
;; the DSSSL standard

(define if-front-page
  (external-procedure "UNREGISTERED::James Clark//Procedure::if-front-page"))

(define if-first-page
  (external-procedure "UNREGISTERED::James Clark//Procedure::if-first-page"))

(define debug
  (external-procedure "UNREGISTERED::James Clark//Procedure::debug"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 5. External characteristic definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; These allow use to use characteristics built into Jade but not part
;; of the DSSSL standard

(declare-characteristic
 page-number-restart?
 "UNREGISTERED::James Clark//Characteristic::page-number-restart?"
 #f)

(declare-characteristic
 page-number-format
 "UNREGISTERED::James Clark//Characteristic::page-number-format"
 "1")

(declare-characteristic
 heading-level
 "UNREGISTERED::James Clark//Characteristic::heading-level"
 0)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 6. Unit declarations
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; All lengths in DSSSL are based upon the meter (m), but Jade "knows"
;; about some others.  Here we define points and picas.  These are
;; "Postscript" points, since "Printers" points are 72.27 points per
;; inch.

;; Picas
(define-unit pi (/ 1in 6))

;; Points
(define-unit pt (/ 1in 72))

;; Color-space for special effects
(define rgb-color-space
  (color-space "ISO/IEC 10179:1996//Color-Space Family::Device RGB"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 7. Variable definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The names of variables that we define to control sizes, etc., in
;; the formatted output all begin and end with "%",
;; e.g. "%toc-indent%".  This is purely so we can differentiate these
;; "user-defined" variables from built-in variables and procedures.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 7.1 Conference name
;;
;; After all, the conference name will change next year, won't it?

(define %conference-name% "Extreme Markup Languages 2002")
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 7.2 Common dimensions

(define %page-width% (cond
          (A4 210mm)
          (else 8.5in)))
(define %page-height% (cond
          (A4 297mm)
          (else 11in)))

(define %term-indent% 12pi)
(define %figure-number-indent% 6pi)
(define %section-number-indent% 3pi)
(define %bibitem-indent% 6pi)
(define %para-sep% 6pt)
(define %table-para-sep% 3pt)
(define %block-sep% (* %para-sep% 2.0))
;; Body font size
(define %bf-size% 12pt)

;; Fonts to use
(define %title-font-family% "Arial")
(define %body-font-family% "Times")
(define %mono-font-family% "Courier New")

(define %bf-line-spacing% 13pt)

;; How much to scale superscripts and subscripts
(define %ss-size-factor% 0.6)
(define %ss-shift-factor% 0.4)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 8. Styles for use for various elements
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define generic-title-style
  (style
   font-weight: 'bold
   font-family-name: %title-font-family%))

(define paper-title-style
  (style
   use: generic-title-style
   font-size: 22pt
   line-spacing: 26pt))

(define section-title-style
  (style
   use: generic-title-style
   font-size: 18pt
   line-spacing: 22pt))

(define subsec1-title-style
  (style
   use: generic-title-style
   font-size: 16pt
   line-spacing: 20pt))

(define subsec2-title-style
  (style
   use: generic-title-style
   font-size: 14pt
   line-spacing: 18pt))

(define subsec3-title-style
  (style
   use: generic-title-style
   font-size: 12pt
   line-spacing: 16pt))

(define subsec4-title-style
  (style
   use: generic-title-style
   font-size: 10pt
   line-spacing: 14pt))

(define header-footer-style
  (style
   font-size: 9pt
   font-posture: 'upright
   font-family-name: %title-font-family%))

(define mono-para-style
  (style
   font-size: 9pt
   font-posture: 'upright
   lines: 'asis
   line-spacing: 11pt
   input-whitespace-treatment: 'preserve
   quadding: 'start
   font-family-name: %mono-font-family%))

(define abstract-style
  (style
   font-posture: 'italic
   font-size: 10pt
   line-spacing: 12pt))

(define para-style
  (style
   font-size: %bf-size%
   font-weight: 'medium
   font-posture: 'upright
   font-family-name: %body-font-family%
;;   min-leading: %bf-line-spacing%
   line-spacing: %bf-line-spacing%))

(define figure-title-style
  (style
      font-family-name: %title-font-family%
      font-weight: 'bold))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 9. Common function definitions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This is where we declare reusable functions or procedures

;; (b2b-space length line-spacing)
;; Return a length spec sufficient to give a specified
;; baseline-to-baseline distance based on the current line-spacing
;; characteristic
(define (b2b-space length #!optional (line-spacing (actual-line-spacing)))
  (if (and
       (quantity? length)
       (> length line-spacing))
      (- length line-spacing)
      0pt))

;; From code posted to the DSSSList by James Clark 4/29/97
(define *small-caps-glyph-table*
  (letrec ((signature (* #o375 256))
      (make-afii
       (lambda (n)
         (glyph-id (string-append "ISO/IEC 10036/RA//Glyphs::"
                   (number->string n)))))
      (gen
       (lambda (from count)
         (if (= count 0)
        '()
        (cons (cons (make-afii from)
               (make-afii (+ from signature)))
         (gen (+ 1 from)
              (- count 1)))))))
    (glyph-subst-table (gen #o141 26))))

(define ($small-caps$ children)
  (make sequence
   glyph-subst-table: *small-caps-glyph-table*
   children))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ISO 10179 procedures

(define (ifollow nl)
  (node-list-map (lambda (snl)
         (let loop ((rest (siblings snl)))
           (cond ((node-list-empty? rest)
             (empty-node-list))
            ((node-list=? (node-list-first rest) snl)
             (node-list-first (node-list-rest rest)))
            (else
             (loop (node-list-rest rest))))))
       nl))

(define (siblings snl)
  (children (parent snl)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 10. Initial values for selected inherited characteristics

(declare-initial-value font-family-name %body-font-family%)
(declare-initial-value font-size %bf-size%)
(declare-initial-value line-spacing %bf-line-spacing%)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 11. Element construction rules
(element paper
  (let ((footer-purpose
    (make sequence
      use: header-footer-style
      (literal %conference-name%)))
   (footer-page-number
    (make sequence
      use: header-footer-style
      (page-number-sosofo)))
   (header-doc-title
    (make sequence
      use: header-footer-style
      (with-mode header
        (process-first-descendant "title"))))
   (header-author-info
    (if blind
      (empty-sosofo)
      (make sequence
      use: header-footer-style
      (with-mode header-author-info
        (process-matching-children "front"))))))
    (make simple-page-sequence
      page-width: %page-width%
      page-height: %page-height%
      top-margin: 1.25in
      bottom-margin: 1.25in
      right-margin: 1in
      left-margin: 1in
      header-margin: 0.75in
      footer-margin: 0.75in
      left-header: (if-first-page
        (empty-sosofo)
        (if recto-verso
      (if-front-page
       (empty-sosofo)
       (sosofo-append
        header-doc-title
        (literal " \bullet ")
        header-author-info))
      (make sequence
        header-author-info
        (literal " \bullet ")
        header-doc-title)))
      right-header: (if-first-page
         (empty-sosofo)
         (if recto-verso
       (if-front-page
       (sosofo-append
        header-author-info
        (literal " \bullet ")
        header-doc-title)
        (empty-sosofo))
       (empty-sosofo)))
      left-footer: (if recto-verso
           (if-front-page
      footer-purpose
      footer-page-number)
           footer-purpose)
      right-footer: (if recto-verso
      (if-front-page
       footer-page-number
       footer-purpose)
      footer-page-number)
      (process-children)
      (let ((footnotes (select-elements
      (descendants
       (current-node))
      "ftnote")))
  (if (node-list-empty? footnotes)
      (empty-sosofo)
      (sosofo-append
       (make paragraph
         use: section-title-style
         keep-with-next?: #t
         space-before: 12pt
         space-after: 6pt
         (literal "Footnotes"))
       (with-mode footnotes
         (process-node-list footnotes)))))
      (if blind
        (empty-sosofo)
        (with-mode bio
     (process-matching-children "front"))))))

;; In the header, four or more author's names are reduced to name of
;; first author plus "et al."
(mode header-author-info
  (element fname
    (with-mode #f (process-node-list (current-node))))
  (element surname
    (with-mode #f (process-node-list (current-node))))
  (element author
    (sosofo-append
     (if (not (first-sibling?))
    (if (last-sibling?)
        (literal " and ")
        (literal ", "))
    (empty-sosofo))
     (process-children)))
  (element front
    (if (< 3 (node-list-length
         (select-elements (children (current-node))
                "author")))
   (make sequence
     (process-first-descendant "author")
     (literal " et al."))
   (process-matching-children "author")))
  (default
    (process-matching-children
     "front" "author" "fname" "surname")))

(define inline-address-elements
  '("city" "state" "province" "postcode" "cntry"))

;; The address elements are an odd combination of elements that are
;; specifically one line and elements that shouldn't be on a line by
;; themselves.  As such, the entire AUTHOR element is a paragraph flow
;; object, elements that should be on a single line include a
;; paragraph-break flow object, and the not-one-per-line elements
;; include a paragraph-break only if followed by a one-per-line
;; element.
(mode bio
  ;; FNAME and SURNAME are empty sosofos here because we explicitly
  ;; process these elements using the default mode as part of AUTHOR,
  ;; and we don't want the contents of these elements appearing again
  ;; because of the process-children in the AUTHOR element
  ;; construction rule.
  (element fname
    (empty-sosofo))
  (element surname
    (empty-sosofo))
  (element author
    (sosofo-append
     ;; Output a fancy title if we're the first AUTHOR
     (if (first-sibling?)
    (make paragraph
      use: section-title-style
      keep-with-next?: #t
      space-before: 12pt
      space-after: 6pt
      (literal "Biography"))
    (empty-sosofo))
     (make display-group
       space-before: 12pt
       keep-with-next?: #t
       (make paragraph
    (make sequence
      font-weight: 'bold
      (with-mode #f (process-matching-children "fname" "surname")))
    (make paragraph-break)
    (process-children)))))
  (element affil
    (sosofo-append
     (process-children-trim)
     (make paragraph-break)))
  (element subaffil
    (sosofo-append
     (process-children-trim)
     (make paragraph-break)))
  (element jobtitle
    (sosofo-append
     (process-children-trim)
     (make paragraph-break)))
  (element aline
    (sosofo-append
     (process-children-trim)
     (make paragraph-break)))
  ;; If the next element is not another not-one-per-line element,
  ;; output a paragraph-break, otherwise output a space.
  (element city
    (sosofo-append
     (process-children-trim)
     (if (not (member (gi (ifollow (current-node)))
            inline-address-elements))
    (make paragraph-break)
    (literal " "))))
  (element state
    (sosofo-append
     (process-children-trim)
     (if (not (member (gi (ifollow (current-node)))
            inline-address-elements))
    (make paragraph-break)
    (literal " "))))
  (element province
    (sosofo-append
     (process-children-trim)
     (if (not (member (gi (ifollow (current-node)))
            inline-address-elements))
    (make paragraph-break)
    (literal " "))))
  (element postcode
    (sosofo-append
     (process-children-trim)
     (if (not (member (gi (ifollow (current-node)))
            inline-address-elements))
    (make paragraph-break)
    (literal " "))))
  (element cntry
    (sosofo-append
     (process-children-trim)
     (if (not (member (gi (ifollow (current-node)))
            inline-address-elements))
    (make paragraph-break)
    (literal " "))))
  (element phone
    (sosofo-append
     (literal "Phone: ")
     (process-children-trim)
     (make paragraph-break)))
  (element fax
    (sosofo-append
     (literal "Fax: ")
     (process-children-trim)
     (make paragraph-break)))
  (element email
    (sosofo-append
     (literal "E-mail: ")
     (process-children-trim)
     (make paragraph-break)))
  (element web
    (sosofo-append
     (literal "Web: ")
     (process-children-trim)
     (make paragraph-break)))
  (element title
    (empty-sosofo))
  (element abstract
    (empty-sosofo))
  (element bio
    (make display-group
      space-before: 6pt
      space-after: 12pt)))


(element front
  (make sequence
    ;; Process the main title
    (process-first-descendant "title")
    ;; Process the abstract
    (process-matching-children "abstract")
    ;; Process the author or authors
    (if blind
      (empty-sosofo)
      (process-matching-children "author"))))

(element (front title)
  (make paragraph
    use: paper-title-style
    keep-with-next?: #t
    space-before: 12pt))

;; We don't want the full-size title in the header, so we process the TITLE
;; element using the "header" mode when we make the header
(mode header
  (element title
    (make sequence
      use: header-footer-style)))

;; Section titles, at whatever level, are numberd only if the value of
;; the "SECNUMBERS" attribute of PAPER is not "0".  As such, we need
;; to handle two different styles of title for each level of section
;; title.
(element (section title)
  (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
      (make paragraph
   use: section-title-style
   keep-with-next?: #t
   space-before: 12pt
   space-after: 6pt)
  (make paragraph
    use: section-title-style
    keep-with-next?: #t
    space-before: 12pt
    space-after: 6pt
    start-indent: (+ (inherited-start-indent) %section-number-indent%)
    first-line-start-indent: (- %section-number-indent%)
    keep-with-next?: #t
    (make line-field
      field-width: %section-number-indent%
      (literal
       (string-append
   (format-number (element-number (parent (current-node))) "1")
   ".")))
    (process-children))))

(element (subsec1 title)
  (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
      (make paragraph
   use: subsec1-title-style
   keep-with-next?: #t
   space-before: 8pt
   space-after: 6pt)
      (make paragraph
   use: subsec1-title-style
   keep-with-next?: #t
   space-before: 8pt
   space-after: 6pt
   start-indent: (+ (inherited-start-indent) %section-number-indent%)
   first-line-start-indent: (- %section-number-indent%)
   keep-with-next?: #t
   (make line-field
     field-width: %section-number-indent%
     (literal
      (format-number-list
       (element-number-list
        '("section" "subsec1")
        (current-node))
      "1"
      ".")))
   (process-children))))

(element (subsec2 title)
  (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
      (make paragraph
   use: subsec2-title-style
   keep-with-next?: #t
   space-before: 8pt
   space-after: 6pt)
      (make paragraph
   use: subsec2-title-style
   keep-with-next?: #t
   space-before: 8pt
   space-after: 6pt
   start-indent: (+ (inherited-start-indent) %section-number-indent%)
   first-line-start-indent: (- %section-number-indent%)
   keep-with-next?: #t
   (make line-field
     field-width: %section-number-indent%
     (literal
      (format-number-list
       (element-number-list
        '("section" "subsec1" "subsec2")
        (current-node))
       "1"
       ".")))
   (process-children))))

(element (subsec3 title)
  (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
      (make paragraph
   use: subsec3-title-style
   keep-with-next?: #t
   space-before: 8pt
   space-after: 6pt)
      (make paragraph
   use: subsec3-title-style
   keep-with-next?: #t
   space-before: 8pt
   space-after: 6pt
   start-indent: (+ (inherited-start-indent) %section-number-indent%)
   first-line-start-indent: (- %section-number-indent%)
   keep-with-next?: #t
   (make line-field
     field-width: %section-number-indent%
     (literal
      (format-number-list
       (element-number-list
        '("section" "subsec1" "subsec2" "subsec3")
        (current-node))
       "1"
       ".")))
   (process-children))))

(element (subsec4 title)
  (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
      (make paragraph
   use: subsec4-title-style
   keep-with-next?: #t
   space-before: 8pt
   space-after: 6pt)
      (make paragraph
   use: subsec4-title-style
   keep-with-next?: #t
   space-before: 8pt
   space-after: 6pt
   start-indent: (+ (inherited-start-indent) %section-number-indent%)
   first-line-start-indent: (- %section-number-indent%)
   keep-with-next?: #t
   (make line-field
     field-width: %section-number-indent%
     (literal
      (format-number-list
       (element-number-list
        '("section" "subsec1" "subsec2" "subsec3" "subsec4")
        (current-node))
       "1"
       ".")))
   (process-children))))

(element acknowl
  (make sequence
    (make paragraph
      use: section-title-style
      keep-with-next?: #t
      space-before: 12pt
      space-after: 6pt
      (literal "Acknowledgements"))
    (process-children)))

(element bibliog
  (make sequence
    (make paragraph
      use: section-title-style
      keep-with-next?: #t
      space-before: 12pt
      space-after: 6pt
      (literal "Bibliography"))
    (process-children)))

(element abstract
  (make display-group
    use: abstract-style
    space-before: 18pt
    space-after: 18pt))

;; Another case of processing the child elements in the order that we want.
(element author
  (make display-group
    space-before: (if (first-sibling?) 18pt 0pt)
    space-after: (if (last-sibling?) 18pt 0pt)
    font-size: 10pt
    line-spacing: 12pt
    (process-matching-children "fname")
    (process-matching-children "surname")
    (process-matching-children "jobtitle")
    (process-first-descendant "affil")))

(element (author name)
  (make paragraph
    space-before: 12pt
    font-size: (+ (inherited-font-size) 2pt)
    font-weight: 'bold))

(element fname
  (make sequence
    (process-children-trim)
    (literal " ")))

(element surname
  (process-children-trim))

(element jobtitle
  (make sequence
    (literal ", ")
    (process-children-trim)))

(element affil
  (make sequence
    (literal ", ")
    (process-children-trim)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Paragraph-level elements

(element para
  (make paragraph
    space-before: 6pt
    (process-children-trim)))

(element sgml.block
  (make paragraph
    use: mono-para-style
    space-before: 6pt
    space-after: 6pt))

(element verbatim
  (make paragraph
    use: mono-para-style
    space-before: 6pt
    space-after: 6pt))

(element randlist
  (make display-group
    start-indent: (+ (inherited-start-indent) 0.5in)
    space-before: 6pt
    space-after: 6pt))

;; The list processing depends on the fact that list items can only
;; contain paragraphs, therefore we emit the bullet for the first
;; paragraph in an item.
(element (randlist li para)
  (if (absolute-first-sibling? (current-node))
      (make paragraph
  space-before: 6pt
  first-line-start-indent: -0.25in
  (make line-field
    field-width: 0.25in
    (literal "\bullet"))
  (process-children))
      (make paragraph
  space-before: 6pt
  (process-children-trim))))

(element seqlist
  (make display-group
    start-indent: (+ (inherited-start-indent) 0.5in)
    space-before: 6pt
    space-after: 6pt))

(element (seqlist li para)
  (if (absolute-first-sibling? (current-node))
      (make paragraph
  space-before: 6pt
  first-line-start-indent: -0.25in
  (make line-field
    field-width: 0.25in
    (literal
     (string-append
      (number->string
       (child-number (parent (current-node))))
      ".")))
  (process-children))
      (make paragraph
  space-before: 6pt
  (process-children-trim))))

(element deflist
  (make display-group
    space-before: 6pt
    space-after: 6pt))

(element (deflist title)
  (make paragraph
    font-weight: 'bold))

(element def.item
  (make paragraph
    space-before: 6pt
    first-line-start-indent: (- %term-indent%)
    start-indent: (+ (inherited-start-indent) %term-indent%)
    (process-first-descendant "def.term")
    (process-first-descendant "def")))

(element def.term
  (make line-field
    field-width: %term-indent%
    font-weight: 'bold
    (process-children-trim)))

(element (def.item def para)
  (if
   (absolute-first-sibling?)
   (process-children-trim)
   (make paragraph
     first-line-start-indent: 0pt
     space-before: %para-sep%
     space-after: %para-sep%
     (process-children-trim))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Figure and graphic

(element figure
 (make display-group
       space-before: %para-sep%
       space-after:  %para-sep%
       ;; Process the title and caption *after* the figure content
       (process-matching-children "graphic" "verbatim" "para")
       (let ((title-nl (select-elements (children (current-node)) "title")))
    (if
     (node-list-empty? title-nl)
     ($figure-title$ (current-node) (empty-sosofo))
     ($figure-title$ (current-node)
           (process-node-list (children title-nl)))))
       (process-matching-children "caption")))

(element (figure title)
    ($figure-title$ (parent (current-node)) (process-children-trim)))

(define ($figure-title$ figure-node children)
 (make paragraph
       use: figure-title-style
       space-before: %block-sep%
       space-after: %para-sep%
       start-indent: (+ (inherited-start-indent) %figure-number-indent%)
       first-line-start-indent: (- %figure-number-indent%)
       keep-with-next?: #t
       (make line-field
        field-width: %figure-number-indent%
        (literal
         (string-append
          "Figure "
          (format-number (element-number figure-node) "1")
          ".")))
       children))

(element caption
  (make display-group
    keep-with-previous?: #t
    start-indent: (+ (inherited-start-indent) %figure-number-indent%)))

(element graphic ($image$))
(element format.examp ($image$))

(define ($image$)
  (let ((entityref (attribute-string "figname" (current-node))))
    (make paragraph
     space-before: %block-sep%
     space-after: %block-sep%
     quadding: 'center
     keep-with-next?: #t
     (make external-graphic
      entity-system-id: (entity-system-id entityref)
      display?: #t
      display-alignment: 'start))))

(element inline.graphic
  (let ((entityref (attribute-string "figname")))
    (make sequence
     min-leading: %bf-line-spacing%
     (make external-graphic
      entity-system-id: (entity-system-id entityref)
      display?: #f))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Text-level elements

;; Make text bold
(define ($bold-seq$)
  (make sequence
    font-weight: 'bold
    (process-children)))

;; Make text italic
(define ($italic-seq$)
  (make sequence
    font-posture: 'italic
    (process-children)))

;; Make text bold-italic
(define ($bold-italic-seq$)
  (make sequence
    font-weight: 'bold
    font-posture: 'italic
    (process-children)))

(element highlight
  (let ((emphasis-type (attribute-string "style")))
    (case emphasis-type
      (("bold" "BOLD")
       ($bold-seq$))
      (else
       ($italic-seq$)))))

(element cit
  ($italic-seq$))

(element expansion
  (make sequence
    (literal " (")
    (process-children)
    (literal ")")))

(define ($ss-seq$ plus-or-minus #!optional (content (process-children-trim)))
  (make sequence
   font-size:
     (* (inherited-font-size) %ss-size-factor%)
   position-point-shift:
     (plus-or-minus (* (inherited-font-size) %ss-shift-factor%))
   content))

(element sup ($ss-seq$ +))
(element sub ($ss-seq$ -))

(element sgml
  (make sequence
    font-family-name: %mono-font-family%
    font-size: (* (inherited-font-size) 0.8)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Footnotes
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(element ftnote
  ($ss-seq$
   +
   (literal
    (format-number
     (element-number
      (current-node))
     "1"))))

(element fnref
  ($ss-seq$
   +
   (literal
    (format-number
     (element-number-list
      '("ftnote")
      (element-with-id (attribute-string "refloc")))
     "1"))))

(mode footnotes
  (element ftnote
    (make display-group
      start-indent: 2pi))
  (element (ftnote para)
    (if (first-sibling?)
  (make paragraph
    first-line-start-indent: -2pi
    (make line-field
      field-width: 2pi
      (literal
       (format-number-list
        (element-number-list
         '("ftnote")
         (current-node))
        "1"
        ".")))
    (process-children-trim))
  (with-mode #f
    (process-node-list (current-node)))))
;;  (default
;;    (process-children))
    )

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Cross-references
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Reference to an element returning its name
(element xref
  (case (attribute-string "type")
    (("title" "TITLE")
     (with-mode title-xref
       (process-element-with-id
  (attribute-string "refloc"))))
    (("number" "NUMBER")
     (with-mode number-xref
       (process-element-with-id
  (attribute-string "refloc"))))))

(element bibref
  (make sequence
    (with-mode number-xref
      (process-element-with-id
       (attribute-string "refloc")))))

(element bibitem
  (make paragraph
    space-before: 6pt
    first-line-start-indent: (- %bibitem-indent%)
    start-indent: (+ (inherited-start-indent) %bibitem-indent%)
    (make line-field
      field-width: %bibitem-indent%
      font-weight: 'bold
      (process-first-descendant "bib"))
    (process-first-descendant "pub")))

(element (bibitem pub)
  (process-children-trim))

(element bib
  (make sequence
    (literal "[")
    (process-children-trim)
    (literal "]")))

(mode number-xref
  (element figure
    (literal
     (format-number (element-number (current-node)) "1")))
  (element section
    (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
  (empty-sosofo)
  (literal
   (format-number-list
    (element-number-list
     '("section")
     (current-node))
    "1"
    "."))))
  (element subsec1
    (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
  (empty-sosofo)
  (literal
   (format-number-list
    (element-number-list
     '("section" "subsec1")
     (current-node))
    "1"
    "."))))
  (element subsec2
    (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
  (empty-sosofo)
  (literal
   (format-number-list
    (element-number-list
     '("section" "subsec1" "subsec2")
     (current-node))
    "1"
    "."))))
  (element subsec3
    (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
  (empty-sosofo)
  (literal
   (format-number-list
    (element-number-list
     '("section" "subsec1" "subsec2" "subsec3")
     (current-node))
    "1"
    "."))))
  (element subsec4
    (if (string=? (attribute-string "secnumbers" (ancestor "paper")) "0")
  (empty-sosofo)
  (literal
   (format-number-list
    (element-number-list
     '("section" "subsec1" "subsec2" "subsec3" "subsec4")
     (current-node))
    "1"
    "."))))
  (element bibitem
    (process-matching-children "bib")))

(mode title-xref
  (element bibitem
    (with-mode content-only
      (process-matching-children "pub")))
  (element figure
    (with-mode content-only
      (process-matching-children "title")))
  (element section
    (with-mode content-only
      (process-matching-children "title")))
  (element subsec1
    (with-mode content-only
      (process-matching-children "title")))
  (element subsec2
    (with-mode content-only
      (process-matching-children "title")))
  (element subsec3
    (with-mode content-only
      (process-matching-children "title")))
  (element subsec4
    (with-mode content-only
      (process-matching-children "title"))))

(mode content-only
  (default
    (with-mode #f
      (process-children))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 12. External module references
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; 12.1 Tables
;;
;; Table code borrowed from Anders Berglund's contribution to
;; Jon Bosak's DocBook stylesheet plus modifications

&table.dsl;

;; End of paper stylesheet

