Finding Harmonics Analytically
What you're asking for is:


  given a periodic signal (e.g. square wave), where are the discrete frequency components (i.e. harmonics)?


You'll find that the harmonics you're looking for are the coefficients of the Fourier series expansion of your signal.

So, if you have a signal that has a known Fourier series expansion, or can be constructed from such signals, it's easy.

But how to find the coefficients in general?

This is answered exactly by the Fourier transform.

So, the relevant formulas are, given a signal $s(t)$ with period $P$


the coefficients $c_n$ of the Fourier series expansion $s(t) = \sum\limits_n c_n e^{j2\pi n\frac tP}$: $$c_n=\frac{1}{P}\int_{t_0}\limits^{t_0+P} s(t)\cdot e^{-j \tfrac{2\pi nt}{P}}\ dt$$ describing the $n$th harmonic. You just plug in your square wave for $s(t)$ and get out the coefficients of your harmonics.


and in the general, you don't get discrete harmonics, but a continuous spectrum, and thus, instead of a discrete Fourier series the Fourier transform.

Not posting info on the Fourier Transform here; it's pretty much common knowledge, and you wouldn't benefit – your profile indicates that you're studying physics, and thus, you've already met the Fourier transform, for example when describing electrons in periodic crystals.