Make a student notes
ls -la /home/daytona/workspace/ 2>/dev/null || echo "workspace empty or missing"
mkdir -p /home/daytona/workspace/acid-base-notes
~/acid-base-notes/make_notes.js
const {
Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
HeadingLevel, AlignmentType, BorderStyle, WidthType, ShadingType,
LevelFormat, VerticalAlign
} = require('docx');
const fs = require('fs');
// ─── Color palette ───────────────────────────────────────────────────────────
const BLUE_DARK = "1A3C5E";
const BLUE_MID = "2E75B6";
const BLUE_LIGHT = "D6E4F0";
const TEAL = "17706E";
const TEAL_LIGHT = "D0EDEC";
const YELLOW_BG = "FFF9C4";
const ORANGE = "C0440A";
const GREEN_DARK = "1F6535";
const GREEN_LIGHT= "D9F0E0";
const RED_DARK = "8B0000";
const RED_LIGHT = "FDECEA";
const GREY_BG = "F2F2F2";
const WHITE = "FFFFFF";
// ─── Helpers ─────────────────────────────────────────────────────────────────
function heading1(text) {
return new Paragraph({
heading: HeadingLevel.HEADING_1,
children: [new TextRun({ text, font: "Arial", bold: true, size: 34, color: WHITE })],
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
spacing: { before: 360, after: 180 },
indent: { left: 200 },
});
}
function heading2(text) {
return new Paragraph({
heading: HeadingLevel.HEADING_2,
children: [new TextRun({ text, font: "Arial", bold: true, size: 28, color: WHITE })],
shading: { type: ShadingType.SOLID, color: BLUE_MID },
spacing: { before: 280, after: 140 },
indent: { left: 200 },
});
}
function heading3(text) {
return new Paragraph({
heading: HeadingLevel.HEADING_3,
children: [new TextRun({ text, font: "Arial", bold: true, size: 24, color: TEAL })],
spacing: { before: 200, after: 80 },
});
}
function para(text) {
return new Paragraph({
children: [new TextRun({ text, font: "Arial", size: 22 })],
spacing: { before: 60, after: 60 },
});
}
function bullet(text, bold_prefix = "") {
const runs = [];
if (bold_prefix) {
runs.push(new TextRun({ text: bold_prefix + " ", font: "Arial", size: 22, bold: true }));
}
runs.push(new TextRun({ text, font: "Arial", size: 22 }));
return new Paragraph({
numbering: { reference: "bullets", level: 0 },
children: runs,
spacing: { before: 40, after: 40 },
});
}
function subbullet(text, bold_prefix = "") {
const runs = [];
if (bold_prefix) {
runs.push(new TextRun({ text: bold_prefix + " ", font: "Arial", size: 20, bold: true }));
}
runs.push(new TextRun({ text, font: "Arial", size: 20 }));
return new Paragraph({
numbering: { reference: "subbullets", level: 1 },
children: runs,
spacing: { before: 30, after: 30 },
});
}
function keyPoint(label, value) {
return new Paragraph({
children: [
new TextRun({ text: label + ": ", font: "Arial", size: 22, bold: true, color: BLUE_DARK }),
new TextRun({ text: value, font: "Arial", size: 22 }),
],
shading: { type: ShadingType.SOLID, color: BLUE_LIGHT },
spacing: { before: 60, after: 60 },
indent: { left: 200, right: 200 },
});
}
function clinicalPearl(text) {
return new Paragraph({
children: [
new TextRun({ text: "⚡ Clinical Pearl: ", font: "Arial", size: 22, bold: true, color: ORANGE }),
new TextRun({ text, font: "Arial", size: 22, italics: true }),
],
shading: { type: ShadingType.SOLID, color: YELLOW_BG },
spacing: { before: 100, after: 100 },
indent: { left: 200, right: 200 },
border: {
left: { style: BorderStyle.THICK, size: 12, color: ORANGE },
},
});
}
function remember(text) {
return new Paragraph({
children: [
new TextRun({ text: "★ Remember: ", font: "Arial", size: 22, bold: true, color: GREEN_DARK }),
new TextRun({ text, font: "Arial", size: 22 }),
],
shading: { type: ShadingType.SOLID, color: GREEN_LIGHT },
spacing: { before: 100, after: 100 },
indent: { left: 200, right: 200 },
border: {
left: { style: BorderStyle.THICK, size: 12, color: GREEN_DARK },
},
});
}
function formulaBox(text) {
return new Paragraph({
children: [new TextRun({ text, font: "Courier New", size: 22, bold: true, color: BLUE_DARK })],
shading: { type: ShadingType.SOLID, color: GREY_BG },
spacing: { before: 80, after: 80 },
indent: { left: 400, right: 400 },
alignment: AlignmentType.CENTER,
border: {
top: { style: BorderStyle.SINGLE, size: 6, color: BLUE_MID },
bottom: { style: BorderStyle.SINGLE, size: 6, color: BLUE_MID },
left: { style: BorderStyle.SINGLE, size: 6, color: BLUE_MID },
right: { style: BorderStyle.SINGLE, size: 6, color: BLUE_MID },
},
});
}
function spacer() {
return new Paragraph({ children: [new TextRun("")], spacing: { before: 60, after: 60 } });
}
function sectionDivider() {
return new Paragraph({
children: [new TextRun({ text: "─".repeat(70), font: "Arial", size: 18, color: "AAAAAA" })],
spacing: { before: 120, after: 120 },
alignment: AlignmentType.CENTER,
});
}
// ─── Simple two-column table ──────────────────────────────────────────────────
function twoColTable(rows, col1width = 3000, col2width = 5500) {
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: rows.map(([left, right, isHeader]) => new TableRow({
children: [
new TableCell({
width: { size: col1width, type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: isHeader ? BLUE_MID : BLUE_LIGHT },
verticalAlign: VerticalAlign.CENTER,
children: [new Paragraph({
children: [new TextRun({ text: left, font: "Arial", size: 20, bold: isHeader, color: isHeader ? WHITE : BLUE_DARK })],
spacing: { before: 60, after: 60 }, indent: { left: 100, right: 100 },
})],
}),
new TableCell({
width: { size: col2width, type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: isHeader ? BLUE_DARK : WHITE },
verticalAlign: VerticalAlign.CENTER,
children: [new Paragraph({
children: [new TextRun({ text: right, font: "Arial", size: 20, bold: isHeader, color: isHeader ? WHITE : "222222" })],
spacing: { before: 60, after: 60 }, indent: { left: 100, right: 100 },
})],
}),
],
})),
});
}
// Four-column disorder table
function disorderTable() {
const headers = ["Disorder", "pH", "Primary Change", "Compensation"];
const rowData = [
["Metabolic Acidosis", "< 7.35", "↓ HCO₃⁻", "↓ pCO₂ (hyperventilation)"],
["Metabolic Alkalosis", "> 7.45", "↑ HCO₃⁻", "↑ pCO₂ (hypoventilation)"],
["Respiratory Acidosis","< 7.35", "↑ pCO₂", "↑ HCO₃⁻ (renal retention)"],
["Respiratory Alkalosis","> 7.45","↓ pCO₂", "↓ HCO₃⁻ (renal excretion)"],
];
const COLS = [2800, 1600, 2400, 2800];
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [
new TableRow({
tableHeader: true,
children: headers.map((h, i) => new TableCell({
width: { size: COLS[i], type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: BLUE_DARK },
children: [new Paragraph({
children: [new TextRun({ text: h, font: "Arial", size: 20, bold: true, color: WHITE })],
spacing: { before: 60, after: 60 }, indent: { left: 80 },
})],
})),
}),
...rowData.map((row, ri) => new TableRow({
children: row.map((cell, ci) => new TableCell({
width: { size: COLS[ci], type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: ri % 2 === 0 ? GREY_BG : WHITE },
children: [new Paragraph({
children: [new TextRun({ text: cell, font: "Arial", size: 20 })],
spacing: { before: 50, after: 50 }, indent: { left: 80 },
})],
})),
})),
],
});
}
// ─── Title page helper ────────────────────────────────────────────────────────
function titlePage() {
return [
new Paragraph({
children: [new TextRun({ text: "ACID-BASE BALANCE", font: "Arial", bold: true, size: 64, color: BLUE_DARK })],
alignment: AlignmentType.CENTER,
spacing: { before: 1800, after: 200 },
}),
new Paragraph({
children: [new TextRun({ text: "Student Study Notes", font: "Arial", size: 36, color: BLUE_MID, italics: true })],
alignment: AlignmentType.CENTER,
spacing: { before: 0, after: 200 },
}),
new Paragraph({
children: [new TextRun({ text: "Biochemistry · Chapter 21", font: "Arial", size: 26, color: "888888" })],
alignment: AlignmentType.CENTER,
spacing: { before: 0, after: 600 },
}),
new Paragraph({
children: [new TextRun({ text: "─".repeat(50), font: "Arial", size: 22, color: BLUE_MID })],
alignment: AlignmentType.CENTER,
spacing: { before: 0, after: 400 },
}),
new Paragraph({
children: [new TextRun({ text: "Topics Covered", font: "Arial", bold: true, size: 26, color: BLUE_DARK })],
alignment: AlignmentType.CENTER,
spacing: { before: 0, after: 200 },
}),
new Paragraph({
children: [new TextRun({
text: "Normal Blood pH • Acid & Base Production • Three Lines of Defense\nBlood Buffer Systems • Respiratory Regulation • Renal Regulation\nHenderson-Hasselbalch Equation • Acid-Base Disorders",
font: "Arial", size: 22, color: "444444",
})],
alignment: AlignmentType.CENTER,
spacing: { before: 0, after: 1200 },
}),
new Paragraph({
children: [new TextRun({ text: "April 2026", font: "Arial", size: 20, color: "AAAAAA" })],
alignment: AlignmentType.CENTER,
spacing: { before: 0, after: 0 },
pageBreakBefore: false,
}),
// Page break after title
new Paragraph({ pageBreakBefore: true, children: [new TextRun("")] }),
];
}
// ═══════════════════════════════════════════════════════════════════════════════
// DOCUMENT
// ═══════════════════════════════════════════════════════════════════════════════
const doc = new Document({
numbering: {
config: [
{
reference: "bullets",
levels: [
{ level: 0, format: LevelFormat.BULLET, text: "•", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 560, hanging: 360 } } } },
{ level: 1, format: LevelFormat.BULLET, text: "◦", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 1080, hanging: 360 } } } },
],
},
{
reference: "subbullets",
levels: [
{ level: 0, format: LevelFormat.BULLET, text: "•", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 560, hanging: 360 } } } },
{ level: 1, format: LevelFormat.BULLET, text: "◦", alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 1080, hanging: 360 } } } },
],
},
],
},
styles: {
default: {
document: { run: { font: "Arial", size: 22 } },
},
paragraphStyles: [
{ id: "Heading1", name: "Heading 1", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 34, bold: true, font: "Arial", color: WHITE },
paragraph: { spacing: { before: 360, after: 180 }, outlineLevel: 0 } },
{ id: "Heading2", name: "Heading 2", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 28, bold: true, font: "Arial", color: WHITE },
paragraph: { spacing: { before: 280, after: 140 }, outlineLevel: 1 } },
{ id: "Heading3", name: "Heading 3", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 24, bold: true, font: "Arial", color: TEAL },
paragraph: { spacing: { before: 200, after: 80 }, outlineLevel: 2 } },
],
},
sections: [
{
properties: {
page: { margin: { top: 720, bottom: 720, left: 900, right: 900 } },
},
children: [
// ── TITLE PAGE ──
...titlePage(),
// ══════════════════════════════════════════════════════
// SECTION 1: OVERVIEW
// ══════════════════════════════════════════════════════
heading1("1. OVERVIEW — BLOOD pH & WHY IT MATTERS"),
spacer(),
keyPoint("Normal blood pH", "7.35 – 7.45 (slightly alkaline)"),
keyPoint("Compatible-with-life range", "6.8 – 7.8"),
keyPoint("Intracellular pH (RBCs)", "7.2 — varies by cell type"),
spacer(),
para("The blood pH is maintained in a narrow range because even small changes alter:"),
bullet("Protein structure"),
bullet("Enzyme activity"),
bullet("Metabolism throughout the body"),
spacer(),
remember("pH of blood is slightly alkaline (7.4). ICF pH varies — as low as 6.0 in skeletal muscle."),
spacer(),
// ══════════════════════════════════════════════════════
// SECTION 2: ACID & BASE PRODUCTION
// ══════════════════════════════════════════════════════
sectionDivider(),
heading1("2. PRODUCTION OF ACIDS & BASES"),
spacer(),
heading2("2.1 Acid Production"),
para("Metabolism continuously generates acids:"),
spacer(),
twoColTable([
["Acid", "Source / Comment", true],
["Carbonic acid (H₂CO₃)", "From CO₂ (metabolic product) — ~20,000 mEq/day (volatile)"],
["Lactic acid", "Anaerobic metabolism"],
["Sulfuric acid", "Proteins containing sulfur amino acids"],
["Phosphoric acid", "Organic phosphates, e.g., phospholipids"],
]),
spacer(),
clinicalPearl("A diet rich in animal proteins → more acid production → urine becomes profoundly acidic."),
spacer(),
heading2("2.2 Base Production"),
bullet("Base formation is negligible under normal conditions."),
bullet("Some HCO₃⁻ is generated from organic acids (lactate, citrate)."),
bullet("Vegetarian diet → sodium lactate & similar salts → utilise H⁺ ions → alkalising effect."),
spacer(),
remember("Vegetarians excrete neutral or slightly alkaline urine; meat-eaters excrete profoundly acidic urine."),
spacer(),
// ══════════════════════════════════════════════════════
// SECTION 3: THREE LINES OF DEFENSE
// ══════════════════════════════════════════════════════
sectionDivider(),
heading1("3. THREE LINES OF DEFENSE"),
spacer(),
para("The body maintains blood pH ~7.4 through three mechanisms (in order of speed):"),
spacer(),
twoColTable([
["Line", "Mechanism", true],
["I — Fastest", "Blood Buffer Systems (immediate)"],
["II — Intermediate", "Respiratory Mechanism (minutes)"],
["III — Slowest", "Renal Mechanism (hours–days; permanent solution)"],
]),
spacer(),
// ══════════════════════════════════════════════════════
// SECTION 4: BLOOD BUFFERS
// ══════════════════════════════════════════════════════
sectionDivider(),
heading1("4. BLOOD BUFFERS (Line I)"),
spacer(),
para("A buffer is a solution of a weak acid (HA) and its salt with a strong base (BA). It resists pH change on addition of acid or alkali."),
spacer(),
remember("Buffers are temporary — they cannot remove H⁺ from the body. Final elimination is by the kidneys."),
spacer(),
heading2("4.1 Bicarbonate Buffer System [Most Important]"),
para("Sodium bicarbonate + carbonic acid (NaHCO₃ – H₂CO₃) — the predominant ECF buffer."),
spacer(),
formulaBox("H₂CO₃ ⇌ H⁺ + HCO₃⁻"),
spacer(),
keyPoint("Plasma HCO₃⁻ (normal)", "22–26 mmol/L (avg 24 mmol/L)"),
keyPoint("H₂CO₃ (= pCO₂ × 0.03)", "40 × 0.03 = 1.2 mmol/L"),
keyPoint("HCO₃⁻ : H₂CO₃ ratio", "20 : 1 ← this ratio determines pH"),
spacer(),
bullet("This 20:1 ratio = alkali reserve; responsible for effective H⁺ buffering."),
bullet("Any change in HCO₃⁻ or H₂CO₃ shifts pH → serves as index for acid-base disturbances."),
spacer(),
heading2("4.2 Phosphate Buffer System"),
para("Sodium dihydrogen phosphate – disodium hydrogen phosphate (NaH₂PO₄ – Na₂HPO₄)."),
bullet("Mostly an intracellular buffer."),
bullet("pK = 6.8 (close to blood pH 7.4) → effective, but low plasma concentration limits usefulness."),
bullet("Base : acid ratio for phosphate = 4 (vs 20 for bicarbonate)."),
spacer(),
heading2("4.3 Protein Buffer System"),
para("Plasma proteins + hemoglobin — constitute the protein buffer of the blood."),
bullet("Buffering depends on pK of ionisable amino acid groups."),
bullet("Histidine imidazole group (pK 6.7) = most effective contributor."),
bullet("Plasma proteins = ~2% of total buffering capacity."),
bullet("Hemoglobin (RBC) buffers fixed acids and is critical for CO₂ transport."),
spacer(),
clinicalPearl("Hemoglobin buffers H⁺ at the tissue level (isohydric transport) — allows CO₂ carriage with minimal pH change."),
spacer(),
// Henderson-Hasselbalch
heading2("4.4 Henderson-Hasselbalch Equation"),
para("Derived from the dissociation constant of a weak acid (HA ⇌ H⁺ + A⁻):"),
spacer(),
formulaBox("pH = pKa + log [Base] / [Acid]"),
spacer(),
para("For the bicarbonate buffer specifically:"),
spacer(),
formulaBox("pH = pKa + log [HCO₃⁻] / [H₂CO₃]"),
spacer(),
para("Substituting normal values:"),
formulaBox("7.4 = 6.1 + log(24 / 1.2) = 6.1 + log 20 = 6.1 + 1.3 = 7.4 ✓"),
spacer(),
remember("pH depends on the RATIO of HCO₃⁻ to H₂CO₃, not their absolute concentrations."),
spacer(),
// ══════════════════════════════════════════════════════
// SECTION 5: RESPIRATORY MECHANISM
// ══════════════════════════════════════════════════════
sectionDivider(),
heading1("5. RESPIRATORY MECHANISM (Line II)"),
spacer(),
para("Controls H₂CO₃ (the denominator in the Henderson-Hasselbalch equation) by regulating CO₂ elimination."),
spacer(),
formulaBox("H₂CO₃ → (Carbonic Anhydrase) → CO₂ + H₂O"),
spacer(),
heading2("5.1 Respiratory Centre"),
bullet("Located in the medulla of the brain."),
bullet("Highly sensitive to changes in blood pH."),
bullet("↓ pH → hyperventilation → blow off CO₂ → ↓ H₂CO₃ → ↑ pH (correction)."),
bullet("↑ pH → hypoventilation → retain CO₂ → ↑ H₂CO₃ → ↓ pH (correction)."),
spacer(),
remember("Respiratory control is RAPID but SHORT-TERM — sustained hyperventilation cannot continue indefinitely."),
spacer(),
heading2("5.2 Hemoglobin as a Buffer (RBC Role)"),
para("Erythrocytes play a dual role in CO₂ transport and pH regulation:"),
bullet("At tissues: Hb binds H⁺; CO₂ enters RBC → combines with H₂O (via carbonic anhydrase) → H₂CO₃ → H⁺ + HCO₃⁻."),
bullet("H⁺ trapped by Hb; HCO₃⁻ diffuses into plasma, exchanging for Cl⁻ (chloride shift / Hamburger phenomenon)."),
bullet("At lungs: Hb-O₂ binding releases H⁺; H⁺ combines with HCO₃⁻ → H₂CO₃ → CO₂ exhaled."),
spacer(),
clinicalPearl("The chloride shift (Cl⁻ / HCO₃⁻ exchange across RBC membrane) is how most CO₂ is transported in blood as plasma HCO₃⁻."),
spacer(),
// ══════════════════════════════════════════════════════
// SECTION 6: RENAL MECHANISM
// ══════════════════════════════════════════════════════
sectionDivider(),
heading1("6. RENAL MECHANISM (Line III — Permanent Solution)"),
spacer(),
para("The kidneys provide the permanent solution by either excreting or reabsorbing acid/base as the situation demands. Urine pH is normally ~6.0 (range 4.5–9.5)."),
spacer(),
keyPoint("Why urine is acidic", "Kidneys acidify urine to eliminate H⁺ generated in metabolism"),
spacer(),
para("Carbonic anhydrase (inhibited by acetazolamide) is central to all renal mechanisms."),
spacer(),
heading2("6.1 Excretion of H⁺ Ions"),
bullet("Kidney is the ONLY route to permanently eliminate H⁺."),
bullet("Occurs in proximal convoluted tubules (renal tubular cells)."),
bullet("Coupled with regeneration of HCO₃⁻."),
subbullet("CA catalyses: CO₂ + H₂O → H₂CO₃ → H⁺ + HCO₃⁻ in tubular cells."),
subbullet("H⁺ secreted into lumen in exchange for Na⁺."),
subbullet("Na⁺ + HCO₃⁻ reabsorbed into blood → adds to alkali reserve."),
spacer(),
heading2("6.2 Reabsorption of Bicarbonate"),
bullet("Conserves blood HCO₃⁻ with simultaneous excretion of H⁺."),
bullet("Normal urine is almost free from HCO₃⁻."),
bullet("Filtered HCO₃⁻ combines with secreted H⁺ in lumen → H₂CO₃ → CO₂ + H₂O."),
bullet("CO₂ diffuses back into tubular cells → re-forms HCO₃⁻ → reabsorbed into blood."),
bullet("Net result: HCO₃⁻ conservation (NOT new HCO₃⁻ generation — H⁺ originates from water)."),
spacer(),
heading2("6.3 Excretion of Titratable Acid"),
bullet("H⁺ secreted into lumen is buffered by phosphate (Na₂HPO₄ → NaH₂PO₄)."),
bullet("pH of tubular fluid falls from 7.4 to as low as 4.5."),
bullet("Titratable acidity = mL of N/10 NaOH needed to titrate 1L of urine back to pH 7.4."),
clinicalPearl("Titratable acidity reflects H⁺ excreted in urine that caused a pH fall from 7.4. Any further fall causes Na⁺ depletion."),
spacer(),
heading2("6.4 Excretion of Ammonium Ions (NH₄⁺)"),
bullet("Renal tubular cells deamidate glutamine → glutamate + NH₃ (via glutaminase)."),
bullet("NH₃ diffuses into tubular lumen, combines with H⁺ → NH₄⁺."),
bullet("NH₄⁺ cannot diffuse back → excreted in urine."),
bullet("~½ to ⅔ of body acid load eliminated as NH₄⁺."),
bullet("Mechanism becomes predominant in acidosis."),
spacer(),
remember("NH₄⁺ excretion is the kidney's most powerful mechanism to eliminate large acid loads."),
spacer(),
// ══════════════════════════════════════════════════════
// SECTION 7: DISORDERS
// ══════════════════════════════════════════════════════
sectionDivider(),
heading1("7. DISORDERS OF ACID-BASE BALANCE"),
spacer(),
para("Use the Henderson-Hasselbalch equation to interpret all disturbances:"),
formulaBox("pH = pKa + log [HCO₃⁻] / [H₂CO₃]"),
spacer(),
disorderTable(),
spacer(),
heading2("7.1 Metabolic Acidosis"),
bullet("↓ HCO₃⁻ → ↓ pH"),
bullet("Causes: diarrhoea, diabetic ketoacidosis, lactic acidosis, renal failure."),
bullet("Compensation: hyperventilation (Kussmaul breathing) → ↓ pCO₂."),
spacer(),
heading2("7.2 Metabolic Alkalosis"),
bullet("↑ HCO₃⁻ → ↑ pH"),
bullet("Causes: vomiting (loss of HCl), excess antacid, hypokalaemia."),
bullet("Compensation: hypoventilation → ↑ pCO₂."),
spacer(),
heading2("7.3 Respiratory Acidosis"),
bullet("↑ pCO₂ → ↑ H₂CO₃ → ↓ pH"),
bullet("Causes: COPD, pneumonia, respiratory depression."),
bullet("Compensation: kidneys retain HCO₃⁻ and excrete more H⁺/NH₄⁺."),
spacer(),
heading2("7.4 Respiratory Alkalosis"),
bullet("↓ pCO₂ → ↓ H₂CO₃ → ↑ pH"),
bullet("Causes: anxiety hyperventilation, high altitude, fever."),
bullet("Compensation: kidneys excrete HCO₃⁻ and retain H⁺."),
spacer(),
// ══════════════════════════════════════════════════════
// SECTION 8: SUMMARY TABLE
// ══════════════════════════════════════════════════════
sectionDivider(),
heading1("8. QUICK SUMMARY — KEY VALUES"),
spacer(),
twoColTable([
["Parameter", "Normal Value", true],
["Blood pH", "7.35 – 7.45"],
["Plasma HCO₃⁻", "22 – 26 mmol/L"],
["pCO₂ (arterial)", "35 – 45 mmHg"],
["H₂CO₃", "1.2 mmol/L"],
["HCO₃⁻ : H₂CO₃ ratio", "20 : 1"],
["Urine pH", "~6.0 (range 4.5 – 9.5)"],
["pKa of H₂CO₃", "6.1"],
["Life-compatible pH", "6.8 – 7.8"],
], 3500, 5000),
spacer(),
// ══════════════════════════════════════════════════════
// SECTION 9: EXAM TIPS
// ══════════════════════════════════════════════════════
sectionDivider(),
heading1("9. EXAM TIPS & MNEMONICS"),
spacer(),
heading3("Mnemonic — Three Lines of Defense"),
para('"BRR" — Buffers → Respiratory → Renal (fastest to slowest)'),
spacer(),
heading3("Henderson-Hasselbalch at a Glance"),
para("If pH = 7.4 and pKa = 6.1, then log(ratio) must = 1.3 → ratio = 20."),
para("Memorise: HCO₃⁻ 24 mmol/L, H₂CO₃ 1.2 mmol/L, ratio = 20:1."),
spacer(),
heading3("Chloride Shift"),
para("HCO₃⁻ leaves RBC, Cl⁻ enters — maintains electrical neutrality."),
spacer(),
heading3("CO₂ is Central"),
para("CO₂ is the central molecule: generated by metabolism → H₂CO₃ in blood → transported as HCO₃⁻ → exhaled via lungs → regenerated as HCO₃⁻ by kidneys."),
spacer(),
heading3("Diet Clue"),
bullet("Animal protein diet → acidic urine."),
bullet("Vegetarian diet → neutral / alkaline urine."),
spacer(),
clinicalPearl("Acetazolamide inhibits carbonic anhydrase → disrupts all renal pH regulation → used clinically to alkalinise urine and in glaucoma."),
spacer(),
sectionDivider(),
new Paragraph({
children: [new TextRun({ text: "End of Notes — Good luck! 🎓", font: "Arial", size: 22, color: "888888", italics: true })],
alignment: AlignmentType.CENTER,
spacing: { before: 200, after: 200 },
}),
],
},
],
});
Packer.toBuffer(doc).then(buf => {
fs.writeFileSync("/home/daytona/workspace/acid-base-notes/Acid_Base_Balance_Student_Notes.docx", buf);
console.log("Done.");
});
cd /home/daytona/workspace/acid-base-notes && node make_notes.js 2>&1
python /home/daytona/skills/docx/scripts/office/validate.py /home/daytona/workspace/acid-base-notes/Acid_Base_Balance_Student_Notes.docx 2>&1
ls -lh /home/daytona/workspace/acid-base-notes/Acid_Base_Balance_Student_Notes.docx && python3 -c "import zipfile; z=zipfile.ZipFile('/home/daytona/workspace/acid-base-notes/Acid_Base_Balance_Student_Notes.docx'); print('Valid ZIP, files:', len(z.namelist()))"
Acid Base Balance Student Notes
Word Document · DOCX
| Section | Content |
|---|---|
| 1. Overview | Normal blood pH (7.35–7.45), why it matters, compatible-with-life range |
| 2. Acid & Base Production | Volatile vs non-volatile acids, vegetarian vs animal-protein diet effects |
| 3. Three Lines of Defense | Buffer → Respiratory → Renal (BRR), ordered by speed |
| 4. Blood Buffers | Bicarbonate (dominant), Phosphate, Protein/Hb systems + Henderson-Hasselbalch with worked example |
| 5. Respiratory Mechanism | Medullary centre, hyperventilation/hypoventilation responses, chloride shift |
| 6. Renal Mechanism | H⁺ excretion, HCO₃⁻ reabsorption, titratable acid, NH₄⁺ excretion |
| 7. Acid-Base Disorders | Summary table (Metabolic/Respiratory Acidosis/Alkalosis + compensation) |
| 8. Quick Reference Values | All key numbers in one table |
| 9. Exam Tips & Mnemonics | BRR mnemonic, H-H at a glance, diet clues, acetazolamide pearl |
Rewrite the notes
~/acid-base-notes/rewrite_notes.js
"use strict";
const {
Document, Packer, Paragraph, TextRun, Table, TableRow, TableCell,
HeadingLevel, AlignmentType, BorderStyle, WidthType, ShadingType,
LevelFormat, VerticalAlign, PageNumber, PageBreak
} = require("docx");
const fs = require("fs");
// ── Palette ────────────────────────────────────────────────────────────────
const C = {
navy: "0D2B55",
blue: "1E5FA8",
blueSoft: "EAF1FB",
teal: "0D6E6E",
tealSoft: "E0F4F4",
amber: "B85C00",
amberSoft: "FFF4E0",
green: "1A5C2E",
greenSoft: "E6F5EC",
red: "8B1A1A",
redSoft: "FDECEA",
grey: "F5F5F5",
greyBorder: "CCCCCC",
white: "FFFFFF",
textMain: "1A1A1A",
textMuted: "555555",
};
// ── Reusable paragraph factories ───────────────────────────────────────────
/** Page-width banner heading (H1) */
function h1(text) {
return new Paragraph({
children: [
new TextRun({ text, font: "Calibri", bold: true, size: 36, color: C.white }),
],
shading: { type: ShadingType.SOLID, color: C.navy },
spacing: { before: 440, after: 160 },
indent: { left: 240, right: 240 },
});
}
/** Sub-section heading (H2) */
function h2(text) {
return new Paragraph({
children: [
new TextRun({ text, font: "Calibri", bold: true, size: 26, color: C.blue }),
],
border: { bottom: { style: BorderStyle.SINGLE, size: 6, color: C.blue } },
spacing: { before: 300, after: 120 },
});
}
/** Minor heading (H3) */
function h3(text) {
return new Paragraph({
children: [
new TextRun({ text, font: "Calibri", bold: true, size: 22, color: C.teal }),
],
spacing: { before: 200, after: 80 },
});
}
/** Normal body text */
function body(text) {
return new Paragraph({
children: [new TextRun({ text, font: "Calibri", size: 22, color: C.textMain })],
spacing: { before: 60, after: 60 },
});
}
/** Body text with an inline bold label */
function bodyLabel(label, text) {
return new Paragraph({
children: [
new TextRun({ text: label + ": ", font: "Calibri", size: 22, bold: true, color: C.navy }),
new TextRun({ text, font: "Calibri", size: 22, color: C.textMain }),
],
spacing: { before: 60, after: 60 },
});
}
/** Bullet (level 0) */
function b(text, boldPart = "") {
const runs = [];
if (boldPart) runs.push(new TextRun({ text: boldPart + " ", font: "Calibri", size: 22, bold: true, color: C.textMain }));
runs.push(new TextRun({ text, font: "Calibri", size: 22, color: C.textMain }));
return new Paragraph({
numbering: { reference: "bullets", level: 0 },
children: runs,
spacing: { before: 40, after: 40 },
});
}
/** Sub-bullet (level 1) */
function sb(text, boldPart = "") {
const runs = [];
if (boldPart) runs.push(new TextRun({ text: boldPart + " ", font: "Calibri", size: 20, bold: true, color: C.textMuted }));
runs.push(new TextRun({ text, font: "Calibri", size: 20, color: C.textMuted }));
return new Paragraph({
numbering: { reference: "bullets", level: 1 },
children: runs,
spacing: { before: 30, after: 30 },
});
}
/** Monospace formula box */
function formula(text) {
return new Paragraph({
children: [new TextRun({ text, font: "Courier New", size: 24, bold: true, color: C.navy })],
shading: { type: ShadingType.SOLID, color: C.grey },
alignment: AlignmentType.CENTER,
spacing: { before: 120, after: 120 },
indent: { left: 720, right: 720 },
border: {
top: { style: BorderStyle.SINGLE, size: 4, color: C.blue },
bottom: { style: BorderStyle.SINGLE, size: 4, color: C.blue },
left: { style: BorderStyle.THICK, size: 12, color: C.blue },
right: { style: BorderStyle.SINGLE, size: 4, color: C.blue },
},
});
}
/** Callout box — generic */
function callout(iconLabel, text, bgColor, borderColor, labelColor) {
return new Paragraph({
children: [
new TextRun({ text: iconLabel + " ", font: "Calibri", size: 22, bold: true, color: labelColor }),
new TextRun({ text, font: "Calibri", size: 22, color: C.textMain }),
],
shading: { type: ShadingType.SOLID, color: bgColor },
spacing: { before: 120, after: 120 },
indent: { left: 280, right: 280 },
border: { left: { style: BorderStyle.THICK, size: 16, color: borderColor } },
});
}
const pearl = (t) => callout("Clinical Pearl:", t, C.amberSoft, C.amber, C.amber);
const remember = (t) => callout("Remember:", t, C.greenSoft, C.green, C.green);
const warning = (t) => callout("Caution:", t, C.redSoft, C.red, C.red);
const note = (t) => callout("Note:", t, C.blueSoft, C.blue, C.blue);
/** Q&A cue card (2-col table, shaded Q col) */
function qna(q, a) {
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [
new TableRow({
children: [
new TableCell({
width: { size: 3200, type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: C.tealSoft },
verticalAlign: VerticalAlign.CENTER,
borders: {
top: { style: BorderStyle.NONE },
bottom: { style: BorderStyle.NONE },
left: { style: BorderStyle.NONE },
right: { style: BorderStyle.SINGLE, size: 4, color: C.teal },
},
children: [new Paragraph({
children: [new TextRun({ text: q, font: "Calibri", size: 20, bold: true, color: C.teal, italics: true })],
spacing: { before: 80, after: 80 }, indent: { left: 120, right: 120 },
})],
}),
new TableCell({
width: { size: 6500, type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: C.white },
verticalAlign: VerticalAlign.CENTER,
borders: {
top: { style: BorderStyle.NONE },
bottom: { style: BorderStyle.NONE },
left: { style: BorderStyle.NONE },
right: { style: BorderStyle.NONE },
},
children: [new Paragraph({
children: [new TextRun({ text: a, font: "Calibri", size: 20, color: C.textMain })],
spacing: { before: 80, after: 80 }, indent: { left: 160 },
})],
}),
],
}),
],
margins: { top: 0, bottom: 0 },
});
}
/** Generic two-column table with header row */
function twoCol(rows /* [[left, right, isHeader?], ...] */) {
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: rows.map(([l, r, hdr]) => new TableRow({
tableHeader: !!hdr,
children: [
new TableCell({
width: { size: 3500, type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: hdr ? C.navy : C.blueSoft },
verticalAlign: VerticalAlign.CENTER,
children: [new Paragraph({
children: [new TextRun({ text: l, font: "Calibri", size: 20, bold: !!hdr, color: hdr ? C.white : C.navy })],
spacing: { before: 60, after: 60 }, indent: { left: 120 },
})],
}),
new TableCell({
width: { size: 6200, type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: hdr ? C.blue : C.white },
verticalAlign: VerticalAlign.CENTER,
children: [new Paragraph({
children: [new TextRun({ text: r, font: "Calibri", size: 20, bold: !!hdr, color: hdr ? C.white : C.textMain })],
spacing: { before: 60, after: 60 }, indent: { left: 120 },
})],
}),
],
})),
});
}
/** Four-column disorder table */
function disorderTable() {
const hdrCols = ["Disorder", "pH", "Primary Change", "Compensation"];
const data = [
["Metabolic Acidosis", "< 7.35", "↓ HCO₃⁻", "Hyperventilation → ↓ pCO₂"],
["Metabolic Alkalosis", "> 7.45", "↑ HCO₃⁻", "Hypoventilation → ↑ pCO₂"],
["Respiratory Acidosis", "< 7.35", "↑ pCO₂", "Kidneys retain HCO₃⁻, excrete H⁺/NH₄⁺"],
["Respiratory Alkalosis","> 7.45", "↓ pCO₂", "Kidneys excrete HCO₃⁻, retain H⁺"],
];
const W = [2700, 1400, 2200, 3300];
const shade4 = (hdr, idx) =>
hdr ? C.navy : (idx % 2 === 0 ? C.grey : C.white);
return new Table({
width: { size: 100, type: WidthType.PERCENTAGE },
rows: [
new TableRow({
tableHeader: true,
children: hdrCols.map((h, ci) => new TableCell({
width: { size: W[ci], type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: C.navy },
children: [new Paragraph({
children: [new TextRun({ text: h, font: "Calibri", size: 20, bold: true, color: C.white })],
spacing: { before: 60, after: 60 }, indent: { left: 80 },
})],
})),
}),
...data.map((row, ri) => new TableRow({
children: row.map((cell, ci) => new TableCell({
width: { size: W[ci], type: WidthType.DXA },
shading: { type: ShadingType.SOLID, color: shade4(false, ri) },
children: [new Paragraph({
children: [new TextRun({ text: cell, font: "Calibri", size: 20, color: C.textMain })],
spacing: { before: 50, after: 50 }, indent: { left: 80 },
})],
})),
})),
],
});
}
function gap(n = 1) {
return Array.from({ length: n }, () =>
new Paragraph({ children: [new TextRun("")], spacing: { before: 40, after: 40 } })
);
}
function rule() {
return new Paragraph({
children: [new TextRun({ text: "", font: "Calibri", size: 4 })],
border: { bottom: { style: BorderStyle.SINGLE, size: 6, color: C.greyBorder } },
spacing: { before: 200, after: 200 },
});
}
// ── Title page ─────────────────────────────────────────────────────────────
function titlePage() {
return [
// Colour band top
new Paragraph({
children: [new TextRun({ text: " ", font: "Calibri", size: 4, color: C.white })],
shading: { type: ShadingType.SOLID, color: C.navy },
spacing: { before: 0, after: 0 },
}),
...gap(6),
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: "ACID–BASE BALANCE", font: "Calibri", bold: true, size: 72, color: C.navy })],
spacing: { before: 1600, after: 120 },
}),
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: "Student Study Notes", font: "Calibri", size: 40, color: C.blue, italics: true })],
spacing: { before: 0, after: 120 },
}),
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: "Biochemistry · Chapter 21 · Water, Electrolyte and Acid-Base Balance", font: "Calibri", size: 24, color: C.textMuted })],
spacing: { before: 0, after: 600 },
}),
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: "─".repeat(48), font: "Calibri", size: 22, color: C.greyBorder })],
spacing: { before: 0, after: 500 },
}),
// Topics grid – plain text list centered
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: "TOPICS", font: "Calibri", bold: true, size: 24, color: C.navy })],
spacing: { before: 0, after: 160 },
}),
...[
"1 Normal Blood pH & Why It Matters",
"2 Acid & Base Production",
"3 Three Lines of Defence",
"4 Blood Buffer Systems",
"5 Henderson-Hasselbalch Equation",
"6 Respiratory Regulation",
"7 Renal Regulation",
"8 Acid-Base Disorders",
"9 Key Values Quick Reference",
"10 Exam Tips & Mnemonics",
].map(t => new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: t, font: "Calibri", size: 22, color: C.textMuted })],
spacing: { before: 40, after: 40 },
})),
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: "April 2026", font: "Calibri", size: 20, color: C.greyBorder })],
spacing: { before: 500, after: 0 },
}),
new Paragraph({ pageBreakBefore: true, children: [new TextRun("")] }),
];
}
// ══════════════════════════════════════════════════════════════════════════════
// DOCUMENT
// ══════════════════════════════════════════════════════════════════════════════
const doc = new Document({
numbering: {
config: [
{
reference: "bullets",
levels: [
{ level: 0, format: LevelFormat.BULLET, text: "•",
alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 600, hanging: 360 } } } },
{ level: 1, format: LevelFormat.BULLET, text: "–",
alignment: AlignmentType.LEFT,
style: { paragraph: { indent: { left: 1080, hanging: 360 } } } },
],
},
],
},
styles: {
default: { document: { run: { font: "Calibri", size: 22 } } },
paragraphStyles: [
{ id: "Heading1", name: "Heading 1", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 36, bold: true, font: "Calibri", color: C.white },
paragraph: { spacing: { before: 440, after: 160 }, outlineLevel: 0 } },
{ id: "Heading2", name: "Heading 2", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 26, bold: true, font: "Calibri", color: C.blue },
paragraph: { spacing: { before: 300, after: 120 }, outlineLevel: 1 } },
{ id: "Heading3", name: "Heading 3", basedOn: "Normal", next: "Normal", quickFormat: true,
run: { size: 22, bold: true, font: "Calibri", color: C.teal },
paragraph: { spacing: { before: 200, after: 80 }, outlineLevel: 2 } },
],
},
sections: [
{
properties: {
page: { margin: { top: 800, bottom: 800, left: 1000, right: 1000 } },
},
children: [
// ── TITLE PAGE ────────────────────────────────────────────────────
...titlePage(),
// ══════════════════════════════════════════════════
// 1. OVERVIEW
// ══════════════════════════════════════════════════
h1("1. NORMAL BLOOD pH & WHY IT MATTERS"),
body("The body keeps blood pH within a narrow window of 7.35–7.45 (slightly alkaline). Even small deviations alter protein structure, enzyme activity, and metabolism throughout the body."),
...gap(),
twoCol([
["Parameter", "Value", true],
["Normal blood pH", "7.35 – 7.45"],
["Life-compatible pH", "6.8 – 7.8 (outside this: incompatible with life)"],
["Intracellular pH", "Variable — e.g. RBCs ≈ 7.2; skeletal muscle ≈ 6.0"],
]),
...gap(),
remember("Blood pH is slightly alkaline. Intracellular pH is lower and more variable."),
...gap(2),
// ══════════════════════════════════════════════════
// 2. ACID & BASE PRODUCTION
// ══════════════════════════════════════════════════
h1("2. ACID & BASE PRODUCTION"),
h2("2.1 Acids Produced by Metabolism"),
body("Metabolism constantly generates acids, which add H⁺ to the blood:"),
...gap(),
twoCol([
["Acid", "Source", true],
["Carbonic acid (H₂CO₃)", "From CO₂ — ~20,000 mEq/day (volatile, exhaled)"],
["Lactic acid", "Anaerobic metabolism"],
["Sulfuric acid", "Protein catabolism (sulfur-containing amino acids)"],
["Phosphoric acid", "Organic phosphate hydrolysis (e.g. phospholipids)"],
]),
...gap(),
pearl("Diet high in animal protein → more acid production → urine becomes profoundly acidic."),
...gap(),
h2("2.2 Bases Produced by Metabolism"),
body("Base production in the body is normally negligible. A small amount of HCO₃⁻ is generated from organic acids (lactate, citrate). A vegetarian diet, however, produces salts of organic acids (e.g. sodium lactate) that consume H⁺ — giving an alkalising effect and neutral/alkaline urine."),
...gap(),
qna("Why does a vegetarian diet alkalinise the body?", "Plant-based diets produce sodium lactate and similar organic acid salts that utilise H⁺ ions, tipping the balance toward base production."),
...gap(2),
// ══════════════════════════════════════════════════
// 3. THREE LINES OF DEFENCE
// ══════════════════════════════════════════════════
h1("3. THREE LINES OF DEFENCE"),
body("The body maintains pH ~7.4 via three mechanisms, acting in sequence from fastest to slowest:"),
...gap(),
twoCol([
["Speed / Line", "Mechanism", true],
["I — Immediate (seconds)","Blood Buffer Systems"],
["II — Minutes", "Respiratory Mechanism"],
["III — Hours–Days", "Renal Mechanism ← only permanent solution"],
]),
...gap(),
remember('Mnemonic: "BRR" — Buffers → Respiratory → Renal.'),
...gap(2),
// ══════════════════════════════════════════════════
// 4. BLOOD BUFFER SYSTEMS
// ══════════════════════════════════════════════════
h1("4. BLOOD BUFFER SYSTEMS (Line I)"),
body("A buffer = weak acid (HA) + its salt with a strong base (BA). It resists pH change by absorbing or releasing H⁺. Buffers are temporary — they cannot excrete H⁺. Final elimination requires the kidneys."),
...gap(),
h2("4.1 Bicarbonate Buffer [Most Important]"),
body("Sodium bicarbonate + carbonic acid (NaHCO₃ / H₂CO₃) is the dominant extracellular buffer, especially in plasma."),
...gap(),
formula("H₂CO₃ ⇌ H⁺ + HCO₃⁻"),
...gap(),
twoCol([
["Component", "Normal Value", true],
["Plasma HCO₃⁻", "22–26 mmol/L (average 24)"],
["H₂CO₃ concentration", "pCO₂ × 0.03 = 40 × 0.03 = 1.2 mmol/L"],
["HCO₃⁻ : H₂CO₃ ratio", "20 : 1 → this ratio determines pH"],
]),
...gap(),
note("The 20:1 ratio (alkali reserve) is responsible for effective H⁺ buffering. Any shift signals an acid-base disturbance."),
...gap(),
h2("4.2 Phosphate Buffer"),
b("NaH₂PO₄ – Na₂HPO₄ system; mainly an intracellular buffer."),
b("pK = 6.8 (close to blood pH) → effective in principle, but low plasma concentration limits contribution."),
b("Base : acid ratio = 4 (much lower than bicarbonate's 20:1)."),
...gap(),
h2("4.3 Protein Buffer (Plasma Proteins + Haemoglobin)"),
b("Buffering capacity depends on pK of ionisable amino acid groups."),
b("Histidine imidazole group (pK ≈ 6.7) is the most effective contributor."),
b("Plasma proteins = only ~2% of total buffering capacity."),
b("Haemoglobin (in RBCs) buffers fixed acids and is crucial for CO₂ transport."),
...gap(),
pearl("Haemoglobin enables isohydric transport — CO₂ is carried from tissues to lungs with minimal blood pH change."),
...gap(2),
// ══════════════════════════════════════════════════
// 5. HENDERSON-HASSELBALCH EQUATION
// ══════════════════════════════════════════════════
h1("5. HENDERSON-HASSELBALCH EQUATION"),
body("Derived from the equilibrium expression for a weak acid dissociation:"),
...gap(),
formula("pH = pKa + log [Base] / [Acid]"),
...gap(),
body("For the bicarbonate buffer:"),
formula("pH = pKa + log [HCO₃⁻] / [H₂CO₃]"),
...gap(),
body("Worked example — substituting normal values (pKa = 6.1, HCO₃⁻ = 24, H₂CO₃ = 1.2):"),
formula("pH = 6.1 + log(24 / 1.2) = 6.1 + log 20 = 6.1 + 1.3 = 7.4 ✓"),
...gap(),
remember("pH depends on the RATIO of HCO₃⁻ to H₂CO₃ — not their absolute values. Ratio = 20:1 at pH 7.4."),
...gap(),
qna("What happens to pH if HCO₃⁻ drops from 24 to 12 (ratio now 10:1)?", "log 10 = 1, so pH = 6.1 + 1.0 = 7.1 → acidosis. The ratio fell from 20:1 to 10:1."),
...gap(2),
// ══════════════════════════════════════════════════
// 6. RESPIRATORY MECHANISM
// ══════════════════════════════════════════════════
h1("6. RESPIRATORY MECHANISM (Line II)"),
body("The lungs regulate the H₂CO₃ concentration (denominator in Henderson-Hasselbalch) by controlling how much CO₂ is exhaled."),
...gap(),
formula("H₂CO₃ → CO₂ + H₂O (catalysed by carbonic anhydrase)"),
...gap(),
h2("6.1 Respiratory Centre"),
b("Located in the medulla of the brain; sensitive to blood pH changes."),
b("↓ pH (acidosis) → hyperventilation → ↓ pCO₂ → ↓ H₂CO₃ → pH rises toward normal."),
b("↑ pH (alkalosis) → hypoventilation → ↑ pCO₂ → ↑ H₂CO₃ → pH falls toward normal."),
...gap(),
remember("Respiratory control is fast but only short-term — sustained hyperventilation cannot be maintained."),
...gap(),
h2("6.2 Role of Haemoglobin (Chloride Shift)"),
body("RBCs cannot perform aerobic metabolism, so they produce little CO₂ directly. Plasma CO₂ diffuses into RBCs along its concentration gradient:"),
...gap(),
b("CO₂ + H₂O → H₂CO₃ (via carbonic anhydrase) → H⁺ + HCO₃⁻."),
b("H⁺ is buffered by haemoglobin (Hb → HHb)."),
b("HCO₃⁻ concentration rises in RBC → diffuses out into plasma, Cl⁻ enters in exchange (chloride shift / Hamburger phenomenon)."),
b("At the lungs: Hb-O₂ binding releases H⁺ → combines with HCO₃⁻ → H₂CO₃ → CO₂ exhaled."),
...gap(),
pearl("The chloride shift is how ~70% of CO₂ is transported in blood — as dissolved plasma HCO₃⁻, not as CO₂ gas."),
...gap(2),
// ══════════════════════════════════════════════════
// 7. RENAL MECHANISM
// ══════════════════════════════════════════════════
h1("7. RENAL MECHANISM (Line III — Permanent Solution)"),
body("The kidneys provide the only permanent solution to acid-base disturbances by excreting H⁺ and regenerating HCO₃⁻. Normal urine pH ≈ 6.0 (range 4.5–9.5). Carbonic anhydrase (CA) is central to all four mechanisms below; it is inhibited by acetazolamide."),
...gap(),
h2("7.1 Excretion of H⁺ Ions"),
body("In proximal convoluted tubular cells, CA catalyses: CO₂ + H₂O → H₂CO₃ → H⁺ + HCO₃⁻."),
b("H⁺ secreted into tubular lumen in exchange for Na⁺."),
b("HCO₃⁻ + Na⁺ reabsorbed into blood → replenishes alkali reserve."),
b("Net effect: H⁺ removed from body; HCO₃⁻ generated."),
...gap(),
h2("7.2 Reabsorption of Bicarbonate"),
body("Conserves filtered HCO₃⁻ (normal urine is almost bicarbonate-free):"),
b("Filtered HCO₃⁻ combines with secreted H⁺ in the lumen → H₂CO₃ → CO₂ + H₂O (by brush-border CA)."),
b("CO₂ diffuses back into tubular cell → re-forms HCO₃⁻ → reabsorbed into blood."),
...gap(),
note("This is a cyclic process. The net excretion of H⁺ here is zero because H⁺ originates from water."),
...gap(),
h2("7.3 Excretion of Titratable Acid"),
body("H⁺ secreted into the lumen is buffered by the phosphate buffer (Na₂HPO₄ → NaH₂PO₄), reducing urine pH from 7.4 to as low as 4.5."),
b("Titratable acidity = volume of N/10 NaOH needed to bring 1 L urine back to pH 7.4."),
b("Reflects H⁺ excreted as titratable acid; any further pH fall risks Na⁺ depletion."),
...gap(),
h2("7.4 Excretion of Ammonium Ions (NH₄⁺)"),
b("Tubular cells deamidate glutamine → glutamate + NH₃ (enzyme: glutaminase)."),
b("NH₃ diffuses into lumen → combines with secreted H⁺ → NH₄⁺."),
b("NH₄⁺ is trapped (cannot diffuse back) → excreted in urine."),
b("Accounts for ½ to ⅔ of body acid load elimination; becomes dominant in acidosis."),
...gap(),
remember("NH₄⁺ excretion is the kidney's most powerful tool for eliminating large acid loads, especially in acidosis."),
...gap(2),
// ══════════════════════════════════════════════════
// 8. ACID-BASE DISORDERS
// ══════════════════════════════════════════════════
h1("8. ACID-BASE DISORDERS"),
body("Blood pH compatible with life: 6.8–7.8. Outside this range, life cannot be sustained. Use the Henderson-Hasselbalch equation to interpret every disturbance."),
...gap(),
disorderTable(),
...gap(),
h2("8.1 Metabolic Acidosis"),
b("Primary change: ↓ HCO₃⁻ → ↓ ratio → ↓ pH."),
b("Causes: diabetic ketoacidosis, lactic acidosis, severe diarrhoea, renal failure."),
sb("Compensation: hyperventilation (Kussmaul breathing) blows off CO₂ → ↓ pCO₂."),
...gap(),
h2("8.2 Metabolic Alkalosis"),
b("Primary change: ↑ HCO₃⁻ → ↑ ratio → ↑ pH."),
b("Causes: vomiting (loss of HCl), excessive antacids, hypokalaemia."),
sb("Compensation: hypoventilation retains CO₂ → ↑ pCO₂."),
...gap(),
h2("8.3 Respiratory Acidosis"),
b("Primary change: ↑ pCO₂ → ↑ H₂CO₃ → ↓ ratio → ↓ pH."),
b("Causes: COPD, pneumonia, respiratory muscle paralysis, sedative overdose."),
sb("Compensation: kidneys retain HCO₃⁻; excrete more H⁺ and NH₄⁺."),
...gap(),
h2("8.4 Respiratory Alkalosis"),
b("Primary change: ↓ pCO₂ → ↓ H₂CO₃ → ↑ ratio → ↑ pH."),
b("Causes: anxiety hyperventilation, fever, high altitude, salicylate poisoning (early)."),
sb("Compensation: kidneys excrete HCO₃⁻; retain H⁺."),
...gap(2),
// ══════════════════════════════════════════════════
// 9. QUICK REFERENCE — KEY VALUES
// ══════════════════════════════════════════════════
h1("9. QUICK REFERENCE — KEY VALUES"),
twoCol([
["Parameter", "Normal Value", true],
["Blood pH", "7.35 – 7.45"],
["Life-compatible pH", "6.8 – 7.8"],
["Plasma HCO₃⁻", "22 – 26 mmol/L"],
["Arterial pCO₂", "35 – 45 mmHg"],
["H₂CO₃", "1.2 mmol/L (= 40 × 0.03)"],
["HCO₃⁻ : H₂CO₃", "20 : 1"],
["pKa of H₂CO₃", "6.1"],
["Urine pH", "~6.0 (range 4.5 – 9.5)"],
["RBC pH", "~7.2"],
["Skeletal muscle pH", "~6.0"],
]),
...gap(2),
// ══════════════════════════════════════════════════
// 10. EXAM TIPS & MNEMONICS
// ══════════════════════════════════════════════════
h1("10. EXAM TIPS & MNEMONICS"),
h3('"BRR" — Order of Defence'),
body("Buffers (immediate) → Respiratory (minutes) → Renal (hours/days, permanent)."),
...gap(),
h3("Henderson-Hasselbalch at a Glance"),
b("pH 7.4 = 6.1 + 1.3, and log 20 = 1.3, so ratio must = 20."),
b("Memorise: HCO₃⁻ = 24, H₂CO₃ = 1.2, ratio = 20:1."),
b("pH tracks the RATIO, not the absolute numbers."),
...gap(),
h3("Diet & Urine pH"),
b("Animal protein diet → acidic urine."),
b("Vegetarian diet → neutral or mildly alkaline urine."),
...gap(),
h3("Chloride Shift"),
body("HCO₃⁻ leaves RBC, Cl⁻ enters — maintains electrical neutrality. This is how most CO₂ is carried in blood."),
...gap(),
h3("CO₂ = Central Molecule"),
body("CO₂ from metabolism → H₂CO₃ in blood → HCO₃⁻ for transport → exhaled by lungs → regenerated as HCO₃⁻ by kidneys."),
...gap(),
h3("Carbonic Anhydrase Inhibition"),
pearl("Acetazolamide inhibits carbonic anhydrase → disrupts all renal pH mechanisms → alkaline urine. Clinical uses: glaucoma, altitude sickness, metabolic alkalosis."),
...gap(),
// Q&A Review Block
h2("Self-Test Q&A"),
qna("What is the normal blood pH range?", "7.35 – 7.45 (slightly alkaline)."),
...gap(0),
qna("Which buffer system is most important in plasma?", "Bicarbonate buffer (NaHCO₃ / H₂CO₃); HCO₃⁻ : H₂CO₃ = 20 : 1."),
...gap(0),
qna("What are the three lines of defence?", "I: Blood buffers (immediate). II: Respiratory (minutes). III: Renal (hours–days, permanent)."),
...gap(0),
qna("How does the kidney permanently eliminate H⁺?", "Excretion as free H⁺ ions, titratable acid (phosphate buffer), and ammonium (NH₄⁺)."),
...gap(0),
qna("What is the chloride shift?", "HCO₃⁻ exits RBC into plasma while Cl⁻ enters — electrical neutrality is maintained. Enables CO₂ transport as plasma HCO₃⁻."),
...gap(0),
qna("Kussmaul breathing suggests which disorder?", "Metabolic acidosis — deep, rapid breathing compensates by blowing off CO₂."),
...gap(0),
qna("Why is the ratio 20:1 important?", "Because pH = pKa + log(ratio) = 6.1 + log 20 = 6.1 + 1.3 = 7.4. Any change in ratio shifts pH."),
...gap(),
rule(),
new Paragraph({
alignment: AlignmentType.CENTER,
children: [new TextRun({ text: "End of Notes — Good luck with your exam!", font: "Calibri", size: 20, color: C.textMuted, italics: true })],
spacing: { before: 160, after: 160 },
}),
],
},
],
});
Packer.toBuffer(doc).then(buf => {
fs.writeFileSync(
"/home/daytona/workspace/acid-base-notes/Acid_Base_Balance_Student_Notes_v2.docx",
buf
);
console.log("Done.");
});