Creating Source Code The command \usepackage[margin=2.5cm]{geometry} affects the printed source code's layout. The command \usepackage{listings} informs LaTeX to include the source code in the document. The command \usepackage{hyperref} is needed for adding links in the text.
The verbatim environment is used to display LaTeX commands instead of having them executed. To display a single command in-line, the \verb|| command can be used. To display a whole block, we can use \begin{verbatim} to open the environment and \end{verbatim} to close it.
If you simply want the character to be printed just as any other letter, include a \ in front of the character. For example, \$ will produce $ in your output. The exception to the rule is the \ itself because \\ has its own special meaning. A \ is produced by typing $\backslash$ in your file.
Load the upquote
package to fix this issue in verbatim mode.
If you want straight quotes in monospaced text mode (e.g., \texttt{...}
), or indeed in any other font, then you can use the \textquotesingle
command defined 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 fonts in any encoding rather than depending on a specific glyph slot (such as \char13
in the default OT1
encoding).
Adding \usepackage{upquote}
to my preamble was sufficient.
Perhaps older versions of LaTeX or upquote required more work.
I have
What is wrong?
New
If you want to get something 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 using the listings
package; it is quite powerful and offers an option to display “straight” quotation marks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With