LaTeXを使ったレポートの作成環境を作る
学校での実験レポートを簡単にLaTeXで書けるようにするため、次のようなシェルスクリプトを書いてみました。
#!/bin/sh
#
#make_report.sh
#レポートの作成環境を作る
#Usage: make_report.sh report_name
if [ $# -ne 1 ]; then
echo "Usage: $0 report_name"
exit 1
fi
mkdir $1 $1/principle $1/method $1/conclusion $1/consideration $1/documents
cd $1
touch main.tex.latexmain
template_dir="$HOME/report/template"
cp "$template_dir/preamble.tex" .
cp "$template_dir/purpose.tex" .
cp "$template_dir/principle.tex" principle/
cp "$template_dir/method.tex" method/
cp "$template_dir/tools.tex" .
cp "$template_dir/conclusion.tex" conclusion/
cp "$template_dir/consideration.tex" consideration/
cp "$template_dir/documents.bib" documents/
vim -c "TTemplate report" -c "write" main.tex
引数として与えられた値の名前でフォルダを作ってその中にレポートの作成環境を作ります。$template_dirに適当にテンプレートを用意してます。
最後の行はVim-LaTeXの機能を使って,自分の場合は ~/.vim/ftplugin/latex-suite/templates/report.tex を読み込んでいます。
report.texの中身はこんな感じです。
<+ +> !comp! !exe!
% レポート名: <++>
% 作成日: !comp!strftime("%Y %b月%d日")!comp!
% 最終変更日: !comp!strftime("%Y %b月%d日")!comp!
%
\documentclass[a4paper]{jsarticle}
%プリアンブル部の読み込み
\input{preamble.tex}
\begin{document}
%1章:目的
\input{purpose.tex}
%2章:原理
\input{principle/principle.tex}
%3章:実験方法
\input{method/method.tex}
%4章:使用器具
\input{tools.tex}
%5章:実験結果
\input{conclusion/conclusion.tex}
%6章:考察
\input{consideration/consideration.tex}
%7章:参考文献
\bibliographystyle{junsrt} %出てきた順に表示
\makeatletter
\def\@cite#1{{[#1]}}
\makeatother
\bibliography{documents/documents.bib}
%最後につけるグラフ・図
%input{<++>}<++>
\end{document}
例えば, ./make_report.sh hoge とすると、カレントディレクトリに以下のようなファイルができます。
./hoge/
main.tex
main.tex.latexmain
preamble.tex
purpose.tex
principle/
principle.tex
method/
method.tex
tools.tex
conclusion/
conclusion.tex
consideration/
consideration.tex
documents/
documents.texちなみにvimだとノーマルモード時にgfでカーソル下のファイルに移動できます。自分はそれぞれの章のテンプレートの先頭に前の章と次の章、それにmain.texの相対パスをかいてます。
実験のレポートはそんなに長く書かないのでわざわざLaTeXで書くのは面倒かなと思いましたが、こうしておくと楽にできそうです。
2009/12/13 追記
Windowsでも同じ良ことができるようにbatファイルも書いてみました。
:: make_report.bat :: Usage: make_report.bat report_name @echo off if "%1" == "" (echo Usage: %0 report_name && goto END) mkdir "%1" "%1"\principle "%1"\method "%1"\conclusion "%1"\consideration "%1"\documents cd "%1" set template_dir="C:\vim72-kaoriya-w32j\template\" copy "%template_dir%main.tex.latexmain" . copy "%template_dir%preamble.tex" . copy "%template_dir%purpose.tex" . copy "%template_dir%principle.tex" principle\ copy "%template_dir%method.tex" method\ copy "%template_dir%tools.tex" . copy "%template_dir%conclusion.tex" conclusion\ copy "%template_dir%consideration.tex" consideration\ copy "%template_dir%documents.bib" documents\ start C:\vim72-kaoriya-w32j\gvim -c "TTemplate report" -c "write" main.tex :END
%template_dir%と最後のgvimのパスは適当に変更してください。touchコマンドの代わりが見つからなかったので、%template_dir%にmain.tex.latexmain(空ファイル)を用意する必要があります。