Scripta Language
#draft #tag:scripta
The main idea: A Scripta document is composed of blocks and elements. In what follows, we explain what blocks and elements are, then give numerous examples.
A [term block] consists of a contiguous bunch of non-empty lines with terminated by an empty line. Notice that if a line consists only of \(n\) spaces with \(n > 0\), it will be “blank” but not empty.[term_ lines, blank][term_ lines, empty]
There are two kinds of blocks: [term named list-as:block, named] and [term unnamed list-as:block, unnamed]. An unnamed block is just a paragraph, like the one you see here. Below is a named block — an image block.
An image block[term_ block, image] places an image in your document. Its general form is
In the example above NAME is “image”, ARG1 is “expandable,”
and PROPERTY1 is “width:300.” In most cases arguments and properties are optional.[term_ argument][term_ property][term_ image, width (property))][term_ image, expandable (argument)] However, arguments always come before
properties. In the example below the image block
has neither arguments no properties.
Below is a rendered example of such a block:
Now look at the next image. It is smaller because it has
the property width:400. The caption comes from the
property caption:Hummingbird. It also has the argument expandaable. If you click on the image,
it opens up to fill the screen. To return to the normal state, click it again.
Here is what we wrote to get the image above:
There is something else we can do. Image blocks
can have the property float:left or float:right. If that is the case, the text below the document flows around the image. We decreased the width property but kept the expandable argument, so clicking on the document still expands it to fill the screen. Even thought the floated image is very small, it uses the full-size image, so when we expand it, it still looks good.
Organizing a document
An import kind of named block is the [term section block, list_as: block, section]. Above you see the text “1.1 Organizng a Document” and further above you see “1. Blocks”. These are section headings. Sections have a [term level, list-as:section, level]. Thus “Organizing a document” heads a level 2 section and “Blocks” heads a level two section.
or just
To write a level two section, or subsection, we write
Shortcut
There is a convenient shortcut for writing blocks. Write
# Blocks
## Organizing a document
for level 1 and level 2 blocks. This shortcut is a syntax borrowed from Markdown. We will see afew other shortcuts as we go along.
Math blocks
Here is an example of a displayed equation:
\[ \int_0^1 x^n dx = \frac{1}{n + 1} \]
It is written using a [term math block list-as:block, math]:
\[ \int_0^1 x^n dx = \frac{1}{n + 1} \]
Here is the same equation with the property label:integral[term_ equation, labeled]:
\[ \int_0^1 x^n dx = \frac{1}{n + 1} \]
It is written like this:
\[ \int_0^1 x^n dx = \frac{1}{n + 1} \]
Labeled equations are numbered automatically. We can use the label to refer to them in text that appears either before or after the equation itself. For example,
You must study equation [eqref integral] for the test.
If you click on [eqref integral], the document will highlight the equation and scroll it so that it is centered in the rendered text. Press ESC to stay where you scrolled to. The equation will remain highlighted. Press ESC once more to remove the highligting.
ETeX
Look again at the way [eqref integral] is written. The body of the equation element has a certain amount of visual noise in the form of backslashes and curly braces. Though traditional, this is not strictly necessary. Our [term ETeX] package provides a way to use a notation closer to the notation we use in mathematics, e.g.:
\[ int_0^1 x^n dx = frac(1,n+1) \]
There is no change in the visual output:
\[ int_0^1 x^n dx = frac(1,n+1) \]
Note how we wrote the fraction: it is as if frac is a
function of two variables. Indeed, it is! The notations
\frac{1}{n+1} and frac(1,n+1) are two ways of expressing the same idea.
Math Macros
TeX, hence LaTeX, KaTeX, etc. provide for a way of making new macros to make it easier to write complex expressions. To see how this works, consider the equations
\[ pdd(u,x) + pdd(u,y) + pdd(u,z) = frac(1,c^2) pdd(u,t) qquad "Wave Equation" \]
It has many second partial derivatives which normall we
would write as \frac{\partial^2 u}{\partial x^2}, and similarly for the partials with respect to \(y\), \(z\),
and \(t\). But using macros in ETeX form we write
pdd(u,x) for the second partial derivative of \(u\) with
respect to \(x\). Then the source text for [eqref wave-equation] looks like this:
\[ pdd(u,x) + pdd(u,y) + pdd(u,z) = frac(1,c^2) pdd(u,t) qquad "Wave Equation" \]
We defined pdd using a [term macro block list-as:block, macro (math)]:
A mathmacros block can have as many definitions
as we like, e.g.,
Then we can write \(pd(u,x)\), \(santa\) and \(isPrime(3)\) by writing the text
Then we can write $pd(u,x)$, $santa$ and $isPrime(3)$
## Theorems
Here is a theorem:
| theorem label:theorem-primes
There are infinitely many primes.
| theorem label:theorem-primes-mod-4
There are infinitely many primes $p \equiv 1 " mod " 4$.
And here is how we wrote it:
| code
| theorem label:theorem-primes
There are infinitely many primes.
Note the label. It allows us to cross-reference the document
by using a `ref` element. Writing `Lets study theorem [ref theorem-primes]`, we produce the rendered text
| indent
Lets study theorem [ref theorem-primes] <<< WRONG.
[par]
Lets study theorem [ref theorem-primes-mod-4] <<< WRONG.
[par]
Lets study lemma [ref theorem-primes]
## Code
We use a `code` block for writing computer code:[term_ block, code]:
| code python
def factorial(n):
if n < 0:
raise ValueError("undefined if input < 0")
if n == 0:
return 1
return n * factorial(n - 1)
Here we said
| code
| code
def factorial(n):
...
If the code has empty lines, we have to indent everything
so as to obey the principle that blocks consist of
a sequence of non-empty lines terminated by an empty line.
| code
fact = 1
print("n n!")
for n in range(11):
if n > 0:
fact *= n
print(n, fact)
To get the result above, we wrote
| code
| code
fact = 1
print("n n!")
...
Note the indentation. The easy way to achieve this is
to write the code without indentation, select it, then
press TAB.
[b Alternate syntax.] Here is another way to write a code block:
| code
fact = 1
print(“n n!”) for n in range(11): if n > 0: fact *= n print(n, fact)
As in Markdown, we begin the code block with three backticks. Again, because a Scripta block consists of non-empty lines, we must indent the document body. For the same reason, there is no need to close the block with three backticks.
Elements
A piece of ordinary text, like this sentence is an element. There are also [term function elements list-as:element, function], like these:[term_ element, italic][term_ element, bold][term_ element, blue]
[i italic text]
[b bold text]
[blue blue text]
Using them, we can write sentences composed of runs of ordinary text and function elements, like this
This is italic text and this is bold text. We can
combine function elements to construct things like bold italic text, [pink pink italic text], etc. For the last example, we wrote [pink [i pink italic text]].[term_ element, function (combine)]
Here is the source text:
This is [i italic text] and this is [b bold text].
We can combine function elements to construct things
like [b [i bold italic text]], [pink [i pink italic text]], etc.
For the last example, we wrote `[pink [i pink italic text]]`
Notice the use of the syntax
`[pink [i pink italic text]]`
to render code inline. We can also use a code element: [code [code [pink pink italic text]]]
The colors available in Scripta are red, blue, green, pink, magent, violet, and gray.[term_ colors, colors available] The general form of a function element is
[NAME BODY]
In [i italic text], “i” is the name of the function element
and “italic text” is its body.[footnote A function element is somewhat like an application of a function].[term_ element, function name][term_ element, function body]
Math Elements
There are two kinds of math elements, inline and display.
A formula like [math a^2 + b^2 + c^2][term_ element, math (inline)] is given by the inline element [math a^2 + b^2 + c^2].[term_ element, math] We saw math blocks in section [ref math-blocks].
Below are two variants which give exactly the same result:
[m a^2 + b^2 + c^2]]
$a^2 + b^2 + c^2$
Chemistry Elements
The chem element gives an easy way of displaying chemical formulas and reactions. Here is water, [chem H2O][term_ element, chem], written
as [chem H20]. There is also a display form, given
by a chem block[term_ block, chem][term_ element. chem]:
and written as
Let’s use this construct to write a chemical reaction
This reaction is an explosion.
Code
Let’s talk about Theorem [ref theorem-primes] and also Lemm [ref divides-is-transitive]