Debian Codegraph @

README

raw
1
2 * Circuit_macros Version 10.1.4, copyright (c) 2023 J. D. Aplevich under *
3 * the LaTeX Project Public Licence in file Licence.txt. The files of *
4 * this distribution may be redistributed or modified provided that this *
5 * copyright notice is included and provided that modifications are clearly *
6 * marked to distinguish them from this distribution. There is no warranty *
7 * whatsoever for these files. *
8
9 This is a set of macros for drawing high-quality line diagrams to
10 include in LaTeX, web, or similar documents, with support for svg
11 (including Inkscape) and other formats. Fundamental electric circuit
12 elements and basic logic gates based on IEEE and European standards are
13 included with several tools and examples of other types of diagrams.
14 Elements can be scaled or drawn in any orientation and are easy
15 to modify. The advantages and disadvantages of such a system in its
16 basic form are similar to those of TeX itself, which is macro-based
17 and non-WYSIWYG. Graphical interfaces are available for specific
18 operating systems.
19
20 The macros are to be processed by an m4 macro processor, and evaluate to
21 drawing commands in the pic "little language," which is easy to read and
22 learn. The diagram is then automatically translated into TiKZ, PSTricks,
23 or other formats for processing by LaTeX or other applications. Pic
24 is well suited to line drawings requiring parametric or conditional
25 components, fine adjustment, geometric calculations, repetition, or
26 recursion. Arbitrary text for formatting by LaTeX can be included.
27 Free interpreters for m4 and pic are readily available.
28
29 Sources are available as a git repository at
30 https://gitlab.com/aplevich/Circuit_macros
31
32 REQUIRED SOFTWARE:
33 Preferred setup:
34 m4, dpic, LaTeX or PDFLaTeX, TikZ-PGF
35 or
36 GNU m4, dpic, LaTeX, PSTricks, dvips
37
38 The GNU m4 macro processor is assumed, and a small number of macros
39 require GNU m4 features. Other versions of m4 will work with most macros.
40
41 The dpic interpreter can translate pic input into several forms,
42 typically a .tex file for processing by latex with pgf/Tikz or PSTicks.
43
44 Alternative:
45 m4, GNU pic (gpic), TeX or LaTeX, and a driver recognizing tpic specials
46 (eg dvips)
47
48 The GNU pic interpreter with option -t produces tpic special commands.
49
50 Also possible for some diagrams:
51 m4 and dpic with output in the following formats:
52 LaTeX graphics or LaTeX eepic (for simple diagrams), mfpic, xfig,
53 MetaPost, svg, pdf, or Postscript.
54
55 USAGE
56 First-time users should read the Quick Start section of Circuit_macros.pdf.
57
58 The following describes the most common basic usage to produce tikz
59 or pstricks graphics for LaTeX; see below for integration with other
60 tools and production of other formats. You probably should try out
61 the basic usage before integrating the macros with sophisticated
62 system-dependent tools. When developing your own diagrams, refer to the
63 macro descriptions in the List of Macros section of Circuit_macros.pdf.
64
65 Suppose that a source file, cct.m4 say, has been created and the top
66 two lines are
67 .PS
68 cct_init
69 ...
70
71 The file is processed by feeding a configuration file followed by the
72 diagram source to m4, and routing the output to dpic. If you have set
73 the M4PATH environment variable as described in the INSTAllATION
74 instructions, the command for Tikz processing is
75
76 m4 pgf.m4 cct.m4 | dpic -g > cct.tex
77
78 NOTE: The order in which the files are given to m4 is important.
79 A configuration file (pgf.m4 in this example) must ALWAYS appear first.
80
81 If you have not set the M4PATH environmental variable then the command is
82
83 m4 -I <path> pgf.m4 cct.m4 | dpic -g > cct.tex
84
85 where <path> is the absolute path to the directory containing the library
86 macros.
87
88 If the first line of cct.m4 is
89 include(pgf.m4)
90 and M4PATH is defined, then this command can be simplified to
91
92 m4 cct.m4 | dpic -g > cct.tex
93
94 In each case, the resulting file cct.tex is normally inserted into
95 a document to be processed by LaTeX. The -g option of dpic produces
96 Tikz-pgf graphics commands in cct.tex so the LaTeX document must have
97 \usepackage{tikz} in the preamble.
98
99 To produce postscript output, the LaTeX preamble must contain
100 \usepackage{pstricks}, pstricks.m4 is read instead of pgf.m4, and the dpic
101 option is -p, so the command is
102
103 m4 pstricks.m4 cct.m4 | dpic -p > cct.tex or m4 cct.m4 | dpic -p > cct.tex
104
105 Read Section 2 of the manual to see how to process the diagram source
106 from within the main .tex source file.
107
108 To use the GNU gpic processor (called pic on some systems) instead of dpic,
109 the command is
110
111 m4 gpic.m4 cct.m4 | gpic -t > cct.tex
112
113 The basic commands given above suffice for documents of moderate
114 size and complexity; otherwise, a "make" facility or equivalent should
115 be used or, for modest documents, diagram processing can be controlled
116 from within the tex document source as described in the manual. For
117 near-immediate viewing of the basic process, three windows can be kept
118 open: one in which to edit the source, one to process the source and
119 produce postscript or pdf, and a viewer such as GSview 5.0, which updates
120 when clicked.
121
122 INSTALLATION AND TESTING: See the INSTALL file.
123
124 SOURCES AND MANUALS:
125 View or print Circuit_macros.pdf in the doc directory.
126
127 M4 is widely available on Unix systems. PC source and executables are
128 also available: http://gnuwin32.sourceforge.net/packages/m4.htm
129 A large set of Unix-like Windows tools, including m4, is available via
130 http://www.cygwin.com/
131 DJGPP versions are available as m4-NNb.zip (where NN is the current
132 release number) on web archives and at
133 http://www.delorie.com/djgpp/dl/ofc/dlfiles.cgi/current/v2gnu/
134
135 There are several sources of hints on m4 usage; some places to look are
136 http://gnuwin32.sourceforge.net/packages/m4.htm (m4 for Windows)
137 http://www.gnu.org/software/m4/manual/ (GNU m4 manual)
138 https://mbreen.com/m4.html (m4 by example)
139 The m4 (computer language) article in Wikipedia gives a concise overview.
140 An academic discussion of the language can be found in
141 http://www.cs.stir.ac.uk/~kjt/research/pdf/expl-m4.pdf.
142 The GNU Autoconf manual contains a chapter on M4 programming:
143 http://www.gnu.org/software/autoconf/manual/index.html
144 (Do not read this manual first). Autoconf uses quote characters [ and ]
145 instead of the default ` and ' which work well with the pic language.
146
147 DPIC:
148 Several Linux distributions will install dpic by command but the version
149 may not be the latest. A git repository containing complete source is at
150 https://gitlab.com/aplevich/dpic
151 and source plus a Windows executable can be obtaied from
152 http://ece.uwaterloo.ca/~aplevich/dpic/
153 The best advice is to obtain the newest version.
154
155 The dpic distribution includes dpic-doc.pdf, a manual containing a summary
156 of the pic language and a detailed description of features unique to dpic.
157
158 GPIC:
159 Gpic is part of the GNU groff distribution, for which the source
160 and documentation is available from http://ftp.gnu.org/gnu/groff/
161 but there are mirror sites as well. A more extensive manual is found
162 in the documentation that comes with GNU pic, which is typically
163 installed as gpic. A pdf copy is included with the dpic distribution.
164 The original AT&T pic manual can be found at
165 http://doc.cat-v.org/unix/v10/10thEdMan/pic.pdf
166
167 SVG output, Inkscape:
168 Dpic -v produces svg output. If the result is to be directly inserted
169 into html, then as for Postscript output, the diagram source file has
170 to be adapted to remove any LaTeX formatting. The configuration file
171 svg.m4 contains macros that can assist. At the expense of an extra
172 postprocessing step, sophisticated text formatting and font selection
173 can be retained by first producing pdf output and then converting to
174 svg using, say, dvisvgm (https://www.ctan.org/pkg/dvisvgm) or pdf2svg
175 (https://github.com/dawbarton/pdf2svg).
176
177 SVG is the native file format for the Inkscape graphics editor.
178 Therefore, elements defined by these macros can be output by dpic -v in
179 svg format for later manipulation by Inkscape. A very basic palette of
180 circuit elements for Inkscape is found in examples/paletteSVG.m4.
181 In the examples subdirectory, type "make paletteSVG.svg", read the resulting
182 file into Inkscape, and then ungroup the elements as desired. You would
183 probably wish to add to or customize these elements for extensive use.
184
185 EXAMPLES
186 A set of examples is included in this distribution, showing electric
187 circuits, block diagrams, flow charts, signal-flow graphs, basic
188 use of colour and fill, and other applications. Some of the examples
189 test the boundaries of the domain of application of dpic with m4
190 macros. Read the manual Circuit_macros.pdf and view examples.pdf
191 in the examples directory or make and view the html file in the
192 examples/svg directory. For the curious, there are additional source
193 files in the examples directory that are not shown in examples.pdf.
194 Try http://ece.uwaterloo.ca/~aplevich/Circuit_macros/
195 for the possibly unstable development version of these macros.
196
197 The examples directory Makefile automates the generation of .ps, .eps,
198 .png, and .pdf files for individual diagrams. Subdirectories of the
199 examples directory are for testing metafont, metapost, pgf, psfrag,
200 and xfig examples.
201
202 WORKFLOW:
203 Installation and usage of the macros have evolved somewhat since the
204 beginning, so archived instructions on the net may be slightly more
205 complicated than currently necessary.
206
207 I use a very simple workflow most of the time: three open windows;
208 one to edit the diagram source, one to run LaTeX and produce pdf or
209 postscript, and a document viewer window. The lines
210 :set mps+=`:'
211 :set mps+=<:>
212 were added to my default .vimrc file to highlight matched pairs of
213 brackets, braces, parentheses, and, expecially for m4 programming,
214 single quotes.
215
216 INTEGRATION WITH OTHER TOOLS:
217 To automate document production, I simply added commands to
218 the appropriate Makefiles. However, others have developed tools
219 that simplify workflow for their circumstances. The following are
220 representative but keep in mind that systems and installations evolve
221 over time:
222
223 A Python-based GUI called PyCirkuit is
224 at https://pypi.org/project/pycirkuit/ and
225 https://github.com/orestesmas/pycirkuit. For an
226 introduction, look at the FOSDEM video by Orestes Mas:
227 https://archive.fosdem.org/2020/schedule/event/pycirkuit/
228
229 A python build-automation tool, m4cm, by Peter Jan Randewijk is at
230 https://m4cmpy.wordpress.com/ and very clear instructions about getting
231 started with Circuit_macros are at
232 https://m4cmpy.wordpress.com/2020/02/23/getting-started-with-m4-circuit-macros/
233
234 Fabrice Salvaire has a blog and a useful bash script at
235 https://www.fabrice-salvaire.fr/en/blog/electronic-circuit-diagrams/
236
237 A set of examples and hints intended for his colleagues has been
238 produced by Alan Robert Clark at http://ytdp.ee.wits.ac.za/cct.html
239
240 A video "Drawing Circuit Diagrams with Circuits Macros" by James Green
241 showing how to use Circuit_macros with his setup is at
242 https://www.youtube.com/watch?time_continue=53&v=pFRIBvUJHS4
243
244 A git repository of a KDE interface by Andrew G. for Linux is at
245 https://github.com/ag-ckt/cirkuit/tree/V0.5.0.
246
247 Another recent introduction is at
248 https://www.root.cz/clanky/publikovanie-elektrickych-schem-a-diagramov-pomocou-circuit-macros/
249 It is in Czech but Google translate works well.
250
251 LaTeX automation tools are discussed at, for example,
252 http://tex.stackexchange.com/questions/64/tools-for-automating-document-compilation
253
254 A Windows batch file for Circuit_macros is found at
255 http://someonehasdonethis.blogspot.ca/2012/12/a-solution-for-drawing-circuit-diagrams.html
256
257 Mac users:
258 A nice description of a Mac installation is at
259 https://www.hamish.science/2020/06/24/circuitmacros
260
261 VARIATIONS
262 Macros such as these will be modified inevitably to suit individual
263 needs and taste. They continue to evolve in my own library as I use
264 them and as others send comments. No such collection can hope to
265 include all possible circuit-related symbols, so you will probably
266 find yourself writing your own macros or adapting some of these.
267 Be careful to rename modified macros to avoid confusion. The learning
268 curve compares well to other packages, but there is no trivially
269 easy way to produce high-quality graphics. (If "a picture is worth
270 a thousand words," ask yourself how long it would take to write, revise,
271 and perfect a thousand words.)
272
273 See eschpic on Github for IEC-style electrical drawings.
274
275 The pic language dates from the 1980s and was first developed
276 as a preprocessor for the *roff family of Unix wordprocessors.
277 Some additional libraries such as chem (for chemical structures)
278 and dformat (for data structures) are still viable.
279
280 Pic macros for drawing graphs are described at
281 http://www.math.uiuc.edu/~west/gpic.html
282 After minor adaptation to dpic syntax, many of them can be simplified.
283
284 A collection of traditional pic resources and related material is
285 available at http://www.kohala.com/start/troff/troff.html In particular,
286 W. Richard Stevens illustrated his books on Unix and TCP/IP using
287 pic macros. Some of the sources found there need minor tuning to work
288 under dpic.
289
290 MetaPost examples: Go to the examples/mpost directory. Check the
291 Makefile as described in the README file, type "make", and stand well back.
292
293 Postscript with embedded psfrag strings:
294 Type "make" in the examples/psfrag directory to process examples
295 using dpic -f for creating .eps files with embedded psfrag strings.
296
297 Postscript, CorelDraw, Adobe Illustrator:
298 Circuits and other diagrams not requiring LaTeX-formatted text can be
299 processed through m4 and dpic -r to produce encapsulated Postscript
300 output. This output can also be imported into CorelDraw or Adobe
301 Illustrator. However, Postscript is not a word processor, so any
302 LaTeX formatting instructions in the source are not obeyed. These programs
303 also import svg output produced by dpic -v.
304
305 Metafont:
306 The file examples/mf/cct.mf is a Metafont source for a few variants of
307 the basic elements, produced using the mfpic output of dpic. It may
308 be of interest to persons who cannot otherwise implement the macros.
309 To see the elements (assuming a typical installation), type "make"
310 in the mf directory.
311
312 Xfig:
313 The file examples/xfig/xfiglib.fig contains circuit elements in xfig
314 3.2 format produced by dpic. The file is a prototype because many
315 more elements could be included. Logic gates often have many labels,
316 and xfig is not a word processor, so some fine tuning of labels is in
317 order. Translation between languages always involves a loss of
318 information and idiom, but Xfig can store diagrams in pic format, so
319 it is possible to alternate between xfig and dpic.
320
321 LIBRARIES:
322 The file libgen.m4 contains general-purpose macros and is read
323 automatically by other libraries. The file libcct.m4 defines basic
324 circuit elements. Binary logic-circuit elements are in liblog.m4 and
325 additional single-line elements are in libSLD.m4. Macros for drawing 3D
326 projections are in lib3D.m4, and some macros for drawing double-line
327 arrows are in darrow.m4. The file dpictools.pic contains pic macros
328 and is read automatically by some of the examples.
329
330 Feel free to contact me with comments or questions. I have retired
331 from full-time work but continue the hobby of maintaining these files.
332 I may now be able to spend more time on individual requests but I may
333 not reply instantly to email.
334
335
336 Dwight Aplevich
337 aplevich (AT) uwaterloo (DOT) ca