ソース・プログラムや、計算結果の数値出力などの形式は、 たいていの場合、いわゆるテキスト・ファイルです。
短いものは verbatim 環境を使って、取り込むことができます。 例えば
\begin{verbatim}
#include <stdio.h>
int main(void)
{
printf("Hello, world\n");
return 0;
}
\end{verbatim}
|
しかし、 ソース・プログラムなどを修正した場合に頻繁にコピペをやり直すのは 案外と面倒なものです。
verbatimtabinput[タブのカラム数]{ファイル名} や listinginput{最初の行番号}{ファイル名} を使うことを勧めます。
どちらも使うためには、\begin{document} の前 (プリアンブルと呼びます) に
\usepackage{moreverb}
|
| \verbatimtabinput{} を使う例 |
\documentclass[12pt,leqno]{jarticle}
\usepackage{moreverb}% パッケージを組み込む ← これが必要
\begin{document}
...
以下に \texttt{hello.c} のソース・プログラムを示す。
\verbatimtabinput[4]{hello.c}
...
\end{document}
|
| こんなふうに組版されます |
| 以下に hello.c のソース・プログラムを示す。 [4]hello.c |
| \listinginput{} を使う例 |
\documentclass[12pt,leqno]{jarticle}
\usepackage{moreverb}% パッケージを組み込む ←重要
\begin{document}
...
以下に \texttt{hello.c} のソース・プログラムを示す。
\listinginput{1}{hello.c}
...
\end{document}
|
| こんなふうに組版されます |
| 以下に hello.c のソース・プログラムを示す。 1hello.c |
桂田 祐史