Skip to main content

The PreTeXt Guide

Subsection 4.15.3 Interactive Programs, ActiveCode

ActiveCode is an interactive environment where a reader may work on code through repeated edit-compile-test cycles. Code can be provided by an author as a complete program to be modified, a partial program to be completed, or nothing at all. One good example is that maybe header files, import statement, and similar are provided, and a skeleton of a main entry-point procedure is also provided. Then a reader can concentrate on the more conceptual parts of the programming. Some languages will be executable “in browser” on any old generic web server, while others must be on a Runestone server (Chapter 32) where a Jobe Server 1  is running to support the execution.
Place the @interactive attribute on a <program> element with the value activecode to elect this behavior (no is the default value). Also, be sure to specify a language from the supported languages. Consult Table below for a summary of various combinations. When an output format does not support an interactive ActiveCode instance, the fallback is a static program listing.
Note that a Python ActiveCode automatically is enabled with a CodeLens button and requires no preparation of any trace data. So a reader can form any type of Python program and closely examine its behavior.
Note also that a data file may be provided independently for consumption by an ActiveCode program. See Section 4.16.
ActiveCode elements that are language sql can make use of an SQLite database file. This is different than a datafile (which is expected to be text or an image). To include a database file, use the @database on the <program> element and specify the file to load as a string relative to the @@external top-level directory
If you want to include code from one or more preceding <program> elements, use the @include attribute whose value is a list (comma-separated or space-separated) of @xml:ids for the code you want included.