Comment commands#
A comment starting with hc: is a command. On its own line it applies to every following
line; at the end of a line it applies to that line. See
the guide for examples.
Flags#
Flag |
Long forms |
Context field |
Value |
Effect |
|---|---|---|---|---|
|
|
|
a format code |
Number format |
|
|
|
flag |
Break calculations over several lines |
|
|
|
flag |
Show target = result only |
|
|
|
flag |
Show a number times units ( |
|
|
|
flag |
Substitute the SymPy expression a name holds ( |
|
|
(opens a grid) |
flag |
Grid of the following assignments and bare names, with comments |
|
|
|
integer |
Columns in |
|
|
(one-shot) |
flag |
Vertical space |
|
|
flag |
A boolean result is shown as a pass/fail mark ( |
|
|
|
flag |
A box is drawn around the result ( |
|
|
(one-shot) |
flag |
Page break (see below) |
|
|
|
|
flag, or flag + condition |
Leave lines out of the output |
|
|
|
flag, or flag + condition |
Show lines again after |
|
|
|
flag, or flag + function names |
Show the bodies of the functions the line calls (see below) |
|
|
|
flag |
Accepted; no effect in 2.0 |
Source: commands.
A flag the comment does not give leaves its setting as it is. -i or -s followed by
an expression (# hc: -s M_f > 0) takes the rest of the comment as the condition; the
parser evaluates it with the values at the comment (for an inline command, after its
line ran) and stores only the outcome: a true condition applies the flag, a false one
the opposite. Hiding is applied by BaseRenderer.render_node for every renderer
(HIDEABLE, is_hidden, render_hidden).
Page breaks#
# hc: --pagebreak on its own line breaks the page before the next line; at the end of
a line it breaks after that line. It is one-shot and never carried forward. It does
nothing at the end of a block header (if ...:) or inside a ; parameter line.
Renderer |
Output (class attribute |
|---|---|
ASCII |
a line holding a form feed ( |
LaTeX |
|
Markdown |
|
HTML |
|
Word |
a page break |
Excel |
a horizontal print page break after the row |
A custom renderer receives the break as the item handcalcs.renderers.base.PAGE_BREAK
("\f") in join_item.
Dives#
# hc: --dive (-d) on a line puts a DiveBlock before it for each call it made to a
Python function: call (the FunctionCall), bindings (a Binding per parameter:
argument → parameter, or parameter=default), lines (the parsed body, run with
that call’s values) and returns (the name a final return <name> gives back). With
names (--dive f g) only those functions are opened. On its own line the command
applies to the following lines until # hc: dive = False. Which lines dive is read from
the source (dive); the calls are recorded while it runs, in
the same pass as each line’s values (line_values, CallRecord).
A renderer draws a dive as a block: its header comes from the header:dive_block
handler, and each binding from the binding handler. The base handler joins an argument
and its parameter with the class attribute DIVE_ARROW (→; LaTeX \rightarrow). The
dive_block handler restores the render context after the body, so the body’s commands
stay in it.
Three context fields change how a dive is drawn. dive_fold makes the base binding
handler (and Word’s) return the parameter alone when the argument is a Name with the
same source identifier (folds() in base). With
dive_header = False, the dive_block handler replaces the header with
HIDDEN_HEADER, a HiddenHeader (an empty str subclass): the join step writes no
line for it but still indents the body. With dive_dedent = True too, the header is a
plain "", so the body is joined flush, like a CalcsBlock’s. A renderer that overrides
join_item should handle a HiddenHeader before its check for an empty header.
Boxed results#
# hc: --boxed draws a box around the last value of a line: its result, or, on a
--check line, the substitution before the mark. Each renderer puts its class
attribute BOX, an (open, close) pair, on either side of that value.
Renderer |
Box |
|---|---|
ASCII |
drawn with |
LaTeX, Markdown |
|
HTML |
|
Word |
a boxed formula ( |
Excel |
a thin border on the value cell |
A custom renderer based on BaseRenderer gets [ and ] unless it sets its own BOX.
Assignment form#
# hc: name = value[; name = value ...] sets context fields directly. The text is run as
Python; if that fails, it is parsed as flags.
Field |
Values |
|---|---|
|
a format code string |
|
|
|
|
|
|
|
|
|
integer |
|
the symbol between steps (default |
|
|
|
a dict of name → display spec, e.g. |
|
|
|
|
|
|
any other name |
stored on the context for custom renderers |