#include "i18n.h"
#include "latex.h"
#include "parser.h"
+#include "scanners.h"
#define print(x) d_string_append(out, x)
print_char(c);
print_char('$');
break;
+ case '|':
+ print("\\textbar{}");
+ break;
case '#':
case '{':
case '}':
print("\\end{verbatim}");
scratch->padded = 0;
break;
+ case BLOCK_DEFINITION:
+ pad(out, 2, scratch);
+
+ temp_short = scratch->list_is_tight;
+ if (!(t->child->next && (t->child->next->type == BLOCK_EMPTY) && t->child->next->next))
+ scratch->list_is_tight = true;
+
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ scratch->padded = 0;
+
+ scratch->list_is_tight = temp_short;
+ break;
+ case BLOCK_DEFLIST:
+ pad(out, 2, scratch);
+
+ // Group consecutive definition lists into a single list.
+ // lemon's LALR(1) parser can't properly handle this (to my understanding).
+
+ if (!(t->prev && (t->prev->type == BLOCK_DEFLIST)))
+ print("\\begin{description}\n");
+
+ scratch->padded = 2;
+
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ pad(out, 1, scratch);
+
+ if (!(t->next && (t->next->type == BLOCK_DEFLIST)))
+ print("\\end{description}\n");
+
+ scratch->padded = 1;
+ break;
case BLOCK_EMPTY:
break;
case BLOCK_H1:
}
scratch->padded = 0;
break;
+ case BLOCK_HR:
+ pad(out, 2, scratch);
+ print("\\begin{center}\\rule{3in}{0.4pt}\\end{center}");
+ scratch->padded = 0;
+ break;
+ case BLOCK_HTML:
+ // Don't print HTML
+ break;
case BLOCK_LIST_BULLETED_LOOSE:
case BLOCK_LIST_BULLETED:
temp_short = scratch->list_is_tight;
mmd_export_token_tree_latex(out, source, t->child, scratch);
scratch->padded = 0;
break;
+ case BLOCK_TERM:
+ pad(out, 2, scratch);
+ print("\\item[");
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ print("]");
+ scratch->padded = 0;
+ break;
case BRACE_DOUBLE_LEFT:
print("\\{\\{");
break;
print_char('#');
}
break;
+ case INDENT_SPACE:
+ print_char(' ');
+ break;
+ case INDENT_TAB:
+ print_char('\t');
+ break;
case LINE_LIST_BULLETED:
case LINE_LIST_ENUMERATED:
mmd_export_token_tree_latex(out, source, t->child, scratch);
case NON_INDENT_SPACE:
print_char(' ');
break;
+ case PAIR_ANGLE:
+ temp_token = t;
+
+ temp_char = url_accept(source, &temp_token, true);
+
+ if (temp_char) {
+ if (scan_email(temp_char)) {
+ print("\\href{mailto:");
+ print(temp_char);
+ } else {
+ print("\\href{");
+ print(temp_char);
+ }
+ print("}{");
+ mmd_print_string_latex(out, temp_char);
+ print("}");
+ } else if (scan_html(&source[t->start])) {
+ print_token(t);
+ } else {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ }
+
+ free(temp_char);
+ break;
case PAIR_BACKTICK:
// Strip leading whitespace
switch (t->child->next->type) {
printf("\\footnote{");
temp_note = stack_peek_index(scratch->used_footnotes, temp_short - 1);
- mmd_export_token_latex(out, source, temp_note->content, scratch);
+ mmd_export_token_tree_latex(out, source, temp_note->content, scratch);
printf("}");
}
} else {
mmd_export_token_tree_latex(out, source, t->child, scratch);
}
break;
+ case PAIR_BRACKET_VARIABLE:
+ temp_char = text_inside_pair(source, t);
+ temp_char2 = extract_metadata(scratch, temp_char);
+
+ if (temp_char2)
+ mmd_print_string_latex(out, temp_char2);
+ else
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+
+ // Don't free temp_char2 (it belongs to meta *)
+ free(temp_char);
+ break;
+ case PAIR_CRITIC_ADD:
+ // Ignore if we're rejecting
+ if (scratch->extensions & EXT_CRITIC_REJECT)
+ break;
+ if (scratch->extensions & EXT_CRITIC) {
+ t->child->type = TEXT_EMPTY;
+ t->child->mate->type = TEXT_EMPTY;
+ if (scratch->extensions & EXT_CRITIC_ACCEPT) {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ } else {
+ print("\\underline{");
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ print("}");
+ }
+ } else {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ }
+ break;
+ case PAIR_CRITIC_DEL:
+ // Ignore if we're accepting
+ if (scratch->extensions & EXT_CRITIC_ACCEPT)
+ break;
+ if (scratch->extensions & EXT_CRITIC) {
+ t->child->type = TEXT_EMPTY;
+ t->child->mate->type = TEXT_EMPTY;
+ if (scratch->extensions & EXT_CRITIC_REJECT) {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ } else {
+ print("\\sout{");
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ print("}");
+ }
+ } else {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ }
+ break;
+ case PAIR_CRITIC_COM:
+ // Ignore if we're rejecting or accepting
+ if ((scratch->extensions & EXT_CRITIC_REJECT) ||
+ (scratch->extensions & EXT_CRITIC_ACCEPT))
+ break;
+ if (scratch->extensions & EXT_CRITIC) {
+ t->child->type = TEXT_EMPTY;
+ t->child->mate->type = TEXT_EMPTY;
+ print("\\todo{");
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ print("}");
+ } else {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ }
+ break;
+ case PAIR_CRITIC_HI:
+ // Ignore if we're rejecting or accepting
+ if ((scratch->extensions & EXT_CRITIC_REJECT) ||
+ (scratch->extensions & EXT_CRITIC_ACCEPT))
+ break;
+ if (scratch->extensions & EXT_CRITIC) {
+ t->child->type = TEXT_EMPTY;
+ t->child->mate->type = TEXT_EMPTY;
+ // 'hl' requires 'soul' package
+ print("\\hl{");
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ print("}");
+ } else {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ }
+ break;
+ case CRITIC_SUB_DIV_A:
+ print("~");
+ break;
+ case CRITIC_SUB_DIV_B:
+ print(">");
+ break;
+ case PAIR_CRITIC_SUB_DEL:
+ if ((scratch->extensions & EXT_CRITIC) &&
+ (t->next->type == PAIR_CRITIC_SUB_ADD)) {
+ t->child->type = TEXT_EMPTY;
+ t->child->mate->type = TEXT_EMPTY;
+ if (scratch->extensions & EXT_CRITIC_ACCEPT) {
+
+ } else if (scratch->extensions & EXT_CRITIC_REJECT) {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ } else {
+ print("\\sout{");
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ print("}");
+ }
+ } else {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ }
+ break;
+ case PAIR_CRITIC_SUB_ADD:
+ if ((scratch->extensions & EXT_CRITIC) &&
+ (t->prev->type == PAIR_CRITIC_SUB_DEL)) {
+ t->child->type = TEXT_EMPTY;
+ t->child->mate->type = TEXT_EMPTY;
+ if (scratch->extensions & EXT_CRITIC_REJECT) {
+
+ } else if (scratch->extensions & EXT_CRITIC_ACCEPT) {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ } else {
+ print("\\underline{");
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ print("}");
+ }
+ } else {
+ mmd_export_token_tree_latex(out, source, t->child, scratch);
+ }
+ break;
case PAIR_MATH:
case PAIR_PAREN:
case PAIR_QUOTE_DOUBLE:
print(")");
break;
case PIPE:
- print_token(t);
+ print("\\textbar{}");
break;
case PLUS:
print_token(t);
+++ /dev/null
-foo ${e}^{i\pi }+1=0$ bar
-
-\[ {x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a} \]
-
-foo ${e}^{i\pi }+1=0$ bar
-
-foo ${e}^{i\pi }+1=0$, bar
-
-$${x}_{1,2}=\frac{-b\pm \sqrt{{b}^{2}-4ac}}{2a}$$
-
-5
-
-foo \$ \{e\}\textsuperscript{{i}\textbackslash{}pi \}+1=0\$ bar
-
-\$\$ \{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\textsuperscript{{2}}--4ac\}\}\{2a\}\$\$
-
-foo \$\{e\}\textsuperscript{{i}\textbackslash{}pi \}+1=0 \$ bar
-
-\$\$\{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\textsuperscript{{2}}--4ac\}\}\{2a\} \$\$
-
-foo a\$\{e\}\textsuperscript{{i}\textbackslash{}pi \}+1=0\$ bar
-
-10
-
-a\$\$\{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\textsuperscript{{2}}--4ac\}\}\{2a\}\$\$
-
-foo \$\{e\}\textsuperscript{{i}\textbackslash{}pi \}+1=0\$b bar
-
-\$\$\{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\textsuperscript{{2}}--4ac\}\}\{2a\}\$\$b
-
-$\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}$
-
-$$\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}$$
-
-15
-
-$\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}$
-
-\[\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\]
-
-\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}
-
-$\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}
-
-\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}
-
-20
-
-\begin{equation}\nabla \times \mathbf{E} = - \frac{\partial \mathbf{B}}{\partial t}\end{equation}
-
-\texttt{\textbackslash{}begin\{equation\}\textbackslash{}nabla \textbackslash{}times \textbackslash{}mathbf\{E\} = - \textbackslash{}frac\{\textbackslash{}partial \textbackslash{}mathbf\{B\}\}\{\textbackslash{}partial t\}\textbackslash{}end\{equation\}}