1 How to Scribble Documentation
2 Scribble Layers
3 @-Reader
4 Structures And Processing
5 Renderer
6 Decoding Text
7 Document Language
8 Document Reader
9 Basic Document Forms
10 Scheme
11 Manual Forms
12 Evaluation and Examples
13 BNF Grammars
14 Cross-Reference Utilities
15 Text Preprocessor
Index
On this page:
15.1 Using External Files
include
Version: 4.0.2

 

15 Text Preprocessor

 #lang scribble/text

The scribble/text language provides everything from scheme/base with a few changes that make it suitable as a preprocessor language:

This means that to write a text file that has scheme code, you simply write it as a module in the scribble/text language, and run it through mzscheme. Here is a sample file:

  #lang scribble/text

  @(define (angled . body) (list "<" body ">"))@;

  @(define (shout . body) @angled[(map string-upcase body)])@;

  blah @angled{blah @shout{blah} blah} blah

(Note how @; is used to avoid empty lines in the output.)

15.1 Using External Files

Using additional files that contain code for your preprocessing is trivial: the preprocessor source is a plain Scheme file, so you can require additional files as usual.

However, things can become tricky if you want to include an external file that should also be preprocessed. Using require with a text file (that uses the scribble/text language) almost works, but when a module is required, it is invoked before the current module, which means that the required file will be preprocessed before the current file regardless of where the require expression happens to be. Alternatively, you can use dynamic-require with #f for the last argument (which makes it similar to a plain load) – but remember that the path will be relative to the current directory, not to the source file.

Finally, there is a convenient syntax for including text files to be processed:

(include filename)

Preprocess the filename using the same syntax as scribble/text. This is similar to using load in a namespace that can access names bound in the current file so included code can refer to bindings from the including module. Note, however, that the including module cannot refer to names that are bound the included file because it is still a plain scheme module – for such uses you should still use require as usual.