/// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     var bld = new StringBuilder("<");
     var tag = _tag;
     if (CommandConverter.MathFunctionsScriptCommandConstants.ContainsKey(expr.Expressions[0][0].Name))
     {
         tag = (_tag == "msup") ? "mover" : "munder";
     }
     bld.Append(tag);
     bld.Append(">\n<mrow>\n");
     var first = expr.Expressions[0][0].Convert();
     if (first != "</mrow>\n</mfenced>\n")
     {
         bld.Append(first);
     }
     bld.Append("</mrow>\n<mrow>\n");
     bld.Append(expr.Expressions[0][1].Convert());
     bld.Append("</mrow>\n</");
     bld.Append(tag);
     bld.Append(">\n");
     if (first != "</mrow>\n</mfenced>\n")
     {
         return bld.ToString();
     }
     return first + bld;
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.Expressions == null) return "";
     var alg = "<code class=\"algorithm\">";
     alg += SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization);
     return alg + "</code>\n";
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.Expressions == null) return "";
     GetParameters();
     var bld = new StringBuilder();
     if (_mathMode)
     {
         bld.Append("<mover accent=\"true\">\n");
         if (!_stretchy)
         {
             bld.Append(expr.Expressions[0][0].Convert());
         }
         else
         {
             bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
         }
         bld.Append("<mo stretchy=\"true\">" + _value + "</mo>\n</mover>\n");
     }
     else
     {
         MathConverter.AppendMathProlog(bld, "accent", true, expr.Customization);
         bld.Append("<mrow>");
         bld.Append("<mover accent=\"true\">\n");
         bld.Append(expr.Expressions[0][0].Convert());
         bld.Append("<mo>" + _value + "</mo>\n</mover>\n");
         bld.Append("</mrow>\n");
         MathConverter.AppendMathEpilog(bld);
     }
     return bld.ToString();
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.Expressions == null || expr.Options == null) return "";
     var contents = SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization);
     var label = expr.Customization.References[expr.Options.AsExpressions[0].Name];
     return "<a href=\"#" + label.Kind + label.Number + "\">" + contents + label.Number + "</a>";
 }
Example #5
0
        /// <summary>
        /// Performs the conversion procedure.
        /// </summary>
        /// <param name="expr">The expression to convert.</param>
        /// <returns>The conversion result.</returns>
        public override string Convert(LatexExpression expr)
        {
            var bld = new StringBuilder();

            ReadDocumentInfo(expr.Expressions[0]);

            var bodyBuilder = bld;
            // Convert the {document} block
            LatexExpression documentExpression = expr.FindDocument();
            if (documentExpression != null)
            {
                try
                {
                    bodyBuilder.Append(documentExpression.Convert());
                }
                // ReSharper disable RedundantCatchClause
#pragma warning disable 168
                catch (Exception e)
#pragma warning restore 168
                {
#if DEBUG
                    throw;
#else
                Log.Error("Failed to convert the document block", e);
#endif
                }
                // ReSharper restore RedundantCatchClause
            }
            return bld.ToString();
        }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.MathMode) return "";
     var bld = new StringBuilder();
     int parentChildNumber = 0;
     if (expr.Expressions.Count > 1)
     {
         parentChildNumber = 1;
         bld.Append("<h4 class=\"");
         bld.Append(expr.Name);
         bld.Append("\">");
         for (int i = 0; i < expr.Expressions[0].Count; i++)
         {
             bld.Append(expr.Expressions[0][i].Convert());
         }
         bld.Append("</h4>\n");
     }
     bld.Append("<p>\n");
     for (int i = 0; i < expr.Expressions[parentChildNumber].Count; i++)
     {
         bld.Append(expr.Expressions[parentChildNumber][i].Convert());
     }
     bld.Append("</p>\n");
     return bld.ToString();
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.Expressions == null) return "";
     var def = "<div class=\"definition\">";
     def += SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization);
     return def + "</div>\n";
 }
Example #8
0
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     var bld = new StringBuilder();
     if (expr.Parent.Name == "enumerate" || expr.Parent.Name == "itemize")
     {
         bld.Append("<li>");
         if (expr.Expressions != null)
         {
             bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
         }
         bld.Append("</li>");
     }
     if (expr.Parent.Name == "description")
     {
         if (expr.Options != null)
         {
             bld.Append("<dt>");
             bld.Append(SequenceConverter.ConvertOutline(expr.Options.AsExpressions, expr.Customization));
             bld.Append("</dt>\n");
         }
         if (expr.Expressions != null)
         {
             bld.Append("<dd>");
             bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
             bld.Append("</dd>\n");
         }
     }
     return bld.ToString();
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (!expr.MathMode)
     {
         var formatDiv = "<span class=\"" + expr.Customization.GetCurrentCssStyle() + "\">";
         formatDiv += LatexStringToXmlString(expr.Name);
         return formatDiv + "</span>";
     }
     if (expr.Name == "InvisibleTimes")
     {
         return "<mo>&#x2062;<!-- &InvisibleTimes; --></mo>\n";
     }
     if (char.IsLetter(expr.Name[0]))
     {
         return "<mi>" + expr.Name + "</mi>\n";
     }
     if (char.IsDigit(expr.Name[0]))
     {
         return "<mn>" + expr.Name + "</mn>\n";
     }
     string str;
     if (MathConstants.TryGetValue(expr.Name, out str))
     {
         return str;
     }
     return "<mo>" + LatexStringToXmlString(expr.Name.Trim()) + "</mo>\n";
 }
Example #10
0
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.Expressions == null) return "";
     var url = expr.Expressions[0][0].Name;
     var text = SequenceConverter.ConvertOutline(expr.Expressions[1], expr.Customization);
     return "<a href=\"" + url + "\">" + text + "</a>";
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.Expressions == null) return "";
     var div = "<h2 class=\"section\">" + (expr.Customization.Localization == "ru"? "Аннотация" : "Abstract") +
         "</h2>\n<span class=\"abstract\">\n";
     div += SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization);
     return div + "</span>\n";
 }
Example #12
0
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.Expressions == null) return "";
     var bld = new StringBuilder("<span class=\"IEEEauthorblockA\">\n");
     bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
     bld.Append("</span><br />\n");
     return bld.ToString();
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     var bld = new StringBuilder("<p style=\"text-align:");
     bld.Append(_alignment);
     bld.Append(";\">\n");
     bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
     bld.Append("</p>\n");
     return bld.ToString();
 }
Example #14
0
        /// <summary>
        /// Performs the conversion procedure.
        /// </summary>
        /// <param name="expr">The expression to convert.</param>
        /// <returns>The conversion result.</returns>
        public override string Convert(LatexExpression expr)
        {
            var bld = new StringBuilder();
            //bld.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
            //bld.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN\" ");
            //bld.Append("\"http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd\">\n");
            //bld.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xml:lang=\"");
            //bld.Append(expr.Customization.Localization);
            //bld.Append("\">\n");

            ReadDocumentInfo(expr.Expressions[0]);
            //WriteHead(expr, bld);
            //bld.Append("<body>\n");
            //MakeTitle(bld);

            var bodyBuilder = expr.Customization.PlacementOfTableOfContents == TableOfContentsPlacement.Top 
                ? new StringBuilder() : bld;
            // Convert the {document} block
            LatexExpression documentExpression = expr.FindDocument();
            if (documentExpression != null)
            {
                try
                {
                    bodyBuilder.Append(documentExpression.Convert());
                }
                // ReSharper disable RedundantCatchClause
#pragma warning disable 168
                catch (Exception e)
#pragma warning restore 168
                {
#if DEBUG
                    throw;
#else
                Log.Error("Failed to convert the document block", e);
#endif
                }
                // ReSharper restore RedundantCatchClause
            }
            //if (expr.Customization.PlacementOfTableOfContents != TableOfContentsPlacement.None)
            //{
            //    MakeTableOfContents(bld, expr.Customization.SectionContents, expr.Customization.TableOfContentsTitle,
            //        expr.Customization.TocSectionFormat, expr.Customization.TocSubsectionFormat);
            //}

            if (expr.Customization.PlacementOfTableOfContents != TableOfContentsPlacement.Bottom)
            {
                bld.Append(bodyBuilder.ToString());
            }
            if (expr.Customization.Bibliography != null && expr.Customization.Bibliography.Count > 0)
            {
                MakeBibliography(bld, expr.Customization.BibliographyTitle, 
                    expr.Customization.BibliographyRecordFormat, expr.Customization.Bibliography);
            }
            //bld.Append("</body>\n</html>");
            return bld.ToString();
        }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.Expressions == null) return "";
     if (expr.Expressions[0][0].ExprType == ExpressionType.PlainText)
     {
         var label = expr.Customization.References[(string)expr.Tag];
         return "<span id=\"" + label.Kind + label.Number + "\" />";
     }
     return "";
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     var bld = new StringBuilder();
     bld.Append("<mfrac>\n<mrow>\n");
     bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
     bld.Append("</mrow>\n<mrow>\n");
     bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[1], expr.Customization));
     bld.Append("</mrow>\n</mfrac>\n");
     return bld.ToString();
 }
Example #17
0
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     var fileName = expr.Expressions[0][0].Name;
     //var sourcePath = Path.GetDirectoryName(expr.Customization.SourcePath)?? "";
     //var destPath = Path.GetDirectoryName(expr.Customization.OutputPath)?? "";
     //var programPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     //if (String.IsNullOrEmpty(sourcePath))
     //{
     //    sourcePath = programPath;
     //}
     //if (String.IsNullOrEmpty(destPath))
     //{
     //    destPath = programPath;
     //}
     //if (String.IsNullOrEmpty(Path.GetExtension(fileName)))
     //{
     //    fileName += ".eps";
     //}
     //var sourceFullName = Path.IsPathRooted(fileName)? fileName : Path.Combine(sourcePath, fileName);
     //var destFullName = Path.Combine(destPath, Path.GetFileName(fileName));
     //var ext = Path.GetExtension(fileName);
     //if ((ext == ".eps" || ext == ".pdf") && File.Exists(sourceFullName))
     //{
     //    destFullName = Path.ChangeExtension(destFullName, "png");
     //    if (!File.Exists(destFullName))
     //    {
     //        Process.Start(LatexToMathMLConverter.GhostScriptBinaryPath,
     //                      "-dSAFER -dBATCH -dNOPAUSE -sDEVICE=pngalpha -dEPSCrop " +
     //                      "-dGraphicsAlphaBits=4 -dTextAlphaBits=4 -sOutputFile=" +
     //                      destFullName + " " + sourceFullName);
     //    }
     //}
     //else
     //{
     //    if (sourceFullName != destFullName)
     //    {
     //        File.Copy(Path.Combine(sourcePath, fileName), Path.Combine(destPath, fileName), true);
     //    }
     //}
     //if (destFullName.StartsWith(programPath))
     //{
     //    destFullName = destFullName.Substring(programPath.Length);
     //    if (destFullName.StartsWith("" + Path.DirectorySeparatorChar))
     //    {
     //        destFullName = destFullName.Substring(1);
     //    }
     //}
     //src="/Portals/0/Logo.png"
     //var img = "<img src=\"" + destFullName + "\" alt=\"\\includegraphics {" + fileName + "}\" />";
     var img = "<img src=\"/Portals/0/" + fileName + "\" />";
     return img;
 }
Example #18
0
        /// <summary>
        /// Performs the conversion procedure.
        /// </summary>
        /// <param name="expr">The expression to convert.</param>
        /// <returns>The conversion result.</returns>
        public override string Convert(LatexExpression expr)
        {
            expr.ExprType = ExpressionType.BlockMath;
            expr.Expressions.Add(new List<LatexExpression> { new LatexExpression("equation", expr, 1, 0, expr.Customization) });
            return expr.Convert();

            //expr.ExprType = ExpressionType.BlockMath;
            ////PJ
            //List<LatexExpression> tmp = expr.Expressions[0];
            //expr.Expressions.Remove(tmp);
            //expr.Expressions.Add(new List<LatexExpression> { new LatexExpression("equation", expr, 1, 0, expr.Customization) });
            //expr.Expressions.Add(tmp);
            //return expr.Convert();
        }
Example #19
0
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     expr.Customization.CurrentSectionType = SectionType.Unnumbered;
     var bld = new StringBuilder("<h2 class=\"section\">\n<a id=\"nns");
     var title = SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization);
     int index = expr.Customization.SectionContents[SectionType.Unnumbered].Count;
     expr.Customization.SectionContents[SectionType.Unnumbered].Add(
         new SectionContentsValue(title));
     bld.Append(index);
     bld.Append("\">");
     bld.Append(title);
     bld.Append("</a></h2>\n");
     return bld.ToString();
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.Expressions == null) return "";
     if (expr.Parent.ExprType == ExpressionType.Block && expr.Parent.Name.IndexOf("script") > -1)
     {
         return SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization);
     }
     var bld = new StringBuilder();
     string tag;
     tag = expr.Name == "^" ? "sup" : "sub";
     bld.Append("<" + tag + ">\n");
     bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
     bld.Append("</" + tag + ">");
     return bld.ToString();
 }
Example #21
0
        /// <summary>
        /// Performs the conversion procedure.
        /// </summary>
        /// <param name="expr">The expression to convert.</param>
        /// <returns>The conversion result.</returns>
        public override string Convert(LatexExpression expr)
        {
            if (expr.Expressions == null) return "";
            var bld = new StringBuilder();
            bld.Append("<table class=\"");
            bld.Append(expr.Name);
            bld.Append("\">\n<tr><td>");
            bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
            bld.Append("</td></tr>");
            string caption = null;
            expr.EnumerateChildren(child =>
            {
                if (child.ExprType == ExpressionType.Command && child.Name == "caption" && child.Expressions != null)
                {
                    caption = SequenceConverter.ConvertOutline(child.Expressions[0], expr.Customization);
                    return true;
                }
                return false;
            });

            #region Add the caption
            bld.Append("\n<tr><td class=\"caption\">");
            if (expr.Name == "figure")
            {
                bld.Append(expr.Customization.Localization == "ru" ? "Рисунок" : "Figure");
            }
            if (expr.Name == "table")
            {
                bld.Append(expr.Customization.Localization == "ru" ? "Таблица" : "Table");
            }
            if (expr.Name == "algorithm")
            {
                bld.Append(expr.Customization.Localization == "ru" ? "Алгоритм" : "Algorithm");
            }
            bld.Append(" ");
            bld.Append((int)expr.Tag);
            bld.Append(".");
            if (caption != null)
            {
                bld.Append(" ");
                bld.Append(caption);
            }
            #endregion
            bld.Append("</td></tr>\n");
            bld.Append("</table>\n");
            return bld.ToString();
        }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     var bld = new StringBuilder("<h3 class=\"subsection\">\n<a id=\"");
     int sectIndex = expr.Customization.SectionContents[expr.Customization.CurrentSectionType].Count - 1;
     var section = expr.Customization.SectionContents[expr.Customization.CurrentSectionType][sectIndex];
     var title = SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization);
     int index = section.Subsections[SectionType.Unnumbered].Count;
     section.Subsections[SectionType.Unnumbered].Add(title);
     bld.Append(expr.Customization.CurrentSectionType == SectionType.Numbered ? "ns" : "nns");
     bld.Append(sectIndex);
     bld.Append("nnss");
     bld.Append(index);
     bld.Append("\">");
     bld.Append(title);
     bld.Append("</a></h3>\n");
     return bld.ToString();
 }
Example #23
0
 /// <summary>
 /// Performs the conversion procedure (comments the expression).
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     var bld = new StringBuilder();
     int parentChildNumber = expr.Expressions.Count == 1 ? 0 : 1;
     var rows = expr.Expressions[parentChildNumber];
     var alignments = parentChildNumber > 0 ? expr.Expressions[0][0].Name : "";
     alignments = alignments.Replace("|", "");
     bld.Append("<table class=\"tabular\">\n");
     for (int i = 0; i < rows.Count; i++)
     {
         bld.Append("<tr>\n");
         for (int j = 0; j < rows[i].Expressions[0].Count; j++)
         {
             #region Determine the alignment
             var alignment = "center";
             if (j < alignments.Length)
             {
                 switch (alignments[j])
                 {
                     case 'c':
                         alignment = "center";
                         break;
                     case 'l':
                         alignment = "left";
                         break;
                     case 'r':
                         alignment = "right";
                         break;
                 }
             }
             #endregion
             bld.Append("<td class=\"tabular_td\" columnalign=\"");
             bld.Append(alignment);
             bld.Append("\">\n");
             bld.Append(SequenceConverter.ConvertOutline(rows[i].Expressions[0][j].Expressions[0], expr.Customization));
             bld.Append("</td>\n");
         }
         bld.Append("</tr>\n");
     }
     bld.Append("</table>\n");
     return bld.ToString();
 }
 /// <summary>
 /// Performs the conversion procedure (comments the expression).
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     var bld = new StringBuilder();
     MathConverter.AppendMathProlog(bld, "eqnarray", false, expr.Customization);
     var rows = expr.Expressions[0];
     bld.Append("<mtable>\n");
     for (int i = 0; i < rows.Count; i++)
     {
         bld.Append("<mtr>\n");
         for (int j = 0; j < rows[i].Expressions[0].Count; j++)
         {
             bld.Append("<mtd columnalign=\"left\">\n<mrow>\n");
             bld.Append(SequenceConverter.ConvertOutline(rows[i].Expressions[0][j].Expressions[0], expr.Customization));
             bld.Append("</mrow>\n</mtd>\n");
         }
         bld.Append("</mtr>\n");
     }
     bld.Append("</mtable>\n");
     MathConverter.AppendMathEpilog(bld);
     return bld.ToString();
 }
Example #25
0
 /// <summary>
 /// Tries to display the expression as the plain text chunk.
 /// </summary>
 /// <param name="expr">The expression to display.</param>
 /// <returns>The string representing the plain text chunk.</returns>
 private static string AsPlainText(LatexExpression expr)
 {
     if (expr.Expressions != null)
     {
         string raw = SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization);
         raw += '<';
         var match = System.Text.RegularExpressions.Regex.Match(raw, @"(?<=(<[^<>]*>\s*)*)[^<>]+(?=\s*<)");
         return match.Value;
     }
     return expr.Customization.Localization == "ru" ? "Без названия" : "Untitled";
 }
Example #26
0
 /// <summary>
 /// Writes the &lt;head&gt; tag.
 /// </summary>
 /// <param name="expr">The expression which is being converted.</param>
 /// <param name="bld">The output StringBuilder instance.</param>
 private void WriteHead(LatexExpression expr, StringBuilder bld)
 {
     bld.Append("<head>\n");
     var path = Path.GetDirectoryName(expr.Customization.OutputPath);
     if (!String.IsNullOrEmpty(path))
     {
         bld.Append("<base href=\"file:///" + expr.Customization.OutputPath.Replace('\\', '/') + "\" />\n");
     }
     bld.Append("<title>" + (_documentInfo.ContainsKey("title") ?
         AsPlainText(_documentInfo["title"]) : expr.Customization.Localization == "ru"? "Без названия" : "Untitled") + "</title>\n");
     bld.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /> \n");
     bld.Append("<meta name=\"description\" content=\"Latex document converted to XHTML 1.1 + MathML 2.0\" />\n");
     LatexExpression authorExpr;
     if (_documentInfo.TryGetValue("author", out authorExpr))
     {
         bld.Append("<meta name=\"author\" content=\"" + AsPlainText(authorExpr) + "\" />\n");
     }
     bld.Append("<meta name=\"generator\" content=\"Latex2MathML, © Markovtsev Vadim, 2010\" />\n");
     bld.Append("<meta name=\"date\" content=\"" + DateTime.Now + "\" />\n");
     bld.Append("<meta name=\"src\" content=\"" + Path.GetFileName(expr.Customization.SourcePath) + "\" />\n");
     bld.Append("<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n");
     bld.Append("<link rel=\"icon\" type=\"image/png\" href=\"favicon.png\" />");
     bld.Append("</head>\n");
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     GetStyle();
     var bld = new StringBuilder();
     var backupTextStyle = expr.Customization.CurrentTextStyle;
     expr.Customization.CurrentTextStyle |= _style;
     bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
     expr.Customization.CurrentTextStyle = backupTextStyle;
     return bld.ToString();
 }
 /// <summary>
 /// Performs the conversion procedure.
 /// </summary>
 /// <param name="expr">The expression to convert.</param>
 /// <returns>The conversion result.</returns>
 public override string Convert(LatexExpression expr)
 {
     if (expr.MathMode == false)
     {
         return base.Convert(expr);
     }
     if (expr.Expressions == null) return "";
     var bld = new StringBuilder();
     bld.Append("<munder accent=\"true\">\n");
     bld.Append(SequenceConverter.ConvertOutline(expr.Expressions[0], expr.Customization));
     bld.Append("<mo stretchy=\"true\">&#x00af;<!-- &OverBar; --></mo>\n</munder>\n");
     return bld.ToString();
 }
Example #29
0
        /// <summary>
        /// Builds a new LatexExpression instance (main).
        /// </summary>
        /// <param name="parent">The parent of the builded expression.</param>
        /// <param name="parentChildNumber">Index of the parent child outline.</param>
        /// <param name="indexInParentChild">Index in the parent child outline.</param>
        /// <param name="verbatimMode">True if verbatim mode is on; otherwise, false.</param>
        /// <param name="beginning">The beginning string.</param>
        /// <param name="rdr">The reader to read ahead.</param>
        /// <param name="mathMode">The math mode switch.</param>
        /// <param name="end">The stub of the unparsed part.</param>
        /// <param name="whitespaceBefore">Indicates whether there was at least one whitespace char before the returned result.</param>
        /// <param name="customization">The LatexToMathMLConverter class instance to customize the conversion result.</param>
        /// <returns>The parsed LatexExpression instance.</returns>
        private static LatexExpression ReadFromTextReaderInner(LatexExpression parent, int parentChildNumber,
            ref int indexInParentChild, ref bool verbatimMode, bool mathMode, LatexToMathMLConverter customization,
            string beginning, TextReader rdr, out string end, ref bool whitespaceBefore)
        {
            string name;

            #region Verbatim
            if (verbatimMode)
            {
                name = ReadToVerbatimEnd(beginning, rdr, out end);
                return new LatexExpression(parent, parentChildNumber, ref indexInParentChild,
                    ref verbatimMode, ExpressionType.Verbatim, false, customization, name, null, null);
            }
            #endregion

            bool whitespaceBeforeGuard;
            string str = ReadToNotEmptyString(beginning, rdr, out whitespaceBeforeGuard);
            whitespaceBefore |= whitespaceBeforeGuard;
            if (str == null)
            {
                end = null;
                return null;
            }
            string value;
            switch (str[0])
            {
                case '\\':
                    #region Command
                    string options;
                    string[] values;
                    name = Regex.Match(str.Substring(1), @"^[a-zA-Z]+\*?").Value;
                    if (String.IsNullOrEmpty(name))
                    {
                        name = "" + str[1];
                        options = null;
                        if (name != "[")
                        {
                            values = null;
                            end = str.Substring(2);
                        }
                        else // Math
                        {
                            value = ParseBraces(ref str, rdr, "\\[", "\\]", out whitespaceBefore);
                            end = str;
                            return new LatexExpression(parent, parentChildNumber, ref indexInParentChild,
                                ref verbatimMode, ExpressionType.BlockMath, mathMode, customization,
                                name, null, value);
                        }
                    }
                    else
                    {
                        ParseCommandOptionsAndValues(
                            str.Substring(name.Length + 1), rdr, out end,
                            out options, out values, out whitespaceBefore);
                    }
                    return new LatexExpression(parent, parentChildNumber, ref indexInParentChild, ref verbatimMode,
                        ExpressionType.Command, mathMode, customization, name, options, values);
                    #endregion
                case '$':
                    #region Math
                    ExpressionType type;
                    if (str[1] == '$')
                    {
                        name = "$$";
                        value = ParseBraces(ref str, rdr, "$$", "$$", out whitespaceBefore);
                        type = ExpressionType.BlockMath;
                    }
                    else
                    {
                        name = "$";
                        value = ParseBraces(ref str, rdr, "$", "$", out whitespaceBefore);
                        type = ExpressionType.InlineMath;
                    }
                    end = str;
                    return new LatexExpression(parent, parentChildNumber, ref indexInParentChild,
                        ref verbatimMode, type, false, customization, name, null, value);
                    #endregion
                case '%':
                    #region Comment
                    end = null;
                    return new LatexExpression(parent, parentChildNumber, ref indexInParentChild, ref verbatimMode,
                        ExpressionType.Comment, false, customization, str.Substring(1), null, null);
                    #endregion
                case '{':
                    #region Block
                    value = ParseBraces(ref str, rdr, "{", "}", out whitespaceBefore);
                    end = str;
                    return new LatexExpression(parent, parentChildNumber, ref indexInParentChild,
                        ref verbatimMode, ExpressionType.Block, mathMode, customization, "{}", null, value);
                    #endregion
                case '&':
                    #region Table cell
                    end = str.Substring(1);
                    return new LatexExpression(parent, parentChildNumber, ref indexInParentChild, ref verbatimMode,
                        ExpressionType.PlainText, mathMode, customization, "&", null, null);
                    #endregion
                case '^':
                case '_':
                    #region Block for sub and sup
                    if (mathMode)
                    {
                        name = "" + str[0];
                        str = ReadToNotEmptyString(str.Substring(1), rdr, out whitespaceBefore);
                        switch (str[0])
                        {
                            case '{':
                                value = ParseBraces(ref str, rdr, "{", "}", out whitespaceBefore);
                                end = str;
                                break;
                            case '\\':
                                var cmdName = Regex.Match(str.Substring(1), @"^[a-zA-Z]+\*?").Value;
                                ParseCommandOptionsAndValues(
                                    str.Substring(cmdName.Length + 1), rdr, out end,
                                    out options, out values, out whitespaceBefore);
                                value = "\\" + cmdName + options;
                                if (values != null)
                                {
                                    for (int i = 0; i < values.Length; i++)
                                    {
                                        value += "{" + values[i] + "}";
                                    }
                                }
                                break;
                            default:
                                value = "" + str[0];
                                if (char.IsDigit(str[0]))
                                {
                                    value = Regex.Match(str, @"\d+").Value;
                                }
                                if (char.IsLetter(str[0]))
                                {
                                    value = Regex.Match(str, @"[a-zA-Z]+").Value;
                                }
                                end = str.Substring(value.Length);
                                break;
                        }
                        return new LatexExpression(parent, parentChildNumber, ref indexInParentChild,
                            ref verbatimMode, ExpressionType.Block, true, customization, name, null, value);
                    }
                    goto default;
                    #endregion
                default:
                    #region Plain text block
                    name = "";
                    var stopChars = mathMode ? new[] { '\\', '$', '{', '%', '&', '^', '_' } :
                        new[] { '\\', '$', '{', '%', '&' };
                    int stopPos;
                    while ((stopPos = GetStopPos(str, stopChars)) == -1)
                    {
                        if (rdr != null)
                        {
                            name += str + " ";
                            str = rdr.ReadLine();
                            if (str == null) // End of the document
                            {
                                name = name.Substring(0, name.Length - 1);
                                break;
                            }
                            if (str.Trim() == "")
                            {
                                str = "\\paragraph";
                                stopPos = 0;
                                break;
                            }
                        }
                        else
                        {
                            stopPos = str.Length;
                            break;
                        }
                    }
                    if (str == null) // End of the document?
                    {
                        end = null;
                    }
                    else
                    {
                        name += str.Substring(0, stopPos);
                        if (stopPos < str.Length && (str[stopPos] == '^' || str[stopPos] == '_'))
                        {
                            var match = Regex.Match(name, @"[a-zA-Z]+\s*\Z");
                            var chunk = match.Value;
                            if (chunk.Trim() == "")
                            {
                                match = Regex.Match(name, @"\d+\s*\Z");
                                chunk = match.Value;
                                if (chunk.Trim() == "")
                                {
                                    match = Regex.Match(name, @"\S\s*\Z");
                                    chunk = match.Value.Trim();
                                }
                            }
                            if (name != chunk)
                            {
                                end = name.Substring(match.Index) + str.Substring(stopPos);
                                name = name.Substring(0, match.Index);
                            }
                            else
                            {
                                end = str.Substring(stopPos);
                            }
                        }
                        else
                        {
                            end = str.Substring(stopPos);
                        }
                    }
                    return new LatexExpression(parent, parentChildNumber, ref indexInParentChild, ref verbatimMode,
                        ExpressionType.PlainText, mathMode, customization, (whitespaceBefore? " " : "") + SmartTextTrim(name), null, null);
                    #endregion
            }
        }
Example #30
0
 /// <summary>
 /// Builds a new LatexExpression instance (front).
 /// </summary>
 /// <param name="parent">The parent of the builded expression.</param>
 /// <param name="parentChildNumber">Index of the parent child outline.</param>
 /// <param name="indexInParentChild">Index in the parent child outline.</param>
 /// <param name="verbatimMode">True if verbatim mode is on; otherwise, false.</param>
 /// <param name="beginning">The beginning string.</param>
 /// <param name="rdr">The reader to read ahead.</param>
 /// <param name="end">The stub of the unparsed part.</param>
 /// <param name="mathMode">The math mode switch.</param>
 /// <param name="whitespaceBefore">Indicates whether there was at least one whitespace char before the returned result.</param>
 /// <param name="customization">The LatexToMathMLConverter class instance to customize the conversion result.</param>
 /// <returns></returns>
 private static LatexExpression ReadFromTextReader(LatexExpression parent, int parentChildNumber, 
     ref int indexInParentChild, ref bool verbatimMode, bool mathMode, LatexToMathMLConverter customization,
     string beginning, TextReader rdr, out string end, ref bool whitespaceBefore)
 {
     if (beginning == null && rdr == null)
     {
         end = null;
         return null;
     }
     return ReadFromTextReaderInner(parent, parentChildNumber, ref indexInParentChild, ref verbatimMode,
         mathMode, customization, beginning ?? rdr.ReadLine(), rdr, out end, ref whitespaceBefore);
 }