6.11.1 Implementing Styles

When a string is used as a style in an element, a multiarg-element, paragraph, table, itemization, nested-flow, or compound-paragraph, it corresponds to a CSS class for HTML output or a Latex macro/environment for Latex output. In Latex output, the string is used as a command name for a paragraph and an environment name for a table, itemization, nested-flow, or compound-paragraph; if the style has a 'command style property for a nested-flow or compound-paragraph, then the style name is used as a command instead of an environment; and if the style has a 'multicommand style property for a nested-flow, then the style name is used as a command with multiple arguments. In addition, for an itemization, the style string is suffixed with "Item" and used as a CSS class or Latex macro name to use for the itemization’s items (in place of \item in the case of Latex).

To add a mapping from your own style name to a CSS configuration, add a css-addition structure instance to a style’s style property list. To map a style name to a Latex macro or environment, add a tex-addition structure instance. A css-addition or tex-addition is normally associated with the style whose name is implemented by the addition, but it can also be added to the style for an enclosing part.

Scribble includes a number of predefined styles that are used by the exports of scribble/base. You can use them or redefine them. The styles are specified by "scribble.css" and "scribble.tex" in the "scribble" collection.

The styles used by scribble/manual are implemented by "racket.css" and "racket.tex" in the "scribble" collection. Other libraries, such as scriblib/autobib, similarly implement styles through files that are associated by css-addition and tex-addition style properties.

To avoid collisions with future additions to Scribble, start your style name with an uppercase letter that is not S. An uppercase letter helps to avoid collisions with macros defined by Latex packages, and future styles needed by scribble/base and scribble/manual will start with S.

For example, a Scribble document

  #lang scribble/manual

  @(require scribble/core




  @(define inbox-style

     (make-style "InBox"

                 (list (make-css-addition "inbox.css")

                       (make-tex-addition "inbox.tex"))))


  @title{Quantum Pet}


  Do not open: @elem[#:style inbox-style]{Cat}

combined with an "inbox.css" that contains

  .InBox {

    padding: 0.2em;

    border: 1px solid #000000;


and an "inbox.tex" that contains



Quantum Pet

Do not open: Cat

Scribble documents can also embed specific html tags and attributes. For example, this Scribble document:
#lang scribble/base
@(require scribble/core
@(define external-image
    (style #f
           (list (alt-tag "img")
                  '((src . "http://racket-lang.org/icon.png")))))))

renders as the the Racket logo at the url http://racket-lang.org/logo.png when producing html.