Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/preview/ohmage/26.12.5/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2026 Louis Grange
Copyright (c) 2026 Hakan GÜLEN

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 50 additions & 0 deletions packages/preview/ohmage/26.12.5/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Ohmage

> **Ohmage is a fork of [Zap](https://codeberg.org/grangelouis/zap)** by [Louis Grange](https://codeberg.org/grangelouis). Zap is no longer maintained, so I picked it up to keep it going.
>
> The original design and symbols are the work of Louis Grange and the [Zap contributors](https://codeberg.org/grangelouis/zap/activity/contributors). Ohmage starts from Zap 0.6.0 and keeps its full commit history.

Ohmage draws electronic circuit diagrams in Typst. The symbols follow IEC and IEEE/ANSI conventions, and the syntax stays out of your way: you place a component between two points, name it, and connect the next one to its pins.

[Symbol catalog](https://github.com/hkngln/ohmage/blob/v26.12.5/SYMBOLS.md) · [Examples](https://github.com/hkngln/ohmage/tree/v26.12.5/examples) · [Changelog](https://github.com/hkngln/ohmage/releases)

## Quick start

```typst
#import "@preview/ohmage:26.12.5"

#ohmage.circuit({
import ohmage: *

node("B", (0, 0))
resistor("r1", "B", (rel: (0, 4)), i: $i_1$)
})
```

Every symbol takes a name and one or two points. Two-point symbols such as resistors and diodes expose `in` and `out`; one-point symbols such as transistors and op-amps expose their pins, for example `"q1.b"` for a transistor's base. Pass `variant: "ieee"` to switch a symbol, or the whole circuit, from the default IEC style.

## Examples

### Operational amplifier

![Operational amplifier example](https://github.com/hkngln/ohmage/raw/v26.12.5/examples/example1.svg)

### Microcontroller

![Microcontroller example](https://github.com/hkngln/ohmage/raw/v26.12.5/examples/example2.svg)

### Logic circuit

![Logic circuit example](https://github.com/hkngln/ohmage/raw/v26.12.5/examples/example3.svg)

## What's in it

Over 110 symbols: passives and sensors, diodes and thyristors, BJTs, IGBTs, MOSFETs and JFETs, optocouplers, sources and grounds, op-amps, ADCs and DACs, logic gates, flip-flops, adders, multiplexers, counters and other digital blocks, relays, switches, meters and audio parts. The [symbol catalog](https://github.com/hkngln/ohmage/blob/v26.12.5/SYMBOLS.md) shows each one in IEC and IEEE style next to the code that draws it. If something is missing, you can build your own symbol with `symbol` and `interface`, the same way the built-in ones are made in [`src/symbols`](https://github.com/hkngln/ohmage/tree/v26.12.5/src/symbols).

## Contributing

Contributions are welcome, whether it's a new symbol, a fix or a better example. Please read the [contribution guide](https://github.com/hkngln/ohmage/blob/v26.12.5/CONTRIBUTING.md) first; it explains the branch flow and how the symbol catalog is generated.

## Legal

Ohmage is licensed under [MIT](LICENSE). The symbols are drawn from scratch. They follow IEC and IEEE conventions for familiarity, but Ohmage is not affiliated with or certified by any standards body, so check the official standards when your work has to comply with them.
19 changes: 19 additions & 0 deletions packages/preview/ohmage/26.12.5/src/circuit.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#import "/src/deps.typ": cetz
#import "/src/styles.typ": default

/// CeTZ native canvas wrapper
///
/// https://github.com/hkngln/ohmage#getting-started
///
/// - drawing (none, array, element): canvas content, typically containing the circuit elements
/// -> content
#let circuit(drawing, ..params) = {
cetz.canvas(..params, {
// Init style directory
cetz.draw.set-ctx(ctx => {
ctx.style.insert("ohmage", default)
return ctx
})
drawing
})
}
119 changes: 119 additions & 0 deletions packages/preview/ohmage/26.12.5/src/decorations.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#import "/src/deps.typ": cetz
#import cetz.draw: bezier-through, catmull, circle, content, get-ctx, hobby, line, mark
#import cetz.styles: merge

#let resolve-directions(direction) = {
let vertical = "north"
let horizontal = "east"
if "south" in direction {
vertical = "south"
}
if "west" in direction {
horizontal = "west"
}
return (x: horizontal, y: vertical)
}

#let resolve-decoration(ctx, deco, decor-type) = {
if type(deco) == dictionary and deco.at("content", default: none) == none { panic("decoration dictionary needs at least the 'content' key") }

let style = cetz.styles.resolve(ctx.style.ohmage.decoration, merge: if type(deco) == dictionary { deco } else { (content: deco) }, root: decor-type)
style.size = cetz.util.measure(ctx, style.content)
style.position = resolve-directions(style.anchor)
style.side = if style.position.y == "north" { 1 } else { -1 }
style.label-distance = style.at("label-distance", default: (0.1 + style.size.last()) * style.side)

return style
}

/// Symbol current decoration
///
/// - label (content | dict): label content
/// -> content
#let current(label) = {
get-ctx(ctx => {
let style = resolve-decoration(ctx, label, "current")

let mark-position = if style.position.x == "west" {
(("in", style.distance, "symbol.west"), "in")
} else {
(("symbol.east", style.distance, "out"), "out")
}

mark(..mark-position, symbol: style.symbol, reverse: style.invert, anchor: "center", fill: cetz.util.resolve-stroke(style.stroke).paint, stroke: 0pt, scale: style.scale)
content((rel: (0, style.label-distance), to: mark-position.at(0)), style.content)
})
}

/// Symbol flow decoration
///
/// - label (content | dict): label content
/// -> content
#let flow(label) = {
get-ctx(ctx => {
let style = resolve-decoration(ctx, label, "flow")

let west = style.position.x == "west"
let a-start = (to: ("symbol." + style.position.x, style.distance, if west { "in" } else { "out" }), rel: (0, style.indent * style.side))
let a-end = (to: a-start, rel: (style.length * if west { -1 } else { 1 }, 0))

line(
a-start,
a-end,
mark: (
(if style.invert { "start" } else { "end" }): style.symbol,
stroke: 0pt,
fill: cetz.util.resolve-stroke(style.stroke).paint,
scale: style.scale,
),
stroke: style.stroke,
)
content((rel: (0, style.label-distance), to: (a-start, style.label-ratio, a-end)), style.content)
})
}

/// Symbol voltage decoration
///
/// - label (content | dict): label content
/// -> content
#let voltage(label, p-rotate) = {
get-ctx(ctx => {
let style = resolve-decoration(ctx, label, "voltage")

let r-distance = cetz.util.resolve-number(ctx, style.distance)
let a-start = (rel: (style.start.at(0), (r-distance + style.start.at(1)) * style.side), to: "symbol." + style.position.y + "-west")
let a-end = (rel: (style.end.at(0), (r-distance + style.end.at(1)) * style.side), to: "symbol." + style.position.y + "-east")
let a-center = (rel: (style.center.at(0), (r-distance + style.center.at(1)) * style.side), to: "symbol." + style.position.y)

let (a-start, a-end) = if style.position.x == "west" { (a-end, a-start) } else { (a-start, a-end) }
content((rel: (0, style.label-distance), to: a-center), style.content)
if (style.shape == "curved") {
hobby(
a-start,
a-center,
a-end,
mark: (
(if style.invert { "start" } else { "end" }): style.symbol,
stroke: 0pt,
fill: cetz.util.resolve-stroke(style.stroke).paint,
scale: style.scale,
),
stroke: style.stroke,
)
} else if (style.shape == "straight") {
line(
a-start,
a-end,
mark: (
(if style.invert { "start" } else { "end" }): style.symbol,
stroke: 0pt,
fill: cetz.util.resolve-stroke(style.stroke).paint,
scale: style.scale,
),
stroke: style.stroke,
)
} else {
panic("Only 'curved' and 'straight' variants are supported for voltage arrows")
}
})
}
1 change: 1 addition & 0 deletions packages/preview/ohmage/26.12.5/src/deps.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#import "@preview/cetz:0.5.3"
52 changes: 52 additions & 0 deletions packages/preview/ohmage/26.12.5/src/lib.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Export dependencies
#import "deps.typ": cetz

// Export circuit
#import "circuit.typ": circuit

// Export decorations
#import "decorations.typ": current, flow, voltage

// Export styles
#import "styles.typ"
#import "utils.typ": set-ohmage-style

// Export core
#import "symbol.typ": interface, symbol

// Export symbols
#import "symbols/antenna.typ": antenna
#import "symbols/transformer.typ": transformer
#import "symbols/stub.typ": estub, nstub, sstub, stub, wstub
#import "symbols/wire.typ": swire, wire, zwire
#import "symbols/circulator.typ": circulator
#import "symbols/node.typ": node
#import "symbols/capacitor.typ": capacitor, pcapacitor
#import "symbols/diode.typ": ccdiode, diac, diode, led, photodiode, schottky, scr, triac, tunnel, tvs, varactor, zener
#import "symbols/switch.typ": switch
#import "symbols/fuse.typ": afuse, fuse
#import "symbols/supply.typ": earth, frame, ground, rground, vcc, vee
#import "symbols/inductor.typ": inductor
#import "symbols/lamp.typ": lamp
#import "symbols/piezo.typ": crystal, piezo
#import "symbols/logic.typ": land, lbuf, lnand, lnor, lnot, lor, lxnor, lxor
#import "symbols/resistor.typ": heater, ldr, potentiometer, resistor, rheostat, thermistor, varistor
#import "symbols/source.typ": acvsource, disource, dvsource, isource, vsource
#import "symbols/battery.typ": battery, cell, multicell, pvcell
#import "symbols/motor.typ": acmotor, dcmotor
#import "symbols/gyrator.typ": gyrator, igyrator
#import "symbols/transistors/bjt.typ": bjt, darlington, igbt, npn, phototransistor, pnp
#import "symbols/transistors/mosfet.typ": mosfet, nmos, nmosd, pmos, pmosd
#import "symbols/transistors/jfet.typ": jfet, njfet, pjfet
#import "symbols/integrated/opamp.typ": opamp
#import "symbols/integrated/mcu.typ": mcu
#import "symbols/integrated/converter.typ": adc, dac
#import "symbols/instruments/round-meter.typ": ammeter, ohmmeter, round-meter, voltmeter, wattmeter
#import "symbols/button.typ": button, ncbutton, ncibutton, nobutton, noibutton
#import "symbols/integrated/flipflop.typ": dflipflop, flipflop, jkflipflop, srlatch

#import "symbols/integrated/digital.typ": comparator, counter, dblock, decoder, demux, encoder, fadder, hadder, mux, shiftreg
#import "symbols/transistors/ujt.typ": ujt
#import "symbols/optocoupler.typ": optocoupler
#import "symbols/hall.typ": hall
#import "symbols/electromech.typ": buzzer, connector, dpdt, microphone, relay, speaker, spdt, testpoint
Loading
Loading