Example #1
0
        public List <string> ParseLine()
        {
            List <string> output = new List <string>();
            StringBuilder sb     = new StringBuilder();

            using (StreamReader r = this)
            {
                sb.Append(r.ReadLine());
                while (CountChar(sb.ToString(), '{') != CountChar(sb.ToString(), '{'))
                {
                    sb.Append(r.ReadLine());
                }
            }

            int j = 1;

            //MatchCollection mc = Regex.Matches(output[0], TeX.RegexLine);

            //foreach (Match m in mc)
            //{
            //    output[0] = output[0].Replace(m.ToString(), "{" + j++ + "}");
            //    output.Add(m.ToString());
            //}
            return(TeX.ReadLine(sb.ToString()));
        }
Example #2
0
        /// <summary>
        /// What I'm thinking is that you pass the entire
        /// \begin{thing} to \end{thing} and it'll work
        /// everything else out from that. We can handle
        /// subfigures as well.
        /// </summary>
        /// <param name="teX"></param>
        public Diagram(string teX)
        {
            // We need to know which figure number we are.
            Number  = ++_Number;
            Files   = new List <FileInfo>();
            Caption = new Dictionary <string, List <string> >();
            Label   = new List <string>();
            string line = teX.Replace("\n", "").Replace("\r", "");

            line = Regex.Replace(line, "\\s+", " ");

            List <string> optionalCaption = TeX.GetTeXPart(line, "caption", '[', ']');

            foreach (string file in TeX.GetTeXPart(line, "includegraphics"))
            {
                Files.Add(new FileInfo(file));
            }

            Label = TeX.GetTeXPart(line, "label");

            foreach (string c in TeX.GetTeXPart(line, "caption"))
            {
                Caption.Add(c, optionalCaption);
            }
        }
Example #3
0
        public void EscapedCommentChar()
        {
            List <string> line        = TeX.ReadLine(@"This is a line with an escaped \% in it. % not kidding");
            List <string> correctLine = new List <string>();

            correctLine.Add(@"This is a line with an escaped % in it. ");

            Assert.AreEqual(line, correctLine);
        }
Example #4
0
        public void LineIn()
        {
            string        line   = "let's get TeXy with \\things and \\textbf{otherThings}% Complete with commenty goodness \\% % ahoyhoy";
            List <string> o      = new List <string>();
            List <string> output = TeX.ReadLine(line);

            o.Add("let's get TeXy with {1} and {2}");
            o.Add("\\things");
            o.Add("\\textbf{otherThings}");

            Assert.AreEqual(output, o);
        }
Example #5
0
        public void ReplaceTex()
        {
            List <string> tex = new List <string>();

            tex.Add(@"This is {1} line with a citation {2}");
            tex.Add(@"\\textbf{a tex}");
            tex.Add(@"\\cite{person}");

            for (int i = 1; i < tex.Count; i++)
            {
                string output = TeX.ReplaceTeX(tex[i]);
            }
        }
Example #6
0
        public void ParseHeader()
        {
            #region Regexs

            // \thing{blah}
            string regexPattern = @"\\(w+)\{(\w+)\}";
            //\thing[optionalBlah]{blah}
            string regexPatternOptionals = @"\\(\w+)\[(\w+)\]\{(\w+)\}";
            //\thing{blah1}{blah2}
            string regexPatternMacro = @"\\(\w+)\{(\w+)\}\{(\w+)\}";
            //\thing
            string regexPatternNoParams = @"\\(\w+)";

            #endregion Regexs

            bool done = false; // keep reading header information until I say so!

            // Let us begin...
            using (StreamReader r = this)
            {
                StringBuilder sb = new StringBuilder();

                while (!done && !r.EndOfStream)
                {
                    string line = r.ReadLine();

                    // We should ignore the line if it's empty and move on.
                    while (line == Environment.NewLine)
                    {
                        line = r.ReadLine();
                    }

                    // We need to make sure we have the whole statement.
                    while (line.Replace("\n", "").Replace("\r", "").Replace(" ", "").Length > 0 ||
                           (TeX.Count(line, new List <char>()
                    {
                        '{', '['
                    })
                            != TeX.Count(line, new List <char>()
                    {
                        '}', ']'
                    })))
                    {
                        line += r.ReadLine();
                    }

                    // Let's remove any newLine characters.
                    line.Replace("\n", "").Replace("\r", "");

                    while (!r.EndOfStream && line[0] == '%')
                    {
                        line = ReadLine();
                    }

                    if (line == @"\\begin{document}")
                    {
                        // We're finished, move onto the next line and let's get outta here.
                        done = true;
                        r.ReadLine();
                        break;
                    }

                    else if (Regex.IsMatch(line, regexPatternMacro))
                    {
                    }

                    else if (Regex.IsMatch(line, regexPatternOptionals))
                    {
                    }

                    else if (Regex.IsMatch(line, regexPattern))
                    {
                    }

                    else if (Regex.IsMatch(line, regexPatternNoParams))
                    {
                    }

                    else
                    {
                        throw new Exception(string.Format("I have no idea what \"{0}\" is in terms of header information.", line));
                    }
                    if (r.EndOfStream)
                    {
                        throw new Exception("Got through the whole file without a \\begin{Document}, This means something went wrong or your input file wasn't right!");
                    }
                }
            }
        }
Example #7
0
 public Reader(string fileName)
     : base(fileName)
 {
     _Tex = new TeX();
 }
Example #8
0
 public Reader(string fileName)
     : base(fileName)
 {
     _Tex = new TeX();
 }