In Part I, I discussed all of the programs (or stuff) that needs to be downloaded to get started. In Part II, I discussed how to install (the bare minimum) to get started. In this part, I will discuss how to “draw” (i.e. program) our first M4 Circuit Macro picture and to basically test if is successfully working together.
Copy and paste the following into your favorite editor and save as (say) ex0.m4cm. I usually save all my M4 Circuit Macro “pictures” with a *.m4cm extension, using *.m4 only for my M4 Circuit Macro include or “library” files.
.PS include(pstricks.m4) scale=25.4 cct_init dx = 12.5 dy = 12.5 O: (0,0) Vs: source(up_ dy from O,S); llabel(,\mathbf{V}_s,) L: inductor(right_ 2*dx,,3,,dimen_/5); llabel(,jX_s,) Zl: ebox(down_ to (Here.x,O.y)); llabel(,\mathbf{Z}_l,) line to O dot ground .PE
On Windows I prefer to use Notepad++ as it allows for easy implementation of customised syntax-highlighting, as well as the NppExec plugin to allow external scripts to be run from within Notepad++.
The next step is to run m4 on the ex0.m4cm file to generate pic output code at the command prompt,
$ m4 ex0.m4cm > ex0.pic
If m4 is able to find the pstricks.m4 file, it implies that the M4PATH was set up correctly. If not, the following error message will be displayed.
m4:ex0.m4cm:3: cannot open `pstricks.m4': No such file or directory
If m4 were enabled to find pstricks.m4, no message will be display and an ex0.pic file will be created, with all the m4 circuit-macros, e.g.
- source
- inductor
- ebox
- ground
expanded into pic code. The m4 macro processor only expands all the m4 macros that was defined, either in the file itself, or in the included *.m4 files, but does not check for any syntax errors in the code.
The next step is to run the dpic compiler on the pic code, to produce LaTeX output code. To generate LaTeX PSTricks output from the ex0.pic file, issue the following command at the command prompt,
$ dpic -p ex0.pic > ex0.tex
If the file was successfully compiled, no output message will be displayed and a ex0.tex file will be created. If there however was some problem with the syntax, an error message will be displayed, e.g.
*** dpic: line 138 ERROR: ; or end of line found. The following were expected: .x .y * /
if (say) the “to” in “line to O” in the ex0.m4cm code above, was omitted.
The next step is to include our newly created M4 Circuit Macro picture, i.e. ex0.tex into our main LaTeX document. For this example, copy and paste the following code into your favorite LaTeX editor, ands save as (say) Example_0.tex.
\documentclass[dvips]{article} \usepackage{pstricks} \usepackage{times} \pagestyle{empty} \begin{document} \begin{figure}[hbt] \begin{center} \include{ex0} \caption{Our first M4 Circuit Macro picture.} \end{center} \end{figure} \end{document}
We can now use LaTeX to compile the above document to a DVI output,
$ latex -quiet Example_0.tex
The Yap viewer that comes with MikTeX can be used to view the Example_0.tex output file.

We can see that the text labels for the source, inductor and load impedance is not correctly displayed in Yap. But don’t fear, this is just an “optical illusion”. After converting the output to Postscript, the labels will be displayed correctly. This is done by issuing the following command at the command prompt,
$ dvips -q Example_0.dvi
This will generate an Example_0.ps file that can be viewed using the legacy GSView,

or we can covert it to PDF, by issuing
$ ps2pdf Example_0.ps
at the command line to create an Example_0.pdf file which can viewed in any PDF viewer, e.g. SumatraPDF.

Alternatively, we can also generate PGF/TikZ code from dpic, and use PdfLaTeX to create a PDF file directly from our LaTeX document. This will be shown on the next page.




