For documents with substantial code, a long appendix can be overwhelming. The collapsible option wraps each language section in an expandable <details> element—readers click to expand only the sections they need.
This feature requires group-by-language: true and only works in HTML output.
# Validation logicdef validate_record(record):"""Check if a record meets quality criteria."""ifnot record["valid"]:returnFalse, "Marked invalid"try: value =float(record["value"].strip())if value <0or value >100:returnFalse, "Out of range"returnTrue, "OK"exceptValueError:returnFalse, "Not numeric"for rec in raw_records: is_valid, reason = validate_record(rec) status ="✓"if is_valid else"✗"print(f"Record {rec['id']}: {status} ({reason})")
Record 1: ✓ (OK)
Record 2: ✗ (Marked invalid)
Record 3: ✓ (OK)
Record 4: ✓ (OK)
In the appendix below, click on “Python” or “R” to expand and view that language’s code. This keeps the appendix compact while still providing access to everything.
# Validation logicdef validate_record(record):"""Check if a record meets quality criteria."""ifnot record["valid"]:returnFalse, "Marked invalid"try: value =float(record["value"].strip())if value <0or value >100:returnFalse, "Out of range"returnTrue, "OK"exceptValueError:returnFalse, "Not numeric"for rec in raw_records: is_valid, reason = validate_record(rec) status ="✓"if is_valid else"✗"print(f"Record {rec['id']}: {status} ({reason})")
Record 1: ✓ (OK)
Record 2: ✗ (Marked invalid)
Record 3: ✓ (OK)
Record 4: ✓ (OK)
R
# Data transformation in Rraw_values <-c(42, NA, 37, 51)# Clean and transformcleaned <-na.omit(raw_values)normalized <- (cleaned -mean(cleaned)) /sd(cleaned)cat("Transformed values (z-scores):\n")print(round(normalized, 3))