The real-time control of plasma position, shape and current in a tokamak has to be ensured by a number of electrical circuits consisting of voltage suppliers and axisymmetric coils. Finding good target voltages/currents for the control systems is a very laborious, non-trivial task due to non-linear effects of plasma evolution. We introduce here an optimal control formulation to tackle this task and present in detail the main ingredients for finding numerical solutions: the finite element discretization, accurate linearizations and Sequential Quadratic Programming. Case studies for the tokamaks WEST and HL-2M highlight the flexibility and broad scope of the proposed optimal control formulation.Abstract. The real-time control of plasma position, shape and current in a tokamak has to be ensured by a number of electrical circuits consisting of voltage suppliers and axisymmetric coils. Finding good target voltages/currents for the control systems is a very laborious, non-trivial task due to non-linear e↵ects of plasma evolution. We introduce here an optimal control formulation to tackle this task and present in detail the main ingredients for finding numerical solutions: the finite element discretization, accurate linearizations and Sequential Quadratic Programming. Case studies for the tokamaks WEST and HL-2M highlight the flexibility and broad scope of the proposed optimal control formulation.Date: December 18, 2018.