I know there is a package called M-code for Matlab code. Is there something similar for Android? Ideally I'd like to just write one line of code in LaTeX that calls a file containing my Android code.
Asked
Active
Viewed 2,209 times
2 Answers
1
I would use the listings
package (see the LaTeX Wikibook) on this topic. My example below is something I've used in the past. It sets up the margins and some reasonable defaults for the code block (e.g., behavior of line breaks, font and line number style, etc.).
This goes in your preamble (based on this SO answer):
% BEGIN java syntax highlighting
%
% \begin{lstlisting}
% ...
% \end{lstlisting}
%
\usepackage{listings}
\usepackage{color}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
\lstset{frame=tb,
language=Java,
aboveskip=3mm,
belowskip=3mm,
showstringspaces=false,
columns=flexible,
basicstyle={\small\ttfamily},
numberstyle=\tiny\color{gray},
keywordstyle=\color{blue},
commentstyle=\color{dkgreen},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true
tabsize=2
}
% END java syntax highlighting
Then you can use \lstinputlisting{/path/to/your/android/code.java}
to include the file in your document.

Community
- 1
- 1

adamdunson
- 2,635
- 1
- 23
- 27