Example #1
0
        bool BibTeXCheck()
        {
            if (!aux.ContainsKey(".aux") || aux[".aux"] == null)
            {
                return(false);
            }
            var  bibcite      = new System.Text.RegularExpressions.Regex("\\\\bibcite\\{(.*?)\\}");
            var  citation     = new System.Text.RegularExpressions.Regex("\\\\citation\\{(.*?)\\}");
            var  bibs         = new List <string>();
            var  cits         = new List <string>();
            bool existbibdata = false;

            Encoding[] encs = KanjiEncoding.GuessKajiEncoding(aux[".aux"]);
            Encoding   enc;

            if (encs.Length == 0)
            {
                enc = Encoding.GetEncoding("shift_jis");
            }
            else
            {
                enc = encs[0];
            }
            using (var fs = new StringReader(enc.GetString(aux[".aux"]))) {
                while (true)
                {
                    string line = fs.ReadLine();
                    if (line == null)
                    {
                        break;
                    }
                    if (!existbibdata && line.IndexOf("\\bibdata{") != -1)
                    {
                        existbibdata = true;
                    }
                    var m = bibcite.Match(line);
                    if (m.Success)
                    {
                        bibs.Add(m.Groups[1].Value);
                    }
                    m = citation.Match(line);
                    if (m.Success)
                    {
                        cits.Add(m.Groups[1].Value);
                    }
                }
            }
            if (!existbibdata)
            {
                return(false);
            }
            cits.Sort(); cits = new List <string>(cits.Distinct());
            bibs.Sort(); bibs = new List <string>(bibs.Distinct());
            return(!(cits.SequenceEqual(bibs)));
        }
Example #2
0
        public static void ImportTeXFile(string path, out string preamble, out string body)
        {
            preamble = null; body = null;
            var extension = Path.GetExtension(path).ToLower();

            byte[] buf;
            using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) {
                buf = new byte[fs.Length];
                fs.Read(buf, 0, (int)fs.Length);
            }

            var  GuessedEncoding = KanjiEncoding.CheckBOM(buf);
            bool bom             = false;

            if (GuessedEncoding != null)
            {
                bom = true;
                buf = KanjiEncoding.DeleteBOM(buf, GuessedEncoding);
            }
            else
            {
                var guessed = KanjiEncoding.GuessKajiEncoding(buf);
                if (guessed.Length == 0)
                {
                    GuessedEncoding = null;
                }
                else
                {
                    GuessedEncoding = guessed[0];
                }
            }
            Encoding encoding;

            switch (Properties.Settings.Default.encode)
            {
            case "euc": encoding = Encoding.GetEncoding("euc-jp"); break;

            case "jis": encoding = Encoding.GetEncoding("iso-2022-jp"); break;

            case "utf8": encoding = Encoding.UTF8; break;

            case "sjis": encoding = Encoding.GetEncoding("shift_jis"); break;

            case "_utf8":
                if (GuessedEncoding != null)
                {
                    encoding = GuessedEncoding;
                }
                else
                {
                    encoding = Encoding.UTF8;
                }
                break;

            case "_sjis":
            default:
                if (GuessedEncoding != null)
                {
                    encoding = GuessedEncoding;
                }
                else
                {
                    encoding = Encoding.GetEncoding("shift_jis");
                }
                break;
            }
            if (encoding.CodePage != GuessedEncoding.CodePage)
            {
                if (bom || MessageBox.Show(String.Format(Properties.Resources.CHECK_ENCODEMSG, encoding.EncodingName, GuessedEncoding.EncodingName, GuessedEncoding.EncodingName), "TeX2img", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
                {
                    encoding = GuessedEncoding;
                }
            }
            using (var sr = new StringReader(encoding.GetString(buf))) {
                if (!TeXSource.ParseTeXSourceFile(sr, out preamble, out body))
                {
                    MessageBox.Show(Properties.Resources.ANALYZESOURCEERROR, "TeX2img");
                }
            }
        }