Example #1
0
        public void ProcessTest()
        {
            var macros = new Macros(@"\newcommand{\norm}[1]{\|#1\|_{p(\cdot),w}}");
            var sb     = new StringBuilder(@"Известно, что $\norm{f}$ определяется... Если $\norm{f}\le \norm{g} $, то...");

            macros.ApplyMacros(ref sb);
            string actual   = sb.ToString();
            string expected =
                @"Известно, что $\|f\|_{p(\cdot),w}$ определяется... Если $\|f\|_{p(\cdot),w}\le \|g\|_{p(\cdot),w} $, то...";

            Assert.AreEqual(expected, actual);
        }
Example #2
0
        private static void Process2(string sourceFilename, string destinationFilename, Encoding encoding = null)
        {
            if (encoding == null)
            {
                encoding = new UTF8Encoding();
            }
            var sb = new StringBuilder(File.ReadAllText(sourceFilename, encoding));

            // Macroses inlining
            var macrosDef = @"\newcommand{\norm}[1]{\|#1\|_{p(\cdot),w}}";

            sb.Replace(macrosDef, "");
            var macros = new Macros(macrosDef);

            macros.ApplyMacros(ref sb);

            // equation labels renaming
            Utils.RenameLabels(ref sb, "mmg_#name#_#num#");

            // replace theorem environments
            Utils.RenameEnvs(ref sb, "lemma", "\r\n\r\n" + @"\textbf{Лемма #counter#.}\textit{", "}\r\n\r\n");
            Utils.RenameEnvs(ref sb, "theorem", "\r\n\r\n" + @"\textbf{Теорема #counter#.}\textit{", "}\r\n\r\n");
            Utils.RenameEnvs(ref sb, "theoremA", "\r\n\r\n" + @"\textbf{Теорема #counter#.}\textit{", "}\r\n\r\n", i => new[] { "A", "B", "C" }[i - 1]);

            // remove block "My notations"

            var lineStart = Utils.FindLine(sb.ToString(), "===My notations");
            var lineEnd   = Utils.FindLine(sb.ToString(), "===/My notations");

            for (int i = lineEnd; i >= lineStart; i--)
            {
                Utils.RemoveLine(sb, i);
            }


            File.WriteAllText(destinationFilename, sb.ToString(), encoding);
        }