Last active
June 3, 2016 08:10
-
-
Save sky-y/4697882 to your computer and use it in GitHub Desktop.
jlatexdiff: latexdiffを日本語LaTeX文書でうまく扱えるようにする
参考:http://blogs.yahoo.co.jp/pentainformation/28571072.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# jlatexdiff: latexdiffを日本語LaTeX文書でうまく扱えるようにする | |
# 参考:http://blogs.yahoo.co.jp/pentainformation/28571072.html | |
# 実行時に指定された引数の数、つまり変数 $# の値が 2 でなければエラー終了 | |
if [ $# -ne 2 ]; then | |
echo "指定された引数は$#個です." 1>&2 | |
echo "実行するには2個の引数が必要です." 1>&2 | |
echo "jlatexdiff [old file name] [new file name]" 1>&2 | |
exit 1 | |
fi | |
echo "ファイル名 '$1' と ’$2' の差分を書き出します." | |
# 文字コードを変換. | |
# Unicodeで濁点を分離する・しないを統一するために, | |
# NFD形式(UTF-8-MAC)からNFC形式 (UTF-8)に統一. | |
fname=`basename $2 .tex` | |
cat $1 | iconv -t UTF-8-MAC | iconv -t UTF-8 > ${fname}-old.tex | |
cat $2 | iconv -t UTF-8-MAC | iconv -t UTF-8 > ${fname}-new.tex | |
# latexdiffで差分作成. | |
latexdiff -e utf8 ${fname}-old.tex ${fname}-new.tex > ${fname}-diff.tex | |
# 改行がうまくできるようにsedで書き換え | |
sed -e 's/}\\DIFdelend/ }\\DIFdelend/g' -e 's/}\\DIFaddend/ }\\DIFaddend/g' ${fname}-diff.tex > tmp.txt | |
mv tmp.txt ${fname}-diff.tex | |
rm -f tmp.txt | |
# platex実行 | |
# latexmk を利用する場合 | |
latexmk -pdfdvi ${fname}-diff.tex | |
# platexを利用する場合 念のため3回実行 | |
# platex ${fname}-diff.tex | |
# platex ${fname}-diff.tex | |
# platex ${fname}-diff.tex | |
# dvipdfmx ${fname}-diff.dvi | |
# 掃除 | |
rm -f ${fname}-old.tex ${fname}-new.tex | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment