# Deriving Canonical Transformation from Generating Function using Principle of Stationary Action

In Hamill's "A Student's Guide to Lagrangians and Hamiltonians", section 5.2, the equations for a canonical transformation $$(q,p) \to (Q,P)$$, induced by the generating function $$F(q,Q,t)$$ are derived using the principle of stationary action and the fact that the equations of motion are indifferent to the addition of a complete time derivative $$d{\Lambda}(q,t)/dt$$ (not a function of $$\dot{q}$$!) to the Lagrangian; this indifference being because the small variations $$\delta q$$ to the extremal path vanish at the endpoints.

In particular, the author states that:

$$\delta \displaystyle\int_{t_1}^{t_2} \left( P\dot{Q} -K(Q,P) \, + dF(q,Q,t)/dt \right)dt = \delta \int_{t_1}^{t_2} \left( P\dot{Q} -K(Q,P)\right)dt$$

(where $$K$$ is the new Hamiltonian) because supposedly we have: $$\delta\int_{t_1}^{t_2} (dF(q,Q,t)/dt)dt=\delta \left(F\left(q(t_2),Q(t_2),t_2\right)-F\left(q(t_1),Q(t_1),t_1\right)\right)=0$$ for the reasons stated above for $$\Lambda$$.

I don't understand why this can be assumed. In general, $$q$$ may be a function of both $$Q$$ and $$P$$, and the small variations of $$P$$ at the endpoints need not necessarily vanish, and therefore $$F$$ may obtain different values at the point $$t_1$$ (and of course at $$t_2$$) for different variations of $$Q$$..

All this can also be stated in terms of $$q$$ and $$\dot{q}$$, in which case I would say that since $$Q$$ is a function of $$q$$ and $$p$$ (and $$p$$ is a function of $$\dot{q}$$), we get $$F(q,\dot{q},t)$$ which may vary at the endpoints since $$\delta \dot{q}$$ need not vanish at the endpoints.

This is an important step in the derivation of a canonical transformation using a generating function... What am I missing?