circuit directive#
The circuit directive generates electric circuit diagrams as inline SVG from a simple topology description. You describe the circuit as nested series(...) / parallel(...) expressions, and the directive renders it using LaTeX circuitikz.
Basic usage#
A simple series circuit with a battery and two resistors:
:::{circuit}
width: 40%
circuit: series(U, R1, R2)
:::
Syntax overview#
:::{circuit}
component: V1, battery, 12 V
component: R1, resistor, 1 kΩ
component: L1, lamp
circuit: series(V1, R1, parallel(L1, R2))
width: 80%
layout: loop
:::
Component declaration#
Components are declared with repeated component: (or comp:) lines:
component: ID, type, value, label
ID — a unique identifier (e.g.
R1,V1,L1)type — component type (see table below)
value — optional display value (e.g.
1 kΩ,12 V)label — optional custom label (defaults to TeX-ified ID, e.g.
R1→ \(R_1\))
If a component is referenced in circuit: but not explicitly declared, its type is inferred from the ID prefix.
Component types#
Type keyword |
Rendered as |
|---|---|
|
Resistor |
|
Variable resistor |
|
Battery / voltage source |
|
Lamp |
|
LED |
|
Diode |
|
Plain wire (default) |
ID prefix auto-detection#
Prefix |
Inferred type |
|---|---|
|
resistor |
|
var_resistor |
|
battery |
|
lamp |
|
led |
Topology expression#
The circuit: line uses nested function calls:
series(A, B, C)— components in seriesparallel(A, B, C)— components in parallelArguments can be component IDs or nested
series(...)/parallel(...)groups
Options#
Option |
Meaning |
Default |
|---|---|---|
|
CSS width |
— |
|
|
|
|
|
|
|
Direction of current flow: |
|
|
Scale factor (float) |
|
|
|
|
|
|
|
|
|
|
|
Parallel branch placement: |
|
|
Show junction dots: |
|
|
Font size for labels |
— |
|
Extra CSS classes |
— |
|
Stable anchor / reference name |
— |
|
Alt text for accessibility |
— |
|
Force regeneration |
— |
|
Keep debug output |
— |
Examples#
Series with parallel branch#
:::{circuit}
width: 40%
fontsize: 18
flow: right
layout: loop
unit: 0.5
circuit: series(U, R1, parallel(R2, R3))
:::
Parallel first, then series#
:::{circuit}
width: 40%
fontsize: 18
flow: right
layout: loop
unit: 0.5
circuit: series(U, parallel(R1, R2), R3)
:::
Deeply nested parallel-series#
:::{circuit}
width: 40%
fontsize: 18
flow: right
layout: loop
unit: 0.5
circuit: series(U, parallel(R1, R2, series(R3, R4)))
nocache:
:::
Tips#
Components not declared with
component:but referenced incircuit:are auto-detected from their ID prefix.Labels default to TeX formatting:
R1→ \(R_1\),RV12→ \(RV_{12}\).The
circuitikzbackend requires a working LaTeX installation with thecircuitikzpackage.Use
layout: loopfor perimeter-style layouts (current flows around a loop) andlayout: ladderfor ladder-style layouts.