Worked Examples & Tips
On this page
Complete calculation scenarios, practical tips, and solutions to common issues.
Worked Examples #
Basic Calculations #
# Simple Math
5 + 3
10 - 2
4 * 5
20 / 4
2 ^ 3
10 % 3Results
| 5 + 3 | → | 8 |
| 10 - 2 | → | 8 |
| 4 * 5 | → | 20 |
| 20 / 4 | → | 5 |
| 2 ^ 3 | → | 8 |
| 10 % 3 | → | 1 |
Variables #
# Budget
salary = $5000
bonus = $500
expenses = $3000
net = salary + bonus - expensesResults
| salary = $5000 | → | $5,000.00 |
| bonus = $500 | → | $500.00 |
| expenses = $3000 | → | $3,000.00 |
| net = salary + bonus - expenses | → | $2,500.00 |
Comparisons #
# Checks
salary = $50000
threshold = $60000
is_high_earner = salary > threshold
needs_raise = salary < $40000
meets_target = salary >= $50000Results
| salary = $50000 | → | $50K |
| threshold = $60000 | → | $60K |
| is_high_earner = salary > threshold | → | false |
| needs_raise = salary < $40000 | → | false |
| meets_target = salary >= $50000 | → | true |
Complex Expressions #
# Mortgage
principal = $200000
rate = 0.04
years = 30
months = years * 12
monthly_rate = rate / 12
payment = principal * (monthly_rate * (1 + monthly_rate) ^ months) / ((1 + monthly_rate) ^ months - 1)Results
| principal = $200000 | → | $200K |
| rate = 0.04 | → | 0.04 |
| years = 30 | → | 30 |
| months = years * 12 | → | 360 |
| monthly_rate = rate / 12 | → | 0.0033 |
| payment = principal * (monthly_rate * (1 + monthly_rate) ^ months) / ((1 + monthly_rate) ^ months - 1) | → | $954.83 |
System Sizing #
# Server Capacity Planning
peak_load = 50000 req/s
server_capacity = 2000 req/s
servers = peak_load at server_capacity per server with 25% buffer
# Storage
daily_data = 100 MB/s over 1 day
monthly_storage = daily_data * 30
disks = monthly_storage at 2 TB per diskResults
| peak_load = 50000 req/s | → | 50K req/s |
| server_capacity = 2000 req/s | → | 2K req/s |
| servers = peak_load at server_capacity per server with 25% buffer | → | 32 server |
| daily_data = 100 MB/s over 1 day | → | 8.24 TB |
| monthly_storage = daily_data * 30 | → | 247 TB |
| disks = monthly_storage at 2 TB per disk | → | 124 disk |
Mixed Markdown #
# My Monthly Budget
I earn a salary and get bonuses.
## Income
monthly_salary = $5000
annual_bonus = $3000
monthly_bonus = annual_bonus / 12
Total monthly income:
total_income = monthly_salary + monthly_bonus
## Expenses
- Rent: $1500
- Food: $600
- Utilities: $200
rent = $1500
food = $600
utilities = $200
total_expenses = rent + food + utilities
## Summary
Monthly surplus:
surplus = total_income - total_expenses
Can I save 20%?
savings_goal = total_income * 0.20
can_save = surplus >= savings_goalResults
| monthly_salary = $5000 | → | $5,000.00 |
| annual_bonus = $3000 | → | $3,000.00 |
| monthly_bonus = annual_bonus / 12 | → | $250.00 |
| total_income = monthly_salary + monthly_bonus | → | $5,250.00 |
| rent = $1500 | → | $1,500.00 |
| food = $600 | → | $600.00 |
| utilities = $200 | → | $200.00 |
| total_expenses = rent + food + utilities | → | $2,300.00 |
| surplus = total_income - total_expenses | → | $2,950.00 |
| savings_goal = total_income * 0.20 | → | $1,050.00 |
| can_save = surplus >= savings_goal | → | true |
Tips #
Organize with Markdown #
Use headers and prose to structure your thinking:
# Q1 Budget
## Revenue Assumptions
monthly_revenue = $50000
q1_months = 3
total_revenue = monthly_revenue * q1_months
## Cost Breakdown
fixed_costs = $20000
variable_pct = 30%
variable_costs = total_revenue * variable_pctResults
| monthly_revenue = $50000 | → | $50K |
| q1_months = 3 | → | 3 |
| total_revenue = monthly_revenue * q1_months | → | $150K |
| fixed_costs = $20000 | → | $20K |
| variable_pct = 30% | → | 30% |
| variable_costs = total_revenue * variable_pct | → | $45K |
Use the Preview Pane #
Press Ctrl+P in the editor to toggle the preview pane, which shows evaluated results alongside your source.
Get Help on Functions #
Run cm help functions to see all available functions with descriptions and usage patterns. Run cm help constants for unit constants, or cm help frontmatter for frontmatter directives.
Troubleshooting #
“Undefined variable” #
Variables must be defined before use. Check that:
- The variable is spelled correctly
- It’s defined on an earlier line
- No typos in the name
“Incompatible units” #
You can’t add meters to kilograms. Check that operations make physical sense.
“Parse error” #
The line isn’t valid CalcMark syntax. Common issues:
- Missing operator between values
- Unclosed parentheses
- Invalid characters