My experience is square rocks cavalry.

On average for me if I have them in square the whole time I usually don't lose much more than 20 men. Even if the AI did double damage (40 men killed) I'd still be winning. Even though we lost the same number of men they lost a whole unit.

What unit size do you use, I use default 120 men most infantry 60 men for specials and cavalry at 45. Sometimes unit size can make a difference.

Now for maximum effect of square (the AI doesnt always charge infantry head on) wait for your infantry to blast a volley at the horses while they are in line and as soon as they do switch to square.

When they outflank you I usually dont get the infantry into position int time to pull this off