Syntax & Component Reference

Reference specification for CircuitMarkdown DSL grammar, component formats, wire routing, and directives.

1. Grid & Coordinates

CircuitMarkdown uses an integer coordinate grid.

  • Grid Scale: 1 grid unit equals 40 pixels.
  • Coordinates: Specify integer values in parentheses, such as (2,3) or (-1,4).
  • Validation: Decimal numbers cause a syntax error.

2. Comments

Comments start and end with double percent signs (%%). The parser ignores all comment text.

  • Single-line: %% This is a single-line comment %%
  • Inline: R R1 "R1" "10k" (2,3) %% Trailing comment %%
  • Multi-line block:
    mdx
    %%
    Comment line 1
    Comment line 2
    %%

3. Component Declaration Syntax

Every component definition uses this format:

mdx
TYPE id "designator" "value" (X,Y) [options]

Required Fields

  1. TYPE: Component mnemonic code (such as R, C, VCC, BAT_MULTI). Refer to the Component Reference for the full 50-symbol list.
  2. id: Unique identifier matching ^[A-Za-z_][A-Za-z0-9_]*$.
  3. "designator": Label string in double quotes (such as "R1").
  4. "value": Value string in double quotes (such as "10k", "5V").
  5. (X,Y): Integer grid coordinates in parentheses.

Optional Parameters

Parameter Type / Values Default Description
orient 0, 90, 180, 270 0 Clockwise rotation angle in degrees.
size Positive number 1 Scale multiplier for component symbol geometry.
refpos (X,Y) Auto Pixel offset for designator label position.
valpos (X,Y) Auto Pixel offset for value label position.
refsize Positive number 16 Font size in pixels for designator label.
valsize Positive number 12 Font size in pixels for value label.
refalign left, center, right Auto Text alignment anchor for designator label.
valalign left, center, right Auto Text alignment anchor for value label.
showref true, false true Visibility switch for designator label.
showval true, false true Visibility switch for value label.

4. Wire Connections

Wires connect component pins, grid coordinates, and intermediate routing waypoints. Declare wires with the W keyword:

mdx
W endpoint1 [waypoint...] endpoint2

Endpoint Formats

  • Pin Identifier: Use ComponentID.PinName (such as BAT_MULTI1.+, R1.1, or Q1.B).
  • Grid Coordinate: Use (X,Y) (such as (1,3)).

Intermediate Waypoints

Insert one or more grid coordinates between endpoints to guide a wire path:

R1 1k D1 red
R1 1k D1 red

Routing Behaviors

  1. Manhattan Routing: Wires route only along horizontal and vertical orthogonal segments.
  2. Junction Dots: When three or more wire paths meet at a coordinate, the renderer draws a filled junction circle.
  3. Hop Arcs: When two unconnected wires cross perpendicularly, the renderer draws a semicircular bridge over the intersection.
  4. Detour Routing: The auto-router guides wire paths around component bodies.

5. Directives & Annotations

CircuitMarkdown includes directives for standalone text annotations and drawing sheets.

TEXT Directive (Annotations)

Place standalone text labels anywhere on the schematic grid:

mdx
TEXT id "Content" (X,Y) [size=<px>] [align=left|center|right] [rot=<degrees>]
Parameter Type / Values Default Description
size Positive number 12 Font size in pixels.
align left, center, right center Horizontal text alignment.
rot Number (0 to 360) 0 Rotation angle in degrees.

SHEET Directive (Drawing Border & Title Block)

Enclose the schematic inside a standard engineering drawing border with coordinate grid markers:

mdx
SHEET <size> [portrait|landscape]
  • Supported Sizes: A4, A3, A2, A1, A0, LETTER, LEGAL, TABLOID.
  • Default Orientation: landscape.

6. Circuit Examples

The examples below demonstrate valid syntax, directives, and routed circuits.

LED Circuit with Annotations

V1 5V R1 500 D1 red Current limit: 10mA
V1 5V R1 500 D1 red Current limit: 10mA

Logic Gate & Switch Circuit

VCC1 U1A 74HC04 S1 Switch GND1
VCC1 U1A 74HC04 S1 Switch GND1