[ACCEPTED]-How to write programming code containing the ' character in latex?-latex
Load the upquote
package to fix this issue in verbatim 7 mode.
If you want straight quotes in monospaced 6 text mode (e.g., \texttt{...}
), or indeed in any other 5 font, then you can use the \textquotesingle
command defined 4 in the textcomp
package:
\documentclass{article} \usepackage{upquote,textcomp} \begin{document} \newcommand\upquote[1]{\textquotesingle#1\textquotesingle} \verb|'c'| \texttt{\upquote{h}} \textsf{\upquote{h}} \upquote{h} \end{document}
This will work well for 3 fonts in any encoding rather than depending 2 on a specific glyph slot (such as \char13
in the 1 default OT1
encoding).
Adding \usepackage{upquote}
to my preamble was sufficient.
Perhaps 2 older versions of LaTeX or upquote required 1 more work.
I have
What is wrong?
New
If you want to get something 1 like this
write
\makeatletter
\let \@sverbatim \@verbatim
\def \@verbatim {\@sverbatim \verbatimplus}
{\catcode`'=13 \gdef \verbatimplus{\catcode`'=13 \chardef '=13 }}
\makeatother
For displaying source code, you might consider 3 using the listings
package; it is quite powerful 2 and offers an option to display “straight” quotation 1 marks.
If you're seeing curly single right quotes 5 in a verbatim environment, then the single 4 right quote in your typewriter font is curly, and 3 that's the correct one to use for what you're 2 doing (which I assume is displaying some 1 C code).
\textsf{``} and \textsf{''} come pretty 2 close to straight quotes. No need for 1 using any special packages.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.