Estilos para escrever Código Fonte em \LaTeX
Författare
Taciano Morais Silva
Last Updated
för 8 år sedan
Licens
Creative Commons CC BY 4.0
Sammanfattning
Estilos para código fonte para Java e R language!
Estilos para código fonte para Java e R language!
\documentclass[a4paper]{article}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
% Pacote para a definição de novas cores
\usepackage{xcolor}
% Definindo novas cores
\definecolor{verde}{rgb}{0.25,0.5,0.35}
\definecolor{jpurple}{rgb}{0.5,0,0.35}
\definecolor{darkgreen}{rgb}{0.0, 0.2, 0.13}
%\definecolor{oldmauve}{rgb}{0.4, 0.19, 0.28}
% Configurando layout para mostrar codigos Java
\usepackage{listings}
\newcommand{\estiloJava}{
\lstset{
language=Java,
basicstyle=\ttfamily\small,
keywordstyle=\color{jpurple}\bfseries,
stringstyle=\color{red},
commentstyle=\color{verde},
morecomment=[s][\color{blue}]{/**}{*/},
extendedchars=true,
showspaces=false,
showstringspaces=false,
numbers=left,
numberstyle=\tiny,
breaklines=true,
backgroundcolor=\color{cyan!10},
breakautoindent=true,
captionpos=b,
xleftmargin=0pt,
tabsize=2
}}
\newcommand{\estiloR}{
\lstset{ %
language=R, % the language of the code
basicstyle=\footnotesize, % the size of the fonts that are used for the code
numbers=left, % where to put the line-numbers
numberstyle=\tiny\color{gray}, % the style that is used for the line-numbers
stepnumber=1, % the step between two line-numbers. If it's 1, each line
% will be numbered
numbersep=5pt, % how far the line-numbers are from the code
backgroundcolor=\color{white}, % choose the background color. You must add \usepackage{color}
showspaces=false, % show spaces adding particular underscores
showstringspaces=false, % underline spaces within strings
showtabs=false, % show tabs within strings adding particular underscores
frame=single, % adds a frame around the code
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. commens (green here))
tabsize=2, % sets default tabsize to 2 spaces
captionpos=b, % sets the caption-position to bottom
breaklines=true, % sets automatic line breaking
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
title=\lstname, % show the filename of files included with \lstinputlisting;
% also try caption instead of title
keywordstyle=\color{blue}, % keyword style
commentstyle=\color{darkgreen}, % comment style
stringstyle=\color{red}, % string literal style
escapeinside={\%*}{*)}, % if you want to add a comment within your code
morekeywords={*,...} % if you want to add more keywords to the set
}}
\title{Estilos para escrever Código Fonte em \LaTeX}
\author{Taciano}
\begin{document}
\maketitle
\begin{abstract}
Estilos para código fonte para Java e R language!
\end{abstract}
\section{Estilo Java}
\begin{scriptsize}
\estiloJava
\begin{lstlisting}[caption={Código fonte em Java}, label=lst:javacode]
private DesignWizard dw;
private ClassNode entity;
Collection<Modifier> modifiers;
@Before
public void setUp() throws Exception {
//Load design for all classes in the project
dw = new DesignWizard("target/classes/");
}
@Test
public void testFinalClassRule() {
entity = dw.getClass("mypackage.ClassA");
modifiers = entity.getModifiers();
assertTrue(modifiers.contains(Modifier.FINAL));
}
\end{lstlisting}
\end{scriptsize}
\section{Estilo R}
\begin{scriptsize}
\estiloR
\begin{lstlisting}[caption={Código fonte em R}, label=lst:rcode]
falhas <- rbind(amostra1, amostra2)
library(lawstat)
# Teste de homocedastidade (Homogeneidade da variancia)
levene.test(falhas$proporcao, falhas$tipo)
# Testes de Normalidade
shapiro.test(amostra1$proporcao)
shapiro.test(amostra2$proporcao)
# Teste da Igualdade das medias
t.test(falhas$proporcao ~ falhas$tipo, paired=TRUE, var.equal=TRUE)
# Grafico com as medias dos projetos
boxplot(falhas$proporcao ~ falhas$tipo, data=falhas, main="Failure proportions of Projects", xlab="Samples", ylab="Proportions")
\end{lstlisting}
\end{scriptsize}
\end{document}