3using System.Collections.Generic;
5using System.Threading.Tasks;
57 bool MakeTitle =
false;
59 this.
Output.Append(
"\\documentclass[");
60 this.
Output.Append(this.LatexSettings.DefaultFontSize.ToString());
61 this.
Output.Append(
"pt, ");
63 switch (this.LatexSettings.PaperFormat)
67 this.
Output.Append(
"a4paper");
71 this.
Output.Append(
"letterpaper");
76 switch (this.LatexSettings.DocumentClass)
80 this.
Output.Append(
"article");
84 this.
Output.Append(
"report");
88 this.
Output.Append(
"book");
92 this.
Output.Append(
"standalone");
95 this.
Output.AppendLine(
"}");
98 this.
Output.AppendLine(
"\\newlength{\\wdth}");
99 this.
Output.AppendLine(
"\\newcommand{\\strike}[1]{\\settowidth{\\wdth}{#1}\\rlap{\\rule[.5ex]{\\wdth}{.4pt}}#1}");
105 foreach (KeyValuePair<string, bool> P
in Values)
107 this.
Output.Append(
"\\title{");
108 this.
Output.Append(P.Key);
109 this.
Output.AppendLine(
"}");
114 foreach (KeyValuePair<string, bool> P2
in Values)
116 this.
Output.Append(
"\\subtitle{");
117 this.
Output.Append(P2.Key);
118 this.
Output.AppendLine(
"}");
127 foreach (KeyValuePair<string, bool> P
in Values)
129 this.
Output.Append(
"\\author{");
130 this.
Output.Append(P.Key);
131 this.
Output.AppendLine(
"}");
139 foreach (KeyValuePair<string, bool> P
in Values)
141 this.
Output.Append(
"\\date{");
142 this.
Output.Append(P.Key);
143 this.
Output.AppendLine(
"}");
149 this.
Output.AppendLine(
"\\usepackage{enumitem}");
150 this.
Output.AppendLine(
"\\usepackage{amssymb}");
151 this.
Output.AppendLine(
"\\usepackage{graphicx}");
152 this.
Output.AppendLine(
"\\usepackage{pifont}");
153 this.
Output.AppendLine(
"\\usepackage{multirow}");
154 this.
Output.AppendLine(
"\\usepackage{ragged2e}");
155 this.
Output.AppendLine(
"\\newlist{tasklist}{itemize}{2}");
156 this.
Output.AppendLine(
"\\setlist[tasklist]{label=$\\square$}");
157 this.
Output.AppendLine(
"\\newcommand{\\checkmarksymbol}{\\ding{51}}");
158 this.
Output.AppendLine(
"\\newcommand{\\checked}{\\rlap{$\\square$}{\\raisebox{2pt}{\\large\\hspace{1pt}\\checkmarksymbol}}\\hspace{-2.5pt}}");
159 this.
Output.AppendLine(
"\\begin{document}");
162 this.
Output.AppendLine(
"\\maketitle");
166 this.
Output.AppendLine(
"\\begin{abstract}");
168 foreach (KeyValuePair<string, bool> P
in Values)
171 this.
Output.AppendLine(
"\\end{abstract}");
174 return Task.CompletedTask;
182 this.
Output.AppendLine(
"\\end{document}");
184 return Task.CompletedTask;
197 private static readonly
char[] latexCharactersToEscape =
new char[] {
'\\',
'#',
'$',
'%',
'&',
'{',
'}' };
198 private static readonly
string[] latexCharacterEscapes =
new string[] {
"\\,",
"\\#",
"\\$",
"\\%",
"\\&",
"\\{",
"\\}" };
200 #region Span Elements
219 return Task.CompletedTask;
230 return Task.CompletedTask;
239 this.
Output.Append(
"\\strike{");
264 return Task.CompletedTask;
273 this.
Output.Append(
"\\emph{");
287 await this.
Render(Footnote);
290 this.
Output.Append(
"\\footnote");
292 if (this.
Document?.TryGetFootnoteNumber(Element.
Key, out
int Nr) ??
false)
295 this.
Output.Append(Nr.ToString());
300 await this.
Render(Footnote);
312 this.
Output.Append(
"\\#");
315 return Task.CompletedTask;
324 string s = Html.HtmlEntity.EntityToCharacter(Element.
Entity);
325 if (!
string.IsNullOrEmpty(s))
328 return Task.CompletedTask;
339 return Task.CompletedTask;
348 this.
Output.Append(
"\\texttt{");
352 return Task.CompletedTask;
361 return Task.CompletedTask;
386 if (Result is XmlDocument Xml)
391 if (Result is
Graph G)
397 if (AloneInParagraph)
399 this.
Output.AppendLine(
"\\begin{figure}[h]");
400 this.
Output.AppendLine(
"\\centering");
403 this.
Output.Append(
"\\fbox{\\includegraphics[width=");
404 this.
Output.Append(((GraphSettings.Width * 3) / 4).ToString());
405 this.
Output.Append(
"pt, height=");
406 this.
Output.Append(((GraphSettings.Height * 3) / 4).ToString());
407 this.
Output.Append(
"pt]{");
408 this.
Output.Append(FileName.Replace(
'\\',
'/'));
411 if (AloneInParagraph)
413 this.
Output.AppendLine(
"\\end{figure}");
419 byte[] Bin = Pixels.EncodeAsPng();
422 if (AloneInParagraph)
424 this.
Output.AppendLine(
"\\begin{figure}[h]");
425 this.
Output.AppendLine(
"\\centering");
428 this.
Output.Append(
"\\fbox{\\includegraphics[width=");
429 this.
Output.Append(((Pixels.Width * 3) / 4).ToString());
430 this.
Output.Append(
"pt, height=");
431 this.
Output.Append(((Pixels.Height * 3) / 4).ToString());
432 this.
Output.Append(
"pt]{");
433 this.
Output.Append(FileName.Replace(
'\\',
'/'));
436 if (AloneInParagraph)
438 this.
Output.AppendLine(
"\\end{figure}");
442 else if (Result is SKImage Img)
444 using (SKData Data = Img.Encode(SKEncodedImageFormat.Png, 100))
446 byte[] Bin = Data.ToArray();
449 if (AloneInParagraph)
451 this.
Output.AppendLine(
"\\begin{figure}[h]");
452 this.
Output.AppendLine(
"\\centering");
455 this.
Output.Append(
"\\fbox{\\includegraphics[width=");
456 this.
Output.Append(((Img.Width * 3) / 4).ToString());
457 this.
Output.Append(
"pt, height=");
458 this.
Output.Append(((Img.Height * 3) / 4).ToString());
459 this.
Output.Append(
"pt]{");
460 this.
Output.Append(FileName.Replace(
'\\',
'/'));
463 if (AloneInParagraph)
465 this.
Output.AppendLine(
"\\end{figure}");
473 Doc.ProcessAsyncTasks();
479 Doc.ProcessAsyncTasks();
481 else if (Result is Exception ex)
487 this.
Output.AppendLine(
"\\texttt{\\color{red}");
489 if (ex is AggregateException ex2)
491 foreach (Exception ex3
in ex2.InnerExceptions)
493 foreach (
string Row
in ex3.Message.Replace(
"\r\n",
"\n").
494 Replace(
'\r',
'\n').Split(
'\n'))
499 this.
Output.AppendLine(
"\\\\");
507 foreach (
string Row
in ex.Message.Replace(
"\r\n",
"\n").
508 Replace(
'\r',
'\n').Split(
'\n'))
513 this.
Output.AppendLine(
"\\\\");
519 this.
Output.AppendLine(
"}");
521 if (AloneInParagraph)
527 else if (Result is
ObjectMatrix M && !(M.ColumnNames is
null))
529 this.
Output.AppendLine(
"\\begin{table}[!h]");
530 this.
Output.AppendLine(
"\\centering");
531 this.
Output.Append(
"\\begin{tabular}{");
532 foreach (
string _
in M.ColumnNames)
535 this.
Output.AppendLine(
"|}");
536 this.
Output.AppendLine(
"\\hline");
540 foreach (
string Name
in M.ColumnNames)
545 this.
Output.Append(
" & ");
550 this.
Output.AppendLine(
"\\\\");
551 this.
Output.AppendLine(
"\\hline");
555 for (y = 0; y < M.Rows; y++)
557 for (x = 0; x < M.Columns; x++)
560 this.
Output.Append(
" & ");
562 object Item = M.GetElement(x, y).AssociatedObjectValue;
565 if (Item is
string s2)
570 await Element.Render(
this);
581 this.
Output.Append(
"</td>");
584 this.
Output.AppendLine(
"\\\\");
587 this.
Output.AppendLine(
"\\hline");
588 this.
Output.AppendLine(
"\\end{tabular}");
589 this.
Output.AppendLine(
"\\end{table}");
592 else if (Result is Array A)
594 foreach (
object Item
in A)
600 if (AloneInParagraph)
614 return Task.CompletedTask;
623 this.
Output.Append(
"\\emph{");
634 this.
Output.AppendLine(
"\\newline");
635 return Task.CompletedTask;
662 bool FirstOnRow =
true;
664 if (Element.
TryGetMetaData(out KeyValuePair<string, bool>[] Values))
666 foreach (KeyValuePair<string, bool> P
in Values)
683 return Task.CompletedTask;
690 public override Task
Render(Model.SpanElements.Multimedia Element)
696 return Renderer.RenderLatex(
this, Element.Items, Element.Children, Element.AloneInParagraph, Element.Document);
723 this.
Output.Append(
"\\strike{");
734 this.
Output.Append(
"\\textbf{");
745 this.
Output.Append(
"\\textsubscript{");
756 this.
Output.Append(
"\\textsuperscript{");
767 this.
Output.Append(
"\\underline{");
774 #region Block elements
782 this.
Output.AppendLine(
"\\begin{quote}");
786 this.
Output.AppendLine(
"\\end{quote}");
796 this.
Output.AppendLine(
"\\begin{itemize}");
800 this.
Output.AppendLine(
"\\end{itemize}");
810 this.
Output.AppendLine(
"\\begin{center}");
814 this.
Output.AppendLine(
"\\end{center}");
839 this.
Output.AppendLine(
"\\texttt{\\color{red}");
841 if (ex is AggregateException ex2)
843 foreach (Exception ex3
in ex2.InnerExceptions)
845 foreach (
string Row
in ex3.Message.Replace(
"\r\n",
"\n").
846 Replace(
'\r',
'\n').Split(
'\n'))
851 this.
Output.AppendLine(
"\\\\");
859 foreach (
string Row
in ex.Message.Replace(
"\r\n",
"\n").
860 Replace(
'\r',
'\n').Split(
'\n'))
865 this.
Output.AppendLine(
"\\\\");
871 this.
Output.AppendLine(
"}");
876 this.
Output.Append(
"\\texttt{");
880 for (i = Element.
Start; i <= Element.
End; i++)
886 this.
Output.AppendLine(
"}");
896 return Task.CompletedTask;
916 this.
Output.AppendLine(
"\\begin{description}");
925 this.
Output.Append(
"\\item[");
926 await Terms.Render(
this);
932 await Terms.Render(
this);
936 this.
Output.AppendLine(
"}");
937 this.
Output.Append(
"\\item[");
939 await Terms.Render(
this);
948 this.
Output.Append(
"\\item{");
949 await Descriptions.Render(
this);
955 await Descriptions.Render(
this);
961 await Descriptions.Render(
this);
970 this.
Output.AppendLine(
"]{}");
974 this.
Output.AppendLine(
"}");
978 this.
Output.AppendLine(
"\\end{description}");
997 this.
Output.Append(
"\\strike{");
1019 switch (this.LatexSettings.DocumentClass)
1023 switch (Element.
Level)
1030 Command =
"chapter";
1034 Command =
"section";
1038 Command =
"subsection";
1042 Command =
"subsubsection";
1046 Command =
"paragraph";
1051 Command =
"subparagraph";
1059 switch (Element.
Level)
1062 Command =
"section";
1066 Command =
"subsection";
1070 Command =
"subsubsection";
1074 Command =
"paragraph";
1079 Command =
"subparagraph";
1085 this.
Output.Append(
'\\');
1086 this.
Output.Append(Command);
1087 this.
Output.Append(
"*{");
1091 this.
Output.AppendLine(
"}");
1092 this.
Output.AppendLine();
1101 this.
Output.AppendLine(
"\\hrulefill");
1102 return Task.CompletedTask;
1113 this.
Output.AppendLine();
1114 this.
Output.AppendLine();
1123 this.
Output.Append(
"\\emph{");
1134 return Task.CompletedTask;
1143 this.
Output.AppendLine(
"\\begin{flushleft}");
1147 this.
Output.AppendLine(
"\\end{flushleft}");
1148 this.
Output.AppendLine();
1157 this.
Output.AppendLine(
"\\begin{justify}");
1161 this.
Output.AppendLine(
"\\end{justify}");
1162 this.
Output.AppendLine();
1182 this.
Output.Append(
"\\item[");
1184 this.
Output.Append(
"]{");
1187 this.
Output.Append(
"\\item{");
1191 this.
Output.AppendLine(
"}");
1200 this.
Output.AppendLine(
"\\begin{enumerate}");
1204 this.
Output.AppendLine(
"\\end{enumerate}");
1205 this.
Output.AppendLine();
1216 this.
Output.AppendLine();
1217 this.
Output.AppendLine();
1226 this.
Output.AppendLine(
"\\begin{flushright}");
1230 this.
Output.AppendLine(
"\\end{flushright}");
1231 this.
Output.AppendLine();
1249 this.
Output.AppendLine();
1250 this.
Output.AppendLine(
"\\newpage");
1251 this.
Output.AppendLine();
1253 return Task.CompletedTask;
1265 int NrRows, RowIndex;
1266 int NrColumns = Element.
Columns;
1270 this.
Output.AppendLine(
"\\begin{table}[!h]");
1271 this.
Output.AppendLine(
"\\centering");
1272 this.
Output.Append(
"\\begin{tabular}{");
1273 foreach (
TextAlignment Alignment
in Element.ColumnAlignments)
1276 this.RenderAlignment(Alignment);
1279 this.
Output.AppendLine(
"|}");
1280 this.
Output.AppendLine(
"\\hline");
1282 NrRows = Element.Headers.Length;
1283 for (RowIndex = 0; RowIndex < NrRows; RowIndex++)
1285 Row = Element.Headers[RowIndex];
1286 CellAlignments = Element.HeaderCellAlignments[RowIndex];
1288 for (i = 0; i < NrColumns; i++)
1291 this.
Output.Append(
" & ");
1295 while (j < NrColumns && Row[j++] is
null)
1300 this.
Output.Append(
"\\multicolumn{");
1301 this.
Output.Append(k.ToString());
1302 this.
Output.Append(
"}{|");
1303 this.RenderAlignment(CellAlignments[i] ?? Element.ColumnAlignments[i]);
1304 this.
Output.Append(
"|}{");
1315 this.
Output.AppendLine(
"\\\\");
1318 this.
Output.AppendLine(
"\\hline");
1320 NrRows = Element.Rows.Length;
1321 for (RowIndex = 0; RowIndex < NrRows; RowIndex++)
1323 Row = Element.Rows[RowIndex];
1324 CellAlignments = Element.RowCellAlignments[RowIndex];
1326 for (i = 0; i < NrColumns; i++)
1329 this.
Output.Append(
" & ");
1333 while (j < NrColumns && Row[j++] is
null)
1338 this.
Output.Append(
"\\multicolumn{");
1339 this.
Output.Append(k.ToString());
1340 this.
Output.Append(
"}{|");
1341 this.RenderAlignment(CellAlignments[i] ?? Element.ColumnAlignments[i]);
1342 this.
Output.Append(
"|}{");
1353 this.
Output.AppendLine(
"\\\\");
1356 this.
Output.AppendLine(
"\\hline");
1357 this.
Output.AppendLine(
"\\end{tabular}");
1359 if (!
string.IsNullOrEmpty(Element.Id))
1361 this.
Output.Append(
"\\caption{");
1363 s =
string.IsNullOrEmpty(Element.Caption) ? Element.Id : Element.Caption;
1367 this.
Output.AppendLine(
"}");
1368 this.
Output.Append(
"\\label{");
1372 this.
Output.AppendLine(
"}");
1375 this.
Output.AppendLine(
"\\end{table}");
1376 this.
Output.AppendLine();
1404 this.
Output.Append(
"\\item");
1407 this.
Output.Append(
"[\\checked]");
1411 this.
Output.AppendLine(
"}");
1420 this.
Output.AppendLine(
"\\begin{tasklist}");
1424 this.
Output.AppendLine(
"\\end{tasklist}");
1425 this.
Output.AppendLine();
1434 this.
Output.Append(
"\\item{");
1436 this.
Output.AppendLine(
"}");
Helps with parsing of commong data types.
static string Escape(string s, char[] CharactersToEscape, string EscapeSequence)
Escapes a set of characters in a string.
const string FileExtensionPng
png
Contains settings that the LaTeX export uses to customize LaTeX output.
Renders LaTeX from a Markdown document.
override Task Render(HtmlEntity Element)
Renders Element .
override async Task Render(SubScript Element)
Renders Element .
override async Task Render(BlockQuote Element)
Renders Element .
override Task Render(EmojiReference Element)
Renders Element .
override async Task Render(InsertBlocks Element)
Renders Element .
override async Task Render(Insert Element)
Renders Element .
override async Task Render(Strong Element)
Renders Element .
override Task Render(NestedBlock Element)
Renders Element .
LatexRenderer(LaTeXSettings LatexSettings)
Renders LaTeX from a Markdown document.
override async Task Render(CenterAligned Element)
Renders Element .
override Task Render(LinkReference Element)
Renders Element .
override Task Render(InlineText Element)
Renders Element .
override Task Render(HtmlEntityUnicode Element)
Renders Element .
override async Task Render(FootnoteReference Element)
Renders Element .
override async Task Render(InlineScript Element)
Renders Element .
override async Task Render(TaskItem Element)
Renders Element .
override Task Render(LineBreak Element)
Renders Element .
override Task Render(Footnote Element)
Renders Element .
override Task Render(Sections Element)
Renders Element .
override async Task Render(RightAligned Element)
Renders Element .
override Task Render(InlineCode Element)
Renders Element .
override async Task Render(StrikeThrough Element)
Renders Element .
override Task Render(Link Element)
Renders Element .
async Task RenderObject(object Result, bool AloneInParagraph, Variables Variables)
Generates HTML from Script output.
override async Task Render(BulletList Element)
Renders Element .
override Task Render(AutomaticLinkUrl Element)
Renders Element .
override Task Render(DefinitionTerms Element)
Renders Element .
override async Task Render(Table Element)
Renders Element .
override async Task Render(Emphasize Element)
Renders Element .
override async Task Render(MarginAligned Element)
Renders Element .
override Task Render(Model.SpanElements.Multimedia Element)
Renders Element .
override async Task Render(HtmlBlock Element)
Renders Element .
override Task Render(InvisibleBreak Element)
Renders Element .
override Task Render(Abbreviation Element)
Renders Element .
override async Task Render(DefinitionList Element)
Renders Element .
override Task Render(MetaReference Element)
Renders Element .
override async Task Render(TaskList Element)
Renders Element .
override Task RenderDocumentHeader()
Renders the document header.
LatexRenderer(StringBuilder Output, LaTeXSettings LatexSettings)
Renders LaTeX from a Markdown document.
override Task Render(MultimediaReference Element)
Renders Element .
override async Task Render(UnnumberedItem Element)
Renders Element .
override Task Render(DefinitionDescriptions Element)
Renders Element .
override Task Render(AutomaticLinkMail Element)
Renders Element .
static string EscapeLaTeX(string s)
Escapes text for output in a LaTeX document.
override Task Render(InlineHTML Element)
Renders Element .
override async Task Render(LeftAligned Element)
Renders Element .
override async Task Render(Delete Element)
Renders Element .
readonly LaTeXSettings LatexSettings
LaTeX settings.
override async Task Render(NumberedList Element)
Renders Element .
override async Task Render(DeleteBlocks Element)
Renders Element .
override async Task Render(Underline Element)
Renders Element .
override Task Render(HashTag Element)
Renders Element .
override Task RenderDocumentFooter()
Renders the document header.
override async Task Render(SuperScript Element)
Renders Element .
override async Task Render(Header Element)
Renders Element .
override async Task Render(Paragraph Element)
Renders Element .
override async Task Render(NumberedItem Element)
Renders Element .
override Task Render(CommentBlock Element)
Renders Element .
override Task Render(SectionSeparator Element)
Renders Element .
override Task Render(DetailsReference Element)
Renders Element .
override Task Render(HorizontalRule Element)
Renders Element .
override async Task Render(CodeBlock Element)
Renders Element .
Class that can be used to encapsulate Markdown to be returned from a Web Service, bypassing any encod...
Contains a markdown document. This markdown document class supports original markdown,...
static async Task< object > TransformXml(XmlDocument Xml, Variables Variables)
Transforms XML to an object that is easier to visualize.
bool TryGetMetaData(string Key, out KeyValuePair< string, bool >[] Value)
Tries to get a meta-data value given its key.
MarkdownDocument Detail
Detail document of a master document.
Multimedia GetReference(string Label)
Gets the multimedia information referenced by a label.
static Task< MarkdownDocument > CreateAsync(string MarkdownText, params Type[] TransparentExceptionTypes)
Contains a markdown document. This markdown document class supports original markdown,...
Contains settings that the Markdown parser uses to customize its behavior.
Represents a block quote in a markdown document.
Represents a bullet list in a markdown document.
Represents a center-aligned set of blocks in a markdown document.
Represents a code block in a markdown document.
string IndentString
String used for indentation.
int Indent
Code block indentation.
string[] Rows
Rows in code block
Represents a definition list in a markdown document.
Represents inserted blocks in a markdown document.
Represents a block of HTML in a markdown document.
Represents inserted blocks in a markdown document.
Represents a left-aligned set of blocks in a markdown document.
Represents a margin-aligned set of blocks in a markdown document.
Represents a nested block with no special formatting rules in a markdown document.
Represents a numbered item in an ordered list.
bool NumberExplicit
If number is explicitly provided (true) or inferred (false).
int Number
Number associated with item.
Represents a numbered list in a markdown document.
Represents a paragraph in a markdown document.
Represents a right-aligned set of blocks in a markdown document.
Represents a sequence of sections.
Represents a table in a markdown document.
int Columns
Number of columns.
Represents a task item in a task list.
bool IsChecked
If the item is checked or not.
Represents a task list in a markdown document.
Represents an unnumbered item in an ordered list.
override IEnumerable< MarkdownElement > Children
Any children of the element.
Abstract base class for all markdown elements.
abstract Task Render(IRenderer Output)
Renders the element.
virtual IEnumerable< MarkdownElement > Children
Any children of the element.
MarkdownDocument Document
Markdown document.
static Task< string > GetTemporaryFile(byte[] BinaryImage)
Stores an image in binary form as a temporary file. Files will be deleted when application closes.
EmojiInfo Emoji
Emoji information.
Represents an HTML entity.
Represents an HTML entity in Unicode format.
int Code
Unicode character
bool AloneInParagraph
If the element is alone in a paragraph.
Variables Variables
Variables.
async Task< object > EvaluateExpression()
Evaluates the script expression.
string Value
Unformatted text.
bool TryGetMetaData(out KeyValuePair< string, bool >[] Values)
Tries to get meta-data from the document.
MultimediaItem[] Items
Multimedia items.
bool AloneInParagraph
If the element is alone in a paragraph.
Abstract base class for Markdown renderers.
readonly StringBuilder Output
Renderer output.
Task RenderChild(MarkdownElementSingleChild Element)
Renders the child of Element .
async Task RenderChildren(MarkdownElementChildren Element)
Renders the children of Element .
virtual async Task RenderDocument(MarkdownDocument Document, bool Inclusion)
Renders a document.
override string ToString()
Returns the renderer output.
MarkdownDocument Document
Reference to Markdown document being processed.
Static class managing the application event log. Applications and services log events on this static ...
static Exception UnnestException(Exception Exception)
Unnests an exception, to extract the relevant inner exception.
Class managing a script expression.
static string ToString(double Value)
Converts a value to a string, that can be parsed as part of an expression.
ToMatrix(ScriptNode Operand, bool NullCheck, int Start, int Length, Expression Expression)
To-Matrix operator.
Interface for code content LaTeX renderers.
Interface for multimedia content LaTeX renderers.
Interface for objects that can be converted into matrices.
LaTeXDocumentClass
Document class of LaTeX output.
LaTeXPaper
LaTeX output paper format
TextAlignment
Text alignment of contents.