0

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.

Nico
  • 109
  • 1
  • 5

2 Answers2

1

Android code is usually Java and XML which you could import using the listings package in LaTex.

listings supports both Java and XML along with many other languages.

See this tutorial

JRomero
  • 4,878
  • 1
  • 27
  • 49
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