Yes, one can do that sort of thing, but none of the static document formats allow for it, AFAIK, one has to use a programming environment --- best example of that would be _Euclid's Elements_ Joyce's Java Version:
http://aleph0.clarku.edu/~djoyce/jav.../elements.html
Or maybe SVG, but I'm not aware of a document-viewing tool which allows the more dynamic aspects of SVG w/o back-end server support.
William