TeXではlistingsパッケージを使用することで,ソースファイルを出力できます.
- 上記リンクからCTANに飛んで,「You can get the contents of this directory bundled as a zip file. 」のzip fileをクリックしてlistings.zipをダウンロードします.
- C:\w32tex\share\texmf-local\tex\latex\listingsのディレクトリ*1を作成し,listings.zipを展開して生成されたファイルをすべて移動します.
- 上記ディレクトリに移動して
latex listings.ins
を実行すると,listings.styなどが生成され,listingsパッケージが使用可能になります.
なお,私はlistingsパッケージをインクルードする際にはデフォルトで次のように設定しています.ご参考までに.
\lstset{% language={C++}, backgroundcolor={\color{white}},% basicstyle={\small\ttfamily},% identifierstyle={\small\ttfamily},% commentstyle={\small\ttfamily\color[cmyk]{0.99, 0, 0.52, 0}},% keywordstyle={\small\bfseries\ttfamily\color{blue}},% ndkeywordstyle={\small\sffamily},% stringstyle={\small\ttfamily\color{red}}, frame={tb}, breaklines=true, columns=[l]{fullflexible},% numbers=left,% xrightmargin=0zw,% xleftmargin=3zw,% numberstyle={\scriptsize\color[cmyk]{0.99, 0, 0.52, 0}},%JungleGreen相当 stepnumber=1, numbersep=1zw,% % lineskip=-0.5ex,% showspaces=false,% showstringspaces=false,% tabsize=2,% showtabs=false,% }
また,外部ファイルを参照する場合は,例えば次のようにします.
\lstinputlisting[caption={CAPTION_NAME\label{src:LABEL_NAME}}, language=C++,]{SOURCE_FILE_NAME.cpp}