Organizing Text Formats

There are several ways to organize text formats. You can apply them directly wherever you need them, as you did when you formatted the sample document in this chapter, and set the options for heading each time you used it.

Defining Text Formats at the Top of the Document

If you are creating only one document, you can organize text formats by defining or redefining them at the top of the document.
For the example document used in this chapter, you might create your own text formats (H1 and H2) and place them at a point in the document that comes before calls to either of them. A common practice is to place them before the document's main content. You can then use them instead of heading.
For example, you can define H1 and H2 as follows:
{define-text-format H1 as heading with
    level = 1,
    font-size=14pt,
    color="green"}

{define-text-format H2 as heading with
    level = 2,
    font-size=10pt,
    color="olive"}

Including a File of Text Formats

If for reasons of organization, you prefer to maintain the document and text formats used by the document in separate files, you can put all the text format definitions in one or more files, then include the file at the top of each document.
For example, you can create a text format file called sales-reports-formats.curl. Then at the top of each sales report document, before the {document-style ...} and {set-document-properties ...} lines, enter the following line of code:
{include "sales-reports-formats.curl"}
If sales-reports-formats.curl is not in the same directory as the sales report document files, use the url format to specify its location. For example:
{include "file:///c:/sales/sales-reports-formats.curl"}

Importing a Package of Text Formats

For documentation sets that require an entire suite of text formats, including text procedures, and possibly support code such as class definitions and procedures, it is more efficient to keep the definitions in separate files which are grouped together as a code package. The documents that call them import the package.
It is better to import a package than to include files, because each applet the includes a file loads and stores that file in a separate area of memory, which is inefficient in terms of both performance and memory usage. Files in an imported package are loaded and stored once and reused by all applets using the same package.
Consider a simplified example. You have two files containing text formats.
c:/sales/report-formats1.curl contains:
{define-text-format public H1 as heading with
    level = 1,
    font-size=14pt,
    color="green"}
c:/sales/report-formats2.curl contains:
{define-text-format public H2 as heading with
    level = 2,
    font-size=10pt,
    color="olive"}
Note: Anything defined in package files, such as formats, classes, or procedures, must be declared public in order to be accessible to code outside the package.
Create a file named load.scurl in the same directory as the two text format files, having the following content:
{curl 6.0 package}
{package SALES}
{include "report-formats1.curl"}
{include "report-formats2.curl"}
Then at the top of each document file, import the package with the following line of code:
{import * from SALES, location = "load.scurl"}
Packaging text formats is no different from packaging any other source code written in the Curl® language. You can create circular dependencies that you must resolve before your source code can work. Since the Curl language is a content-based language, the seamless binding between content and source code also extends to binding text formats and support source code in the same package.
To fully understand packages, you need to understand the Curl language as a development language. See the language sections of the Developer's Guide, which begin with the Files chapter . See the Packages chapter for additional information on packages. Also see the API Reference on include, import, and package.