For plasticity, I’d strongly suggest to have a look at Rankine demo in dolfiny, dolfiny/rankine.py at master · michalhabera/dolfiny · GitHub
The way it is done in dolfiny would be a preferred way for composition of custom and generated code.
You could also generate code for expression similar to what you do, but then the rest of the code would have to be written manually, including the quadrature loop and basis functions for u
etc.