Created
February 18, 2017 15:33
-
-
Save ryuichiueda/830484752aabaa75739ee711d9cf91e7 to your computer and use it in GitHub Desktop.
tex to plain
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 | |
###文献リスト### | |
cat ../rpim_book.bbl | | |
grep '^\\bibitem' | | |
sed 's/bibitem/cite/' | | |
awk '{print "s/\\"$1"/["NR"]/g"}' > ./cite.sed | |
cat ../rpim_book.bbl | | |
sed 's/bibitem/cite/' | | |
sed -f ./cite.sed | | |
sed 's/{\\noop.*}}//' | | |
tr '~' ' ' | | |
sed 's/{\\em\(.*\)}/▲\1▲/g' | | |
sed 's/\\newblock *//' > ./文献.txt | |
###索引のリスト### | |
cat ../rpim_book.ind | | |
gsed 's/ \\item //' | | |
gsed 's/ \\subitem //' | | |
gsed 's/ \\subsubitem //' | | |
gsed 's/\( *\)see/\1→/' | | |
gsed 's/\\hyperpage.*//' | | |
gsed 's/\\hyperindexformat//' | | |
gsed 's/{[0-9]*}//' | | |
gsed 's/{\\→{\(.*\)}}/→ \1/' | | |
gsed 's/{\\\(→.*\)}/\1/' | | |
grep -v 'indexspace' | | |
grep -v '\\begin' | | |
grep -v '\\end' | | |
gsed 's/, $//' | | |
gsed 's/\\_/_/g' | | |
gsed 's/\\\#/#/g' | | |
gsed 's/\\\$/$/g' > ./索引.txt | |
###目次### | |
cat ../rpim_book.toc | | |
tr ' ' _ | | |
tr '{}' ' ' | | |
awk '{print $NF,$(NF-2),$2}' | | |
gsed 's/[^.*]*\.//' | | |
grep -v 'paragraph$' | | |
awk ' | |
$NF=="part"{print "第"$1"部",$2} | |
$NF=="chapter"{print $1"章",$2} | |
$NF=="section"{print $1"節",$2} | |
$NF=="subsection"{print $1"項",$2}' | | |
tr _ ' ' > ./目次.txt | |
###番号リスト### | |
cat ../*.aux | | |
grep '^\\newlabel' | | |
tr '{}' ' ' | | |
awk '{print $2,$NF}' | | |
gsed 's/figure\.//g' | | |
gsed 's/table\.//g' | | |
gsed 's/part\.//g' | | |
gsed 's/chapter\.//g' | | |
gsed 's/subsection\.//g' | | |
gsed 's/appendix\.//g' | | |
gsed 's/section\.//g' | | |
awk '{print "s/\\\\label{"$1"}/"$2"/g"} | |
{print "s/\\\\ref{"$1"}/"$2"/g"}' > ./label.sed | |
###本文の整形### | |
ls ../*.tex | | |
gsed 's;../;;' | | |
while read file ; do | |
cat ../$file | | |
gawk ' /\\begin/{ref+=1;print ""} | |
/^\\(begin|end|section|subsection|part|chapter)/{a=""} | |
ref==0{printf("%s%s",a,$0);a=""} | |
ref!=0{print} | |
ref==0&&NF==0{print "\n";a=" "} | |
/\\end/{ref-=1}' | | |
gsed 's/ \\subsubsection{\([^{]*\)}/▲\1▲/g' | | |
gsed 's/\\begin{Verbatim}.*/# # 網/' | | |
gsed 's/\\end{Verbatim}.*/# #/' | | |
gsed 's/\\textbf{\([^{}]*\)}/▲\1▲/g' | | |
gsed 's/\\url{\([^{}]*\)}/\1/g' | | |
gsed 's/\\footnote{\([^{}]*\)}/\n■\1■\n/g' | | |
gsed 's/\\index{\([^{}]*\)}/▼\1▼/g' | | |
gsed 's/\\texttt{\([^{}]*\)}/\1/g' | | |
awk '/# #$/{f=0;a=0} | |
!f{print} | |
f{a+=1;print sprintf("%02d ",a),$0} | |
/# # 網$/{f=1}' | | |
gsed -f ./label.sed | | |
gsed -f ./cite.sed | | |
gsed 's/\\verb|\([^|]*\)|/\1/g' | | |
gsed 's/\\.*{\([^{}]*\)}\([1-9][0-9]*.*\)/#\2 \1/' | | |
gsed 's/\\_/_/g' | | |
gsed 's/\\begin{itemize}.*//' | | |
gsed 's/\\end{itemize}.*//' | | |
gsed 's/\\item/*/' > ./tmp/$file.tmp | |
done | |
ls ./tmp/*.tmp | | |
sed 's;.*/;;' | | |
while read FILE ; do | |
sed -n '/\\begin{figure}/,/\\end{figure}/p' < "./tmp/$FILE" | | |
grep -v centering | | |
gawk '{if(/\\caption/){printf("%s",$0)}else{print}}' | | |
gsed 's/[\t ]*\\caption{\(.*\)}[\t ]*\([1-9].*\)$/図\2: \1/' | | |
gsed '/図/s/\\_/_/g' | | |
sed 's/\\includegraphic.*\]{\(.*\)}/\1/' | | |
sed -e 's/\\begin.*//' -e 's/\\end.*//' > "./tmp/fig.$(sed s/tex\.tmp/txt/ <<< $FILE)" | |
sed -n '/\\begin{table}/,/\\end{table}/p' < "./tmp/$FILE" | | |
gawk '{if(/\\caption/){printf("%s",$0)}else{print}}' | | |
gsed '/表/s/\\_/_/g' | | |
gsed 's/[\t ]*\\caption{\(.*\)}[\t ]*\([1-9].*\)$/表\2: \1/' | | |
sed -e 's/\\begin.*//' -e 's/\\end.*//' > "./tmp/table.$(sed s/\tex\.tmp/txt/ <<< $FILE)" | |
sed -n '/\\begin{table}/,/\\end{table}/!p' < "./tmp/$FILE" | | |
sed -n '/\\begin{figure}/,/\\end{figure}/!p' > "./tmp/text.$(sed s/tex\.tmp/txt/ <<< $FILE)" | |
done | |
rm ./tmp/*.tmp | |
rm ./tmp/*.rpim_book.txt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment