# File rtex.rb, line 1447
def start_from_desktop( )
        #Create the logger and initialize the program
        log    = Logger.create()
        run    = Chain.new()
        run.pdflatex()
        gui    = false
        
        opt    = GetoptLongWithHelp.new(
                        [ "--level", '-l', GetoptLong::REQUIRED_ARGUMENT ],
                        [ "--action",        '--chain', 
                                                '-a', GetoptLong::REQUIRED_ARGUMENT ],
                        [ "--overfull", '-o',GetoptLong::REQUIRED_ARGUMENT ],
                        [ "--underfull", '-u',GetoptLong::REQUIRED_ARGUMENT ],
                        [ "--precompile", '-p',GetoptLong::REQUIRED_ARGUMENT ],
                        [ "--nohyperrefwarnings", GetoptLong::NO_ARGUMENT ],
                        [ "--gui",           '-g',GetoptLong::NO_ARGUMENT ],
                        [ "--wait",  '-w', GetoptLong::NO_ARGUMENT ]
                )
        opt.addHelp2('--level', %Q|set the level of informations you get.
                0 No information at all
                1 Tool-Error + Summary information from TeX
                2 Level 1 + Summary information from tools
                3 Level 2 + Executed steps + Statistics + Errors
                4 Level 3 + Warnings
                5 Level 4 + hints from process
                6 Level 5 + detailed hints from process
                9 Everything
                All levels are reported in the Log-File|.gsub(/^\t/, ''))
        opt.addHelp2( '-a', %Q|Define the action chain
                A chain defines the steps from source to the target.
                - pdfLaTeX    [default]
                - LaTeX
                - LaTeXPS     Call LaTeX and then create a 
                                Postscript file (dvips)
                - LaTeXPSPDF  Call LaTeX and then create a PDF 
                                via dvips and ghostscript
                -LaTeXPDF     Call LaTeX and then create a PDF with dvipdfm
                remark:       Each tool may define a "subchain"
                        (pdf)LaTeX calls bibtex, makeindex, rail if necessary|.gsub(/^\t/, ''))
        opt.addHelp2( '-o',    "Set the limit, from which overfull boxes are reported")
        opt.addHelp2( '-u',    "Set the limit, from which underfull boxes are reported")
        opt.addHelp2( '-w',    "Wait after finishing the script\n\t(helpfull, when started by another programms)")
        opt.addHelp2( '-g',    "Call GUI" )
        opt.addHelp2( '-p',    %q|The given file(s) are precompiled.
                Conversions of the precompiler:
                - listings.sty:
                        \lstinputlisting[fromlabel=<label>,tolabel=<label>]{file} to 
                        \lstinputlisting[firstline=<num>,lastline=<num>] {file}
                        file must contain tags like "TeXlabel{label}"
                        
        |.gsub(/^\t/, ''))
        opt.mkHelp( %q|runtex.rb: Translate a TeX-File.
                This tool checks, how often the file must be translated to 
                create a document with correct references.
                Usage:
                        runtex.rb [switches] source[.tex]
                Switches:|.gsub(/^\t\t/, ''),
        %q|-h <switch> for details of option <switch>
                Known Problems:
                - Not tested on different systems (PS2PDF will work only on windows)
                - The errors statistic count some errors twice (or do you want to loose errors)
                - index.sty is not supported. Use index2.sty instead 
                        (I hope it is obsolete for the future)
                Detailed informations: http://www.lickert.net/dev/ruby/rtex|.gsub(/^\t\t/, '')
        )

        opt.each{ |option, selection|
                selection = selection.downcase()
                case option
                when '--help'
                        puts opt.help( selection )
                        STDIN.getc if @@wait
                        exit
                when '--HELP'
                        puts opt.help( '--HELP' )
                        STDIN.getc if @@wait
                        exit
                when '--level'
                        log.level=selection.to_i
                when '--action'
                        case selection 
                        when 'latex'
                                run.latex()
                        when 'pdflatex'
                                run.pdflatex
                        when 'latexps'
                                run.latex_ps
                        when 'latexpdf'
                                run.latex_pdf
                        when 'latexpspdf'
                                run.latex_ps_pdf
                        when 'htlatex'
                                run.htlatex
                        else
                                puts "Action chain #{selection} not valid"
                                STDIN.getc if @@wait
                                exit
                        end  #case selection
                when '--overfull'     #set tolerance for overfull boxes
                        Config.overfull= selection.to_i
                when '--underfull'    #set tolerance for underfull boxes
                        Config.underfull= selection.to_i
                when '--nohyperrefwarnings'   #Display no warnings of hyperref
                        Config.showhyperrefwarning= false
                when '--wait' #Wait after running the script
                        @@wait = true
                when '--precompile'
                        selection.each{|f|
                                Precompile.mix_references!( f )
                                }
                when '--gui'  #call GUI for settings
                        gui = true
                else
                        puts "Option #{option}#{selection} not known\nUse -h for help"
                        STDIN.getc if @@wait
                        exit
                end   #case otion
        }
        if ARGV.size == 0
                #Message if called by exe created with rubyscript2exe
                puts "Add file to translate or -h for help" if /app.rb/ =~ $0
        end 
        ARGV.each{|arg|
                        run.file=( arg )
        }

        puts "No TeX-File given" if !run.filename
        if gui
                run.file = Dir.pwd() + '/test.tex' if !run.filename   #fixme
                gui( run )
        else
                run.execute()
                log.save(Config.logfile)
        
                puts "Thanks for using #{File.basename($0)}."
                STDIN.getc if @@wait
        end

end