Local picture is explained in
Suppose we choose a Lagrangean submanifold, what gives the splitting between submanifold coordinates , and the corresponding moment where the Hamiltonian is and , . The canonical transformation by definition preserves the equations of motion; let the new coordinates be and momenta and the new Hamiltonian is . Thus both variations
vanish. Here we of course write . Subtracting the left and right hand side variations we get that the difference must be a (variation of the integral of the) total differential of a function, which can be chosen as a function of some set of old and new coordinates in a consistent way. For example in 1 dimension, we have 4 possibilities of one new and one old generalized coordinate.
therefore if then , , , what gives the relation between the old and new coordinates and momenta and the new Hamiltonian , which must be expressed in terms of .
If then we add , use the Leibniz rule and we see that for the generating function of the “second kind”, the total differential
and , , . A similar analysis can be done straightfowardly for other possibilities of the choice of arguments.
An invariant picture of generating functions on symplectic manifolds is in