[Tex/LaTex] Typewriter apostrophe in typewriter font for apostrophe symbol


Is there a way of producing a typewriter apostrophe (U+0027) in a typewriter font when an apostrophe symbol is entered in .tex document?

To give an example, I’d like \texttt{'hello'} to produce 'hello' with typewriter apostrophes (U+0027) rather than ’hello’ with quotation marks (U+2019) currently produced by PDFLaTeX. There are command-based solutions that offer \texttt{\something hello\something} syntax, but there might be a way of using \texttt{'hello'} in a document and getting the desired result, perhaps through changing typewriter font encoding or by another trick. I’m willing to put into document preamble a code of any complexity.

upquote package delivers the result for verbatim environment. I'm looking for exactly the same functionality but for \texttt.

Best Answer

A streamlined version of karlkoeller's solution:





% fix \@resetactivechars not to redefine the active apostrophe
\def {\@activechar@info{space}\space}%


\texttt{'hello'} `here the quotation marks are normal'

Also \verb|'hello'| works

And here is some math $f''(x)$

enter image description here