Changelog#
2.2.0 (2026-12-01)#
Three settings make a
# hc: --divequieter (#400).dive_foldshows an argument passed under its own name as the name alone (F_y, notF_y → F_y).dive_header = Falseleaves out the “Calculating …” line, anddive_dedentthen sets the function’s lines flush with the lines around them. Set them with# hc: dive_fold = True,render_context=,set_optionor the command line. See A quieter dive.
2.1.0 (2026-11-30)#
# hc: --dive(-d) shows the working inside the functions a line calls, before the line: a header matching each argument to its parameter (Z_x → Z,φ=0.9for a default), then the function’s body with the values of that call. A function’s own--divelines go a level deeper. Every renderer draws it. In Excel, a dive is a group of rows that folds away, and its names have the function’s name in front. See The functions a calculation calls.Comments inside a function or class definition are no longer shown at the top level of the calculation.
A function’s name is shown upright and whole in every renderer:
glulam_mr(b, d), not “glulam” with a subscript “mr”. The HTML and Excel renderers used to split it like a variable’s name.A
@handcalcfunction’s docstring is set as prose in every renderer. With the Markdown and LaTeX renderers it used to land inside the maths block.The HTML renderer marks a block header (
Since ...,Iterating over ...,Calculating ...) with a small square in place of ▸, which looked like a control that folds the block.
2.0.1 (2026-11-27)#
A
# hc: -ggrid also takes bare names (b_won its own line): each is a cell showing its value, so a grid can list inputs defined in an earlier cell. Before, a bare name ended the grid.A chained assignment (
a = b = 2 + 3) in a# hc: -gor;grid is a cell for each name (a = 5,b = 5), each with the line’s comment. Before, its cell lost the value (a = b =). Outside a grid it is unchanged (a = b = 2 + 3 = 5); the Excel renderer still refuses it.
2.0.0 (2026-11-24)#
handcalcs 2.0 is a rewrite: the parser builds a tree of nodes, and pluggable
renderers turn it into Markdown (the Jupyter default), LaTeX, HTML, ASCII text,
Excel (live formulas) or Word (editable equations). pip install handcalcs now
installs 2.0. Notebooks written for 1.x need a few changes; see
Coming from handcalcs v1, or pin
"handcalcs<2" to stay on 1.x for now.
The sections for 2.0.0rc1 to rc5 below list everything that is new. For people coming from 1.x, the main points:
Comment commands (
# hc: -f .2f,-m,-g,-i/-swith conditions,--check,--boxed,--pagebreak) replace the v1 cell override tags.Headings, prose and light Markdown in comments, and Jinja templating.
More of Python renders: nested
if/for, indexing, comprehensions, conditional expressions,withblocks, line continuations, bare expressions.Units: forallpeople and pint quantities,
# hc: -ufor unit inputs.SymPy substitution with
# hc: -y(v1’s%%render sympy),%%source latex(v1’s%%tex),%renderfor one line,@handcalc(display=True), a command line (handcalcs script.py -o calc.docx) andinputs=to render one script with many input sets.
Behaviour changed during the release candidates (see each section): comment commands
are read, never run (rc3); a value keeps the -f format of its line (rc3); a lone
line ending in ; is a one-cell grid row and # hc: -c no longer reshapes ;
lines (rc5).
@handcalc(jupyter_display=True) still works, with a deprecation warning; it will
be removed in handcalcs 3.0.
Changes since 2.0.0rc5#
The
exportersextra is gone. nb-hideinputs, which it installed, no longer hides input cells with current nbconvert. Use nbconvert’s own--no-inputinstead (jupyter nbconvert --to html --no-input calcs.ipynb; see Exporting a notebook).
Fixes since 2.0.0rc5#
A
@handcalcfunction in a rendered script works: calling it raisedOSError: could not get source code, because the decorator reads its function’s source and a script run byHandCalcs(...)(path)or thehandcalcscommand had no source file Python could find. The script’s source is now registered forinspect.# ##and# ##are headings, the same as###: spaces between the comment marker and the heading’s#s no longer turn it into a comment line.# hc: -badds about one blank line in every renderer. The HTML renderer added nothing; it now adds a spacer (.hc-break). The Markdown renderer’s paragraph added about two lines between equations in Jupyter; it is now a small spacer<div>. In LaTeX the break is\vspace{\baselineskip}instead of\medskip.Long equations no longer run off the page in Word: the Word renderer estimates each equation’s width against the document’s text width. A substituted row that is too wide is split one step per row, as with
-m; a wide# hc: -ggrid is set in fewer columns; and a row that is still too wide is set in a smaller font, down to 60% (details).Line magics and
!commands inside a%%rendercell (%time x = f(y),!ls) raised aSyntaxError. They now run with the cell and are left out of the render. Withinputs=they give a clear error instead.Long equations no longer run off the page in LaTeX: TeX cannot break a line inside an
alignedgroup, so long calculations overflowed the right margin (anOverfull \hboxwarning). The LaTeX renderer now estimates each row’s typeset width: a substituted row wider than the line (MAX_ROW_WIDTH, 345 pt) is split one step per line as with-m, a wide# hc: -ggrid is set in fewer columns, and a group that is still too wide is scaled down to the line by\hcfit. The scaling needsgraphicx, now in the file preamble (details).pint quantities of numpy arrays show their values (#384): in the LaTeX and Markdown renderers,
array([2, 4]) * ureg.kNrendered every element as the format code (.5g). The array is now drawn as other numpy arrays are,[2, 4] kN, in every renderer, so the format code andmax_itemsapply to its elements.
2.0.0rc5 (2026-11-19)#
The fifth release candidate of handcalcs 2.0. Install it with
pip install "handcalcs>=2.0.0rc5"; a plain pip install handcalcs still installs
1.x until 2.0.0 is released.
Features#
;grids keep the layout you write: each;line is a row of the grid, soa = 1; b = 2overc = 3; d = 4; e = 5lays out two cells over three. Before, the cells were reflowed three to a row. End a line with;(f = 6;) for a one-cell row.# hc: -c Nnow sets the width of# hc: -ggrids only, which still reflow (details).SymPy substitution,
# hc: -y:x = f, wherefholds a SymPy expression, runs and renders asx = <the expression>with the values its symbols have when the line runs, so the algebra done in SymPy becomes a calculation, as v1’s%%render sympydid. On its own line it applies to every such line until# hc: sympy = False. Works in scripts,%%renderand@handcalc(where the expression may be an argument). SymPy is not a dependency.%%sourceprints a cell’s rendered text (LaTeX, Markdown, HTML, plain text) instead of displaying it, to copy into another document.%%source latexuses the LaTeX renderer for that cell, as v1’s%%texdid. It takes%%render’sinputs=arguments, and%sourceprints one line.# hc: -ushows unit inputs as values (#353): a line that is a number times units,P = 5 * kN, renders asP = 5 kNinstead ofP = 5 · kN = 5 · 1 kN = 5 kN. Lines that calculate keep every step. Turn it on for what follows, for one line (inline), or everywhere withset_option("units", True)(details).Stacked fractions in the HTML renderer, with typeset maths: italic names in a serif maths font.
HTMLRenderer(fractions="inline")keeps divisions on one line (details).@handcalc(display=True)shows the render (displayed in Jupyter, printed elsewhere) and returns only the function’s result;jupyter_display=Truefrom handcalcs 1 still works (#369, details).A command line:
handcalcs script.py -o calc.docx(see Command line).Excel formulas with US units have unit factors only where they are needed. Formulas used to convert every reference to SI and back, so a sheet in US units was full of factors that cancel:
M_u = w_u * L**2 / 8was=w_u*14593.9029372*(L*0.3048)^2/8/1355.81794833. It is now=w_u*L^2/8. A factor is written only where units do not cancel, in its simplest form:DCR = M_u / phi_M_n(kip·ft over kip·in) is=M_u/phi_M_n*12. Factors are exact with forallpeople 3.5 or later, and its newus_structuralenvironment shows mixed-unit results in US units (details). Formulas give the same results as before. Sheets in base SI units are unchanged; with prefixed units the factors fold too (=F*Lfor kN and mm, instead of=F*1000*(L*0.001)).# hc: --boxeddraws a box around a line’s result:\boxed{}in LaTeX and Markdown, a framed result in HTML, a boxed formula in Word, a bordered value cell in Excel, and a box drawn with line characters in ASCII. On its own line it boxes the result of every following line (reference).float()andint()in the Excel renderer:float(x)is the value itself andint(x)becomesTRUNC. With units, both match Python: forallpeople gives the magnitude in the displayed unit (float(4 * ksi)is4), and pint the dimensionless value. This means the ACI patternsqrt(float(f_c / psi))now works (details).
Fixes#
A substituted value that is itself a sum is bracketed (#224): a complex number with a real and an imaginary part, or a SymPy sum, product or power, now reads
2 · (3+4j),(3+4j)²and-(3+4j)instead of2 · 3+4j,3+4j²and-3+4j, in every renderer. The LaTeX renderer no longer brackets a SymPy value standing on its own (z = 3 + 4i, notz = (3 + 4i)).A bare expression under
--checkwhose symbolic and substituted forms are the same (2 <= 3 # hc: --check) showed both (2 ≤ 3 = 2 ≤ 3 ✓); the repeat is now dropped, as for an assignment.round()of a value with units in the Excel renderer gave a different result from Python. forallpeople’sround(x, n)only changes how many digits are shown, but the sheet usedROUNDon the SI value:round(M / P, 3)withM / P = 4.80 mmbecame5 mm(0.0048 m rounded to 0.005 m). The formula now leaves the value unchanged. With pint, it rounds the magnitude in the quantity’s own unit, as pint does.The HTML renderer’s tints (the result highlight, parameter grids, block headers, import chips, muted comments) now print in WeasyPrint PDFs.
A power with an exponent that isn’t a number (
a**(1/2)) rendered asa**(1 / 2)in HTML; it is now a superscript.The test dependencies require forallpeople 3.5.0 (3.4.1 fixed how a value is displayed when its factor matches no defined unit, #352; 3.5 gives the Excel renderer exact unit factors).
A parameter line (
w = 5) in a mode without the result column, such asmode = "ass sym"(v1’s%%render symbolic), showed only its name (w). It now shows its value:w = 5.
2.0.0rc4 (2026-11-11)#
The fourth release candidate of handcalcs 2.0. Install it with
pip install "handcalcs>=2.0.0rc4"; a plain pip install handcalcs still installs
1.x until 2.0.0 is released.
Features#
.to()unit conversions in the Excel renderer:F = F.to("kip")orM = (F * L).to("kipft")sets the unit a row displays, with forallpeople or pint (a unit string or a unit expression such asureg.kip * ureg.ft). The formula is unchanged, since the row’s unit already scales the SI result, and the symbolic column shows only the value being converted (details).
2.0.0rc3 (2026-11-06)#
The third release candidate of handcalcs 2.0. Install it with
pip install "handcalcs>=2.0.0rc3"; a plain pip install handcalcs still installs
1.x until 2.0.0 is released.
Breaking changes#
Comment commands are read, never run (#354). In the assignment form (
# hc: multiline = False), each value must be a literal: a number, a string,True,FalseorNone. An expression such as# hc: format_code = "." + "2f"is now an error.A value keeps the
-fformat of the line that calculated it (#357), on the lines that substitute it: afterDCR = C_f / C_r # hc: -f .3f,ok = DCR <= 1.0shows0.833 <= 1.0, not0.83292 <= 1.0. A line’s own-fstill wins, and a name assigned again without-fgoes back to the format in effect. Calculations with an inline-fcan show different numbers in the lines below it (details).Light markup in comments (#356) changes how some existing comments render:
**bold**and*italic*are now styled (the Markdown renderer used to escape them),\*is a literal*, and in the LaTeX and Markdown renderers a pair of$is math. Formulas (w*L**2/8) and prices (“costs \(5 to \)10”) stay as written; see Features.The ASCII renderer spaces comparison operators (#357) like the arithmetic ones:
DCR <= 1.0, notDCR<=1.0, as the HTML renderer does.
Features#
Math in comments (#350, #356):
$...$in a heading, comment line or inline comment is LaTeX math in the LaTeX and Markdown renderers, as in v1.\$is a literal$. Turn it off withLatexRenderer(comment_math=False)orMarkdownRenderer(comment_math=False)(details).Bold, italic and code in comments (#356):
**bold**,*italic*and`code`are styled in every renderer: Markdown, LaTeX, HTML, Word (including inline comments) and Excel (rich text). The ASCII renderer shows them as written.@handcalc(..., docstring=False)(#339, #355): leave the function’s docstring out of the render. It is rendered by default, as before.find_inputs(..., detail=True)(#358): each input as anInputSpecwith its value, the units it is written in ("mm","kN / m"), the comment at the end of its line and its line number, for building a form or an input file from a script (details).handcalcs.testing(#349): a renderer-neutral feature suite.FEATURE_CASESholds a calculation for each feature with the names its output must show and hide, andcheck_case(renderer, case)checks a renderer against one, so renderers in other packages can test every feature (details).
Fixes#
# hc: -sand# hc: -mwork after forallpeople’ssi.environment(..., top_level=True)(#354). Before,s(seconds) andm(metres) inbuiltinsmade them valid Python expressions, and they were silently ignored: after# hc: -i, everything that followed stayed hidden.Two or more multi-line calculations in a row (after a standalone
# hc: -m) render one below the other, instead of being joined into one row (= 0.8 M_p = 7 * 8), in every renderer (#354).In the Excel renderer, a comment command inside an
ifblock (# hc: -s,-i,-f) now applies to the lines after the block, as in the other renderers.Docs: the migration guide explains that a standalone comment command stays in effect for the lines after it (#359).
Development:
uv.lockupdates certifi, nbconvert and tornado for security fixes (#360). The package’s own requirements are unchanged.
2.0.0rc2 (2026-10-29)#
The second release candidate of handcalcs 2.0. Install it with
pip install "handcalcs>=2.0.0rc2"; a plain pip install handcalcs still installs
1.x until 2.0.0 is released.
# hc: -s(--show) shows lines again after# hc: -i; at the end of a line it shows that line of a hidden section.Conditional show and hide (#343):
# hc: -s M_f > 0shows what follows if the expression is true and hides it if not;# hc: -i A_s < A_reqthe opposite. The expression uses the values at the comment (details).hidden_by_defaultoption (#343): start every calculation hidden and show only what-smarks.destination=on@handcalcand%%render, as onHandCalcs: write the render to a file.%%render destination=writes the file instead of displaying the render.Fixed: a hidden section (
# hc: -ion its own line) no longer shows its headings, comments,if/forheaders, or an empty parameter grid, in any renderer.Changed: a comment command changes only the settings it names. Before,
# hc: -f .2falso turned off an earlier# hc: -m,-por-i; to turn one off, use the assignment form (# hc: multiline = False) or, for-i,# hc: -s.Fixed: a value with its own
_repr_latex_that is not a quantity (e.g. an uncertain value, 1 ± 0.1) is rendered with that LaTeX in the LaTeX and Markdown renderers, instead of its plain text (#340).Fixed: an inline comment stays at the end of its calculation’s row in the LaTeX, Markdown and Word renderers, instead of moving to a row of its own.
Fixed: a parameter written in scientific notation is shown as written (
10E6, not 107;12.5e3, not 12500).Changed: the parameter grid command is
# hc: -g(--grid). The rc1 spelling-hstill works.
2.0.0rc1 (2026-10-23)#
The first release candidate of handcalcs 2.0: a rewrite around a node tree and
pluggable renderers. Install it with pip install "handcalcs>=2.0.0rc1"; a plain
pip install handcalcs still installs 1.x until 2.0.0 is released.
Renderers: Markdown (the Jupyter default), LaTeX, HTML, ASCII text, Excel, Word (editable Word equations; #222) and the base renderer. Renderers can be subclassed and customized, or written from scratch.
ASCIIRenderer(ascii) for terminals, logs and docstrings: setext-underlined headings and calc lines aligned on=. It replaces the 2.0 pre-releasePlainTextRenderer(plain_text), which has no alias.HandCalcsinterface for rendering source strings and files from Python.destination=writes the render to a file ready to open: a complete LaTeX document or HTML page (the renderer’spreambleandpostamble), or the saved.docxor.xlsx(details).# hc:comment commands, per line or per section, replacing the v1 cell override tags.Headings, prose and Jinja templating in comments.
Nested conditionals and
forloops.Configuration reduced to
format_code,default_renderer,jupyter_rendererandline_values, plus custom options for renderers.Names (naming variables): comma subscripts by default (
N_pl_Rd→ Npl,Rd; #101), Greek letters joined to other letters (DeltaH,ΔH→ ΔH; #117), accents (x_hat,V_dot,M_star) and thesymbolsoption for display specs, all parsed once and shared by every renderer.Line continuations (
\) break a long equation at the same place (#259).%renderline magic renders a single line (#179).Bare expressions (
2 * a) show their result when they use only arithmetic, built-ins, andmathor numpy functions (#54).Many input sets from one script:
HandCalcs(...)(script, inputs={...})renders a script with different given values, keeping their units (quantities are converted to them);find_inputslists a script’s inputs (details);%%render inputs=casedoes the same for a notebook cell.Each line shows the values it ran with. A name assigned again later, an
iftest whose variable changes in its branch, and a bare expression that calls a function all show the values from when their line ran (theline_valuesoption).More of Python is rendered: indexing and slices (
xs[i]as a subscript), tuple unpacking and chained assignment, augmented assignment (a += basa = a + b), the body of awithblock, f-strings, lambdas, generator expressions and attributes of an expression ((L * 2).magnitude).Numbers: integers are never shown in scientific notation by the default format; format codes apply to numpy arrays, and 2-D arrays are shown as matrices.
Errors in a
%%rendercell are raised, with the usual traceback, instead of rendering nothing.@handcalcstops at thereturnthat ran, and uses thedefault_rendererwhen no renderer is given (@handcalcor@handcalc()).HandCalcs()with no renderer uses it too.Long collections show their first and last items around an ellipsis (the
max_itemsandedge_itemssettings).
See Coming from handcalcs v1 for how to update notebooks.