0

This package is basically writting R codes in LaTeX but I am typing codes in TeXnicCenter when I use this command it doesn't work to copy codes from R. Please tell me how I can write my R codes in TeXnicCenter? I'm using this code:

 \documentclass[preprint,12pt,authoryear]{elsarticle} 
 \usepackage{listing}
 \begin{lstlisting}[language=R]
fib <- function(n) {
  if (n < 2)
    n
  else
    fib(n - 1) + fib(n - 2)
}
fib(10) # => 55enter code here
\end{lstlisting}

I would want to write this code in TeXnicCenter:

 okfd <- function(coord, data, argvals=seq(0, 1, len = dim(data)[1]), 
                 argnames=c("argument", "sites", "values"),
                 new.coord=NULL,                
                 nbasis=max(50,dim(data)[1]), lambda = 0,
                 max.dist.variogram=NULL,nugget.fix=NULL){
1

This requires the listings package. Your code works like this:

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}

\usepackage{listings}

\begin{document}

\begin{lstlisting}[language=R]
enter code h`okfd <- function(coord, data,
 argvals=seq(0, 1, len = dim(data)[1]), 
argnames=c("argument", "sites", "values"),
new.coord=NULL,                
nbasis=max(50,dim(data)[1]), lambda = 0,
max.dist.variogram=NULL,nugget.fix=NULL){
\end{lstlisting} 

\end{document}

which results in:

second listing

In case you don't have the listings package

If you don't have the listings package, you have to install it. For MiKTeX, you go to the start menu > MiKTeX > MiKTeX Console (you might have to start it as an administrator) and then go to the options. It has an option called "Always install missing packages on-the-fly". Select this option and close the window.

  • \documentclass[preprint,12pt,authoryear]{elsarticle} – rizwan niaz Jan 24 at 12:48
  • will ur given command work in texniccenter sir?? im using \documentclass[preprint,12pt,authoryear]{elsarticle} in texniccenter – rizwan niaz Jan 24 at 12:49
  • not working in texnicenter ,. even just i installed textstudio to check ur code it gives an error File `listings.sty' not found. \usepackage , when i install this package listing.sty still same error – rizwan niaz Jan 24 at 13:08
  • im using MiktTeX ,....plz tell me how to install this listing ?? – rizwan niaz Jan 24 at 13:20
  • yes at the end u given , im trying to get this , will tell u , it works r not ,,,thnks sooo much – rizwan niaz Jan 24 at 13:53

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.