4
\documentclass{article}
\usepackage{listings}
\begin{document}
\lstset{language=Lisp,
keywordstyle=\ttfamily\color{keywordcolor},
    stringstyle=\ttfamily\color{stringcolor},
    commentstyle=\ttfamily\color{commentcolor},
    identifierstyle=\texttt}
\begin{lstlisting}
(> 3 2)
(a 3 2)
\end{lstlisting}
\end{document}

produces

enter image description here

Notice how the ">" symbol is much larger in this output than it is, say, in the latex file just above. Is there a way to say "just give me the one that looks like it's in the same font as all the other characters in this font"? (Now that I look at it, the numbers seem to be in a different font as well -- less "Courier"-like than I'd expect.)

2
  • Isn't it easier to do basicstyle=\ttfamily than repeating it for every part?
    – egreg
    Oct 18 '16 at 21:24
  • It surely is...but that would have required that I read the whole"listings" doc rather than just editing what someone else had already done. :) Thanks for the tip.
    – John
    Oct 18 '16 at 22:45
5

In my opinion it's easier to do basicstyle=\ttfamily than repeating the declaration for each part of the language.

However, you can do it in an indirect way:

\documentclass{article}
\usepackage{listings}

\newcommand{\ttgt}{\texttt{\char`\>}}

\lstset{
  language=Lisp,
  keywordstyle=\ttfamily\color{keywordcolor},
  stringstyle=\ttfamily\color{stringcolor},
  commentstyle=\ttfamily\color{commentcolor},
  identifierstyle=\texttt,
  literate={>}{\ttgt}1,
}

\begin{document}

\begin{lstlisting}
(> 3 2)
(a 3 2)
\end{lstlisting}

\end{document}

enter image description here

Not sure why preferring numbers in normal font. Here's the other approach:

\documentclass{article}
\usepackage{listings}

\lstset{
  language=Lisp,
  basicstyle=\ttfamily,
}

\begin{document}

\begin{lstlisting}
(> 3 2)
(a 3 2)
\end{lstlisting}

\end{document}

enter image description here

1

You need to use a typewriter font that has a nice >, i.e. Source Code Pro:

\documentclass{article}
\usepackage{listings}
\usepackage[default]{sourcecodepro}
\usepackage[T1]{fontenc}
\begin{document}
\lstset{language=Lisp,
    keywordstyle=\ttfamily\color{keywordcolor},
    stringstyle=\ttfamily\color{stringcolor},
    commentstyle=\ttfamily\color{commentcolor},
    identifierstyle=\texttt}
\begin{lstlisting}
(> 3 2)
(a 3 2)
\end{lstlisting}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.