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

-f CODE

--format-code

format_code

a format code

Number format

-m

--multiline, --mult

multiline

flag

Break calculations over several lines

-p

--param-line

param_line

flag

Show target = result only

-u

--units

units

flag

Show a number times units (5 * kN) as its value only (handcalcs.units.is_units_input)

-y

--sympy

sympy

flag

Substitute the SymPy expression a name holds (x = f runs as x = <f's expression>); see handcalcs.parsing.sympy_substitution

-g

--grid, --params-block, --params

(opens a grid)

flag

Grid of the following assignments and bare names, with comments

-c N

--param-cols, --param_cols

param_cols

integer

Columns in -g parameter grids (default 3)

-b

--line-break

(one-shot)

flag

Vertical space

--check

check

flag

A boolean result is shown as a pass/fail mark (CHECK_MARKS)

--boxed

boxed

flag

A box is drawn around the result (BOX; see below)

--pagebreak, --page-break

(one-shot)

flag

Page break (see below)

-i

--ignore

ignore

flag, or flag + condition

Leave lines out of the output

-s

--show

ignore (False)

flag, or flag + condition

Show lines again after -i

-d [NAME ...]

--dive

dive

flag, or flag + function names

Show the bodies of the functions the line calls (see below)

-w

--if-winner-only, --winner

if_winner_only

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 PAGE_BREAK)

ASCII

a line holding a form feed (\f)

LaTeX

\newpage

Markdown

<div style="break-after: page;"></div> (takes effect when printed or converted through HTML)

HTML

<div class="hc-page-break" style="break-after: page;"></div>

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 ┌─┐ │ └─┘ on the rows above, at and below the result

LaTeX, Markdown

\boxed{...} (amsmath; MathJax and KaTeX have it too)

HTML

<span class="hc-boxed">, a border in the text colour

Word

a boxed formula (m:borderBox)

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

format_code

a format code string

mode

"full", or a string containing any of ass, sym, num, res

multiline, param_line, units, sympy, ignore

True / False

dive

True / False, or a string of function names ("f g")

dive_fold, dive_header, dive_dedent

True / False (see Dives above)

param_cols

integer

assign

the symbol between steps (default "=")

subscripts

"comma" or "nested"

symbols

a dict of name → display spec, e.g. {"N_plRd": "N_{pl,Rd}"}

greek_prefixes

True / False

check

True / False

boxed

True / False

any other name

stored on the context for custom renderers