Hamlet, or Hamlet, Prince of Denmark was a tragic historical play written by the Human poet William Shakespeare in the early 17th century. It is widely considered his most famous and most often-quoted play, even into the 23rd and 24th centuries.
In 2153, a day after being provided the play as an example of Earth literature, Vissian Captain Drennik quoted from Hamlet Act I, Scene V: "There are more things in Heaven and Earth than are dreamt of in your philosophy." (ENT: "Cogenitor")
Spock also quoted a line from later in Act I, Scene V to Burnham, his foster sister, before she undertook a dangerous mission: "Time is out of joint. O cursed spite, that I was born to set it right." (DIS: "Perpetual Infinity")
The Karidian Company of Players ran an interstellar theatrical tour of Shakespearean performances, including Hamlet. In 2266, Anton Karidian had a book of Hamlet in his quarters aboard the USS Enterprise. Soon thereafter, he and the rest of the theatrical company performed the play aboard the Enterprise, providing an ironic parallel to real life, when Karidian was revealed as actually being Governor Kodos. As Kodos' daughter Lenore Karidian quoted, "The play's the thing, wherein I'll catch the conscience of the king." (TOS: "The Conscience of the King")
In 2286, when told that Spock had programmed computer variables for time travel from memory (shortly following the restoration of his katra on Vulcan, Leonard McCoy exclaimed, "Angels and ministers of grace defend us!" – which Spock correctly identified as a quote from Hamlet, Act I Scene IV. (Star Trek IV: The Voyage Home)
In 2293, Klingon general Chang was particularly fond of Hamlet, and one line in particular: "taH pagh taHbe'" (in English, "To be or not to be!"). Chancellor Gorkon also quoted Hamlet by making reference to "the undiscovered country". Though Shakespeare presumably intended the line to be a reference to death, Gorkon more optimistically chose to use it as a reference to the future. Also, the chameloid Martia described her decision to "assume a pleasing shape", making reference to Hamlet Act II, Scene II. (Star Trek VI: The Undiscovered Country)
In a conversation with Captain Jean-Luc Picard in 2364, Q quoted, "The play's the thing" to describe his need for playing games with the USS Enterprise crew. Later in the conversation, Picard defended the Human race by quoting from Hamlet, saying, "What he said with irony, I say with conviction. 'What a piece of work is man! How noble in reason! How infinite in faculty. In form, in moving, how express and admirable. In action, how like an angel. In apprehension, how like a god!'" (TNG: "Hide and Q")
In 2366, when Data was abducted by Kivas Fajo and presumed dead, Geordi La Forge returned Data's volume of the complete Shakespeare to Captain Jean-Luc Picard. He read two lines from Hamlet Act I, Scene II to himself:
- "He was a man, take him for all in all,
- I shall not look upon his like again." (TNG: "The Most Toys")
In 2399, Doctor Agnes Jurati referenced an oft-quoted line from the play, saying "there's the rub" when explaining how no one had been able to redevelop the science used to create the android Data. (PIC: "Remembrance")
"Hamlet is a violent play, about violent times; when life was cheap, and ambition was god."
- - Lenore Karidian
"I am thy father's spirit, doom'd for a certain term to walk the night, and for the day confined to fast in fires till the foul crimes done in my days of nature are burnt and purged away. But that I am forbid to tell the secrets of my prison-house, I could a tale unfold whose lightest word would harrow up thy soul, freeze thy young blood, make thy two eyes, like stars, start from their spheres, thy knotted and combined locks to part and each particular hair to stand an end like quills upon the fretful porpentine. But the details of this eternal blazon must not be to ears of flesh and blood."
- - Hamlet's father's ghost (Act I, Scene V)
In the final revised draft script of TOS: "The Conscience of the King", the production of Hamlet aboard the Enterprise was referred to as having "decor carried out in a strange Venusian version of castle and grounds."
Because of the comment that Chancellor Gorkon made that "you have never experienced Shakespeare until you have read him in the original Klingon," the Klingon Language Institute has completely translated Hamlet to Klingon and sold it to the public as The Klingon Hamlet. In 2010, selections from Hamlet and Much Ado About Nothing were performed in Klingon by the Washington Shakespeare Company, as part of a fundraiser which also featured George Takei. 
Many episode titles originate in quotations from Hamlet, including TOS: "The Conscience of the King", TNG: "Thine Own Self", VOY: "Mortal Coil", the subtitle of Star Trek VI: The Undiscovered Country, and possibly TNG: "Remember Me" and TNG: "The Mind's Eye".
A character called B. Ornot Tobe was mentioned on an unused okudagram.