[vox-tech] circuits with latex

Mark K. Kim vox-tech@lists.lugod.org
Sun, 8 Feb 2004 09:25:45 -0800 (PST)


Hmm... it's been a LOOOOOOOONG time since I've used circuit macros... ^_^;

The way I used circuit macros, I first create something called "nodes" --
coordinates on the figure.  You can specify what each node should look
like, to make it invisible or put dots over 'em or whatever.  Then I draw
lines or circuit elements (like resistors) across each node.  It gives
much more flexibility, I think.  You can draw arrowed lines and stuff,
too.  I don't think you can control spacing exactly, but you can always
put more nodes and control the spacing if you really need it.

I'm including an example figure from my Physics 9C lab report.  I can send
you the whole report with four figures (but all of 'em very much look
alike), if you wanna see how it fits in a TeX file:

  .PS
  cct_init


  ########################################################################
  # All the nodes

  NodeA: dot(at (0, 0))
  NodeB: (-1, 0)
  NodeC: (-1, 1)
  NodeD: dot(at (0, 1))
  NodeE: (1, 1)
  NodeF: (1, 0)


  ########################################################################
  # Elements

  line from NodeA to NodeB
  battery(up_ from NodeB to NodeC, 2);    llabel(-, \varepsilon_1, +)
  resistor(right_ from NodeC to NodeD);   llabel(,R_1,); b_current(I_1)
  resistor(down_ from NodeD to NodeA);    rlabel(,R_3,); b_current(I_3)
  battery(right_ from NodeE to NodeD, 2); llabel(+, \varepsilon_2, -)
  resistor(down_ from NodeE to NodeF);    rlabel(,R_2,); b_current(I_2)
  line from NodeF to NodeA


  ########################################################################
  # Labels

  #"\sl a" at NodeA below
  #"\sl b" at NodeB below
  #"\sl c" at NodeC above
  #"\sl d" at NodeD above
  #"\sl e" at NodeE above
  #"\sl f" at NodeF below


  .PE

Yeah, circuit_macros *is* awesome =)

-Mark


On Sun, 8 Feb 2004, Peter Jay Salzman wrote:

> mark,
>
> thanks for turning me on to this.  it was a chore to install, and at
> first looked too complicated to learn quickly, but i found that i only
> really needed to read about 2 or 3 pages of the manual, and the included
> examples carried me the rest of the way.
>
> i created my first circuit, and it looks really good!
>
>
> .PS
>
> cct_init
>
> elen = 0.75
>
> Origin: Here
>    line up_ elen
>
>    dot; llabel(,$a$,)
>
>    resistor(right_ elen); llabel(,4\Omega,)
>
>    dot; clabel(,,$b$)
>
>    gpar_(
>    resistor(right_ elen);
>       rlabel(,\scriptstyle 2\Omega,);
>       b_current(\scriptstyle I_2,,Out,End),
>    resistor(right_ elen);
>       llabel(,\scriptstyle 8\Omega,);
>       b_current(\scriptstyle I_3,,Out,End),
>    elen)
>
>    dot; clabel($c$,,)
>
>    line right_ elen/5
>    line down_ elen
>    dot; llabel(,$d$,)
>    ground
>    line left_ elen/2
>
>    battery(left_ elen); llabel(,10v,)
>    line to Origin
>    b_current(\scriptstyle I_1)
>
> .PE
>
>
>
> i do have one question.  in the upper parallel resistor structure (the
> gpar macro), all my attempts to insert a little space between the
> resistor element and the current label (b_current) have failed.  if i
> insert a line between them, like:
>
>    line right_ elen/5
>
> the circuit becomes a rhomboid(!?!?!) and the current labels become
> interestingly placed.  theh circuit doesn't screw up if i place
>
>    line right_ elen
>
> between them, but of course, that make the circuit needless long.
>
> i can live with the resistors butted up against the current arrows, but
> if possible, i'd like to open up a little space between them.
>
> any ideas?
>
> thanks!
> pete
>
> ps- circuit_macros is awesome!
>
>
>
>
> On Sat 07 Feb 04,  9:37 PM, Mark K. Kim said:
> > Oh, one more thing: Last time I used circuit_macros, you had to edit all
> > the *.m4 files it comes with by hand.  Most of the *.m4 files it comes
> > with has reference to its installation path, but it's all hard-coded and
> > needs to be modified to reflect the correct installation path on your
> > system.  A little whacky but I guess there's no equivalent to $0 or
> > argv[0] in m4.  =(
> >
> > BTW, m4 is nice to learn (even a little.)  It'll help you not only use
> > circuit_macros better, but it's also used by autoconf/automake so you'll
> > be able to write your own subroutines and codes in autoconf/automake as
> > well.
> >
> > -Mark
> >
> >
> > On Sat, 7 Feb 2004, Mark K. Kim wrote:
> >
> > > Well, m4 is a macro processor, like the C preprocessor.  It doesn't do
> > > anything but translate a sequence of strings to another set of strings.
> > > Any text it hasn't been instructed to process goes straight through m4,
> > > without any translation.
> > >
> > > So to use circuit_macros, you need to pass 2 files to m4:
> > >
> > >    1. The file you want to process.
> > >    2. A file containing instructions on which strings to process,
> > >       and how.
> > >
> > > #1 is the file you create.  #2 is libcct.m4 file that comes with
> > > circuit_macros.  So you end up with:
> > >
> > >    $ m4 /path/to/libcct.m4 circuit.m4 > circuit.pic
> > >    $ gpic -t circuit.pic > circuit.tex
> > >
> > > BUT, I highly recommend you use dpic instead of gpic.  The output looks so
> > > much nicer (at least it was last time I checked).  You can get dpic from:
> > >
> > >    http://www.ece.uwaterloo.ca/~aplevich/dpic/
> > >
> > > dpic also requires an additional file, pstricks.m4 (comes with
> > > circuit_macros), so you end up with:
> > >
> > >    $ m4 /path/to/pstricks.m4 /path/to/libcct.m4 circuit.m4 > circuit.pic
> > >    $ gpic -t circuit.pic > circuit.tex
> > >
> > > It's a little complicated to remember (and cumbersome to write out each
> > > time) so you probably want to wrap everything in a script.
> > >
> > > -Mark
> > >
> > >
> > > On Sat, 7 Feb 2004, Peter Jay Salzman wrote:
> > >
> > > > HA!!!!!
> > > >
> > > > i wish i could.  i don't even get that far!  here's my m4 file:
> > > >
> > > >    p@satan$ cat circuit.m4
> > > >    .PS
> > > >    cct_init
> > > >    gridsize = 0.1
> > > >    .PE
> > > >    \usebox{\graph}
> > > >
> > > >
> > > >    p@satan$ m4 circuit.m4  > circuit.pic
> > > >    p@satan$ gpic -t circuit.pic > circuit.tex
> > > >    gpic:circuit.pic:3: syntax error before newline
> > > >    gpic:circuit.pic:3: giving up on this picture
> > > >
> > > > it's giving up on cct_init.  what my belief in what should happen is
> > > > this:
> > > >
> > > > 1. m4 creates a .pic file.
> > > > 2. gpic takes a .pic file and creates a .tex file.
> > > > 3. i \input the .tex file at the appropriate location.
> > > >
> > > > am i completely off base here?
> > > >
> > > > thanks!
> > > > pete
> > > >
> > > >
> > > > On Sat 07 Feb 04,  8:56 PM, Mark K. Kim <markslist@cbreak.org> said:
> > > > > Can you post a sample latex file and the error messages from running
> > > > > latex on it?
> > > > >
> > > > > -Mark
> > > > >
> > > > >
> > > > > On Sat, 7 Feb 2004, Peter Jay Salzman wrote:
> > > > >
> > > > > > has anyone successfully used the circuit_macros package for latex?
> > > > > >
> > > > > > i keep getting gpic errors, no matter how simple my circuit is (even the
> > > > > > null circuit generates errors.
> > > > > >
> > > > > > pete
> > > > >
> > > > > --
> > > > > Mark K. Kim
> > > > > AIM: markus kimius
> > > > > Homepage: http://www.cbreak.org/
> > > > > Xanga: http://www.xanga.com/vindaci
> > > > > Friendster: http://www.friendster.com/user.jsp?id=13046
> > > > > PGP key fingerprint: 7324 BACA 53AD E504 A76E  5167 6822 94F0 F298 5DCE
> > > > > PGP key available on the homepage
> > > > > _______________________________________________
> > > > > vox-tech mailing list
> > > > > vox-tech@lists.lugod.org
> > > > > http://lists.lugod.org/mailman/listinfo/vox-tech
> > > >
> > > > --
> > > > Make everything as simple as possible, but no simpler.  -- Albert Einstein
> > > > GPG Instructions: http://www.dirac.org/linux/gpg
> > > > GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
> > > > _______________________________________________
> > > > vox-tech mailing list
> > > > vox-tech@lists.lugod.org
> > > > http://lists.lugod.org/mailman/listinfo/vox-tech
> > > >
> > >
> > > --
> > > Mark K. Kim
> > > AIM: markus kimius
> > > Homepage: http://www.cbreak.org/
> > > Xanga: http://www.xanga.com/vindaci
> > > Friendster: http://www.friendster.com/user.jsp?id=13046
> > > PGP key fingerprint: 7324 BACA 53AD E504 A76E  5167 6822 94F0 F298 5DCE
> > > PGP key available on the homepage
> > > _______________________________________________
> > > vox-tech mailing list
> > > vox-tech@lists.lugod.org
> > > http://lists.lugod.org/mailman/listinfo/vox-tech
> > >
> >
> > --
> > Mark K. Kim
> > AIM: markus kimius
> > Homepage: http://www.cbreak.org/
> > Xanga: http://www.xanga.com/vindaci
> > Friendster: http://www.friendster.com/user.jsp?id=13046
> > PGP key fingerprint: 7324 BACA 53AD E504 A76E  5167 6822 94F0 F298 5DCE
> > PGP key available on the homepage
> > _______________________________________________
> > vox-tech mailing list
> > vox-tech@lists.lugod.org
> > http://lists.lugod.org/mailman/listinfo/vox-tech
>
> --
> Make everything as simple as possible, but no simpler.  -- Albert Einstein
> GPG Instructions: http://www.dirac.org/linux/gpg
> GPG Fingerprint: B9F1 6CF3 47C4 7CD8 D33E 70A9 A3B9 1945 67EA 951D
> _______________________________________________
> vox-tech mailing list
> vox-tech@lists.lugod.org
> http://lists.lugod.org/mailman/listinfo/vox-tech
>

-- 
Mark K. Kim
AIM: markus kimius
Homepage: http://www.cbreak.org/
Xanga: http://www.xanga.com/vindaci
Friendster: http://www.friendster.com/user.jsp?id=13046
PGP key fingerprint: 7324 BACA 53AD E504 A76E  5167 6822 94F0 F298 5DCE
PGP key available on the homepage