This is a demonstration of a mechanical setup consisting of a double-rack plate surrounding a sector pinion. Rotation of the center pinion causes alternating linear motion of the rack.
Note that this is not reversible: driving the rack with alternating linear motion will not reliably drive the pinion, as there is a small amount of clearance in the middle of each rotation of the pinion where it is engaged with neither rack.
The setup can be optionally driven by a small hobby gearmotor, available for about $3.25 each on Amazon or about $1.70 each including shipping from AliExpress. They're advertised as Car or Robot motors, and have standard dimensions. This GrabCad Model has proved accurate.
Other hardware needed for assembly includes:
Both the gear and the rack have a module of 3mm. The pinion has 6 teeth of a 20-tooth gear.
The largest single piece (the racks) fits within a 200mm x 200mm build place easily.
The bottom side of the pinion and rack (in printing orientation) has a small 0.5mm fillet to alleviate elephant's foot
If you find that the rack has a tendency to "slip" teeth in one direction or the other, there are holes in the end of the rack assembly for additional m3 x 5mm knurled inserts where bolts can be added to limit the travel of the rack.
There are additional holes in the top of the "floor" unit (which holds the motor) for m3 x 3mm threaded inserts, to install a small m3 machine screw through the slots in the rack unit. This captures the rack unit if you want to demonstrate/use this mechanism at an angle. I found this unnecessary for level use.