In the nineteenth century American culture, Shakespeare was no secret. Twain uses several scenes from Shakespeare in Adventures of Huckleberry Finn to prove this in a humorous way when the characters the "duke" and the "king" perform Hamlet.
"To be, or not to be; that is the bare bodkin
That makes calamity of so long life:..."
In a time when only the educated Americans knew their Shakespeare from books, most of the general public was familiar with it through performances, many times as parodies.These performances were almost always part of a variety show of entertainment in one evening including dancers, singers, minstrels, etc. Incorporating Shakespeare with Huck Finn is almost expected for the 19th century.