Pan-Magic Algebraic Squares

The complete symbolic solution for an N×N square in which every row, every column and every diagonal — including the broken (wrapped) ones — sums to N·M. Cells shown in amber are the free parameters; the rest are forced.

Check every line re-added symbolically

Numbers set the free parameters, get a square

Copy out