Ejemplo n.º 1
0
        public void IsStandaloneTest()
        {
            string code     = string.Empty; // TODO: Initialize to an appropriate value
            bool   expected = false;        // TODO: Initialize to an appropriate value
            bool   actual;

            actual = TexCompiler.IsStandalone(code);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Starts the compilation.
        /// </summary>
        /// <param name="TexCode">The raw Tex code, possibly without preamble.</param>
        /// <param name="OutputFile">The desired output file. The extension determines the file type.</param>
        public void DoCompile(string TexCode, string OutputFile)
        {
            DesiredOutputFile = OutputFile;
            WorkingDir        = Directory.GetCurrentDirectory();



            // add pre- and postamble if file is not standalone... don't use precompiled headers here since we need
            // to add a \def\pgfsysdriver{pgfsys-tex4ht.def}
            if (!TexCompiler.IsStandalone(TexCode))
            {
                TexCode = CompilerSettings.Instance.Tex_Preamble
                          + Environment.NewLine
                          + "\\begin{document}"
                          + Environment.NewLine
                          + TexCode
                          + Environment.NewLine
                          + CompilerSettings.Instance.Tex_Postamble;
            }

            switch (System.IO.Path.GetExtension(OutputFile).ToLower())
            {
            case ".htm":
            case ".html":
            case ".svg":
                // inject a \def\pgfsysdriver{pgfsys-tex4ht.def} after the line with \documentclass
                TexCode = InsertAfterDocumentClass(TexCode, @"\def\pgfsysdriver{pgfsys-tex4ht.def}");
                break;

            default:
                AddStatusLine("Error: unsupported file type: " + System.IO.Path.GetExtension(OutputFile));
                return;
            }

            // get a temp filename and save the tex file
            TempFile = Consts.cTempExportFile + DateTime.Now.Ticks.ToString();
            try
            {
                File.WriteAllText(TempFile + ".tex", TexCode);
            }
            catch (Exception)
            {
                AddStatusLine("Failed to save temporary tex file to: " + TempFile + ".tex");
                AddStatusLine("Export cancelled");
                return;
            }

            // finally run htlatex...
            texProcess.StartInfo.Arguments = TempFile + ".tex"; // ".tex \"\" \"\" \"\" \"-interaction=nonstopmode \"";
            AddStatusLine("Running htlatex: " + texProcess.StartInfo.FileName + " " + texProcess.StartInfo.Arguments);
            texProcess.Start();
            texProcess.BeginOutputReadLine();
        }