I am trying to type computer code in my document using the alltt environment. Some symbols, such as ' and {, do not appear in the document the way they do in the code. I solved the problem with ' by using the upquote package. But I still have a problem with { and }; these symbols are taller than the surrounding text in the alltt environment. For example,
\documentclass{article}
\usepackage[margin=2cm]{geometry} %set margins
\usepackage{color}
\usepackage{alltt}
\usepackage{upquote}
\begin{document}
\begin{alltt}
for (i in 1:3){
print(i^2)
}
\end{alltt}
\end{document}
doesn't do what I want (since the braces do not appear), and neither does using \{ and \} in place of { and } (the braces are too tall). I think this question is something similar, but I do not understand the answers given there.

\documentclass{...}and ending with\end{document}. – jub0bs May 26 '13 at 23:15verbatimenvironment? – egreg May 26 '13 at 23:19listingspackage. – cacamailg May 26 '13 at 23:21allttabstract:This package defines the alltt environment, which is like the verbatim environment except that \, {, and } have their usual meanings. Thus, other commands and environments can appear within an alltt environment. – cacamailg May 26 '13 at 23:24allttyou can use\textbackslashfor \ and\}and\{for}and{, respectively. – cacamailg May 26 '13 at 23:30allttenvironment you should use\{\}and\usepackage[T1]{fontenc}(which is a good idea anyway - a lot problems with wrong symbols are due to the restrictions of the default OT1-encoding). – Ulrike Fischer May 27 '13 at 08:37