0

我知道有一个名为 M-code 的包用于 Matlab 代码。Android有类似的东西吗?理想情况下,我只想在 LaTeX 中编写一行代码,调用包含我的 Android 代码的文件。

4

2 回答 2

1

我会在这个主题上使用listings包(参见LaTeX Wikibook )。下面的示例是我过去使用过的。它为代码块设置边距和一些合理的默认值(例如,换行的行为、字体和行号样式等)。

这在你的序言中(基于这个 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

然后您可以使用\lstinputlisting{/path/to/your/android/code.java}将文件包含在您的文档中。

于 2013-06-18T18:42:22.380 回答
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

于 2013-06-18T18:31:56.343 回答