M4 Circuit Macros - Getting Started

From Peter Jan Randewijk
Jump to: navigation, search

Contents

Getting Started

Let's say we want to create an (M4) Circuit_Macros "picture", called "my_m4cm_picture.m4"

Use your favourite editor to "draw" i.e. program you figure. On openSUSE I prefer to use Kate, Kile or KWrite. On Windows I use either Programmers Notepad or Notepad++.

For syntax highlighting on:

  • Kate, Kile or KWrite, copy m4cm.xml to (usually) /usr/share/kde4/apps/katepart/syntax
  • Programmers Notepad, copy m4cm.scheme to (usually) C:\Program Files (x86)\Programmer's Notepad\schemes
  • Notepad++, import m4cm_notepad++.xml from the menu under [Language]->[Define your language...]->[Import...]

STEP 1: "Drawing" (i.e. writing/programming) "my_m4cm_picture.m4"

.PS
# Include Required M4CM libraries #
include(pstricks.m4) # to translate pic code to pstricks code with the dpic -p option
include(libcct.m4)   # main M4 Circuit Macros library

scale=25.4 # scale now in [mm]

cct_init # initialise "libcct.m4" variables

dy=12 # y spacing variable
dx=10 # x spacing variable

toff = 0.05

# Custom M4 macros #
define(`termrad_',`sourcerad_/4')
define(`terminal',`circle rad termrad_')

# Circuit Diagram Origin #
O: (0,0)

# Begin "Drawing" #
T2: terminal with .c at O
T1: terminal with .c at O+(0,dy*2)
    line left dx/2 from T1.c chop termrad_ chop 0
Va: source(down_ dy*2,S);rlabel(_+,\mathbf{V}_a,_-)
    line right to T2.c chop 0 chop termrad_
Xs: inductor(right_ dx*2 chop termrad_ chop 0 from T1.c,W,,)
    rlabel(,jX_s,)
    llabel(-,\mathbf{V}_{{}_{X_s}},+)
Ia: reversed(`arrowline',right_ dx);llabel(,\mathbf{I}_a,)
Eaf: source(down_ dy*2,S);llabel(_+,\mathbf{E}_{af},_-)
    line left to (T1.x,Here.y) chop 0 chop termrad_

.PE

STEP 2: Running M4 on "my_m4cm_picture.m4"

> m4 my_m4cm_picture.m4 > my_m4cm_picture.pic

STEP 3: Running dpic on "my_m4cm_picture.m4"

dpic provides a number of different outputs:

> dpic -h
*** dpic version 2014.Jan.01
options:
    (none) output latex drawing commands
    -e pict2e output
    -f Postscript output, psfrag strings
    -g PGF-TikZ output
    -h write this message and quit
    -m mfpic output
    -p PSTricks output
    -r Postscript output
    -s MetaPost output
    -t eepicemu output
    -v SVG output
    -x xfig output
    -z safe mode (sh, copy, and print to file disabled)

e.g., to produce PSTricks LaTeX output code, run:

> dpic -p my_m4cm_picture.pic > my_m4cm_picture.tex

STEP 4: Using "my_m4cm_picture.m4" in LaTeX

The (M4) Circuit_Macros "picture", "my_m4cm_picture.m4" has now been converted to a PSTricks LaTeX "picture", "my_m4cm_picture.tex" and can now be included into you LaTeX document as follows:

\documentclass[a4paper,12pt]{article}
\usepackage{pstricks}
\usepackage[utf8]{inputenc}

...

\begin{document}

...

\begin{figure}
  \input{my_m4cm_picture}
\end{figure}

...

\end{document}

OUTPUT

Except for the font used, the output should be similar to the picture shown below:

My_m4cm_picture

Personal tools