Circuit macros intro

# Introduction

Here I will be covering the setup of circuit macros for mac but most steps should work on other platforms too. I will show how to create a circuit diagram using PSTricks and Tikz PGF.

# M4

First of all download M4 from Here or if that link is down check here for updates. Uncompress the file and store it where you would like. After that point the M4PATH variable to the location of the folder as seen below.

    export M4PATH=\$M4PATH:~/Desktop/Projects/CircuitMacros


# Dpic

Download DPIC from gitlab here and unzip the folder. On mac the installation is required to be local due to SIP (System Integrity Protection) so use the command below. Otherwise if not on mac (sudo) make install should work.

    sudo make PREFIX=local install


# Create a circuit

First create the m4 file explaining the circuit, if you would like a test file, create a file called quick.m4 with the contents:

    .PS # Pic input begins with .PS
cct_init # Read in macro definitions and set defaults
elen = 0.75 # Variables are allowed; default units are inches
Origin: Here # Position names are capitalized
source(up_ elen,V); llabel(,v_s,)
resistor(right_ elen,,E); rlabel(,R,)
dot
{ # Save the current position and direction
capacitor(down_ to (Here,Origin)) #(Here,Origin) = (Here.x,Origin.y)
rlabel(,,); llabel(,C,)
dot
} # Restore position and direction
line right_ elen*2/3
inductor(down_ Here.y-Origin.y); rlabel(,L,); b_current(i)
line to Origin
.PE


# Compile a file

Compile using the commands:

    m4 pstricks.m4 quick.m4 > quick.pic
dpic -p quick.pic > quick.tex


# Insert into LaTeX

To insert the .tex file into an actual document you will require the basic LaTex info and the pstricks package.
    \documentclass[11pt]{article}
\usepackage{pstricks}
\begin{document}
\begin{figure}[hbt]
\centering
\input quick
\caption{Customized caption for the figure.}
\label{Symbolic_label}
\end{figure}
\end{document}


and compile using XeLaTeX.

# Compile a file

Compile using the commands:

    m4 pgf.m4 quick.m4 > quick.pic
dpic -g quick.pic > quick.tex


# Insert into LaTeX

To insert the .tex file into an actual document you will require the basic LaTex info and the tikz package.
    \documentclass[11pt]{article}
\usepackage{tikz}
\begin{document}
\begin{figure}[hbt]
\centering
\input quick
\caption{Customized caption for the figure.}
\label{Symbolic_label}
\end{figure}
\end{document}


and compiling using LaTeX.

# Result

Figure 1: Resulting schematic, identical in both methods.

If you would instead like an SVG image you can re-render using the SVG.m4 package and dpic -v but I would personally use the pdf2svg package here and is as simple as:

    pdf2svg input.pdf output.svg


resulting in a shape for shape identical svgremake of the PDF. and gives the following result:

Figure 2: Resulting SVG schematic.

I did change the color to white to be visable on the website but it would naturally be black.