Пример #1
0
 public LaTeXDocument(
     LaTeXCfg config,
     string html,
     string selection = null)
 {
     Config    = config;
     Html      = html;
     Selection = selection ?? html;
 }
Пример #2
0
        private void LoadConfigOrDefault()
        {
            Config = Svc.Configuration.Load <LaTeXCfg>().Result;

            if (Config == null || Config.IsValid() == false)
            {
                Config = LaTeXConst.Default;

                //Svc.Configuration.Save(Config).ConfigureAwait(false);
            }
        }
        public static (bool success, string pathOrError) GenerateImgFile(LaTeXCfg config)
        {
            string imgFilePath = GetPlaceholderValue(config.ImageGenerationCmd.Last());

            if (File.Exists(imgFilePath))
            {
                File.Delete(imgFilePath);
            }

            var(success, output) = Execute(config.ImageGenerationCmd, config.ExecutionTimeout);

            return(success, success ? imgFilePath : output);
        }
Пример #4
0
        public static (bool success, string pathOrError) GenerateImgFile(LaTeXCfg config)
        {
            string imgFilePath = GetPlaceholderValue(config.ImageGenerationCmd.FirstOrDefault(s => s.StartsWith("{outImg}")));

            if (File.Exists(imgFilePath))
            {
                File.Delete(imgFilePath);
            }

            var(success, output) = Execute(config.ImageGenerationCmd, config.ExecutionTimeout);

            // Log for debugging purpose
            LogTeXLogs();

            return(success, success ? imgFilePath : output);
        }
        public static (bool success, string pathOrError) GenerateDviFile(LaTeXCfg config,
                                                                         LaTeXTag tag,
                                                                         string latexContent)
        {
            if (File.Exists(LaTeXConst.Paths.TempTexFilePath))
            {
                File.Delete(LaTeXConst.Paths.TempTexFilePath);
            }

            if (File.Exists(LaTeXConst.Paths.TempDviFilePath))
            {
                File.Delete(LaTeXConst.Paths.TempDviFilePath);
            }

            latexContent = tag.LaTeXBegin + latexContent + tag.LaTeXEnd;

            File.WriteAllText(LaTeXConst.Paths.TempTexFilePath,
                              latexContent);
            var(success, output) = Execute(config.DviGenerationCmd, config.ExecutionTimeout);

            return(success, success ? LaTeXConst.Paths.TempDviFilePath : output);
        }
        public static (bool success, string pathOrError) GenerateDviFile(LaTeXCfg config,
                                                                         LaTeXTag tag,
                                                                         string latexContent)
        {
            // Make sure to delete existing .tex, .dvi or .log file to start with a clean slate
            if (File.Exists(LaTeXConst.Paths.TempTexFilePath))
            {
                File.Delete(LaTeXConst.Paths.TempTexFilePath);
            }

            if (File.Exists(LaTeXConst.Paths.TempDviFilePath))
            {
                File.Delete(LaTeXConst.Paths.TempDviFilePath);
            }

            if (File.Exists(LaTeXConst.Paths.TexErrorLog))
            {
                File.Delete(LaTeXConst.Paths.TexErrorLog);
            }

            // Build .tex file content and write it
            latexContent = tag.LaTeXBegin + latexContent + tag.LaTeXEnd;

            File.WriteAllText(LaTeXConst.Paths.TempTexFilePath, latexContent);

            // Log for debugging purpose
            LogTo.Verbose(
                "Wrote TeX file {TempTexFilePath}:\r\n\r\n-------------------------------------------------\r\n{LatexContent}\r\n-------------------------------------------------\r\n",
                LaTeXConst.Paths.TempTexFilePath, latexContent);

            // Build the .dvi from the .tex file using dvi2png or another processor depending on user's config
            var(success, output) = Execute(config.DviGenerationCmd, config.ExecutionTimeout);

            // Log for debugging purpose
            LogTeXLogs();

            return(success, success ? LaTeXConst.Paths.TempDviFilePath : output);
        }