Consider a particle which occupy $(t_1,q_1)$ and $(t_2,q_2)$ where $t$ denotes time and $q$ denotes spatial coordinate. The dynamics of the particle is determined by extremising $$S[q]=\int^{t_2}_{t_1}L(q,\dot{q},t)dt$$ which is the well-known Hamilton’s principle in non-relativistic theories. It is stated and proved in Goldstein’s Classical Mechanics that the dynamics of the particle will not change if we change the Lagrangian $L$ by a total derivative of a function which is dependent on $q$ and $t$ only. $$L\mapsto L(q,\dot{q},t)+\frac{dK(q,t)}{dt}$$ will not change the path which extremises the action. I would like to verify this statement because in one of Qmechanic’s posts he said there is no constraint on the form of $K$, i.e. you can take $K(q,\dot{q},t)$ as well and this is also what my lecture notes say. Yet I am not so sure about that because we do not fix the velocities at end points (whereas we fix $q$ at end points).
This leads to the second question concerning the derivation of energy-momentum tensor. The energy momentum tensor is defined as the conserved current arising from space-time symmetry, where the transformation on space-time is $x^\mu\mapsto x^\mu-\epsilon a^\mu$ for some constant $a^\mu$. A vital step in its derivation, much similar to the equaiton above, is by asserting the transformation of $\mathcal{L}$ due to it being a scalar: $$\mathcal{L}(x)\mapsto \mathcal{L}(x)+\epsilon a^\mu\partial_\mu\mathcal{L}(x).$$ Just like my problem with constraints on $K$, my problem here is the change in the Lagrangian density, whilst being a total derivative, is a total derivative of a function which depends not only on the field $\phi$ but also on its derivatives $\partial \phi$. Thus if we do have the constraint on $K$ this constraint shall apply to $\mathcal{L}$ as well.