Friday, March 13, 2015

Drawing Circuit diagrams in LaTeX

Those of you who are familiar with my interests would know that I am both an electronics hobbyist and a huge fan of LaTeX. Therefore I am thrilled with my recent discovery of the ability to draw publication quality circuit diagrams in LaTeX, using the circuitikz package. Take a look at the sample below:


The LaTeX code used to generate this diagram can be found at circuit-ups on GitHub. A simple example of constructing a circuit diagram is
  \begin{figure}
      \begin{circuitikz}

          \draw (0,0)
          to[V,v=$U_q$] (0,2) % The voltage source
          to[short] (2,2)
          to[R=$R_1$] (2,0) % The resistor
          to[short] (0,0);

      \end{circuitikz}

      \caption{My first circuit.}

  \end{figure}
and it creates the following circuit diagram:

Image Source: tutorial

All that is required are the circuitikz and siunitx packages which can be easily downloaded using tlmgr (the Tex-Live manager). On Ubuntu this can be done by running:
    tlmgr install circuitikz
    tlmgr install siunitx

I learned about using circuitikz from the following this tutorial which also contains a link to the circuitikz manual which came in handy.

All of the components in the circuit diagram on top are provided by the circuitikz package with the exception of the 7805 IC which I created by using primitive pgf directives I learned from this second tutorial. This was surprisingly easier than it sounds. And the output is very elegant.

(Note: The LaTeX commands generate pdf which I converted to a png using imagemagick before inserting it in to this blog)

No comments:

Post a Comment