convert.sh 647 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. #
  3. # from wikifile to latex file
  4. # e.g.
  5. # bash convert.sh <filename>
  6. #
  7. input=$1
  8. output=${input}.tex
  9. err(){
  10. echo $1
  11. exit
  12. }
  13. [ -z ${input} ] && err "no input file"
  14. [ ! -f ${input} ] && err "no valid input file, check your path"
  15. pandocbin=`which pandoc`
  16. [ -z "${pandocbin}" ] && err "no pandoc binary"
  17. echo "pandoc..." > /dev/stderr
  18. ${pandocbin} ${input} -o ${output}
  19. echo "pleas check ${output}" > /dev/stderr
  20. cat ${output} | sed -e 's/h5\.\ \(.*\)/\\subsubsection{\1}/' -e 's/h4\.\ \(.*\)/\\subsection{\1}/' -e 's/h3\.\ \(.*\)/\\section{\1}/' -e 's/h2\.\ \(.*\)/\\chapter{\1}/' -e 's/h1\./\%h1\./' -e 's/h0/\%h0/'