Download CMman. - Electrical and Computer Engineering

Transcript
2
Using the macros
This section describes the basic process of adding circuit diagrams to LATEX documents to produce
postscript or pdf files. On some operating systems, project management software with graphical
interfaces can be used to automate the process but the steps can be performed by a script, makefile,
or by hand for simple documents as described in Section 2.1.
The diagram source file is preprocessed as illustrated in Figure 1. The predefined macros,
followed by the diagram source, are read by m4. The result is passed through a pic interpreter to
produce .tex output that can be inserted into a .tex document using the \input command.
.tex
files
.m4
macros
.m4
diagram
m4
LATEX
or
PDFlatex
pic
interpreter
.dvi
or
.pdf
Figure 1: Inclusion of figures and macros in the LATEX document.
The interpreter output contains PSTricks [16] commands, Tikz PGF [15] commands, basic LATEX
graphics, tpic specials, or other formats, depending on the chosen options, These variations are
described in Section 14.
There are two principal choices of pic interpreter. One is dpic, described later in this document.
A partial alternative is GNU gpic -t (sometimes simply named pic) [11] together with a printer driver
that understands tpic specials, typically dvips [13]. The dpic processor extends the pic language in
small but important ways; consequently, some of the macros and examples in this distribution work
fully only with dpic. Pic processors contain basic macro facilities, so some of the concepts applied
here do not require m4.
2.1
Quick start
The contents of file quick.m4 and resulting diagram are shown in Figure 2 to illustrate the language,
to show several ways for placing circuit elements, and to provide sufficient information for producing
basic labeled circuits.
.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); llabel(-,v_s,+)
resistor(right_ elen); rlabel(,R,)
dot
{
# Save the current position and direction
capacitor(down_ to (Here,Origin))
#(Here,Origin) = (Here.x,Origin.y)
rlabel(+,v,-); llabel(,C,)
dot
}
# Restore position and direction
R
+
line right_ elen*2/3
+
vs
v
inductor(down_ Here.y-Origin.y); rlabel(,L,); b_current(i)
−
line to Origin
−
.PE
# Pic input ends
i
C
L
Figure 2: The file quick.m4 and resulting diagram. There are several ways of drawing the same picture;
for example, nodes (such as Origin) can be defined and circuit branches drawn between them; or
absolute coordinates can be used (e.g., source(up_ from (0,0) to (0,0.75)) ). Element sizes
and styles can be varied as described in later sections.
2