# Introduction

One of the problems with (M4) Circuit_Macros are that while one is busy programming/developing one's picture, one usually wants to viewing the picture before inserting it into the final LaTeX document which may consist of (say) 100 pages with (say) 50 pictures etc. in it.

The easiest way of doing that is to create a "temporary" LaTeX file with a:

``` \input{my_m4cm_picture_under_development}
```

command in it and then compile and view this "temporary" LaTeX file in order to view one's (M4) Circuit_Macros "picture".

The second problem with (M4) Circuit_Macros "pictures" are that a LaTeX document with a lot of:

``` \input{my_m4cm_picture}
```

commands, i.e. a lot of (M4) Circuit_Macros "pictures", results in a huge file that has to be processed by LaTeX and this could ends up taking a lot of time to compile.

Then finally, once you have created a beautiful (M4) Circuit_Macros "pictures" with (say) pstricks or Tikz PGF output code generated by dpic, is difficult to share with those - unfortunate - non-LaTeX users.

m4cm.py solves all of these problems by creating a PNG, JPG, PDF or EPS picture directly from an (M4) Circuit_Macros "picture"

# Doing it the long way

It basically consists of repeating STEPS 1, 2, 3 and 4 as discussed in M4 Circuit Macros - Getting Started, with (again say) "my_picture.m4" but with a few additional steps...

## On Windows XP

The following additional software is also required on Windows XP:

• Ghostscript required by epstool and eps2pdf
• optional GhostView to view PS and EPS files
• epstool to convert PS to EPS (Development of Epstool was stopped in 2005, see Epstool Home Page)
• epstopdf (which is now luckily part of MikTeX) to convert EPS to PDF
• convert, which is part of ImageMagick - see also [1], to convert EPS to PNG

Install Ghostscript and GhostView anywhere, but place epstool and eps2pdf in the path, e.g. C:\Program Files\MikTeX 2.x\MikTeX\bin

The first time eps2pdf is executed, it will ask for the path to Ghostscript. This can be done from the Configure menu.

### STEP 1:

"Draw"/program your "my_m4cm_picture.m4" and then run:

### STEP 2:

Pre-process with M4:

```> m4 my_m4cm_picture.m4 > my_m4cm_picture.pic
```

### STEP 3:

Invoke the dpic compiler:

```> dpic -p my_m4cm_picture.pic > my_m4cm_picture.tex
```

### STEP 4:

Now create a "dummy" LaTeX file, say "my_picture.tex" with the necessary preamble and a "\input{my_m4cm_picture}" somewhere inside it and then run:

```> latex my_picture.tex
```

### STEP 5:

Convert the DVI output to Postscript:

```> dvips my_picture.dvi
```

### STEP 6:

Edit the first line in "my_picture.ps" and change it to "%!PS-Adobe-3.0 EPSF-3.0" in order for epstool to convert the Postscript file to Encapsulated Postscript:

```> epstool --copy --bbox --quiet my_picture.ps  my_picture.eps
```

### STEP 7:

Then finally run eps2pdf to convert the Encapsulated Postscript picture to an (Encapsulated) PDF picture.

```> epstopdf my_picture.eps
```

## On Linux

• Ghostscript, gs
• ps2eps
• epstopdf
• convert

but which is usually already installed on Linux.

```> which gs
gs is usr/bin/gs
gs is /usr/bin/X11/gs
> which ps2eps
ps2eps is /usr/bin/ps2eps
ps2eps is /usr/bin/X11/ps2eps
> which epstopdf
epstopdf is /usr/bin/epstopdf
epstopdf is /usr/bin/X11/epstopdf
```

### STEP 1:

"Draw"/program your "my_m4cm_picture.m4" and then run:

### STEP 2:

Pre-process with M4:

```> m4 my_m4cm_picture.m4 > my_m4cm_picture.pic
```

### STEP 3:

Invoke the dpic compiler:

```> dpic -p my_m4cm_picture.pic > my_m4cm_picture.tex
```

### STEP 4:

Now create a "dummy" LaTeX file, say "my_picture.tex" with the necessary preamble and a "\input{my_m4cm_picture}" somewhere inside it and then run:

```> latex my_picture.tex
```

### STEP 5:

Convert the DVI output to Postscript:

```> dvips my_picture.dvi
```

### STEP 6:

Convert the Postscript file to Encapsulated Postscript:

```> ps2eps --force --quiet --loose my_picture.ps  my_picture.eps
```

### STEP 7:

Then finally run epstopdf to convert the Encapsulated Postscript picture to an (Encapsulated) PDF picture.

```> epstopdf my_picture.eps
```

## Converting to JPG or PNG

With ImageMagick installed in either Windows XP or Linux, run:

```> convert -density  600 my_picture.eps my_picture.jpg
```

to convert the EPS file to a JPG, or

```> convert -density  600 my_picture.eps my_picture.png
```

to convert the EPS file to a PNG.

# Doing it the short way using m4cm.py

Edit default.ltx and change the font setting and macros definitions to your requirements, and copy it into the directory/foder where you want to create your (M4) Circuit Macro "pictures".

## Setting up m4cm.py on Windows XP

Copy m4cm.py so somewhere in you path, e.g. C:\Program Files\MikTeX 2.x\MikTeX\bin

If you add ".PY" to your PATHEXT System variable definition, you only have to type m4cm at the DOS prompt instead of m4cm.py.

The following additional software is also required, the same as for Doing it the long way, but now the python script will call them directly:

• Ghostscript required by epstool and eps2pdf m4cm.py
• optional GhostView to view PS and EPS files
• epstool to convert PS to EPS - Not required any more, done by m4cm.py internally
• eps2pdfepstopdf to convert EPS to PDF -- Which should already be install

Install Ghostscript and GhostView anywhere, but place epstool and eps2pdf in the path, e.g. C:\Program Files\MikTeX 2.x\MikTeX\bin

The first time eps2pdf is executed, it will ask for the path to Ghostscript. This can be done from the Configure menu.

## Setting up m4cm.py on Linux

Copy m4cm.py anywhere.

## STEP 1:

"Draw"/program your (M4) Circuit Macro "picture", say "my_m4cm_picture.m4".

## STEP 2:

Excecute:

```> m4cm -p my_m4cm_picture.m4
```

in order to generate a PDF picture called "my_m4cm_picture.pdf", or

```> m4cm -n my_m4cm_picture.m4
```

to generate a PNG picture, "my_m4cm_picture.png".

To view all the possible options available, type:

```> m4cm -h
Usage: m4cm [options] M4CM_FILE.m4

Options:
-h, --help            show this help message and exit
-a APPEND_CHARS, --append=APPEND_CHARS
Character/String to append to the end of the output
file(s)
-b L T R B, --boundingbox_offset=L T R B
the BoundingBox Offset: left offset point value, top
offset point value, right offset point value, bottom
offset point values, the default is: 1 1 1 1, i.e. 1pt
in each direction
-d, --delete_eps      delete EPS file after converting to PNG or PDF
-e, --eps             convert to EPS format [default option]
-g, --ghostscript     use GhostScript to convert to PNG format
-j, --jpg             convert to JPG format
-n, --png             convert to PNG format
-o OUTPUT_DIR, --output_dir=OUTPUT_DIR
the Output Directory for the EPS/PDF/PNG/JPG output
files
-p, --pdf             convert to PDF format
-q, --quiet           run quietly
-r PNG_RESOLUTION, --resolution=PNG_RESOLUTION
PNG resolution (or density)
-t LATEX_TEMPLATE_FILE, --template=LATEX_TEMPLATE_FILE
LaTeX template file to be used [default="default.ltx"]
-w, --web             convert to PNG and resample at 150x150 with
antialiasing and alpha transparancy
```