ABG analysis from basic to clinicals?

Reading File
ABG analysis is a broad clinical topic. Let me search the library comprehensively across all relevant sections simultaneously.
Finding Sources
Finding Sources
Finding Sources
Excellent results. Now let me read the most comprehensive sections in parallel - focusing on the best sources for each component:
Reading File
Reading File
Reading File
Great material. Now let me get the compensation formulas, oxygenation parameters, delta-delta ratio, and clinical scenarios sections:
Reading File
Reading File
Finding Sources
Reading File
Finding Sources
Finding Sources
Reading File
Reading File
Reading File
Now let me fetch the acid-base map diagram and the ABG stepwise flowchart:
Loading Image
Loading Image
Reading File
I now have comprehensive material from multiple authoritative textbooks. Let me compile the full ABG analysis guide.

Arterial Blood Gas (ABG) Analysis: Basic to Clinical

Sources: Roberts & Hedges' Clinical Procedures in Emergency Medicine; Symptom to Diagnosis (4th Ed.); Goldman-Cecil Medicine; Barash Clinical Anesthesia; Miller's Anesthesia; Tintinalli's Emergency Medicine

1. What Is an ABG?

An ABG samples arterial blood (standard reference: radial artery) to directly measure:
ParameterNormal ValueWhat It Tells You
pH7.35 - 7.45Overall acid-base status
PaCO235 - 45 mm HgVentilation (how much CO2 is blown off)
PaO280 - 100 mm HgOxygenation
HCO3-22 - 26 mEq/LMetabolic (renal) component
SpO2/SaO295 - 100%Oxygen saturation of hemoglobin
Base Excess (BE)-2 to +2 mEq/LMetabolic deviation from normal
The HCO3- on the ABG printout is calculated (not directly measured) from pH and PaCO2 via the Henderson-Hasselbalch equation: pH = 6.1 + log([HCO3-] / 0.003 × PaCO2). The "total CO2" on a basic metabolic panel is a direct measurement and usually runs ~1-2 mEq/L higher.

2. The Underlying Chemistry

The central reaction:
CO2 + H2O ⇌ H2CO3 ⇌ HCO3- + H+
This means:
  • ↑ PaCO2 → reaction shifts right → more H+ → pH falls (respiratory acidosis)
  • ↓ PaCO2 → reaction shifts left → less H+ → pH rises (respiratory alkalosis)
  • ↑ HCO3- → reaction shifts left → less H+ → pH rises (metabolic alkalosis)
  • ↓ HCO3- → reaction shifts right → more H+ → pH falls (metabolic acidosis)

3. The 7-Step Systematic Approach

Step 1 - Determine pH (Acidosis vs. Alkalosis)

  • pH < 7.35: Acidemia
  • pH 7.35 - 7.45: Normal
  • pH > 7.45: Alkalemia
pH < 7.20 or > 7.60 is life-threatening and needs urgent action.

Step 2 - Identify the Primary Disorder (Respiratory vs. Metabolic)

Look at PaCO2 and HCO3- together with the pH direction:
pHPrimary causeDistinguishing feature
< 7.35 (acidosis)Respiratory acidosisPaCO2 > 45 mm Hg
< 7.35 (acidosis)Metabolic acidosisHCO3- < 22 mEq/L
> 7.45 (alkalosis)Respiratory alkalosisPaCO2 < 35 mm Hg
> 7.45 (alkalosis)Metabolic alkalosisHCO3- > 26 mEq/L
Key rule: The parameter that explains the pH direction is the primary disorder. If both are abnormal, check compensation.

Step 3 - Check for Appropriate Compensation

Compensation is never complete - it only partially corrects the pH. If compensation is more or less than predicted, a second (mixed) disorder is present.

Compensation Formulas:

Primary DisorderExpected CompensationFormula
Metabolic acidosis↓ PaCO2 (hyperventilation)Winter's formula: PaCO2 = (1.5 × HCO3-) + 8 ± 2
Metabolic alkalosis↑ PaCO2 (hypoventilation)ΔPaCO2 = 0.6 × ΔHCO3-
Acute respiratory acidosis↑ HCO3- (immediate buffering)HCO3- ↑ 1 mEq/L per 10 mm Hg ↑ PaCO2
Chronic respiratory acidosis↑ HCO3- (renal retention, 3-5 days)HCO3- ↑ 3.5-4 mEq/L per 10 mm Hg ↑ PaCO2
Acute respiratory alkalosis↓ HCO3-HCO3- ↓ 2 mEq/L per 10 mm Hg ↓ PaCO2
Chronic respiratory alkalosis↓ HCO3- (renal wasting)HCO3- ↓ 5 mEq/L per 10 mm Hg ↓ PaCO2
Clinical pearl: Metabolic compensation is respiratory (fast, minutes to hours). Respiratory compensation is metabolic/renal (slow, 3-5 days to complete).

Step 4 - Calculate the Anion Gap (if metabolic acidosis present)

AG = Na+ - (Cl- + HCO3-)
  • Normal: 12 ± 4 mEq/L (some labs use 7-9 if they omit K+)
  • If albumin is low, correct: Corrected AG = measured AG + 2.5 × (4 - measured albumin)
Elevated AG Metabolic Acidosis (MUDPILES)Normal AG Metabolic Acidosis (HARDUPS)
MethanolHyperchloremia
UremiaAdministration of saline/TPN
DKA / alcoholic ketoacidosisRenal tubular acidosis (RTA)
Propylene glycol / propofol infusionDiarrhea (HCO3- loss)
Isoniazid / IronUreteral diversion
Lactic acidosisPancreatic fistula
Ethylene glycolSpironolactone / acetazolamide
Salicylates

Step 5 - Calculate the Delta-Delta Ratio (for elevated AG acidosis)

Used to detect a hidden concurrent metabolic disorder behind the elevated AG.
Delta-Delta (Δ/Δ) = (Measured AG - Normal AG) / (Normal HCO3- - Measured HCO3-) = (AG - 12) / (24 - HCO3-)
ResultInterpretation
< 1Concurrent normal AG metabolic acidosis (e.g., diarrhea + DKA)
1 - 2Pure elevated AG metabolic acidosis (expected)
> 2Concurrent metabolic alkalosis (e.g., vomiting + lactic acidosis)

Step 6 - Assess Oxygenation

PaO2 and the alveolar-arterial (A-a) gradient:
PAO2 = FiO2 × (Patm - PH2O) - PaCO2/R
On room air at sea level:
PAO2 = 0.21 × (760 - 47) - PaCO2/0.8
(approximately: PAO2 ≈ 150 - 1.25 × PaCO2)
A-a gradient = PAO2 - PaO2
Normal A-a gradient:
  • Young healthy adult: ~5-10 mm Hg
  • Age-adjusted: (Age / 4) + 4 mm Hg
  • On supplemental O2: up to 100 mm Hg can be normal
A-a GradientMechanism of Hypoxemia
NormalHypoventilation or low FiO2 (altitude)
ElevatedV/Q mismatch, diffusion impairment, right-to-left shunt
PaO2/FiO2 ratio (P/F ratio):
  • 300: Normal
  • 200-300: Mild ARDS
  • 100-200: Moderate ARDS
  • < 100: Severe ARDS

Step 7 - Identify Mixed Disorders

A mixed disorder is present when:
  1. Compensation is outside the predicted range
  2. pH is normal but both PaCO2 and HCO3- are abnormal
  3. The delta-delta ratio is outside 1-2
The acid-base map (below) is a powerful visual tool - a point falling outside the confidence bands of any single disorder indicates a mixed disorder:
Acid-Base Map showing confidence bands for all six simple acid-base disorders
Acid-Base Map - Roberts & Hedges' Clinical Procedures in Emergency Medicine

4. The Four Primary Disorders - Causes and Clinical Features

Metabolic Acidosis

Causes: DKA, lactic acidosis, renal failure (uremia), diarrhea, RTA, toxins (methanol, salicylates, ethylene glycol)
Clinical features: Kussmaul respirations (deep, rapid breathing as compensation), weakness, confusion, arrhythmias at severe pH
Key: Use Winter's formula to check if respiratory compensation is adequate. If measured PaCO2 < predicted: superimposed respiratory alkalosis. If measured PaCO2 > predicted: superimposed respiratory acidosis.

Metabolic Alkalosis

Causes: Vomiting/NG suction (most common - loss of HCl), diuretics (loop/thiazide), hyperaldosteronism, exogenous alkali, volume contraction
Clinical features: Hypocalcemia symptoms (tetany, Chvostek's, Trousseau's), weakness, hypokalemia often co-exists
Saline-responsive (urine Cl- < 20): vomiting, diuretics, post-hypercapnia
Saline-resistant (urine Cl- > 20): hyperaldosteronism, Cushing's, Bartter/Gitelman syndrome

Respiratory Acidosis

Causes: COPD exacerbation, severe asthma, OSA, neuromuscular disease (GBS, MG), opiate/sedative overdose, airway obstruction
Acute vs. Chronic:
  • Acute: pH low, PaCO2 high, HCO3- only mildly elevated (~normal)
  • Chronic: pH near-normal (compensated), PaCO2 high, HCO3- clearly elevated (> 28-30)

Respiratory Alkalosis

Causes: Anxiety/panic, pain, fever, sepsis (early - most common cause in ICU), liver failure, salicylate toxicity (early), PE, mechanical over-ventilation, pregnancy, CNS disorders
Key clinical point: Respiratory alkalosis in a septic patient is often the first ABG finding, before metabolic acidosis develops.

5. Base Excess (BE)

SBE = [HCO3-]actual - 24.8 + (16.2 × [pH - 7.40])
  • Normal: -2 to +2 mEq/L
  • Negative BE (base deficit): metabolic acidosis
  • Positive BE: metabolic alkalosis
  • Base deficit > -10 in trauma = marker of severe hemorrhagic shock

6. Venous Blood Gas vs. ABG

ParameterArterialPeripheral VenousClinical Use
pHStandard~0.03-0.05 lowerVBG pH correlates well; acceptable for screening
PaCO2Standard~3-8 mm Hg higherVBG PaCO2 unreliable for hypercapnia
PaO2StandardUselessDo NOT use VBG PaO2 for oxygenation
LactateReliableAcceptableMildly elevated venous lactate may need arterial confirmation
VBGs are increasingly used in emergency medicine. A normal venous PaCO2 reliably excludes hypercapnia. However, VBGs are unreliable in shock or severe hypercapnia.

7. Worked Clinical Examples

Case 1 - Diabetic Ketoacidosis

ABG: pH 7.15, PaCO2 20 mm Hg, HCO3- 6 mEq/L, PaO2 80 mm Hg
Electrolytes: Na+ 138, Cl- 100, K+ 6.2, glucose 389
  1. pH 7.15 → Acidemia
  2. HCO3- 6 → Primary metabolic acidosis
  3. Winter's formula: Expected PaCO2 = (1.5 × 6) + 8 = 17 ± 2 → actual 20 is within range → appropriate compensation, no secondary respiratory disorder
  4. AG = 138 - (100 + 6) = 32 (markedly elevated)
  5. Delta-delta = (32-12)/(24-6) = 20/18 = 1.1 → pure elevated AG metabolic acidosis
  6. Diagnosis: DKA with appropriate respiratory compensation (Kussmaul breathing)

Case 2 - Septic Patient (UTI/Pyelonephritis)

ABG: pH 7.32, PaCO2 30 mm Hg, HCO3- 14 mEq/L
Electrolytes: Na+ 138, Cl- 102
  1. pH 7.32 → Acidemia
  2. HCO3- 14 → Primary metabolic acidosis
  3. AG = 138 - (102+14) = 22 (elevated) → anion gap metabolic acidosis
  4. Delta-delta = (22-12)/(24-14) = 10/10 = 1.0 → pure AG acidosis
  5. Clinical context: fever, hypotension, leukocytosis → Lactic acidosis from sepsis

Case 3 - COPD Exacerbation

ABG: pH 7.30, PaCO2 65 mm Hg, HCO3- 30 mEq/L
  1. pH 7.30 → Acidemia
  2. PaCO2 65 → Primary respiratory acidosis
  3. Compensation check (acute): expected HCO3- = 24 + (65-40)/10 × 1 = 24 + 2.5 = 26.5 - but actual HCO3- is 30, suggesting chronic respiratory acidosis with renal compensation: expected HCO3- = 24 + (25/10) × 3.5 = ~33 → HCO3- is 30, slightly below → mostly compensated chronic resp. acidosis, possibly during an acute-on-chronic exacerbation

Case 4 - Mixed Disorder (Sepsis + Vomiting)

ABG: pH 7.45, PaCO2 30 mm Hg, HCO3- 20 mEq/L
Electrolytes: Na+ 140, Cl- 92
  1. pH 7.45 → Normal, but borderline
  2. PaCO2 low + HCO3- low → could be respiratory alkalosis OR metabolic acidosis with overcompensation
  3. AG = 140 - (92+20) = 28 (elevated)
  4. Delta-delta = (28-12)/(24-20) = 16/4 = 4 → > 2, indicating underlying metabolic alkalosis (e.g., from vomiting) hidden behind the AG acidosis
  5. Diagnosis: Triple disorder - elevated AG metabolic acidosis + metabolic alkalosis + respiratory alkalosis (from sepsis-driven hyperventilation)

8. Quick Reference Summary

pH < 7.35 → Acidosis        pH > 7.45 → Alkalosis

↑ PaCO2 causes acidosis    ↓ PaCO2 causes alkalosis
↑ HCO3- causes alkalosis   ↓ HCO3- causes acidosis

Compensation rules:
  Met. acidosis  → lungs blow off CO2 (Winter's: PaCO2 = 1.5×HCO3 + 8 ± 2)
  Met. alkalosis → lungs retain CO2 (ΔPaCO2 = 0.6 × ΔHCO3)
  Resp. acidosis → kidneys retain HCO3 (acute: +1/10; chronic: +3.5/10)
  Resp. alkalosis → kidneys excrete HCO3 (acute: -2/10; chronic: -5/10)

Anion Gap = Na - (Cl + HCO3)   Normal: 8-12 (albumin-corrected)
Delta-delta < 1 → also normal AG acidosis
Delta-delta > 2 → also metabolic alkalosis

A-a gradient = PAO2 - PaO2    Normal ≈ age/4 + 4
Normal A-a gradient + hypoxia → hypoventilation or low FiO2
Elevated A-a gradient + hypoxia → V/Q mismatch, shunt, diffusion problem

References:
  • Roberts & Hedges' Clinical Procedures in Emergency Medicine, 15th Ed., p. 1734-1735
  • Symptom to Diagnosis: An Evidence-Based Guide, 4th Ed., pp. 69-72
  • Goldman-Cecil Medicine, International Ed., p. 1040
  • Barash Clinical Anesthesia, 9th Ed., pp. 4249-4250
  • Miller's Anesthesia, 10th Ed., pp. 6495-6496
  • Tintinalli's Emergency Medicine, p. 121

Now can you explain me all these concepts…in a stodry format from the very basics explaining the whys and hows of every thing reach upto the depth required for a internist. Create a visual story diagram or mind map too if you can.

Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Finding Sources
Reading File
Reading File
Finding Sources
Reading File
Finding Sources
Finding Sources
Reading File
Finding Sources
Reading File
Finding Sources
Excellent - rich Guyton physiology content. Now let me get the renal mechanisms and then generate the diagram:
Reading File
Finding Sources
Now let me generate the visual mind map while I compose the story:
Generating Image

A detailed medical education mind map / visual story diagram for ABG (Arterial Blood Gas) Analysis. Central node: "ABG ANALYSIS" in bold. Branching into 6 major color-coded sections: 1) "THE CHEMISTRY ENGINE" (blue) - showing CO2+H2O→H2CO3→H++HCO3-, Henderson-Hasselbalch equation pH=6.1+log(HCO3/0.03xPaCO2), bicarbonate buffer system diagram, 3 buffer lines (bicarbonate, phosphate, protein/hemoglobin). 2) "LUNG - The Fast Responder" (green) - respiratory compensation arrows, seconds-to-minutes timeline, increases/decreases ventilation, blowing off CO2, chemoreceptors respond to H+. 3) "KIDNEY - The Slow Fixer" (orange) - renal compensation 3-5 days, proximal tubule 80% HCO3 reabsorption via NHE3, distal tubule H+ secretion via H-ATPase, ammonia buffer system, new HCO3 generation. 4) "THE 4 DISORDERS" (red) - 2x2 grid: Metabolic Acidosis (low pH, low HCO3), Metabolic Alkalosis (high pH, high HCO3), Respiratory Acidosis (low pH, high CO2), Respiratory Alkalosis (high pH, low CO2). Each with key causes listed. 5) "TOOLS FOR INTERNIST" (purple) - Anion Gap formula, Winter's Formula, Delta-Delta ratio, A-a gradient, compensation formulas table. 6) "CLINICAL STORY TIMELINE" (teal) - patient story arc from initial insult → buffer response → respiratory compensation → renal compensation → resolution or mixed disorder. Arrows connecting sections. Professional medical illustration style, clean white background, color-coded boxes, readable fonts, organized layout.

Now let me generate the visual mind map while I compose the story:Here is the mind map, followed by the full story:
ABG Analysis Mind Map

The Story of ABG Analysis

From the chemistry of a single cell to the bedside of a critically ill patient


PROLOGUE: Why the Body Cares So Much About pH

Before we draw a single blood gas, we need to understand why the body treats pH regulation as a matter of life and death.
Every enzyme in your body has an optimal pH at which it folds correctly and functions. Stray too far from that range - even by 0.1 units - and enzymes begin to misfold, cell membranes become unstable, hemoglobin can't release oxygen properly, and cardiac contractility crashes. The body tolerates a temperature range of about 35-41°C before death. But the pH range it tolerates is astonishingly narrow: 7.0 to 7.7. Outside that, you die.
Normal arterial pH: 7.35 to 7.45. That's a 0.1-unit window. Think about that - the entire chemistry of human life runs within a band narrower than a single decimal place.
So what creates acid in the body, and how does the body fight back?

ACT 1: The Enemy - Where Does Acid Come From?

Every moment you're alive, your cells are making acid. There are two major sources:
1. The Volatile Acid - Carbon Dioxide
Your mitochondria burn glucose and fat for energy through aerobic metabolism. The byproduct is CO2 - about 15,000 mmol per day. CO2 is not itself an acid, but the instant it dissolves in water, it becomes one:
CO2 + H2O ⇌ H2CO3 ⇌ H+ + HCO3-
This reaction is normally sluggish, but in the lungs and kidney tubules, carbonic anhydrase (CA) catalyzes it at lightning speed - up to 10 million times faster. So CO2 dissolving in blood plasma immediately generates H+ ions. This is why we call CO2 the "volatile acid" - it can be eliminated by breathing, which is your escape valve.
2. The Non-Volatile (Fixed) Acids
Metabolism also generates fixed acids that can't be blown off - they must be excreted by the kidneys. These include:
  • Sulfuric acid from protein catabolism (methionine, cysteine)
  • Phosphoric acid from phospholipids
  • Lactic acid when oxygen delivery fails
  • Ketoacids (acetoacetate, beta-hydroxybutyrate) during fasting or insulin deficiency
  • Uric acid
Normally, the kidneys handle about 70 mEq of these fixed acids per day. But in disease, that number can explode: a patient in DKA may generate 500+ mEq/day of ketoacid. The system gets overwhelmed.

ACT 2: The First Defenders - The Buffer Systems

The body doesn't wait for the lungs or kidneys. The first line of response is chemical buffering - instantaneous (within seconds).
A buffer is a substance that can absorb H+ (when acid is added) or release H+ (when base is added) to minimize pH change. Think of it as a shock absorber for the blood.
The body has three main buffer systems, and they all operate simultaneously - what Guyton calls the isohydric principle: since they all share the same pool of H+, changing one affects all.

Buffer 1: The Bicarbonate System (The Star)

This is the most important extracellular buffer, not because it's the most powerful chemically (it isn't - its pK of 6.1 is far from physiologic pH of 7.4), but because it's the only buffer whose components are independently controlled by two organ systems.
The reaction: CO2 + H2O ⇌ H2CO3 ⇌ H+ + HCO3-
When acid enters the blood:
  • H+ ions combine with HCO3- → forming H2CO3
  • H2CO3 breaks down → CO2 + H2O
  • Extra CO2 stimulates breathing → blown off
  • Net result: A strong acid (HCl) was converted into water and a gas
When base enters the blood:
  • OH- combines with H2CO3 → HCO3- + H2O
  • CO2 levels fall → breathing slows to rebuild CO2
The elegance here is that the end products are either a gas (breathable) or a soluble ion (excretable by kidney). The bicarbonate system is unique because it's open at both ends - continuously regulated.
Using the Henderson-Hasselbalch equation:
pH = 6.1 + log ( [HCO3-] / 0.03 × PaCO2 )
A practical clinical version: [H+] = 24 × (PaCO2 / HCO3-)
This equation is the single most important formula in ABG interpretation. It tells you that pH is not determined by PaCO2 or HCO3- alone - it's determined by their ratio. This is why compensation works: even if PaCO2 is high (respiratory acidosis), if the kidney raises HCO3- proportionately, the ratio stays near normal, and pH is preserved.

Buffer 2: The Phosphate System

pK = 6.8, which is closer to physiologic pH than bicarbonate. But phosphate is present in low concentrations extracellularly, so its contribution there is minor. However, inside kidney tubules, phosphate becomes highly concentrated - it's a critical urinary buffer, allowing the kidney to excrete large amounts of H+ as H2PO4- (titratable acid) without the urine becoming dangerously acidic.

Buffer 3: Proteins and Hemoglobin (The Intracellular Reservoir)

Proteins contain histidine residues with imidazole side chains that can accept or donate H+. This makes them powerful intracellular buffers. About 60-70% of the total chemical buffering of the body happens intracellularly - mostly via proteins.
Hemoglobin is the star here. In the red blood cell: H+ + Hb ⇌ HHb
Deoxygenated hemoglobin is actually a better H+ acceptor than oxygenated hemoglobin (the Haldane effect). This is useful in peripheral tissues: oxygen is released, hemoglobin deoxygenates, and can now buffer the H+ generated by CO2 transport. By the time blood reaches the lungs, CO2 is off-loaded and O2 is loaded, reversing the process.
Important caveat: Intracellular buffering is powerful but slow - it takes hours for H+ to equilibrate across cell membranes (except RBCs, which equilibrate almost instantly). So in acute acid-base disorders, the extracellular bicarbonate buffer handles the immediate shock.

ACT 3: The Fast Responder - The Lungs (Minutes)

Chemical buffers buy time. But the body's second line of defense - and the fastest organ-level response - is the lung.
Here's the elegant feedback loop: when blood pH drops (acidosis), chemoreceptors (especially the central chemoreceptors in the medulla which sense CO2 in CSF, and peripheral chemoreceptors in the carotid bodies which sense pH and PaO2) signal the respiratory centers to increase ventilation. Breathing faster and deeper blows off more CO2.
Since CO2 is a volatile acid: ↑ ventilation → ↓ PaCO2 → ↓ H+ → ↑ pH
Conversely, in alkalosis, ventilation decreases, CO2 is retained, and pH is pulled back down.
This response takes minutes and is nearly complete within 12-24 hours.
But - and this is a key insight - respiratory compensation for metabolic disorders is never complete. The pH returns toward normal, but not all the way to 7.40. Why? Because if pH fully normalized, the chemoreceptor drive to breathe would disappear, and ventilation would relax. The system reaches a new setpoint that's slightly abnormal.
This gives us Winter's Formula for metabolic acidosis: Expected PaCO2 = (1.5 × HCO3-) + 8 ± 2
If the actual PaCO2 is higher than predicted: the lungs aren't compensating enough → there's a concurrent respiratory acidosis (the patient can't breathe well, perhaps COPD is the hidden culprit).
If the actual PaCO2 is lower than predicted: the patient is hyperventilating more than expected → there's a concurrent respiratory alkalosis (sepsis? PE? anxiety?).

ACT 4: The Slow Fixer - The Kidneys (Days)

The kidney is the most powerful acid-base regulator, but it's slow. Full renal compensation takes 3-5 days. This temporal delay is the reason we distinguish acute from chronic respiratory disorders on an ABG.
The kidney handles acid through three mechanisms - all using the same basic biochemistry:

Mechanism 1: Reabsorbing the Filtered Bicarbonate (80-90% in Proximal Tubule)

Every day, about 4,500 mEq of HCO3- is filtered at the glomerulus. If all of this were lost in the urine, the body would die of acidosis within hours. So the proximal tubule works obsessively to reabsorb it.
How? The proximal tubule cell uses carbonic anhydrase intracellularly to generate H+ and HCO3-. The H+ is pumped out into the tubular lumen via NHE3 (Na-H exchanger 3) - it secretes H+ into the lumen in exchange for Na+. In the lumen, this secreted H+ meets filtered HCO3-, and carbonic anhydrase on the luminal brush border converts them back to CO2 + H2O. The CO2 diffuses back into the cell, gets rehydrated, and generates more HCO3- which exits into the bloodstream via basolateral transporters.
Net effect: HCO3- appears to be "reabsorbed," but it's actually regenerated. For every H+ secreted into the lumen, one HCO3- is added back to the blood.

Mechanism 2: Excreting Titratable Acid (Phosphate Buffer in Distal Tubule)

The 10% of H+ secretion that makes it past the proximal tubule reaches the distal segments. Here, secreted H+ binds phosphate (HPO4²- → H2PO4-) and other filtered buffers. These protons are trapped in the urine and cannot be reabsorbed. This is "titratable acid." It's limited by how much phosphate is filtered.

Mechanism 3: The Ammonia Trick (The Most Powerful - and Adaptable - Mechanism)

This is the kidney's secret weapon for prolonged acidosis. Proximal tubule cells take glutamine (from the blood) and convert it to NH4+ and HCO3-. The HCO3- is exported to the blood (new bicarbonate - not filtered, but newly made). The NH4+ is secreted into the lumen, travels down to the collecting duct, and is excreted in urine.
Why is this important? Because ammonia production can increase 10-fold during chronic acidosis. This is how the kidney handles DKA, starvation acidosis, and chronic renal failure's acid load. When kidneys fail, ammonia production fails, and metabolic acidosis develops (the non-anion gap type of renal tubular acidosis, or the anion-gap type of uremic acidosis from sulfates and phosphates accumulating).
Summary of renal responses:
  • In acidosis: ↑ H+ secretion, ↑ HCO3- reabsorption, ↑ ammonia production, ↑ titratable acid → HCO3- rises in blood, urine becomes acidic
  • In alkalosis: ↓ H+ secretion, ↓ HCO3- reabsorption → HCO3- spills in urine, urine becomes alkaline

ACT 5: Reading the ABG - The Internist's Investigation

Now you arrive at the bedside. An ABG comes back. You're an investigator - every number is a clue.

Scene 1: The pH - The Verdict

pH < 7.35: guilty of acidosis
pH > 7.45: guilty of alkalosis
pH 7.35-7.45: apparently innocent - but don't be fooled. A "normal" pH with wildly abnormal PaCO2 and HCO3- means two competing disorders are canceling each other out (mixed disorder).

Scene 2: The PaCO2 - The Lung's Testimony

PaCO2 is the lung's voice. Normal: 35-45 mm Hg.
  • High PaCO2 = too much CO2 = lungs are hypoventilating = respiratory acidosis (or metabolic alkalosis compensation)
  • Low PaCO2 = too little CO2 = lungs are hyperventilating = respiratory alkalosis (or metabolic acidosis compensation)
Critical question: Is the PaCO2 moving in the same direction as the pH problem (primary) or opposite direction (compensation)?

Scene 3: The HCO3- - The Kidney's Testimony

HCO3- is the kidney's voice. Normal: 22-26 mEq/L.
  • Low HCO3-: metabolic acidosis (primary) OR respiratory alkalosis compensation
  • High HCO3-: metabolic alkalosis (primary) OR respiratory acidosis compensation

Scene 4: The Anion Gap - Unmasking the Hidden Criminal

When metabolic acidosis is present, the anion gap tells you how the HCO3- was consumed.
AG = Na+ - (Cl- + HCO3-) Normal: 8-12 mEq/L (or 12 ± 4 if K+ included in numerator)
The logic is electrical neutrality: all positive charges in plasma must equal all negative charges.
Measured cations: Na+ (main), K+ (small)
Measured anions: Cl-, HCO3-
The gap between measured cations and measured anions represents unmeasured anions (albumin, phosphate, sulfate, organic acids like lactate and ketones).
If AG is high: Something is producing unmeasured anions (lactic acid, ketoacids, methanol metabolites, salicylate, etc.). As these anions accumulate, HCO3- is consumed to buffer their H+, but the foreign anion remains - it fills the "gap."
If AG is normal (hyperchloremic acidosis): HCO3- is being lost directly (diarrhea, RTA, urinary diversion), and chloride rises to replace it electrically. No unmeasured anions - so gap stays normal.
The albumin correction: Each 1 g/dL drop in albumin below 4 g/dL reduces the normal AG by 2.5. A hypoalbuminemic patient with an "apparently normal" AG of 8 may actually have a significantly elevated corrected AG, masking a real anion-gap process.

Scene 5: The Delta-Delta Ratio - The Double Agent Detector

This is where internist-level thinking separates from junior thinking.
In a pure anion-gap metabolic acidosis, every mEq of acid that raises the AG by 1 should also consume 1 mEq of HCO3-. So the rise in AG should equal the fall in HCO3-.
Delta-Delta (Δ/Δ) = (Measured AG - 12) / (24 - Measured HCO3-)
  • = 1-2: Pure AG acidosis. One crime, one criminal.
  • < 1: The HCO3- fell more than the AG rose. Where did the extra HCO3- go? Answer: there's a concurrent normal-AG metabolic acidosis (e.g., diarrhea on top of DKA).
  • > 2: The HCO3- didn't fall as much as expected. The AG acid was buffered against a higher-than-expected HCO3-. Answer: there's a concurrent metabolic alkalosis hiding underneath (e.g., a patient with chronic vomiting who develops sepsis - the high baseline HCO3- from alkalosis partially masked the drop from lactic acidosis).

Scene 6: Compensation Check - Asking "Is This Response Appropriate?"

This is the most important detective step. For every primary disorder, the body should produce a predictable compensatory response. If the compensation is too little or too much, there is a second disorder.
Primary DisorderCompensatory ResponseFormula
Metabolic acidosisHyperventilate (↓ PaCO2)Winter's: PaCO2 = 1.5×HCO3 + 8 ± 2
Metabolic alkalosisHypoventilate (↑ PaCO2)ΔPaCO2 = 0.6 × ΔHCO3
Acute resp. acidosisKidney buffers (↑ HCO3)HCO3 rises 1 per 10 mm Hg ↑ CO2
Chronic resp. acidosisKidney retains HCO3 (3-5d)HCO3 rises 3.5 per 10 mm Hg ↑ CO2
Acute resp. alkalosisHCO3 falls (immediate)HCO3 falls 2 per 10 mm Hg ↓ CO2
Chronic resp. alkalosisKidney wastes HCO3 (3-5d)HCO3 falls 5 per 10 mm Hg ↓ CO2
Why acute vs. chronic for respiratory disorders? Acute = only blood buffers and RBCs have had time to respond (1 mEq/L HCO3 change). Chronic = the kidney has had 3-5 days to fully compensate (3.5-4 mEq/L HCO3 change). An HCO3 of 34 with a PaCO2 of 70 in a COPD patient means chronic, well-compensated respiratory acidosis. The same HCO3 of 34 but a PaCO2 of only 50 means the HCO3 is too high for the CO2 - there must be a concurrent metabolic alkalosis (maybe from diuretics).

ACT 6: The Oxygenation Story (Often Forgotten, Clinically Critical)

Acid-base is one half of the ABG story. Oxygenation is the other half - and they're independent. A patient can have a perfectly normal pH with fatal hypoxemia.
PaO2 (normal 80-100 mm Hg on room air) tells you the oxygen dissolved in plasma. But dissolved O2 is a tiny fraction of total oxygen delivery. Most oxygen is carried by hemoglobin, reflected by SaO2.

The Alveolar Gas Equation

To know if the lungs are doing their job, you need to compare what's available in the alveolus (PAO2) vs. what actually made it to the artery (PaO2).
PAO2 = (FiO2 × [Patm - PH2O]) - (PaCO2 / R)
On room air at sea level: PAO2 ≈ 150 - 1.25 × PaCO2 (using R = 0.8, PH2O = 47)
A-a gradient = PAO2 - PaO2
Normal: approximately age/4 + 4 mm Hg (e.g., a 40-year-old: ~14 mm Hg)
The clinical power of the A-a gradient:
Hypoxemia with a normal A-a gradient means the lungs are working fine - the problem is upstream:
  • Pure hypoventilation (opioid overdose, neuromuscular disease) - CO2 is displacing O2 in alveoli
  • High altitude (low FiO2)
Hypoxemia with an elevated A-a gradient means the lung's gas exchange machinery is broken:
  • V/Q mismatch (pneumonia, PE, COPD, pulmonary edema)
  • Shunt (ASD, hepatopulmonary syndrome, ARDS)
  • Diffusion impairment (ILD)
The P/F ratio (PaO2 / FiO2):
  • 300: Normal
  • 200-300: Mild ARDS
  • 100-200: Moderate ARDS
  • < 100: Severe ARDS

ACT 7: The Four Disorders - Their Stories in Full

Metabolic Acidosis: "The Acid Flood"

What happened: Either acid poured in (AG type) or HCO3- was drained away (non-AG type).
The body's response: The medullary chemoreceptors sense the acidemia within seconds. The respiratory centers fire. The patient begins to breathe faster and deeper. You see Kussmaul respirations - the classic deep, sighing breaths of DKA or severe metabolic acidosis. This is the lungs desperately trying to blow off CO2 to save the pH. It's working.
The kidney joins the fight hours later - suppressing HCO3- excretion, ramping up ammonia production, acidifying the urine.
The causes - why the story matters:
Anion-gap acidosis: Something is dumping anions into the blood. MUDPILES mnemonic. The key ones:
  • Lactic acidosis (Type A): Tissue hypoperfusion - the cell is hypoxic, switches to anaerobic glycolysis, generates pyruvate → lactate. In shock, sepsis, cardiac arrest. Lactate > 2 mmol/L is abnormal; > 4 mmol/L is severe. The body is telling you it's not getting enough oxygen.
  • Lactic acidosis (Type B): Normal tissue oxygenation but impaired lactate clearance or mitochondrial dysfunction. Metformin toxicity, antiretrovirals, thiamine deficiency (B1 is required for pyruvate dehydrogenase), liver failure.
  • DKA: Insulin deficiency → fat breakdown → free fatty acids → ketone bodies in liver (acetoacetate, beta-hydroxybutyrate). Not just an AG acidosis - often a profound volume-depleted state too.
  • Uremic acidosis: In ESRD, sulfates and phosphates (from protein catabolism) can't be excreted. Accumulate as unmeasured anions. Also, the diseased kidney can't generate enough new HCO3-.
  • Toxic alcohols: Methanol → formic acid (blindness). Ethylene glycol → oxalic acid (renal calcium oxalate stones → renal failure). Both have elevated osmolar gaps to screen for them.
  • Salicylates: Uncouples oxidative phosphorylation → lactic acid + ketoacids. Also directly stimulates medullary respiratory center → creates a mixed picture of metabolic acidosis + respiratory alkalosis.
Normal AG (hyperchloremic) acidosis: The HCO3- was lost, not consumed.
  • Diarrhea: The GI tract normally secretes HCO3- into the lumen. Severe diarrhea drains it. This is the most common cause of metabolic acidosis worldwide.
  • Renal tubular acidosis (RTA): The kidney can't secrete enough H+. Type 1 (distal): can't acidify urine below pH 5.5 - the H-ATPase is broken. Type 2 (proximal): can't reabsorb filtered HCO3- - the NHE3 or CA is dysfunctional. Type 4: aldosterone deficiency/resistance - aldosterone normally stimulates H+ secretion; without it, hyperkalemia + acidosis.

Metabolic Alkalosis: "The Alkali Flood"

What happened: Either H+ was lost (vomiting, NG suctioning removing gastric HCl) or HCO3- was gained (alkali infusion, blood products with citrate).
Why does it persist? This is the key concept most students miss. Metabolic alkalosis is easy to generate but equally easy for the kidney to correct - the kidney just excretes the excess HCO3-. So for alkalosis to persist, there must be something preventing the kidney from doing its job. Usually that something is:
  1. Volume contraction (from vomiting/diuretics): Low blood volume triggers renin-angiotensin-aldosterone system. Aldosterone tells the distal tubule to save Na+ and secrete H+ and K+. By secreting H+, the kidney is paradoxically making the alkalosis worse. This creates the famous "paradoxical aciduria" - the patient is alkalemic but the urine is acidic because the kidney is desperately saving volume at the cost of pH.
  2. Hypokalemia: K+ depletion causes K+ to shift out of cells in exchange for H+ shifting in. Intracellular acidosis stimulates the kidney to secrete more H+.
  3. Aldosterone excess (Conn's, Cushing's): Directly drives H+ secretion independent of volume.
Treatment clue: Saline-responsive alkalosis (urine Cl- < 20) = give volume. Saline-resistant (urine Cl- > 20) = aldosterone-driven, needs to address the hormonal problem.
Clinical features: Hypocalcemia symptoms (alkalosis causes albumin to bind more Ca²+, lowering ionized calcium) → Trousseau's sign, Chvostek's sign, tetany. Hypokalemia. Cardiac arrhythmias at severe pH.

Respiratory Acidosis: "The CO2 Trap"

What happened: The lungs can't get rid of CO2 fast enough. CO2 accumulates. The reaction shifts right. H+ builds up. pH falls.
Acute vs. chronic - this distinction is everything:
Acute respiratory acidosis (minutes to hours): The only buffering is from extracellular bicarbonate and hemoglobin. HCO3- rises very slightly - just 1 mEq/L per 10 mm Hg rise in PaCO2. pH is significantly low. Patient is in acute distress.
Chronic respiratory acidosis (days to weeks): The kidney has had time to ramp up H+ secretion and HCO3- generation. HCO3- rises 3.5-4 mEq/L per 10 mm Hg rise in PaCO2. pH is near-normal (well-compensated). Patient may appear comfortable despite a PaCO2 of 60-70 mm Hg.
Clinical pearl for COPD: A "normal" pH in a COPD patient with PaCO2 of 65 and HCO3- of 32 is a chronic compensated respiratory acidosis. They're used to it. If that same patient comes in with an acute exacerbation and the pH drops to 7.28 with PaCO2 now 75, they're acutely decompensating on a chronic background. The acute component - the difference between current and their usual PaCO2 - is what's making them sick now.
Causes: COPD, severe asthma, OSA, opiate overdose (opioids suppress the medullary respiratory center), Guillain-Barré (respiratory muscle paralysis), myasthenic crisis, massive pulmonary edema, chest wall trauma, obesity-hypoventilation.
Why you must not give high-flow oxygen to a COPD patient blindly: In chronic CO2 retainers, the central chemoreceptors have been desensitized to high CO2 (they've adapted). The main drive to breathe comes from hypoxic drive via peripheral chemoreceptors. If you correct their PaO2 fully, you may remove that drive, causing them to hypoventilate further and worsen the hypercapnia.

Respiratory Alkalosis: "Too Much Breathing"

What happened: Ventilation increased beyond what's needed to eliminate CO2. CO2 falls. The reaction shifts left. H+ drops. pH rises.
The internist's most underappreciated disorder. In the ICU, respiratory alkalosis is often the first ABG sign of sepsis - before hemodynamic collapse, before metabolic acidosis. Sepsis causes direct stimulation of respiratory centers (via cytokines and direct CNS effects), producing hyperventilation.
Other causes: Anxiety (panic attack), pain, fever, early PE (hypoxia drives hyperventilation), liver failure (ammonia stimulates respiratory centers), pregnancy (progesterone drives chronic hyperventilation - normal in pregnancy: PaCO2 ~30-34 mm Hg), CNS disorders, early salicylate toxicity, mechanical over-ventilation.
Acute vs. chronic: Acute: HCO3- falls only 2 mEq/L per 10 mm Hg fall in PaCO2 (just blood buffering). Chronic: HCO3- falls 5 mEq/L per 10 mm Hg fall (full renal compensation).
Clinical features: Perioral tingling, paresthesias, carpopedal spasm (from reduced ionized Ca²+), lightheadedness, syncope.

ACT 8: Mixed Disorders - The Real World

Pure single disorders are textbook cases. Real patients - especially ICU patients - have mixed disorders, sometimes triple.
How to spot a mixed disorder:
  1. pH is normal but PaCO2 and HCO3- are both abnormal
  2. Compensation is outside predicted range
  3. Delta-delta ratio is outside 1-2
The most clinically important mixed disorders:
1. Metabolic acidosis + Respiratory alkalosis (Delta-delta > 1, pH near normal or high) Classic: Salicylate toxicity (uncouples mitochondria = metabolic acidosis, directly stimulates respiratory center = respiratory alkalosis). Also: Sepsis + lactic acidosis. Hepatic failure.
2. Metabolic alkalosis + Respiratory acidosis Classic: COPD patient on diuretics. The COPD produces chronic respiratory acidosis (high CO2, compensatory high HCO3-). The diuretic causes metabolic alkalosis (even higher HCO3-). The combined HCO3- is sky-high, pH may be surprisingly normal or high.
3. Metabolic acidosis + Metabolic alkalosis (detected via delta-delta < 1 or > 2) Classic: Alcoholic patient with vomiting (metabolic alkalosis) + alcoholic ketoacidosis (AG metabolic acidosis). Or DKA patient who was also vomiting before admission.
4. Triple disorder Example: Septic patient with acute tubular necrosis (metabolic acidosis, AG type) + nasogastric suction (metabolic alkalosis) + mechanical hyperventilation (respiratory alkalosis). Three concurrent disorders, pH deceptively near normal.

EPILOGUE: The Full ABG Report - What the Machine Prints

When you hold the ABG printout, here is what each number is saying:
ParameterWhat it's measuringThe story it tells
pHOverall H+ concentrationThe final verdict - acidemic or alkalemic
PaCO2Dissolved CO2 tensionThe lung's current ventilatory effort
PaO2Dissolved O2 tensionOxygenation status (compare with alveolar equation)
HCO3-Calculated bicarbonateThe metabolic (kidney) component
Base ExcessHow far metabolic component is from normalPositive = alkalosis contribution; Negative = acidosis contribution
SaO2Hemoglobin saturationMost of the oxygen delivery story
Lactate (if included)Anaerobic metabolism byproductTissue oxygen debt - the ICU's vital sign
Base excess (SBE) = [HCO3-] - 24.8 + (16.2 × [pH - 7.40])
A base excess of -10 means you need to add 10 mEq/L of bicarbonate equivalent to return the metabolic component to normal. In trauma, a base deficit > -10 is a marker of severe hemorrhagic shock and tells you the tissues have been starving for oxygen.

THE COMPLETE WORKFLOW (The Internist's 7-Step Protocol)

STEP 1: pH → Acidosis? Alkalosis? Life-threatening?
    ↓
STEP 2: PaCO2 + HCO3- → Which parameter explains the pH?
        That's the PRIMARY disorder.
    ↓
STEP 3: Check compensation → Is it appropriate?
        Use Winter's / compensation formulas.
        If NOT appropriate → mixed disorder present.
    ↓
STEP 4: If metabolic acidosis → Calculate Anion Gap
        High AG → MUDPILES
        Normal AG → HARDUPS (loss of HCO3-)
    ↓
STEP 5: If high AG → Calculate Delta-Delta
        < 1 → Also normal-AG acidosis
        1-2 → Pure AG acidosis
        > 2 → Also metabolic alkalosis
    ↓
STEP 6: Assess oxygenation
        Calculate A-a gradient
        Normal A-a? → Hypoventilation / Low FiO2
        Elevated A-a? → V/Q mismatch / Shunt / Diffusion
        PaO2/FiO2 ratio for ARDS staging
    ↓
STEP 7: Integrate with clinical picture
        Name ALL disorders present.
        Find the cause of each.
        Treat the underlying disease - not just the numbers.

Sources: Guyton and Hall Medical Physiology (14th Ed.) - acid-base chapters; Morgan & Mikhail's Clinical Anesthesiology (7th Ed.) p. 2211-2212; Roberts & Hedges' Clinical Procedures in Emergency Medicine p. 1734-1735; Symptom to Diagnosis (4th Ed.) p. 69-72; Goldman-Cecil Medicine p. 1040; Barash Clinical Anesthesia (9th Ed.) p. 4249-4250; Brenner & Rector's The Kidney - tubular physiology chaptersThat's the full story - from atomic chemistry to the ICU bedside. Here's a quick map of what was covered:
The narrative arc has 8 acts:
  1. Prologue - Why pH is a matter of survival (the 0.1-unit window of life)
  2. Act 1 - Where acid comes from (CO2 = volatile acid, fixed acids = the overflow)
  3. Act 2 - The three buffer systems (bicarbonate as the "open" buffer; phosphate in urine; proteins/Hb intracellularly; the isohydric principle tying them all together)
  4. Act 3 - The lungs (chemoreceptors → ventilation change in minutes; why compensation is never complete; Winter's Formula as the lung's accountability test)
  5. Act 4 - The kidneys in detail (proximal tubule NHE3, carbonic anhydrase, distal H-ATPase, the ammonia trick - the kidney's most powerful but slowest tool)
  6. Act 5 - Reading the ABG like an investigator (pH as verdict, PaCO2 as lungs' testimony, HCO3- as kidney's testimony, anion gap, delta-delta, compensation checks)
  7. Act 6 - Oxygenation: the alveolar gas equation, A-a gradient, P/F ratio
  8. Act 7 - All four disorders with full pathophysiology (including the COPD oxygen danger, paradoxical aciduria in metabolic alkalosis, salicylate triple disorder)
The mind map at the top ties all the branches visually. The 7-step protocol at the end is your bedside cheat sheet.

Where is it?

You're asking about the mind map image - it should be visible right at the top of my previous response. Let me fetch it directly so it renders for you:
Loading Image
There it is! Here's a quick guide to reading the mind map:
  • Top-left (blue) - The Chemistry Engine: the core CO2/H2O reaction, Henderson-Hasselbalch equation, and the three buffer systems (bicarbonate, phosphate, protein/hemoglobin) plotted by pH range
  • Top-right (green) - Lung as the Fast Responder: chemoreceptors → respiratory center → increased/decreased ventilation, all within seconds to minutes
  • Right-middle (orange) - Kidney as the Slow Fixer: proximal tubule NHE3 for 80% HCO3 reabsorption, distal H+ secretion, and the ammonia trap - full effect takes 3-5 days
  • Bottom-center (red) - The 4 Disorders: 2×2 grid with pH, HCO3, and key causes for each
  • Bottom-left (purple) - Tools for the Internist: Anion Gap, Winter's Formula, Delta-Delta, A-a Gradient, and the compensation formulas table
  • Bottom-right (teal) - Clinical Story Timeline: the arc from initial insult → buffer response → respiratory compensation → renal compensation → resolution or mixed disorder

But i am not seeing any images?

That's likely a display issue on your end - the image exists and loads correctly (I can see it fully when I fetch it). Here are a few things to try:
Quick fixes:
  1. Refresh the page - images sometimes don't load on first render
  2. Check your internet connection - the image is hosted externally at cdn.orris.care
  3. Try a different browser - Chrome or Firefox tend to handle these best
  4. Disable any ad blockers or privacy extensions - they sometimes block CDN image domains
Direct image link: You can open the mind map directly in your browser by clicking or copying this URL:
👉 https://cdn.orris.care/image-gen/cc894d61ed294a3aa2dced84a800b9de.png

Alternatively, I can create a downloadable version - I can build the mind map as a high-quality PNG or PDF file saved to the sandbox that you can download directly. Would you like me to do that? That way it's fully independent of any CDN or network issues.

Generate a downloadable PDF version of the mind map for your device

Reading File
Running Command

ls -la /home/daytona/workspace/ 2>/dev/null || mkdir -p /home/daytona/workspace

Running Command

mkdir -p /home/daytona/workspace/abg-mindmap && cd /home/daytona/workspace/abg-mindmap && python3 -c "import requests; r = requests.get('https://cdn.orris.care/image-gen/cc894d61ed294a3aa2dced84a800b9de.png'); open('mindmap.png','wb').write(r.content); print('Downloaded:', len(r.content), 'bytes')"

Good, image downloaded. Now converting to a full A3 landscape PDF with a title and caption:
Writing File

~/abg-mindmap/make_pdf.py

from reportlab.lib.pagesizes import A3, landscape
from reportlab.platypus import SimpleDocTemplate, Image, Paragraph, Spacer
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import cm
from reportlab.lib.colors import HexColor
from reportlab.lib.enums import TA_CENTER
from PIL import Image as PILImage

# Page setup: A3 landscape
output_path = "/home/daytona/workspace/abg-mindmap/ABG_MindMap.pdf"
page_width, page_height = landscape(A3)

doc = SimpleDocTemplate(
    output_path,
    pagesize=landscape(A3),
    leftMargin=1.5*cm,
    rightMargin=1.5*cm,
    topMargin=1.2*cm,
    bottomMargin=1.2*cm,
)

styles = getSampleStyleSheet()

title_style = ParagraphStyle(
    "title",
    parent=styles["Normal"],
    fontSize=22,
    fontName="Helvetica-Bold",
    textColor=HexColor("#1a1a2e"),
    alignment=TA_CENTER,
    spaceAfter=4,
)

subtitle_style = ParagraphStyle(
    "subtitle",
    parent=styles["Normal"],
    fontSize=11,
    fontName="Helvetica",
    textColor=HexColor("#444466"),
    alignment=TA_CENTER,
    spaceAfter=6,
)

caption_style = ParagraphStyle(
    "caption",
    parent=styles["Normal"],
    fontSize=8,
    fontName="Helvetica-Oblique",
    textColor=HexColor("#777788"),
    alignment=TA_CENTER,
    spaceBefore=4,
)

# Get original image dimensions
img_path = "/home/daytona/workspace/abg-mindmap/mindmap.png"
pil_img = PILImage.open(img_path)
orig_w, orig_h = pil_img.size
print(f"Original image size: {orig_w} x {orig_h}")

# Available area after margins
avail_w = page_width - 3*cm
avail_h = page_height - 5.5*cm  # leave room for title + caption

# Scale to fit
ratio = min(avail_w / orig_w, avail_h / orig_h)
img_w = orig_w * ratio
img_h = orig_h * ratio
print(f"Scaled image size: {img_w:.1f} x {img_h:.1f}")

# Build elements
elements = [
    Paragraph("ABG Analysis — Visual Mind Map", title_style),
    Paragraph("From Basic Chemistry to Clinical Internist-Level Practice", subtitle_style),
    Image(img_path, width=img_w, height=img_h),
    Paragraph(
        "Sources: Guyton & Hall Medical Physiology · Morgan & Mikhail's Clinical Anesthesiology · "
        "Goldman-Cecil Medicine · Barash Clinical Anesthesia · Roberts & Hedges' Emergency Medicine · "
        "Symptom to Diagnosis (4th Ed.) · Brenner & Rector's The Kidney",
        caption_style,
    ),
]

doc.build(elements)
print(f"PDF saved to: {output_path}")
Running Command

cd /home/daytona/workspace/abg-mindmap && python3 make_pdf.py

Your credits are exhausted. Your daily credits reset tomorrow, or you can purchase a top-up for more.

Hi

Your credits are exhausted. You can purchase a top-up or subscribe to a plan to continue using Orris. If you're already subscribed, your daily credits will reset tomorrow.
This is a shared conversation. Sign in to Orris to start your own chat.