#!/bin/sh
#
# This script is a part of ChiTeX
# By Hung-Yih Chen    
#           Last updated  May. 12, 1999
#
# This script is used for giving help for using ChiTeX"
# plain TeX or LaTeX source file
#
# Usage: chitexhelp [-option]
#

SAVEPWD=`pwd`

if test -s $SAVEPWD/kaipfb.tgz; then
   cd /tmp
   mkdir temp
   cd temp
fi

   /bin/rm -f *@

# no newline script
  echoprompt=`echo -n "."`
  if test "$echoprompt" = "."; then
     echomode="-n "; echocr=""
  else
     echoprompt=`echo  ".\c"`
     if test "$echoprompt" = "."; then
        echomode=""; echocr="\c"
     else 
        echomode="-e "; echocr="\c"
     fi
  fi

gawkbin="awk"
echo "yes" > tmp@
texmfcnffile=`kpsexpand -w cnf texmf.cnf`
TEXMFCNF=`
$gawkbin  '
{texmfcnfloc=index(texmfcnffile,"/texmf.cnf")
 print substr(texmfcnffile,1,texmfcnfloc-1)
}' texmfcnffile=$texmfcnffile tmp@ `

echo $TEXMFCNF > tmp@


TEXMF=`
$gawkbin '
{
  inline=$0
  gsub(/web2c/,"",inline)
  inline=substr(inline,1,length(inline)-1)
  print inline
}' tmp@ `

texmf=$TEXMF

if test "$1" = "-big5"; then
   option="big5"   
   menuoption="big5"
else
   if test "$1" = "-gb"; then
        option="gb"
        menuoption="gb"
   else
      if test "$1" = "-help"; then  
         option="help"
      else
         option="none"
      fi
   fi
fi

if test "$2" = "-test"; then 
   secondoption="testmenu"
else
   if test "$2" = "-font"; then 
      secondoption="fontmenu"
   fi
fi

if test "$option" = "help"; then
   echo " "; echo " "
   echo "  Usage: chitexhelp [option]"
   echo " "
   echo "  This script is used for giving help for using ChiTeX"
   echo "  option are:"
   echo "  -gb      for using in GB encoded chinese"
   echo "  -big5    for using in Big5 encoded chinese" 
   echo "  -help    help"
   echo " "
   exit
fi





rm -f tmp@

#if test "$option" = "big5"; then
if test "$option" = "none"; then
menu="1"
while test "$menu" = "1"
do
  clear
  echo " "
  echo "                                                      "
  echo "        Choose interfaces:                          "  
  echo "                                                    "
  echo "        1. Big5 chinese                             "
  echo "        2. GB chinese                               "
  echo "        q. Quit        "
  echo "                                                      "
  echo $echomode "        To choose one of the above, type '1',...,or 'q':" $echocr 
  read inkey

  if test "$inkey" != "1" -a "$inkey" != "2" -a "$inkey" != "q"; then
     menu="1"
  else
     menu="0"
     if test "$inkey" = "2"; then
        menuoption="gb"
     else 
       if test "$inkey" = "1"; then 
          menuoption="big5"
       else
          if test "$inkey" = "q";then
             exit
          fi
       fi
     fi
  fi
done  
fi

if test "$menuoption" = "big5"; then

  help="1"
  while test "$help" = "1"
  do
  if test "$secondoption" != "testmenu" -a "$secondoption" != "fontmenu"; then
  clear
  echo " "
  echo "       Choose one of the following:"
  echo " "
  echo "       1. Read README.use, *.ps about the usage of ChiTeX"
  echo "       2. Read README.* about installation of fonts(r)"
  echo "       3. Read README.* about others"
  echo "       4. Test demo documents and read source documents"
  echo "       5. The use of chinese fonts commands of Adobe Type1"
#  echo "       4. Use old ttf2pk(Y xdvi,dvips ɦY~T, "
#  echo "          LkQͤ pk ɮ, i^_ϥ ttf2pk,"
#  echo "          PɧiD(email: yih@math.ncu.edu.tw)oT)"
#  echo "       5. Use new ttf2pk"
  echo "       q. Quit"
  echo " "
  echo $echomode "       J '1', '2'  ,,, : " $echocr
  read inkey
  clear
  fi

  if test "$secondoption" = "testmenu"; then
     inkey="4"; help="0"
  else 
     if test "$secondoption" = "fontmenu"; then
        inkey="5"; help="0"
     fi
  fi

  case "$inkey" in
       "2")
          subhelp="1"
          while test "$subhelp" = "1"
          do
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. vi README.install.advance "
          echo "       2. vi README.fonttable (rΫO²) "
          echo "       3. vi README.fonts (rΫOӸԪ) "
          echo "       q. quit "
          echo " "
          echo $echomode "       J '1', '2'  ,,, : " $echocr
          read subinkey
          case "$subinkey" in         
             "1")
                 vi $texmf/doc/chitex/README.install.advance
                 ;;
             "2")
                 vi $texmf/doc/chitex/README.fonttable 
                 ;;
             "3")
                 vi $texmf/doc/chitex/README.fonts
                 ;;
             "q")
                 subhelp="0"
                 ;;
               *)
                 subhelp="1";;
         esac
         done;;
       "1")
          subhelp="1"
          while test "$subhelp" = "1"
          do
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. vi README.use"
          echo "       2. ghostview intro.ps "
          echo "       3. ghostview newmac.ps "
          echo "       4. ghostview maverb.ps "
          echo "       5. acroread math2a_dvipdfm.pdf "
          echo "       q. quit "
          echo " "
          echo $echomode "       J '1', '2'  ,,, : " $echocr
          read subinkey
          case "$subinkey" in         
             "1")
                 vi $texmf/doc/chitex/README.use
                 ;;
             "2")
                 ghostview $texmf/doc/chitex/intro.ps
                 ;;
             "3")
                 ghostview $texmf/doc/chitex/newmac.ps
                 ;;
             "4")
                 ghostview $texmf/doc/chitex/maverb.ps
                 ;;
             "5")
                 acroread $texmf/tex/chinese/math2a_dvipdfm.pdf
                 ;;
             "q")
                 subhelp="0"
                 ;;
               *)
                 subhelp="1";;
          esac
          done;;
       "3")
          subhelp="1"
          while test "$subhelp" = "1"
          do
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. vi README"
          echo "       2. vi README.first"
          echo "       3. vi README.inst.quick"
          echo "       4. vi README.install.advance"
          echo "       5. vi README.chtable"
          echo "       6. vi README.print"
          echo "       7. vi README.fonts.suggetion "
          echo "       8. vi ChangeLog "
          echo "       q. quit "
          echo " "
          echo $echomode "       J '1', '2'  ,,, : " $echocr
          read subinkey
          case "$subinkey" in         
             "1")
                 vi $texmf/doc/chitex/README
                 ;;
             "2")
                 vi $texmf/doc/chitex/README.first
                 ;;
             "3")
                 vi $texmf/doc/chitex/README.inst.quick
                 ;;
             "4")
                 vi $texmf/doc/chitex/README.install.advance
                 ;;
             "5")
                 vi $texmf/doc/chitex/README.chtable
                 ;;
             "6")
                 vi $texmf/doc/chitex/README.print
                 ;;
             "7")
                 vi $texmf/doc/chitex/README.fonts.suggetion
                 ;;
             "8")
                 vi $texmf/doc/chitex/ChangeLog
                 ;;
             "q")
                 subhelp="0"
                 ;;
               *)
                 subhelp="1";;
          esac
          done;;

        "4") 

          demosubmenu (){
          bibind="n"
          case "$cmd" in 
          "math1") compilecmd="chitex -xdvi";;
          "math2") compilecmd="chitex -psv";;
          "samp1") compilecmd="chitex -xdvi";;
#          "samp2") compilecmd="chitex -xdvi";;
          "tabdemo") compilecmd="chitex -dvi";;
          "math2_pdftex") compilecmd="chitex -pdftex";;
          "math1_pdftex") compilecmd="chitex -pdftex";;
          "mabibind") compilecmd="chitex"; bibind="y";;
          "ƾ_chapbib") compilecmd="chitex"; bibind="2";;
          "ƾ_bibunits") compilecmd="chitex"; bibind="3";;
          *) compilecmd="chitex -psv";;

          esac            
          while test "$subsubhelp" = "1"
          do
            clear
            echo " "
            echo "       Choose one of the following:"
            echo " "
            
              echo "       1. Read source document file:  "
              echo "               $cmd.tex "
              echo "          in $texmf/tex/chinese "
            if test "$bibind" = "y"; then
              echo "       1a. Read source document file:  "
              echo "               $cmd.tex "
              echo "           with help "
            fi
            if test "$bibind" != "n"; then 
              echo "       1b. Read 'bib' file used in bibtex:  "
              echo "               $cmd.bib "
              echo "          in $texmf/tex/chinese "
            fi
            if test "$bibind" = "y"; then 
              echo "       1c. Read 'mymacros.tex' used in defining your "
              echo "           favorite chinese title and others "
            fi

              echo "       2. Compile and preview document: "
              echo "                 $cmd.tex "
              echo "          (choose this is as giving command: "
              echo "             $compilecmd $cmd  ) "
              echo "       q. quit"
              echo " "
          echo $echomode "       J '1', '2'  ,,, : " $echocr
              read subsubkey

              case $subsubkey in
              "1")  vi $texmf/tex/chinese/$cmd.tex;;
              "1a")  ghostview $texmf/doc/chitex/$cmd"ps.ps";;
              "1b")  vi $texmf/tex/chinese/$cmd.bib;;
              "1c")  vi $texmf/tex/chinese/mymacros.tex;;
              "2") if test "$bibind" = "n"; then 
                    $compilecmd $cmd 
                   else
                    if test ! -s $cmd.bib; then
                       cp $texmf/tex/chinese/$cmd.bib .
                       chmod +w $cmd.bib
                    fi

            clear
            echo " "; echo " "
            echo "       This document use utlities of bibtex/makeindex "
            echo "       with chinese. It needs excute commands 'cbibtex'"
            echo "       and 'cmakeindex' in addition to command of "
            echo "       compilation. So, the following commands should be"
            echo "       excuted to complete 'compile' :"
            echo "           chitex $cmd "
           if test "$bibind" = "y"; then
            echo "           cbibtex $cmd "
            echo "           cmakeindex $cmd "
           else 
             if test "$bibind" = "2"; then

               if test ! -s ƾ11.tex; then
                  cp $texmf/tex/chinese/ƾ11.tex .
                  chmod +w ƾ11.tex
               fi

               if test ! -s ƾ12.tex; then
                  cp $texmf/tex/chinese/ƾ12.tex .
                  chmod +w ƾ12.tex
               fi

               echo "           cbibtex ƾ11 "
               echo "           cbibtex ƾ12 "
             else
               if test "$bibind" = "3"; then
                 if test ! -s $cmd.tex; then
                    cp $texmf/tex/chinese/$cmd.tex .
                    chmod +w $cmd.tex
                 fi
                 echo "           cbibtex $cmd.1 "
                 echo "           cbibtex $cmd.2 "
               fi
             fi
           fi
            echo "           chitex -psv $cmd "
            echo "           (chitex+dvips+ghostview) "
            echo " "
            echo $echomode "       Press any key to start to excute the above commands: " $echocr
            read xxyyzzz
            echo " "
            echo "       Press any key to excute: "
            echo "                 chitex $cmd " 
            echo $echomode "       :" $echocr
            read xxyyzzz
                       chitex $cmd 
            echo " "
            echo "       Press any key to excute: "

           if test "$bibind" = "y"; then
            echo "                 cbibtex $cmd " 
           else
            if test "$bibind" = "2"; then
              echo "           cbibtex ƾ11 "
              echo "           cbibtex ƾ12 "
            else
                 echo "           cbibtex $cmd.1 "
                 echo "           cbibtex $cmd.2 "
            fi
           fi

            echo $echomode "       :" $echocr
            read xxyyzzz

           if test "$bibind" = "y"; then
                       cbibtex $cmd
           else
              if test "$bibind" = "2"; then
                 cbibtex ƾ11
                 cbibtex ƾ12
              else
                 cbibtex $cmd.1
                 cbibtex $cmd.2
              fi
           fi
                  
           if test "$bibind" = "y"; then
            echo " "
            echo "       Press any key to excute: "
            echo "                 cmakeindex $cmd " 
            echo $echomode "       :" $echocr
            read xxyyzzz
                       cmakeindex $cmd
           fi

            echo " "
            echo "       Press any key to excute: "
            echo "                 chitex -psv $cmd " 
            echo $echomode "       :" $echocr
            read xxyyzzz
                       chitex -psv $cmd

                    fi  
                    ;;
              "q")  subsubhelp="0" ;;
                *)  subsubhelp="1" ;;             
              esac
            rm *@; rm -rf .tmp00
            done
            }

          subhelp="1"
          demomenu (){
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. Test or read LaTeX document: math2.tex"
          echo "       2. Test or read LaTeX document: samp2.tex"
          echo "       3. Test or read LaTeX document: charex2.tex"
          echo "       4. Test or read LaTeX document: samp1.tex"
          echo "       5. Test or read LaTeX document: math2_pdftex.tex"
          echo "            (compile with pdftex) "
          echo "       6. Test or read Tex document: math1.tex"
          echo "       7. Test or read Tex document: charex1.tex"
          echo "       8. Test or read Tex document: math1_pdftex.tex"
          echo "            (compile with pdftex) "
          echo "       9. Test or read LaTeX document: tabdemo.tex"
          echo "      10. Test or read LaTeX document: mabibind.tex"
          echo "            (Test utilities of cbibtex and cmakeindex)"
          echo "      11. Test or read LaTeX document: maverb.tex"
          echo "            (Test using chinese in verbatim's like macros)"
          echo "      12. Test or read LaTeX document: ƾ_chapbib.tex"
          echo "            (Test using chapterbib.sty and chinese filename)"
          echo "      13. Test or read LaTeX document: ƾ_bibunits.tex"
          echo "            (Test using bibunits.sty and chinese filename)"
          echo "      14. Test or read LaTeX document: D1.tex"
          echo "      15. Test or read LaTeX document: samp_quotcha.tex"
          echo "            (Test using quotcha.sty)"

          echo "       q. quit "
          echo " "
          echo $echomode "       J '1', '2'  ,,, : " $echocr
          read subinkey          
          case $subinkey in
          "1") cmd="math2";subsubhelp="1"
               if test -s lotka.eps; then
                  cp lotka.eps lotka.eps.old
               fi
               if test -s graf3d.eps; then
                  cp graf3d.eps graf3d.eps.old
               fi
               cp $texmf/tex/chinese/*.eps .
               chmod +w *.eps
               demosubmenu;;
          "2") cmd="samp2";subsubhelp="1";demosubmenu;;
          "3") cmd="charex2";subsubhelp="1";demosubmenu;;
          "4") cmd="samp1";subsubhelp="1";demosubmenu;;
          "5") cmd="math2_pdftex";subsubhelp="1";demosubmenu;;
          "6") cmd="math1";subsubhelp="1";demosubmenu;;
          "7") cmd="charex1";subsubhelp="1";demosubmenu;;
          "8") cmd="math1_pdftex";subsubhelp="1";demosubmenu;;
          "9") cmd="tabdemo";subsubhelp="1";demosubmenu;;
          "10") cmd="mabibind";subsubhelp="1";demosubmenu;;
          "11") cmd="maverb";subsubhelp="1";demosubmenu;;
          "12") cmd="ƾ_chapbib";subsubhelp="1";demosubmenu;;
          "13") cmd="ƾ_bibunits";subsubhelp="1";demosubmenu;;
          "14") cmd="D1";subsubhelp="1";demosubmenu;;
          "15") cmd="samp_quotcha";subsubhelp="1";demosubmenu;;
          "q") subhelp=0;;
          "*") subhelp=1;;
          esac
          }

          while test "$subhelp" = "1"
          do
             demomenu
          done   
          ;;

        "5") clear
             echo "  ChiTeX ؤrΫO:"
             echo "    '^jg' P '^jg' rΫO "
             echo "  1. SΨ^jgrΫO: "
             echo "     uϥ TrueType rΩҲͪ pk r, preview iΫO: "
             echo "                 xdvi  Υ  chitex -xdvi "
             echo "         Υ:   dvips + ghostview Υ  chitex -psv "
             echo "         Ҧp,  math2.tex ϥΤrΫO \\moekai "
             echo "         sĶPw ip:  chitex -xdvi math2     chitex -psv math2"
             echo "  2. Ψ^jgrΫO: "
             echo "     (1) ϥ TrueType rΩҲͪ Adobe Type1 r"
             echo "     (2) preview uiΫO: "
             echo "                dvips + ghostview "
             echo "         Ҧp,  charex2.tex ϥΤrΫO \\MOEKAI "
             echo "         sĶPw ip:"
             echo "            chitex math2 "
             echo "            dvips math2 "
             echo "            ghostview math2.ps "
             echo "             chitex -psv math2 "          
             echo "     (3) ϥ pdftex (pUO chitex -pdftex math2_pdftex "
             echo "         chitex -psv -pdftex math2_pdftex) ϥΥjgrΫO"
             echo "     (4) ϥΨ  '', '', 'Ŧr', ''"
             echo "         O]nϥΥjgrΫO(Ԩ newmac.ps)"
             echo " "
             echo $echomode "     Press any key to continue " $echcr
             read subkey
             ;;
            
        "q")
           help="0"
           ;;
        *)
           help="1";;
  esac
  done

else

  help="1"

  while test "$help" = "1"
  do
  if test "$secondoption" != "testmenu" -a "$secondoption" != "fontmenu"; then
  clear
  echo " "
  echo "       Choose one of the following:"
  echo " "
  echo "       1. Read README.use*, *.ps about the usage of ChiTeX"
  echo "       2. Read README.* about installation of fonts()"
  echo "       3. Read README.* about others"
  echo "       4. Test demo documents and read source documents"
  echo "       5. The use of chinese fonts commands of Adobe Type1"
#  echo "       4. Use old ttf2pk(ִ xdvi,dvips ʱشѶϢ, "
#  echo "          ޷˳ pk ʱ, Ȼظʹþ ttf2pk,"
#  echo "          ͬʱ(email: yih@math.ncu.edu.tw)ѶϢ)"
#  echo "       5. Use new ttf2pk"
  echo "       q. Quit"
  echo " "
  echo $echomode "        '1', '2'  ,,, ѡȡӦĿ: " $echocr
  read inkey
  clear
  fi

  if test "$secondoption" = "testmenu"; then
     inkey="4"; help="0"
  else 
     if test "$secondoption" = "fontmenu"; then
        inkey="5"; help="0"
     fi
  fi

  case "$inkey" in
       "2")
          subhelp="1"
          while test "$subhelp" = "1"
          do
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. vi README.install.advance.gb "
          echo "       q. quit "
          echo " "
          echo $echomode "        '1', '2'  ,,, ѡȡӦĿ: " $echocr
          read subinkey
          case "$subinkey" in         
             "1")
                 vi $texmf/doc/chitex/README.install.advance.gb
                 ;;
             "q")
                 subhelp="0"
                 ;;
               *)
                 subhelp="1";;
         esac
         done;;
       "1")
          subhelp="1"
          while test "$subhelp" = "1"
          do
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. vi README.use.gb"
          echo "       2. ghostview introgb.ps "
          echo "       3. ghostview newmacgb.ps "
          echo "       4. ghostview maverbgb.ps "
          echo "       q. quit "
          echo " "
          echo $echomode "        '1', '2'  ,,, ѡȡӦĿ: " $echocr
          read subinkey
          case "$subinkey" in         
             "1")
                 vi $texmf/doc/chitex/README.use.gb
                 ;;
             "2")
                 ghostview $texmf/doc/chitex/introgb.ps
                 ;;
             "3")
                 ghostview $texmf/doc/chitex/newmacgb.ps
                 ;;
             "4")
                 ghostview $texmf/doc/chitex/maverbgb.ps
                 ;;
             "q")
                 subhelp="0"
                 ;;
               *)
                 subhelp="1";;
          esac
          done;;
       "3")
          subhelp="1"
          while test "$subhelp" = "1"
          do
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. vi README"
          echo "       2. vi README.first.gb"
          echo "       3. vi README.inst.quick.gb"
          echo "       4. vi README.install.advance.gb"
          echo "       5. vi README.print.gb"
          echo "       6. vi README.fonts.suggetion.gb"
          echo "       7. vi ChangeLog.gb"
          echo "       q. quit "
          echo " "
          echo $echomode "        '1', '2'  ,,, ѡȡӦĿ: " $echocr
          read subinkey
          case "$subinkey" in         
             "1")
                 vi $texmf/doc/chitex/README
                 ;;
             "2")
                 vi $texmf/doc/chitex/README.first.gb
                 ;;
             "3")
                 vi $texmf/doc/chitex/README.inst.quick.gb
                 ;;
             "4")
                 vi $texmf/doc/chitex/README.install.advance.gb
                 ;;
             "5")
                 vi $texmf/doc/chitex/README.print.gb
                 ;;
             "6")
                 vi $texmf/doc/chitex/README.fonts.suggetion.gb
                 ;;
             "7")
                 vi $texmf/doc/chitex/ChangeLog.gb
                 ;;
             "q")
                 subhelp="0"
                 ;;
               *)
                 subhelp="1";;
          esac
          done;;

        "4") 

          demosubmenu (){
          bibind="n"
          case "$cmd" in 
          "math1gb") compilecmd="chitex -xdvi";;
          "math2gb") compilecmd="chitex -xdvi";;
          "samp1gb") compilecmd="chitex -xdvi";;
 #         "samp2gb") compilecmd="chitex -xdvi";;
          "math2gb_pdftex") compilecmd="chitex -pdftex";;
          "math1gb_pdftex") compilecmd="chitex -pdftex";;
          "mabibindgb") compilecmd="chitex"; bibind="y";;
          "ѧgb_chapbib") compilecmd="chitex"; bibind="2";;
          "ѧgb_bibunits") compilecmd="chitex"; bibind="3";;
                *) compilecmd="chitex -psv";;
          esac            
          while test "$subsubhelp" = "1"
          do
            clear
            echo " "
            echo "       Choose one of the following:"
            echo " "
            
              echo "       1. Read source document file:  "
              echo "               $cmd.tex "
              echo "          in $texmf/tex/chinese "

            if test "$bibind" = "y"; then
              echo "       1a. Read source document file:  "
              echo "               $cmd.tex "
              echo "           with help "
            fi
            if test "$bibind" != "n"; then 
              echo "       1b. Read 'bib' file used in bibtex:  "
              echo "               $cmd.bib "
              echo "          in $texmf/tex/chinese "
            fi
            if test "$bibind" = "y"; then 
              echo "       1c. Read 'mymacros.tex' used in defining your "
              echo "           favorite chinese title and others "
            fi

              echo "       2. Compile and preview document: "
              echo "                 $cmd.tex "
              echo "          (choose this is as giving command: "
              echo "             $compilecmd $cmd  ) "
              echo "       q. quit"
              echo " "
           echo $echomode "        '1', '2'  ,,, ѡȡӦĿ: " $echocr
              read subsubkey
              
              case $subsubkey in
              "1")  vi $texmf/tex/chinese/$cmd.tex;;
              "1a")  ghostview $texmf/doc/chitex/$cmd"ps.ps";;
              "1b")  vi $texmf/tex/chinese/$cmd.bib;;
              "1c")  vi $texmf/tex/chinese/mymacros.tex;;
              "2") if test "$bibind" = "n"; then 
                    $compilecmd $cmd 
                   else
                    if test ! -s $cmd.bib; then
                       cp $texmf/tex/chinese/$cmd.bib .
                       chmod +w $cmd.bib
                    fi
            clear
            echo " "; echo " "
            echo "       This document use utlities of bibtex/makeindex "
            echo "       with chinese. It needs excute commands 'cbibtex'"
            echo "       and 'cmakeindex' in addition to command of "
            echo "       compilation. So, the following commands should be"
            echo "       excuted to complete 'compile' :"
            echo "           chitex $cmd "
           if test "$bibind" = "y"; then
            echo "           cbibtex $cmd "
            echo "           cmakeindex $cmd "
           else 
             if test "$bibind" = "2"; then

               if test ! -s ѧ11gb.tex; then
                   cp $texmf/tex/chinese/ѧ11gb.tex .
                   chmod +w ѧ11gb.tex
               fi

               if test ! -s ѧ12gb.tex; then
                   cp $texmf/tex/chinese/ѧ12gb.tex .
                   chmod +w ѧ12gb.tex
               fi

               echo "           cbibtex ѧ11gb "
               echo "           cbibtex ѧ12gb "
             else
               if test "$bibind" = "3"; then

                 if test ! -s $cmd.tex; then 
                    cp $texmf/tex/chinese/$cmd.tex .
                    chmod +w $cmd.tex
                 fi

                 echo "           cbibtex $cmd.1 "
                 echo "           cbibtex $cmd.2 "
               fi
             fi
           fi
            echo "           chitex -psv $cmd "
            echo "           (chitex+dvips+ghostview) "
            echo " "
            echo $echomode "       Press any key to start to excute the above commands: " $echocr
            read xxyyzzz
            echo " "
            echo "       Press any key to excute: "
            echo "                 chitex $cmd " 
            echo $echomode "       :" $echocr
            read xxyyzzz
                       chitex $cmd 
            echo " "
            echo "       Press any key to excute: "

           if test "$bibind" = "y"; then
            echo "                 cbibtex $cmd " 
           else
            if test "$bibind" = "2"; then
              echo "           cbibtex ѧ11gb "
              echo "           cbibtex ѧ12gb "
            else
                 echo "           cbibtex $cmd.1 "
                 echo "           cbibtex $cmd.2 "
            fi
           fi

            echo $echomode "       :" $echocr
            read xxyyzzz

           if test "$bibind" = "y"; then
                       cbibtex $cmd
           else
              if test "$bibind" = "2"; then
                 cbibtex ѧ11gb
                 cbibtex ѧ12gb
              else
                 cbibtex $cmd.1
                 cbibtex $cmd.2
              fi
           fi
                  
           if test "$bibind" = "y"; then
            echo " "
            echo "       Press any key to excute: "
            echo "                 cmakeindex $cmd " 
            echo $echomode "       :" $echocr
            read xxyyzzz
                       cmakeindex $cmd
           fi

            echo " "
            echo "       Press any key to excute: "
            echo "                 chitex -psv $cmd " 
            echo $echomode "       :" $echocr
            read xxyyzzz
                       chitex -psv $cmd

                    fi  
                    ;;

              "q")  subsubhelp="0" ;;
                *)  subsubhelp="1" ;;             
              esac
            done
            }

          subhelp="1"
          demomenu (){
          clear
          echo " "
          echo "       Choose one of the following:"
          echo " "
          echo "       1. Test or read LaTeX document: math2gb.tex"
          echo "       2. Test or read LaTeX document: samp2gb.tex"
          echo "       3. Test or read LaTeX document: charex2gb.tex"
          echo "       4. Test or read LaTeX document: samp1gb.tex"
          echo "       5. Test or read LaTeX document: math2gb_pdftex.tex"
          echo "            (compile with pdftex) "
          echo "       6. Test or read Tex document: math1gb.tex"
          echo "       7. Test or read Tex document: charex1gb.tex"
          echo "       8. Test or read Tex document: math1gb_pdftex.tex"
          echo "            (compile with pdftex) "
          echo "       9. Test or read LaTeX document: mabibindgb.tex"
          echo "            (Test utilities of cbibtex and cmakeindex)"
          echo "      10. Test or read LaTeX document: maverbgb.tex"
          echo "            (Test using chinese in verbatim's like macros)"
          echo "      11. Test or read LaTeX document: ѧgb_chapbib.tex"
          echo "            (Test using chapterbib.sty and chinese filename)"
          echo "      12. Test or read LaTeX document: ѧgb_bibunits.tex"
          echo "            (Test using bibunits.sty and chinese filename)"
          echo "      13. Test or read LaTeX document: ĩ1gb.tex"
          echo "      14. Test or read LaTeX document: sampgb_quotcha.tex"
          echo "            (Test using quotcha.sty)"


          echo "       q. quit "
          echo " "
          echo $echomode "        '1', '2'  ,,, ѡȡӦĿ: " $echocr
          read subinkey          
          case $subinkey in
          "1") cmd="math2gb";subsubhelp="1"
               if test -s lotka.eps; then
                  cp lotka.eps lotka.eps.old
               fi
               if test -s graf3d.eps; then
                  cp graf3d.eps graf3d.eps.old
               fi
               cp $texmf/tex/chinese/*.eps .
               chmod +w *.eps
               demosubmenu;;
          "2") cmd="samp2gb";subsubhelp="1";demosubmenu;;
          "3") cmd="charex2gb";subsubhelp="1";demosubmenu;;
          "4") cmd="samp1gb";subsubhelp="1";demosubmenu;;
          "5") cmd="math2gb_pdftex";subsubhelp="1";demosubmenu;;
          "6") cmd="math1gb";subsubhelp="1";demosubmenu;;
          "7") cmd="charex1gb";subsubhelp="1";demosubmenu;;
          "8") cmd="math1gb_pdftex";subsubhelp="1";demosubmenu;;
          "9") cmd="mabibindgb";subsubhelp="1";demosubmenu;;
          "10") cmd="maverbgb";subsubhelp="1";demosubmenu;;
          "11") cmd="ѧgb_chapbib";subsubhelp="1";demosubmenu;;
          "12") cmd="ѧgb_bibunits";subsubhelp="1";demosubmenu;;
          "13") cmd="ĩ1gb";subsubhelp="1";demosubmenu;;
          "14") cmd="sampgb_quotcha";subsubhelp="1";demosubmenu;;

          "q") subhelp=0;;
          "*") subhelp=1;;
          esac
          }

          while test "$subhelp" = "1"
          do
             demomenu
          done   
          ;;

        "5") clear
             echo "  ChiTeX ָ:"
             echo "    'ȫΪӢĴд'  'ȫΪӢĴд' ָ "
             echo "  1. ûõȫΪӢĴдָ: "
             echo "     ֻʹ TrueType  pk , preview ָ: "
             echo "                 xdvi    chitex -xdvi "
             echo "         :   dvips + ghostview   chitex -psv "
             echo "         , ļ math2gb.tex ļʹָ \\songGB "
             echo "         Ԥ :  chitex -xdvi math2gb   chitex -psv math2gb"
             echo "  2. õȫΪӢĴдָ: "
             echo "     (1) ʹ TrueType  Adobe Type1 "
             echo "     (2) preview ָֻ: "
             echo "                dvips + ghostview "
             echo "         , ļ charex2gb.tex ļʹָ \\SONGGB "
             echo "         Ԥ :"
             echo "            chitex math2gb "
             echo "            dvips math2gb "
             echo "            ghostview math2gb.ps "
             echo "             chitex -psv math2 "          
             echo "     (3) ʹ pdftex ʱ(ָ chitex -pdftex math2gb_pdftex "
             echo "         chitex  -pdftex math2gb_pdftex) ʹȫΪдָ"
             echo "     (4) ʹõ  'б', '', 'п', 'ֱ'"
             echo "         ָҲҪʹȫΪдָ( newmacgb.ps)"
             echo " "
             echo $echomode "     Press any key to continue " $echocr
             read subkey
             ;;

        "q")
           help="0"
           ;;
        *)
           help="1";;
  esac
  done

fi


/bin/rm -f *@
if test -s lotka.eps.old; then
   mv -f lotka.eps.old lotka.eps
else
   /bin/rm -f lotka.eps
fi
if test -s graf3d.eps.old; then
   mv -f graf3d.eps.old graf3d.eps
else
   /bin/rm -f graf3d.eps
fi

/bin/rm -f *.lo* *.aux *.bbl *.dvi *.to* *.blg *.idx *.ind *.ilg

exit
  

