  Under certain circumstances, the equations for the magnetic field lines can
be recast in a canonical form, after defining a suitable field line
Hamiltonian. This analogy is extremely useful for dealing with a variety of
problems involving magnetically confined plasmas, like in tokamaks and other
toroidal devices, where there is usually one symmetric coordinate which plays
the role of time in the canonical equations. In this tutorial paper we review
the basics of the Hamiltonian description for magnetic field lines, emphasizing
the role of a variational principle and gauge invariance. We present
representative applications of the formalism, using cylindrical and magnetic
flux coordinates in tokamak plasmas.
