We discuss trace formulae for the operator \begin{equation*} f(PAP) - Pf(A)P, \end{equation*} where $A$ is a pseudo-differential operator on $L^2(\mathbb R^d)$ with a smooth or discontinuous symbol, and $P$ is a multiplication by the indicator of a piece-wise smooth domain in $\mathbb R^d$. The function $f$ is not supposed to be smooth. The obtained formulae generalise results obtained by H. Widom in the 80's. These results are used to study the entanglement entropy of free fermions at positive temperature both in the low and high temperature limits.