fore-and-aft rigging sails to windward waaaaay better than square-rigging, and seems (to my mind as a modern-trained sailor at least) generally superior to square rigging, and lateen rigging was adopted widely in the middle east, so why did square-rigged ships persist so much up until the age of sail was over? Is there some other advantage to square-rigged ships that I'm just totally missing right now?
Square rig has a number of advantages over fore and aft rig, and the advantages increase as the size of the ship increases.
In general, the fore and aft rig has only one advantage. It can point higher into the wind. This is considerably more apparent on modern yachts with very taught, stainless steel rigging, than it was in earlier times when rigging was hemp rope, and could not be set up so tightly.
If you sail a gaff rigged schooner, especially one still rigged with hemp rigging and canvas sails, I don't think you will be exceedingly impressed with the windward ability.
Even so, square sails are quite effective to windward. The lack of ability to point up high was more often a function of how hard the yards could be braced around (before coming up against the standing rigging) rather than any particular inefficiency in the shape of the sail (although it is probably also possible to get a tighter luff from a taught headstay than from the unstayed luff between two yards, especially if the rigging is steel wire and the hull is stiff enough to set it up tight).
On all points of sailing except to windward, the square rig was more efficient and stable than a fore and aft rig (fore and aft rigged yachts use spinnakers, jennakers and drifters to add power when off the wind, and these are very unstable, difficult, and dangerous sails).
Some of the advantages of the square rig include:
Very flexible sail plan. Sails can be carried high up (royals and skysails) which is valuable in light winds as there is sometimes wind aloft when there is less or none down near the sea.
Light winds were a major consideration in the days of sail. There are a lot of light wind conditions, especially in coastal waters. These days a yacht can just fire up the auxiliary, but in the days of sail, being able to make progress and remain maneuverable in light winds was an important consideration.
If you look at the complex and risky sails early fore and aft rigged America's cup racing yachts used to try to make speed in light winds, such as gaff topsails set with flying spars, you will see some of the problems fore and aft rigged ships have had with trying to get more sail area up high.
Sails can also be carried in many more combinations and variations of sail area on square rigged ships than on fore and aft rigged ships, and the individual sails are smaller in size and easier and safer to handle. The rig is more stable, with all square sails being held in place by running rigging in all dimensions.
The ship is much more maneuverable the sails can be backed as well as filled. Some sails can be backed while others are filled so the ship can be stopped. Sailing in and out of tight harbors can be done both forwards and backwards. So can tactical maneuvers in battle. (Little needed now with auxiliary power available, but valuable in the days of sail).
The larger the ship, the more problems there are with fore and aft rig. Whether Marconi or Gaff rigged, the sails (both mainsails and jibs - especially if masthead jibs) become very large and difficult to handle.
Even on modern yachts of modest size, jib sheets are handled with powerful winches, while ships in the age of sail had no winches (until late in the age of sail when brace winches were introduced on short handed square rigged ships) and had to have sails that could be sheeted in with muscle power alone. The size of crew or complications of block and tackles which would have been needed to manage the jib sheets of a 200 foot or 400 foot Marconi rigged ship in the age of sail would have been either impossible or impractical.
Large fore and aft rigged ships in the age of sail were invariably multi masted schooners. The many masts were an attempt to keep the sails to a size small enough to be manageable by manpower. The masts were generally more, and shorter, and carried less potential sail area than similar sized square rigged ships of the period. This meant that they were better at going to windward, and needed slightly fewer crew, but could carry less sail area, were much worse in light airs, and were less safe stable, and speedy on most of the world's sailing trade routes.
Who wants to go to windward anyway? Long passages to windward are avoided by cruising yachtsmen today. They are slow, wet and uncomfortable. All the main trade routes of the world in the days of sail were arranged to have the least possible windward work.
Modern materials, stiffer hulls and rigs, synthetic sails, dacron running rigging, steel standing rigging, aluminum (or composite) spars, auxiliary power, all make the fore and aft rig for modern yachts much better (especially for going to windward) than the fore and aft rig was in the days of sail. Modern yachts are usually less than 100 feet long (generally much less) so the sails are not too big and roller reefing and large powerful winches make them possible to handle. (Once they get up to 70 feet or so, the sheet winches are generally powered, as genoas get too big for even powerful human cranked winches to easily handle.)
If one applied modern materials to square riggers, their performance and ease of handling would improve massively as well. I suspect that for long voyages and larger vessels the square rig would be as superior to the fore and aft rig now as it was in olden days. No one, however, is investing much money in building large, long distance, sail powered ships nowadays, so it is difficult to know.