Just showing them as duplicates is probably the easiest and clearest thing to do. Besides myheritage, I think Crusader Kings II's in-game family trees also show people as duplicates, if they show up multiple times in a family tree. In that game, you have the choice between a fully dynastic tree similar to the ones shown here (marriages of females to non-dynasty members are shown, but any of their descendants are left out), or 2 smaller-scale family trees. One being an ancestor tree that showed the parents, grandparents and great-grandparents of the selected person, and the other a family tree, which showed IIRC wife, kids, grandkids etc. I'm a bit hazy on the latter 2 versions, since I mostly look at the dynasty one.
I remember in one of my wife's games, she intermarried with her own dynasty a lot, and there was eg. some character for who only had 4-5 actual unique great-grandparents, instead of the expected 8 or so, due to extensive cousin-to-cousin marriages (which wasn't all that rare with European nobility/royalty even in the start of the 20th century). The game rewards inbreeding by keeping money and the titles in the family, but punishes it by higher risk for negative traits: minor physical defects like clubfooted or harelip, or major negative traits like "imbecile".
I actually used myheritage to build a family tree for one of my games in Crusader Kings I, which didn't have an in-game gui for that, beyond showing the selected characters parents, siblings, children, and IIRC grandparents and grandchildren.
Anyway, back on track: It shouldn't be too complex to code a family tree generator (somebody did one for CKI, I think), although I probably wouldn't be able to do it myself, at least not just with what I know now. Assuming the dfhack dwarfexport command includes familial relations (and if it doesn't, can a similar script be made?), it shouldn't be much more than first identifying dwarfs based on their names, then recording the relations they have in their descriptions, then building the family tree off of comparing those links. I initially thought 2 dwarves with the same name might cause trouble, but they'd of course have different family ties.