示例#1
0
        public void ExportFileTest()
        {
            TexCompiler tc = new TexCompiler();                     
            //MainWindowVM parent = new MainWindowVM(tc); // TODO: Initialize to an appropriate value
            TEDocumentVM target = new TEDocumentVM(null, tc);           

            GlobalUI.MockResult = MessageBoxResult.Cancel;
            GlobalUI.LastMessage = "";
            string jpgfile = GlobalUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\test.jpg";
            if (File.Exists(jpgfile))
                File.Delete(jpgfile);
            GlobalUI.MockFileDialogResult = true;
            target.ExportFileCommand.Execute(null);
            Assert.IsTrue(File.Exists(jpgfile));
            
            // now save file, and try again with different extension
            string filename = GlobalUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\" + "temp2.tex";
            GlobalUI.MockFileDialogResult = true;
            target.SaveCurFile();

            jpgfile = GlobalUI.MockFileDialogFileName = GlobalUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\test.png";
            if (File.Exists(jpgfile))
                File.Delete(jpgfile);
            target.ExportFileCommand.Execute(null);
            // check that file is actually there
            Assert.IsTrue(File.Exists(jpgfile));

        }
示例#2
0
        public void TestSetup()
        {
            tc = new TexCompiler();
            tc.JobDone += (s, e) => { LastReceivedJob = e.job; LastReceivedEA = e; JobFailed_Reported = e.ExitCode != 0; };                  

            LastReceivedJob = null;
            LastReceivedEA = null;
            JobFailed_Reported = false;
        }
示例#3
0
        public void SavePdfTest()
        {
            TexCompiler tc = new TexCompiler();
            //MainWindowVM parent = new MainWindowVM(tc); // TODO: Initialize to an appropriate value
            string cFile = string.Empty; // TODO: Initialize to an appropriate value
            TEDocumentVM<AvalonDocumentWrapper> target = new TEDocumentVM<AvalonDocumentWrapper>(null, tc); 
            string filename = GlobUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\" + "temp2.tex";
            GlobUI.MockFileDialogResult = true;
            target.SaveCurFile();
            
            Thread.Sleep(1000);

            target.SavePdf(false);

            Assert.IsTrue(File.Exists(Helper.RemoveFileExtension(filename)+".pdf"));
            
        }
示例#4
0
        public void SavePdfTest()
        {
            TexCompiler tc = new TexCompiler();
            //MainWindowVM parent = new MainWindowVM(tc); // TODO: Initialize to an appropriate value
            string cFile = string.Empty; // TODO: Initialize to an appropriate value
            TEDocumentVM target = new TEDocumentVM(null, tc);
            GlobalUI.MockResult = MessageBoxResult.Cancel;
            GlobalUI.LastMessage = "";
            // try to save pdf -> should not work, file should be saved first
            string pdffile = target.SavePdf(false);
            Assert.AreEqual("", pdffile);
            
            // now save file                      
            string filename = GlobalUI.MockFileDialogFileName = Directory.GetCurrentDirectory() + "\\" + "temp2.tex";
            GlobalUI.MockFileDialogResult = true;
            target.SaveCurFile();

            pdffile = target.SavePdf(false);            
            Assert.That(pdffile, Is.EqualTo(Helper.RemoveFileExtension(filename) + ".pdf").IgnoreCase);

            // check that file is actually there
            Assert.IsTrue(File.Exists(pdffile));

        }
示例#5
0
 void Instance_OnTexOutput(object sender, TexCompiler.CompileEventArgs e)
 {
     //this.BeginInvoke(new InvokeDelegate(() =>
     //{
         txtTexOutput.AppendText(e.Message + Environment.NewLine);
     //}));
 }
示例#6
0
 void Instance_OnCompileEvent(object sender, TexCompiler.CompileEventArgs e)
 {
     AddStatusLine(e.Message, e.Type == TexCompiler.CompileEventType.Error);
     if (e.Type == TexCompiler.CompileEventType.Start)
         txtTexOutput.Clear();
 }
示例#7
0
        public void TryDisposeFileTest()
        {
            TexCompiler tc = new TexCompiler();
            //MainWindowVM parent = new MainWindowVM(tc); // TODO: Initialize to an appropriate value
            TEDocumentVM target = new TEDocumentVM(null, tc);

            GlobalUI.MockResult = MessageBoxResult.Cancel;
            GlobalUI.LastMessage = "";

            // no changes made -> user should not be asked
            bool ret = target.TryDisposeFile();
            Assert.AreEqual(GlobalUI.LastMessage, "");
            Assert.IsTrue(ret);

            // make a change 
            target.Document.Insert(0, " ");
            ret = target.TryDisposeFile();
            Assert.AreNotEqual(GlobalUI.LastMessage, "");
            Assert.IsFalse(ret);
            Assert.IsTrue(target.ChangesMade);

            // say we don't want to save changes
            GlobalUI.MockResult = MessageBoxResult.No;
            ret = target.TryDisposeFile();
            Assert.IsTrue(ret);

        }
示例#8
0
 /**
  * Updates the stack that determines which file we are currently
  * parsing, so that errors can be annotated in the correct file. 
  * 
  * @param logLine A line from latex' output containing which file we are in
  */
 private static void updateParsedFile(String logLine, TexCompiler.Job job, Stack<string> parsingStack, List<TexError> ErrorList, ref bool alreadyShowError)
 {
     if (logLine.IndexOf('(') == -1 && logLine.IndexOf(')') == -1)
         return;
     for (int i = 0; i < logLine.Length; i++)
     {
         if (logLine[i] == '(')
         {
             int j;
             for (j = i + 1; j < logLine.Length
                     && isAllowedinName(logLine[j]); j++)
                 ;
             parsingStack.Push(logLine.Substring(i, j-i).Trim());
             i = j - 1;
         }
         else if (logLine[i] == ')' && !(parsingStack.Count == 0))
         {
             parsingStack.Pop();
         }
         else if (logLine[i] == ')' && !alreadyShowError)
         {
             alreadyShowError = true;
             // There was a parsing error, this is very rare
             string err = "Error while parsing the LaTeX output. " +
                     "Please consult the console output";
             GlobalUI.UI.AddStatusLine(null, err, true);
             addProblemMarker(err, "file", 0, Severity.ERROR, job, ErrorList);
         }
     }
 }
示例#9
0
        /// <summary>
        /// clears the current code
        /// </summary>
  //      public void Clear()
  //      {
  //          WholeOutput = "";
  //      }

  /*      public TexOutputParser()
        {
            parsingStack = new Stack<string>();
            parseNewOutput();
        }
        private void parseNewOutput()
        {
            parsingStack.Clear();
            alreadyShowError = false;
            citeNotfound = false;
            hasProblem = false;
            error = "";
            occurance = "";
            linenr = -1;
            severity = Severity.WARNING;
            errorsFound = false;
            WholeOutput = "";
        } */

        public static ParseResult parseOutput( string WholeOutput, TexCompiler.Job job)
        {
            List<TexError> ErrorList = new List<TexError>();
            ParseResult ret = new ParseResult() { Errors= ErrorList, ErrorsFound=false };

            //if WholeOutput is not complete, ignore it. However, this should NEVER happen.
            if (!WholeOutput.Contains("Transcript written on"))
            {
                ret.ErrorsFound = true;
                return ret;
            }

            Stack<String> parsingStack = new Stack<string>();
            bool alreadyShowError = false;
            bool citeNotfound = false;
            bool hasProblem = false;
            string error = "";
            string occurance = "";
            int linenr = -1;
            Severity severity = Severity.WARNING;
            bool errorsFound = false;
            

            WholeOutput = DebreakLines(WholeOutput);


            //take WholeOutput and use each line as token
            StringTokenizer st = new StringTokenizer(WholeOutput, Environment.NewLine);

            Regex LATEXERROR = new Regex("^! LaTeX Error: (.*)$");
            Regex LATEXCERROR = new Regex("^(.+?\\.\\w{3}):(\\d+): (.+)$");
            Regex TEXERROR = new Regex("^!\\s+(.*)$");            
            Regex FULLBOX = new Regex("^(?:Over|Under)full \\\\[hv]box .* at lines? (\\d+)-?-?(\\d+)?");
            Regex WARNING = new Regex("^.+[Ww]arning.*: (.*)$");
            Regex ATLINE = new Regex("^l\\.(\\d+)(.*)$");
            Regex ATLINE2 = new Regex(".* line (\\d+).*");
            Regex NOBIBFILE = new Regex("^No file .+\\.bbl\\.$");
            Regex NOTOCFILE = new Regex("^No file .+\\.toc\\.$");

            String line = "";
            while (st.hasMoreTokens())
            {
                line = st.nextToken();

                #region Skipped
                /* //This is assumed to be performed before adding lines to WholeOutput by calling addLine()
                //Add more lines if line length is a multiple of 79 and
                //it does not end with ...
                while (!line.endsWith("...") && st.hasMoreTokens()
                      && line.length() % MAX_LINE_LENGTH == 0)
                {
                    line = line + st.nextToken();
                }
                */
                #endregion 

                //not sure what this is good for
                line = line.Replace(" {2,}", " ").Trim();

                Match m = LATEXCERROR.Match(line);
                if (m.Success)
                {
                    //C-Style LaTeX error
                    addProblemMarker(m.Groups[3].Value, m.Groups[1].Value, Convert.ToInt32(m.Groups[2]), Severity.ERROR, job, ErrorList);
                    //Maybe parsingStack is empty...
                    if (parsingStack.Count == 0)
                    {
                        //Add the file to the stack
                        parsingStack.Push("(" + m.Groups[1]);
                    }
                    continue;
                }

                 m = TEXERROR.Match(line);
                if (m.Success && line.IndexOf("warning", StringComparison.InvariantCultureIgnoreCase) == -1)
                {
                    if (hasProblem)
                    {
                        // We have a not reported problem
                        addProblemMarker(error, occurance, linenr, severity, job, ErrorList);
                        linenr = -1;
                    }
                    hasProblem = true;
                    errorsFound = true;
                    severity = Severity.ERROR;
                    occurance = determineSourceFile(parsingStack);
                    Match m2 = LATEXERROR.Match(line);
                    if (m2.Success)
                    {
                        // LaTex error
                        error = m2.Groups[1].Value; ;


                        String part2 = st.nextToken().Trim();

                        if (part2 != "" && Char.IsLower(part2[0]))
                        {
                            error += ' ' + part2;
                        }
                        updateParsedFile(part2, job, parsingStack, ErrorList, ref alreadyShowError);
                        continue;
                    }
                    if (line.StartsWith("! Undefined control sequence."))
                    {
                        // Undefined Control Sequence
                        error = "Undefined control sequence: ";
                        continue;
                    }
                    m2 = WARNING.Match(line);
                    if (m2.Success)
                        severity = Severity.WARNING;
                    error = m.Groups[1].Value;
                    continue;
                }
                m = WARNING.Match(line);
                if (m.Success)
                {
                    if (hasProblem)
                    {
                        // We have a not reported problem
                        addProblemMarker(error, occurance, linenr, severity, job, ErrorList);
                        linenr = -1;
                        hasProblem = false;
                    }
                    if (line.IndexOf("Label(s) may have changed.") > -1)
                    {
                        // prepare to re-run latex
                        /*TexlipseProperties.setSessionProperty(resource.getProject(),
                                TexlipseProperties.SESSION_LATEX_RERUN, "true");*/
                        GlobalUI.UI.AddStatusLine(null, "SHOULD RERUN LATEX.", true);
                        continue;
                    }
                    else if (line.IndexOf("There were undefined") > -1)
                    {
                        if (citeNotfound)
                        {
                            // prepare to run bibtex
                            /*TexlipseProperties.setSessionProperty(resource.getProject(),
                                    TexlipseProperties.SESSION_BIBTEX_RERUN, "true");*/
                            GlobalUI.UI.AddStatusLine(null, "SHOULD RERUN BIBTEX.", true);
                        }
                        continue;
                    }

                    // Ignore undefined references or citations because they are
                    // found by the parser
                    if (line.IndexOf("Warning: Reference `") > -1)
                        continue;
                    if (line.IndexOf("Warning: Citation `") > -1)
                    {
                        citeNotfound = true;
                        continue;
                    }
                    severity = Severity.WARNING;
                    occurance = determineSourceFile(parsingStack);
                    hasProblem = true;
                    if (line.StartsWith("LaTeX Warning: ") || line.IndexOf("pdfTeX warning") != -1)
                    {
                        error = m.Groups[1].Value;
                        //Try to get the line number
                        Match pm = ATLINE2.Match(line);
                        if (pm.Success)
                        {
                            linenr = Convert.ToInt32(pm.Groups[1].Value);
                        }

                        String nextLine = st.nextToken().Replace(" {2,}", " ");
                        pm = ATLINE2.Match(nextLine);
                        if (pm.Success)
                        {
                            linenr = Convert.ToInt32(pm.Groups[1].Value);
                        }
                        updateParsedFile(nextLine, job, parsingStack, ErrorList, ref alreadyShowError);
                        error += nextLine;
                        if (linenr != -1)
                        {
                            addProblemMarker(line, occurance, linenr, severity, job, ErrorList);
                            hasProblem = false;
                            linenr = -1;
                        }
                        continue;
                    }
                    else
                    {
                        error = m.Groups[1].Value;
                        //Try to get the line number
                        Match pm = ATLINE2.Match(line);
                        if (pm.Success)
                        {
                            linenr = Convert.ToInt32((pm.Groups[1].Value));
                        }
                        continue;
                    }
                }
                m = FULLBOX.Match(line);
                if (m.Success)
                {
                    if (hasProblem)
                    {
                        // We have a not reported problem
                        addProblemMarker(error, occurance, linenr, severity, job, ErrorList);
                        linenr = -1;
                        hasProblem = false;
                    }
                    severity = Severity.WARNING;
                    occurance = determineSourceFile(parsingStack);
                    error = line;
                    linenr = Convert.ToInt32(m.Groups[1].Value);
                    addProblemMarker(line, occurance, linenr, severity, job, ErrorList);
                    hasProblem = false;
                    linenr = -1;
                    continue;
                }
                m = NOBIBFILE.Match(line);
                if (m.Success)
                {
                    // prepare to run bibtex
                    GlobalUI.UI.AddStatusLine(null, "SHOULD RUN BIBTEX.", true);
                    continue;
                }
                m = NOTOCFILE.Match(line);
                if (m.Success)
                {
                    // prepare to re-run latex
                    GlobalUI.UI.AddStatusLine(null, "SHOULD RERUN LATEX.", true);
                    continue;
                }
                m = ATLINE.Match(line);                
                if (hasProblem && m.Success)
                {
                    linenr = Convert.ToInt32(m.Groups[1].Value);
                    String part2 = st.nextToken();
                    int index = line.IndexOf(' ');
                    if (index > -1)
                    {
                        error += " " + line.Substring(index).Trim() + " (followed by: "
                                + part2.Trim() + ")";
                        addProblemMarker(error, occurance, linenr, severity, job, ErrorList);
                        linenr = -1;
                        hasProblem = false;
                        continue;
                    }
                }
                m = ATLINE2.Match(line);
                if (hasProblem && m.Success)
                {
                    linenr = Convert.ToInt32(m.Groups[1].Value);
                    addProblemMarker(error, occurance, linenr, severity, job, ErrorList);
                    linenr = -1;
                    hasProblem = false;
                    continue;
                }
                updateParsedFile(line, job, parsingStack, ErrorList, ref alreadyShowError);

            }

            if (hasProblem)
            {
                // We have a not reported problem
                
                  // do not add "==> Fatal error blabla " to error list (is not an error)
                  //addProblemMarker(error, occurance, linenr, severity);
                //hasProblem = false;
            }
            ret.ErrorsFound = errorsFound;
            return ret;
        }
示例#10
0
 /// <summary>
 /// Private function that is called for each found problem in output of pdflatex when
 /// calling parseOutput(). addProblemMarker() fits the arguments into addProblemEventArgs
 /// so that addProblemEventHandler addProblem can be triggered. 
 /// </summary>
 private static void addProblemMarker(String error, String causingSourceFile, int linenr, Severity severity, TexCompiler.Job job, List<TexError> AddToThisList)
 {
    // if (OnTexError != null)
    // {
         TexError e = new TexError();
         e.error = error;
         e.causingSourceFile = causingSourceFile;
         e.Line = linenr;
         if (job != null)
         {
             if (e.causingSourceFile == null)
                 e.inincludefile = true;
             else
                 e.inincludefile = (String.Compare(e.causingSourceFile.Trim().Replace('/','\\'),
                                     System.IO.Path.GetFullPath(job.path), true) != 0);
             if (!e.inincludefile && linenr > 0)
             {                        
                 e.Line = job.TempFileLineToEditorLine(e.Line);                        
             }
             if (!e.inincludefile && e.causingSourceFile != null)
             {
                 // trim preview file ending.
                 e.causingSourceFile = e.causingSourceFile.Trim();
                 if (e.causingSourceFile.EndsWith(Consts.PreviewFilename+Consts.PreviewFilenameExt))
                     e.causingSourceFile = e.SourceFileName.Substring(0, (e.SourceFileName.Length - Consts.PreviewFilename.Length - Consts.PreviewFilenameExt.Length));
             }
         }
         e.Pos = -1;
         e.severity = severity;
         AddToThisList.Add(e);
  //       OnTexError(this, e, job);
  //   }
 }
 void TexCompiler_OnCompileEvent(object sender, string Message, TexCompiler.CompileEventType type)
 {
     AddStatusLine(Message, type == TexCompiler.CompileEventType.Error);
     if (type == TexCompiler.CompileEventType.Start)
     {
         txtTexout.Document.Blocks.Clear();
         clearProblemMarkers();
     }
 }
        void TheCompiler_JobSucceeded(object sender, TexCompiler.Job job)
        {
            // it may happen that pdflatex returns after a new document has been created->then don't load the pdf
            if (job.DocumentID == CurDocumentID)
            {
                if (!job.GeneratePrecompiledHeaders)
                {
                    // set the currrent BB
                    if (job.hasBB && !job.GeneratePrecompiledHeaders)
                    {
                        currentBB = job.BB;
                    }

                    // (re-)load the pdf to display                
                    string pdfpath = Helper.RemoveFileExtension(job.path) + ".pdf";
                    tikzDisplay1.PdfPath = pdfpath;
                }
            }
        }
 // this is called upon latex error,... the error is extracted from the latex output in the TexCompiler class
 void addProblemMarker(object sender, TexOutputParser.TexError err, TexCompiler.Job job = null) //String error, int linenr, TexCompiler.Severity severity)
 {
     // if job = null, the error was generated by the parser => always display
     // otherwise display only if the job really was the current document
     if (job == null || job.DocumentID == CurDocumentID)
         TexErrors.Add(err);            
 }
示例#14
0
 /// <summary>
 /// Private function that is called for each found problem in output of pdflatex when
 /// calling parseOutput(). addProblemMarker() fits the arguments into addProblemEventArgs
 /// so that addProblemEventHandler addProblem can be triggered. 
 /// </summary>
 private void addProblemMarker(String error, String causingSourceFile, int linenr, Severity severity, TexCompiler.Job job)
 {
     if (OnTexError != null)
     {
         TexError e = new TexError();
         e.error = error;
         e.causingSourceFile = causingSourceFile;
         e.linenr = linenr;
         if (job != null)
         {
             if (e.causingSourceFile == null)
                 e.inincludefile = true;
             else
                 e.inincludefile = (String.Compare(e.causingSourceFile.Trim(),
                                     System.IO.Path.GetFullPath(job.path), true) != 0);
             if (!e.inincludefile && linenr > 0)
             {                        
                 e.linenr = job.TempFileLineToEditorLine(e.linenr);                        
             }
             if (!e.inincludefile)
             {
                 //trim preview file ending.
                 e.causingSourceFile = e.SourceFileName.Substring(0, (e.SourceFileName.Length - Helper.GetPreviewFilename().Length - Helper.GetPreviewFilenameExt().Length));
             }
         }
         e.pos = -1;
         e.severity = severity;
         OnTexError(this, e, job);
     }
 }
示例#15
0
    void TexCompiler_OnCompileEvent(object sender, TexCompiler.CompileEventArgs e)
    {
        AddStatusLine(e.Message, e.Type == TexCompiler.CompileEventType.Error);
        if (e.Type == TexCompiler.CompileEventType.Start)
        {
            txtTexout.Document.Blocks.Clear();
            //clearProblemMarkers();
        }
 
    } 
示例#16
0
 private void TexCompiler_OnTexOutput(object sender, TexCompiler.CompileEventArgs e)
 {
     //add whole line as paragraph to txtTexout
     Paragraph p = new Paragraph();
     p.Margin = new Thickness(0);
     p.Inlines.Add(new Run(e.Message));
     txtTexout.Document.Blocks.Add(p);
     EditingCommands.MoveToDocumentEnd.Execute(null, txtTexout);
     txtTexout.ScrollToEnd();
 }