1

I'm trying to paste some R code into my latex file but when I use the listing package it fails to display the - next to the <. My latex file is as follows:

\documentclass[12pt]{article}
\usepackage{listing}

\begin{document}
    \begin{lstlisting}[language=R]
ftn_deriv_1 <- function(x) {
# Input: n-dimensional vector x0
# Output: n-dimensional vector x with first derivative 
#of scalar function ftn(x)
x1 <- 1/(x[1]*(1+x[2]))-log(x[2])/(1+x[1])^2;
x2 <- -log(x[1])/(1+x[2])^2 + 1/(x[2]*(1+x[1]));
y <- c(x1,x2);
return(y);
}

ftn_deriv_2 <- function(x) {
# Input: n-dimensional vector x0
# Output: n by n matrix with second derivative of scalar function ftn(x)
x11 <- -1/((1+x[2])*x[1]^2)+2*log(x[2])/(1+x[1])^3;
x21 <- -1/(x[1]*(1+x[2])^2) -1/(x[2]*(1+x[1])^2);
x12 <- -1/(x[1]*(1+x[2])^2) -1/(x[2]*(1+x[1])^2);
x22 <- 2*log(x[1])/(1+x[2])^3 -1/((1+x[1])*x[2]^2);
y <- matrix(c(x11,x21,x12,x22),2,2);
return(y);
}
\end{lstlisting}
\end{document}

When I compile this I get the following output: Output

As you can see the - does not show after the <. I am using TeXstudio version 2.11.2 for macboook. Any remedy for this? Thanks in advance!

Pim
  • 141
  • I can't believe that this is the output when you compile the given code. (1) The package is called listings, not lstlisting; the latter doesn't seem to exist. (2) There is a closing brace missing after \begin{document. With these two changes the code compiles, and the minuses show up. – gernot Oct 25 '16 at 08:26
  • If after these corrections the minus signs are still missing, try to magnify the pdf, or try a different pdf viewer. My guess is that at a low resolution the viewer doesn't show thin lines. – gernot Oct 25 '16 at 08:28
  • 6
    Try including \lstset{basicstyle=\ttfamily} before the lstlisting environment; see also the post "missing minus sign in R code using latex". – gernot Oct 25 '16 at 08:32
  • After adding \lstset{basicstyle=\ttfamily} it finally showed the minus signs. Thank you for the solution. – Pim Oct 25 '16 at 08:39

0 Answers0