As for literature...
Clifton Fadiman's Fantasia Mathematica is a compendium of stories and peoms related to mathematics.
Jacques Roubaud, one of the members of the French literary group "Oulipo", founded by Raymond Queneau and sometime mathematician Francois Le Lionnais. His The Princess Hoppy has a group theory puzzle.
Georges Perec, another member of Oulipo, has a linear algebra proof in his novel, La Vie: Mode d'Emploi (Life: A User's Manual), correctly typeset in French and horribly mangled in the English translation.
Victor Snaith, a mathematician, has written a novel, The Yukiad, but I'm not sure how much math is in it.
Mark Twain, Roughing It, "I acknowledge freely that I have had hard feelings against Mr. Ballou for abusing me and calling me a logarithm, which is a thing I do not know what, but no doubt a thing considered disgraceful and unbecoming in America."
Yoko Ogawa, The Housekeeper and the Professor, a mathematics professor had a car accident which left him unable to form new permanent memories. With the help of a new housekeeper, he is able to create through post-it notes an axiomatic system that allows him to recreate his life each morning. It's a charming novel.
P.G. Wodehouse, Uncle Fred in the Springtime: "Nature, stretching Horace Davenport out, had forgotten to stretch him sideways, and one could have pictured Euclid, had they met, nudging a friend and saying: 'Don’t look now, but this chap coming along illustrates exactly what I was telling you about a straight line having length without breadth.'" A similar line appears in Uneasy Money (Wodehouse was never one to waste a good line.)
Tom Stoppard, Arcadia, a play. Fermat's last theorem; iteration & chaos.
David Auburn, Proof, a play. Primes.
Jay Wright, Polynomials and Pollen, poems.
Andrew Marvell, "The Definition of Love," poem. Euclidean geometry.
Strange Attractors: Poems of Love and Mathematics, a collection.
All involve mathematics to varying degrees.
Gert Jonke Geometrischer Heimatroman, (Geometric Regional Novel)
Thomas Pynchon, Gravity's Rainbow. Contains a PDE, a Poisson distribution, and other aspects of rocket science.