Perhaps relevant are this link and this link. I never found an elegant way … and I’d like to see if there is one.