Create beautiful circuit diagram with Circuit_macro package

Steps to output SVG format diagrams

Circuit schematics embodies circuit designs that can be turned into PCBs or fed into SPICE simulators. There are plenty of EDA tools to capture schematics for these purposes.

For example, you can draw schematic in LTspice (free SPICE circuit simulator). That is certainly a big step forward, considering many SPICE simulators still relies on text-based netlist files.

Image for post
LTspice schematic for SPICE simulation

Sometimes you’d like the schematics to look nice. Just like the ones in electronics textbooks or magazines. Here is a powerful software package that can help. It’s called Circuit_macro, by Dwight Alpevich. (link)

It comes with ample documentation and lots of usage examples (example website). The software leverages M4 macro, PIC language and LaTeX capabilities to produce beautiful circuit diagrams that can be embedded into a LaTeX document, or simply as standalone PDF files.

Ironically, it’s a text-based tool, not mouse click-and-drag kind of drawing program. So expect to have a steep learning curve ahead.

Now once you’ve learned how to write M4 files to make nice looking circuit diagrams in PDFs, how do you turn them into SVG format to be put into HTML pages.

Image for post

Though Circuit_macro now supports “dpic” command that turns M4 directly into SVG (left above), the result still doesn’t look as beautiful as the PDF version (right above).

The solution is to produce PDF first, then use tools like pdf2svg (link) to convert to SVG afterwards. That way all the nice looking fonts from the PDFs are preserved. Such SVG can also go into free vector graphics software, such as InkScape for further editing.

In summary, here are the steps to follow:

  • Download the latest version of Circuit_macro
  • Install TexLive or TinyTeX
  • Download m4, dpic and pdf2svg
  • Test the setup with “quick.m4”
 m4 pgf.m4 quick.m4 | dpic -g > tmp.tex
  • Embed “tmp.tex” into the following LaTeX template file (template.tex)
  • pdflatex to produce PDF from template.tex
  • pdf2svg to convert PDF to SVG
  • done and enjoy!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store