Estoy escribiendo un libro que incluirá código en dos lenguajes (R y SAS). Sé que podría usar \verbatim
o \alltt
para configurar las secciones de código, pero el listings
paquete tiene algunas características interesantes.
¿Hay alguna manera de usarlo listings
con dos idiomas?
Respuesta1
Si tiene diferentes opciones para los dos idiomas, puede definir dos estilos y usar la opción apropiada style=...
de sus lstlisting
entornos.
\documentclass{book}
\usepackage{xcolor}
\usepackage{listings}
\lstdefinestyle{SAS}{
language=SAS,
basicstyle=\ttfamily,
}
\lstdefinestyle{R}{
language=R,
breaklines=true,
basicstyle=\ttfamily
}
\begin{document}
Example of SAS code:
\begin{lstlisting}[style=SAS]
data myoutput;
set myinput;
if myvar = "OK" then output;
run;
\end{lstlisting}
Example of R code:
\begin{lstlisting}[style=R]
# I don't know R, code copied from http://www.rexamples.com/2/Functions
Square <- function(x) {
return(x^2)
}
print(Square(4))
print(Square(x=4)) # same thing
\end{lstlisting}
\end{document}