Skip to content

Commit

Permalink
Update auto_input.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
JavaLangRuntimeException authored Sep 23, 2024
1 parent 7306f0b commit 5d4edf4
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions tools/auto_input.sh
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
#!/bin/bash
# - written by @aonrjp

TYPES=("houshin" "soukatsu")
SECTIONS=("kaikei" "kensui" "soumu" "syogai" "system" "zentai")

for type in ${TYPES[@]}
for type in "${TYPES[@]}"
do
for section in ${SECTIONS[@]}
# 各タイプ(houshin, soukatsu)のメインファイルを作成
main_file="src/${type}.tex"
echo "\\documentclass{article}" > "$main_file"
echo "\\begin{document}" >> "$main_file"

for section in "${SECTIONS[@]}"
do
# 所定ディレクトリ以下に含まれるtexファイルを取得してソート
files=`find src/${type}/${section} -type f -name "*.tex" | sort`
files=$(find "src/${type}/${section}" -type f -name "*.tex" | sort)

if [ "$1" = "show" ]; then
# 見つかったtexファイルのパスを出力
echo "${files}"
else
# input文を生成 (シェルによって\\\\が\\となり、正規表現で\\は\を表す)
doc=`echo "${files}" | sed -e 's/^/\\\\input{/' | sed -e 's/$/}/'`
# セクションごとにサブセクションを作成
echo "\\section{${section^}}" >> "$main_file"

# texファイルが発見できなければ虚無を
if [[ $files == '' ]]; then
doc=''
# input文を生成し、メインファイルに追加
if [ -n "$files" ]; then
while IFS= read -r file; do
echo "\\input{${file}}" >> "$main_file"
done <<< "$files"
else
echo "% No .tex files found in ${type}/${section}" >> "$main_file"
fi

# 書き込む
echo "${doc}" > src/${type}/${section}.tex
echo "" >> "$main_file" # 空行を追加
fi
done

# ドキュメントを閉じる
echo "\\end{document}" >> "$main_file"
done

0 comments on commit 5d4edf4

Please sign in to comment.