function dM_dp_Tehat = matJac(dMvar_dp,mm,Tehat,nx,tt)

% indices into matrix
dM_dp_Tehat = zeros(tt.nsp,nx); % init
dM_dpi = zeros(tt.nsp,tt.nsp); % initialize
% indices into matrix
if any(any(dMvar_dp~=0)) % do this only for nonzero d_dx
  dM_dpi_entries =  mm.XI*dMvar_dp;
  for ii=1:nx % for each element of x
    dM_dpi(mm.XIindex) = dM_dpi_entries(:,ii);
    dM_dp_Tehat(:,ii) = dM_dpi*Tehat;
  end
end
end
