UzonCalc User Guide

This document is generated with UzonCalc.

UzonCalc is a Python-based tool for hand-written engineering calculation reports. Focus on content and calculation logic; UzonCalc handles result rendering, formatting, and typesetting. It supports units, Excel calls, tables, charts, and more, enabling reuse of existing Excel models.


Features

1. Write calculation reports using Pythonsimple and expressive

2. AI-friendly: Python works well with AI assistance

3. All operations are functions, easy to understand and use

4. Automatically substitute and display computed values

5. Focus on logic; UzonCalc handles the dirty work

6. Unit-aware calculations with automatic conversions and checks

7. Call Excel calculations to reuse existing models

8. Output to HTML for viewing and printing to PDF/Word

9. Highly customizable with templates and styles

10. Open-source (MIT)


Getting started: basic Python syntax and conventions useful for UzonCalc

Table of Contents

Installation and Usage

Install via pip:

pip install uzoncalc

A simple example script is as follows:

from uzoncalc import *

@uzon_calc()
def sheet():
    doc_title("uzoncalc example")

    "Hello, UzonCalc!"

    save()


if __name__ == "__main__":
    sheet()

Run the script with:

python example.py

Python Basics

Here are some Python basics to help you get started with UzonCalc.

1. Strings: use single, double, or triple quotes

2. Numbers: integers and floats (e.g. 42, 3.14)

3. Booleans: True and False

4. Lists: use [ ] for lists, e.g. [1,2,3]

5. Assignment: use = to assign values

6. Operators: +, -, *, /, ** for math; comparison operators available

7. Variable names: letters, digits and underscores; cannot start with digit

8. Indentation: use 4 spaces for blocks

9. Comments: start with #


Coding suggestions:

- Prefer English names for variables

- Use camelCase for variable names (UzonCalc treats _ as subscript)

- Add comments where helpful

- Keep functions small and focused

Automatic Table of Contents

Call `toc()` to automatically generate the document contents here.

Variables and Naming

Naming rules

Variable names can include letters, digits and underscores but cannot start with a digit.

Use camelCase in UzonCalc to avoid conflict with subscript notation.

Aliases

You can define display aliases for variables. Aliases may include non-ASCII characters.

age_xm = 30
alias("age_xm", "Person's age")
age_xm
name_xm = "Xiao Ming"
alias("name_xm", "Name_XiaoMing")
name_xm

agexm=30

Person's age=30

namexm=Xiao Ming

NameXiaoMing=Xiao Ming

You can remove an alias by setting it to None.

NameXiaoMing=Xiao Ming

agexm=30

Strings

Single, double or triple quotes can be used to output paragraphs.

'single quoted'

"double quoted"

"""
Triple quoted text becomes a paragraph when rendered.
"""

single quoted

double quoted

Triple quoted text becomes a paragraph when rendered.

Numbers

# integer
integerNumber = 100
# float
floatNumber = 3.1415
# scientific
scientificNumber = 1.2e3
# complex
complexNumber = 2 + 3j

integerNumber=100

floatNumber=3.1415

scientificNumber=1200.0=1200

complexNumber=2+3j=(2+3j)

Tensors / Arrays

UzonCalc supports NumPy for tensor/matrix operations.

arr=np.array([[1,2,3],[4,5,6]])=[[1,2,3],[4,5,6]]

firstRow=arr0,:=[1,2,3]

secondColumn=arr:,1=[2,5]

firstCell=arr0,0=1

Units

Using units

UzonCalc uses pint for unit handling. Use `unit.*` to access units.

l_cp = 5 * unit.meter
w_cp = 10 * unit.m
h_cp = 2 * unit.meter
v_cp = l_cp * w_cp * h_cp

lcp=5m

wcp=10m

hcp=2m

vcp=lcp·wcp·hcp=5m·10m·2m=100

force = 100 * unit.newton
A_top = l_cp * w_cp
stress_cp = force / A_top

force=100N

Atop=lcp·wcp=5m·10m=50

stresscp=forceAtop=100N50=2N/m²

Unit calculations

You can perform arithmetic directly on quantities with units.

sqrtArea = sqrt(A_top + 10 * unit.meter**2)
acceleration = force * 1000 / (10 * unit.kilogram)

sqrtArea=Atop+10=50+10=7.745966692415m

acceleration=force·100010kg=100N·100010kg=10000N/kg

Unit conversion

originalSpeed = 18 * unit.meter / unit.second
speedKmh = originalSpeed.to(unit.kilometer / unit.hour)
"Original speed (m/s):"
originalSpeed
"Converted speed (km/h):"
speedKmh

originalSpeed=18m/s

speedKmh=originalSpeed.to(km/h)=64.8km/h

Original speed (m/s):

originalSpeed=18m/s

Converted speed (km/h):

speedKmh=64.8km/h

Advanced String Usage

Formatting

You can use f-strings for formatting.

name = "Uzon"
f"Hello, {name}! Welcome to UzonCalc."
π = 3.1415926535
f"Value of pi up to 3 decimal places: {pi:.3f}"

name=Uzon

Hello, Uzon! Welcome to UzonCalc.

π=3.1415926535

Value of π up to 3 decimal places: 3.142

Show equations in f-strings

Enable equation display inside f-strings with `enable_fstring_equation()` and disable with `disable_fstring_equation()`.

Hello, name=Uzon! Welcome to UzonCalc.

The value of π is approximately π=3.142, which is useful in calculations.

Operators

Use standard arithmetic and comparison operators.

operatorResult=(5+3)·2-422=15

comparisonResult=5>32245=True

Plotting

You can create plots using Matplotlib inside UzonCalc.

hide()
import matplotlib.pyplot as plt
x = np.linspace(0, 2 * np.π, 100)
y = np.sin(x)
plt.plot(x, y)
plt.title("Sine Wave")
plt.xlabel("x (radians)")
plt.ylabel("sin(x)")
plt.legend(["sin(x)"])
plt.grid(True)
show()
Plot(plt)

Subscripts

Default rule

Use underscore to indicate subscript in rendered names, e.g. H_2 becomes H.

ax=10m/s²

speedcar=ax·2·second=10m/s²·2·second=20m/s

Complex subscripts

Python identifiers cannot contain non-ASCII characters, but you can use aliases for display.

speed汽车=20m/s

distance=speed汽车·5·second=20m/s·5·second=100m

Alias removed; variable displays its original name

speedcar=20m/s

Array subscripts

Square bracket contents are treated as subscripts for arrays.

arr2d=np.array([[1,2,3],[4,5,6]])=[[1,2,3],[4,5,6]]

firstRow=arr2d0,:=[1,2,3]

secondColumn=arr2d:,1=[2,5]

firstCell=arr2d0,0=1

Greek letters

Use names like 'alpha', 'beta', 'gamma' to render Greek letters. Capitalized names render uppercase Greek letters.

ρwater=1000kg/m³

γ0=9.81m/s²

Function converters

Functions like sqrt and abs are rendered in math style.

edge1=3m

edge2=4m

diagonal=edge12+edge22=(3m)2+(4m)2=5m

value=-15N

absValue=|value|=|-15N|=15N

Tables

Tables can be created with `Table()`; headers can use rowspan/colspan.

Example Table
ComponentMaterialElastic Modulus (MPa)Design Strength (MPa)Standard Strength (MPa)
Ec/EsCompressiveTensileCompressiveTensile
Cap BeamC6036000.026.51.9638.52.85
Cap Beam 2C6036000.026.51.9638.52.85

Calling Excel calculations

You can update cell values in an Excel workbook and retrieve the result table.

Solid Params
Width Length Height Volume
6 10 2 240

By default, Excel results are cached when inputs do not change to speed up rendering.

Saving the document

Save as HTML

Use `save()` to export the document to an HTML file.

Print to PDF

Open the generated HTML in a browser and use the print feature to save as PDF.

Export to Word

You can convert HTML to Word using pandoc.