We can use sine waves to construct a square wave.
Summing of sine waves with correct amplitude and frequency will result in a square wave.
In this circuit, the orange graph is the sum of all harmonic sine waves.
The green graph is the real square wave.
The purple graph is to keep the scale of the graph plane between -2V and 2V. (as you know, the scale of the plane will adjust automatically #^_^)
This circuit can be improved by adding more harmonic waves.