Exemplo n.º 1
0
        public static IList <Eqref> GetEqrefs(string text)
        {
            List <Eqref> items   = new List <Eqref>();
            var          matches = Regex.Matches(text, @"\\eqref(?:.|\r?\n)*?\{(.+?)\}");

            foreach (Match match in matches.OfType <Match>())
            {
                var item = new Eqref(match.Index, match.Value);
                items.Add(item);
            }
            return(items);
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="format">#name#</param>
        public static void RenameLabels(ref StringBuilder sb, string format)
        {
            var labels = Utils.GetLabels(sb.ToString()).ToList();

            Dictionary <string, string> labelsOldNew = new Dictionary <string, string>();
            var eqNumber = labels.Count;

            foreach (var label in labels.OrderByDescending(l => l.Block.StartPos))
            {
                Console.WriteLine(label.Name + "; " + label.EnvironmentName);
                var newName = format.Replace("#name#", label.Name).Replace("#num#", eqNumber.ToString());
                labelsOldNew[label.Name] = newName;
                sb.Remove(label.Block.StartPos, label.Block.Length);
                sb.Insert(label.Block.StartPos, Label.GenerateMarkup(newName));
                --eqNumber;
            }

            // replaces labels in eqref
            var eqrefs = Utils.GetEqrefs(sb.ToString());

            foreach (var eqref in eqrefs.OrderByDescending(e => e.Block.StartPos))
            {
                if (labelsOldNew.ContainsKey(eqref.Value))
                {
                    sb.Remove(eqref.Block.StartPos, eqref.Block.Length);
                    sb.Insert(eqref.Block.StartPos, Eqref.GenerateMarkup(labelsOldNew[eqref.Value]));
                }
            }

            // replaces labels in refs
            var refs = Utils.GetRefs(sb.ToString());

            foreach (var reff in refs.OrderByDescending(e => e.Block.StartPos))
            {
                if (labelsOldNew.ContainsKey(reff.Value))
                {
                    sb.Remove(reff.Block.StartPos, reff.Block.Length);
                    sb.Insert(reff.Block.StartPos, Ref.GenerateMarkup(labelsOldNew[reff.Value]));
                }
            }
        }