If you have a function:
[tex]
z = f(x, y)[/tex]
and the derivative of [itex]z[/itex] w.r.t. [itex]x[/itex] is denoted by:
[tex]
X(x, y) \equiv \frac{\partial z}{\partial x}[/tex]
then, the function:
[tex]
w \equiv z - X \, x[/tex]
is a Legendre transform of [itex]z[/itex], w.r.t. [itex]x[/itex] only! Its total differential is:
[tex]
dw = dz - X \, dx - x \, dX = X \, dx + \frac{\partial z}{\partial y} \, dy - X \, dx - x \, dX[/tex]
[tex]
dw =\frac{\partial z}{\partial y} \, dy - x \, dX[/tex]
i.e. w is to be treated as a function of X and y:
[tex]
\frac{\partial w}{\partial X} = -x, \ \frac{\partial w}{\partial y} = \frac{\partial z}{\partial y}[/tex]
Of course, you need to eliminate [itex]x[/itex] from the equation:
[tex]
X = X(x, y) \Rightarrow x = f(X, y)[/tex]
Notice that the variables w.r.t. which we have not performed a Legendre transform still remain arguments of the transforme dfunction.
Similarly, [itex]-H[/itex] is a Leg. trans. of [itex]L[/itex] w.r.t. [itex]\dot{q}[/itex] and the respective partial derivative:
[tex]
p \equiv \frac{\partial L(t, q, \dot{q})}{\partial \dot{q}}[/tex]
is the generalized momentum. Therefore, [itex]H[/itex] is to be treated as a function of [itex]q[/itex] (a variable over which we had not performed a Legendre transform). [itex]p[/itex] (the derivative w.r.t. the variable that we had transformed, namely the generalized velocity) and, possibly time [itex]t[/itex] for open systems.