7. Scribe User Manual -- Computer programs

7. Scribe User Manual -- Computer programs

Browsing

Home: Scribe User Manual

Previous chapter: Bibliography
Next chapter: Graphical User Interfaces


Computer programs

Prgm
From-file


Chapters

Getting Started
Syntax
Standard Library
Hyperlinks and References
Index
Bibliography
Computer programs
Graphical User Interfaces
Customization
Scribe style files
Editing Scribe Programs
Compiling Scribe programs
Compiling Texi documents
Using Bibtex databases
Functions and Variables


Scribe

Home page:Scribe

Documentation:user
expert


It is common that some parts of a Scribe text represent other texts. For instance, for a document describing a computer programming language, it is frequent to include excerpt of programs. These embedded texts are frequently displayed in a specific font and with no justification but with a precise indentation. This indentation is important because it helps in understanding the text; it is thus desirable to preserve it in the Scribe text. The pre text layout already enables such a text formating. In this chapter we present a new Scribe function: prgm that is specially designed to represent computer programs in Scribe text.

A prgm function call preserves the indentation of the program. It may automatically introduce line numbers. It enables fontification. That is, some words of the program can be rendered using different colors or faces. This function is presented in this chapter.

7.1 Prgm

(prgm [:lnum #f] [:bg #f] [:frame #f] [:width 1.0] [:language #f] . exp)Scribe function

argumentdescription
:lnumThe boolean value #f disables line numbering. An integer value enables line number. The number of the first line is the value of :lnum.
:bgThe color of the background of the computer program.
:frameEnables or disables a frame around the text of the program.
:widthThe width of the program. An integer value specifies a pixel width. A floating point value specifies a percentage of the text line width.
:languageThe name of a function implementing fontification for that text. The plain Scribe implementation comes with four predefined functions:
  • scribe that suits Scribe computer programs.
  • xml that suits XML texts.
  • bigloo that suits Scheme computer programs.
  • c that suits C computer programs.
New customized fontification functions can be defined. However, it is beyond the scope of this manual to explain how to proceed. This is documented in the Scribe Programming Manual.
expThe text of the computer program.

The first example uses no fontification:

(prgm :frame #t :bg "#dddddd" [
SCRIBE = scribe

all: demo.html demo.man

demo.html: demo.scr
        $(SCRIBE) demo.scr -o demo.html

demo.man: demo.scr
        $(SCRIBE) demo.scr -o demo.man
])
                

produces:

SCRIBE = scribe

all: demo.html demo.man

demo.html: demo.scr
	$(SCRIBE) demo.scr -o demo.html

demo.man: demo.scr
	$(SCRIBE) demo.scr -o demo.man

The second example uses some fontification and line numbering:

(prgm :language c :bg "#dddddd" :lnum 10 [
#include <stdio.h>

int main( int argc, char *argv,(char 91),(char 93) ) {
   printf( "Hello word: %d (%s)\n", argc, argv,(char 91) 0 ,(char 93) );
   return 0;
}])
                

produces:

  10:#include <stdio.h>
  11:
  12:int main( int argc, char *argv[] ) {
  13:   printf( "Hello word: %d (%s)\n", argc, argv[ 0 ] );
  14:   return 0;
  15:}


7.2 From-file

(from-file [:definition #f] [:start #f] [:stop #f] file)Scribe function

argumentdescription
:definitionA string denoting the definition name. This option is not implemented for all languages. Currently only Bigloo and Scribe languages implement it.
:startA line number where to start the text inclusion.
:stopA line number where to stop the text inclusion.
fileThe file to be included.

It is convenient not to embed the computer program text inside the Scribe document but leave it inside separate files. The Scribe function from-file enable inclusion inside a prgm call. An entire file or only some parts of the file can be included. The example:

(prgm :language scribe :lnum 1 [,(from-file "prgm.scr" :start 17 :stop 22)])

produces:

   1:It is common that some parts of a Scribe text represent other
   2:texts. For instance, for a document describing a computer programming
   3:language, it is frequent to include excerpt of programs. These
   4:embedded texts are frequently displayed in a specific font and with no
   5:justification but with a precise ,(emph "indentation"). This indentation is
   6:important because it helps in understanding the text;

The example:

(prgm :language bigloo [,(from-file :definition "fib" "prgm-fib.scm")])

produces:

(define (fib x)
   (if (< x 2)
       1
       (+ (fib (- x 1)) (fib (- x 2)))))



This
Scribe page is generated by scribeinfo.
Last update Fri May 10 20:19:00 2002