Wikipedia:WikiProject Electronics/How to draw SVG circuits using Xcircuit

From Wikipedia, the free encyclopedia

Negative impedance converter drawn with Xcircuit
Negative impedance converter drawn with Xcircuit

This howto is Linux-based. If you can do it for any other OS, please improve it

Xcircuit cannot export in SVG straight away, but the format it uses to save data (PostScript) is a vectorial format, so it can be converted to SVG. These are the steps I followed to create the picture on the right.

  • Create the circuit with Xcircuit without any text (we'll add it later). Then go to File -> Write Xcircuit PS. In the window that comes up, write the name of the file in the Filename box and click on Apply, than change the scale from 1.00000 to 5.00000 and click on Apply again. I have chosen 5 after several tests, but I think it would be better to make all the circuits with this scale, in order to get a uniform output.
  • now we have a filename.ps and we want to convert it to SVG. Working under Linux, here is a small Bash script that will do everything by itself. Open any text editor and put the following code into it:
#!/bin/bash

# you need gs-common, pstoedit and skencil to
# get this script working
export BASENAME="`basename $1 .ps`";

# Outline fonts
eps2eps -dNOCACHE ${BASENAME}.ps ${BASENAME}2.ps

# Fix bounding box
ps2epsi  ${BASENAME}2.ps  ${BASENAME}.ps
rm ${BASENAME}2.ps

# Convert to Sketch
pstoedit -f sk  ${BASENAME}.ps  ${BASENAME}.sk

# Convert to SVG
skconvert  ${BASENAME}.sk  ${BASENAME}.svg

save it with the name ps2svg.sh and make it executable running the following command on the terminal:

chmod a+x ps2svg.sh

Check if you have all the necessary programs. In particular you will need Sketch; if you use Debian/Ubuntu, there is everything in the standard repositories.

Now you can run:

ps2svg.sh filename.ps

and you will get a nice filename.svg in the same directory. Now open the new file with Inkscape to add the text. For the text in the picture on the top, I used font family Serif (you can choose it, whichever OS you are working on), font weight Bold, size 72px. Then I made the subscripts smaller, using the same font style, changing only the size to 56px. Optionally you can actually move the subscripts downwards pressing Alt+down, but sometimes it is not rendered properly by Wikipedia.

[edit] See also