From 8ac321ae4a0e44727457d22594ffd66dd4bd5ee6 Mon Sep 17 00:00:00 2001 From: "Fletcher T. Penney" Date: Mon, 13 Feb 2017 12:18:32 -0500 Subject: [PATCH] FIXED: Get Math working in LaTeX --- src/html.c | 3 + src/latex.c | 38 +- src/lexer.c | 901 ++++++++++++++++++++------------------- src/lexer.re | 5 +- src/libMultiMarkdown.h | 3 + tests/MMD6Tests/Math.tex | 51 +++ 6 files changed, 548 insertions(+), 453 deletions(-) create mode 100644 tests/MMD6Tests/Math.tex diff --git a/src/html.c b/src/html.c index fd5fd9e..fef4882 100644 --- a/src/html.c +++ b/src/html.c @@ -1333,6 +1333,9 @@ void mmd_export_token_html(DString * out, const char * source, token * t, size_t if (t->next) print_char('\n'); break; + case TEXT_BACKSLASH: + case TEXT_BRACE_LEFT: + case TEXT_BRACE_RIGHT: case TEXT_HASH: case TEXT_NUMBER_POSS_LIST: case TEXT_PERCENT: diff --git a/src/latex.c b/src/latex.c index 111e9ed..7c7384a 100644 --- a/src/latex.c +++ b/src/latex.c @@ -688,7 +688,10 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat print("\\$"); break; case MATH_DOLLAR_DOUBLE: - print("$$"); + if (t->mate) + print("$$"); + else + print("\\$\\$"); break; case MATH_PAREN_OPEN: print("\\("); @@ -1036,10 +1039,14 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat } break; case PAIR_MATH: - // Math is raw LaTeX -- use string itself - mmd_export_token_latex(out, source, t->child, scratch); + if (strncmp(&source[t->child->start + t->child->len], "\\begin", 6) != 0) + mmd_export_token_latex(out, source, t->child, scratch); + + // Math is raw LaTeX -- use string itself rather than interior tokens d_string_append_c_array(out, &(source[t->child->start + t->child->len]), t->child->mate->start - t->child->start - t->child->len); - mmd_export_token_latex(out, source, t->child->mate, scratch); + + if (strncmp(&source[t->child->start + t->child->len], "\\begin", 6) != 0) + mmd_export_token_latex(out, source, t->child->mate, scratch); break; case PAIR_PAREN: case PAIR_QUOTE_DOUBLE: @@ -1112,6 +1119,9 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat print("\\^{}"); } break; + case TEXT_BACKSLASH: + print("\\textbackslash{}"); + break; case TEXT_EMPTY: break; case TEXT_HASH: @@ -1124,6 +1134,9 @@ void mmd_export_token_latex(DString * out, const char * source, token * t, scrat case TEXT_PERCENT: print("\\%"); break; + case TEXT_BRACE_LEFT: + case TEXT_BRACE_RIGHT: + print("\\"); case TEXT_NUMBER_POSS_LIST: case TEXT_PERIOD: case TEXT_PLAIN: @@ -1177,7 +1190,7 @@ void mmd_export_token_latex_raw(DString * out, const char * source, token * t, s if (t->next) t->next->type = TEXT_EMPTY; case TEXT_EMPTY: - break; + break; default: if (t->child) mmd_export_token_tree_latex_raw(out, source, t->child, scratch); @@ -1235,6 +1248,21 @@ void mmd_export_token_latex_tt(DString * out, const char * source, token * t, sc t->next->type = TEXT_EMPTY; case TEXT_EMPTY: break; + case SLASH: + print("\\slash "); + break; + case TEXT_BACKSLASH: + print("\\textbackslash{}"); + break; + case BRACE_DOUBLE_LEFT: + print("\\{\\{"); + break; + case BRACE_DOUBLE_RIGHT: + print("\\}\\}"); + break; + case TEXT_BRACE_LEFT: + case TEXT_BRACE_RIGHT: + print("\\"); default: if (t->child) mmd_export_token_tree_latex_tt(out, source, t->child, scratch); diff --git a/src/lexer.c b/src/lexer.c index 1982779..28227fd 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.14.3 on Sun Feb 12 19:24:07 2017 */ +/* Generated by re2c 0.14.3 on Mon Feb 13 10:36:45 2017 */ /** MultiMarkdown 6 -- Lightweight markup processor to produce HTML, LaTeX, and more. @@ -84,24 +84,24 @@ int scan(Scanner * s, const char * stop) { yych = *YYCURSOR; switch (yych) { - case '\t': goto yy42; - case '\n': goto yy50; - case '\r': goto yy52; - case ' ': goto yy44; + case '\t': goto yy45; + case '\n': goto yy53; + case '\r': goto yy55; + case ' ': goto yy47; case '!': goto yy18; - case '"': goto yy26; - case '#': goto yy45; - case '$': goto yy38; - case '%': goto yy47; - case '&': goto yy33; - case '\'': goto yy28; - case '(': goto yy19; - case ')': goto yy21; - case '*': goto yy53; + case '"': goto yy28; + case '#': goto yy48; + case '$': goto yy41; + case '%': goto yy50; + case '&': goto yy35; + case '\'': goto yy30; + case '(': goto yy20; + case ')': goto yy22; + case '*': goto yy56; case '+': goto yy4; case '-': goto yy6; - case '.': goto yy30; - case '/': goto yy35; + case '.': goto yy32; + case '/': goto yy37; case '0': case '1': case '2': @@ -111,42 +111,42 @@ int scan(Scanner * s, const char * stop) { case '6': case '7': case '8': - case '9': goto yy49; - case ':': goto yy31; + case '9': goto yy52; + case ':': goto yy33; case '<': goto yy8; case '=': goto yy12; - case '>': goto yy23; + case '>': goto yy24; case '[': goto yy14; - case '\\': goto yy37; + case '\\': goto yy39; case ']': goto yy16; - case '^': goto yy40; - case '_': goto yy55; - case '`': goto yy57; + case '^': goto yy43; + case '_': goto yy58; + case '`': goto yy60; case '{': goto yy2; - case '|': goto yy59; - case '}': goto yy25; + case '|': goto yy62; + case '}': goto yy26; case '~': goto yy10; - default: goto yy61; + default: goto yy64; } yy2: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case '+': goto yy259; - case '-': goto yy258; - case '=': goto yy255; - case '>': goto yy257; - case '{': goto yy253; - case '~': goto yy256; + case '+': goto yy262; + case '-': goto yy261; + case '=': goto yy258; + case '>': goto yy260; + case '{': goto yy256; + case '~': goto yy259; default: goto yy3; } yy3: - { goto scan; } + { return TEXT_BRACE_LEFT; } yy4: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case '+': goto yy250; + case '+': goto yy253; default: goto yy5; } yy5: @@ -154,7 +154,7 @@ yy5: yy6: ++YYCURSOR; switch ((yych = *YYCURSOR)) { - case '-': goto yy244; + case '-': goto yy247; default: goto yy7; } yy7: @@ -163,7 +163,7 @@ yy8: yyaccept = 2; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case '<': goto yy241; + case '<': goto yy244; default: goto yy9; } yy9: @@ -172,8 +172,8 @@ yy10: yyaccept = 3; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case '>': goto yy237; - case '~': goto yy236; + case '>': goto yy240; + case '~': goto yy239; default: goto yy11; } yy11: @@ -182,7 +182,7 @@ yy12: yyaccept = 4; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case '=': goto yy233; + case '=': goto yy236; default: goto yy13; } yy13: @@ -190,9 +190,9 @@ yy13: yy14: ++YYCURSOR; switch ((yych = *YYCURSOR)) { - case '#': goto yy229; - case '%': goto yy227; - case '^': goto yy231; + case '#': goto yy232; + case '%': goto yy230; + case '^': goto yy234; default: goto yy15; } yy15: @@ -201,148 +201,154 @@ yy16: ++YYCURSOR; { return BRACKET_RIGHT; } yy18: - yych = *++YYCURSOR; - switch (yych) { - case '[': goto yy225; - default: goto yy3; + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case '[': goto yy228; + default: goto yy19; } yy19: + { goto scan; } +yy20: ++YYCURSOR; { return PAREN_LEFT; } -yy21: +yy22: ++YYCURSOR; { return PAREN_RIGHT; } -yy23: +yy24: ++YYCURSOR; { return ANGLE_RIGHT; } -yy25: - yych = *++YYCURSOR; - switch (yych) { - case '}': goto yy223; - default: goto yy3; - } yy26: ++YYCURSOR; - { return QUOTE_DOUBLE; } + switch ((yych = *YYCURSOR)) { + case '}': goto yy226; + default: goto yy27; + } +yy27: + { return TEXT_BRACE_RIGHT; } yy28: + ++YYCURSOR; + { return QUOTE_DOUBLE; } +yy30: ++YYCURSOR; switch ((yych = *YYCURSOR)) { - case '\'': goto yy221; - default: goto yy29; + case '\'': goto yy224; + default: goto yy31; } -yy29: +yy31: { return QUOTE_SINGLE; } -yy30: +yy32: YYCTXMARKER = YYCURSOR + 1; - yyaccept = 0; + yyaccept = 5; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case '\t': goto yy211; - case '\n': goto yy208; - case '\r': goto yy210; - case ' ': goto yy213; - case '.': goto yy214; - default: goto yy3; + case '\t': goto yy214; + case '\n': goto yy211; + case '\r': goto yy213; + case ' ': goto yy216; + case '.': goto yy217; + default: goto yy19; } -yy31: +yy33: ++YYCURSOR; { return COLON; } -yy33: - yyaccept = 5; +yy35: + yyaccept = 6; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { case 'A': - case 'a': goto yy203; - default: goto yy34; + case 'a': goto yy206; + default: goto yy36; } -yy34: +yy36: { return AMPERSAND; } -yy35: +yy37: ++YYCURSOR; { return SLASH; } -yy37: - yych = *++YYCURSOR; - switch (yych) { - case ' ': goto yy131; - case '!': goto yy191; - case '"': goto yy181; - case '#': goto yy161; - case '$': goto yy159; - case '%': goto yy157; - case '&': goto yy145; - case '\'': goto yy179; - case '(': goto yy173; - case ')': goto yy171; - case '*': goto yy137; - case '+': goto yy155; - case ',': goto yy187; - case '-': goto yy153; - case '.': goto yy193; - case '/': goto yy141; - case ':': goto yy183; - case ';': goto yy185; - case '<': goto yy149; - case '=': goto yy151; - case '>': goto yy147; - case '?': goto yy189; - case '@': goto yy143; - case '[': goto yy165; - case '\\': goto yy129; - case ']': goto yy163; - case '^': goto yy139; - case '_': goto yy135; - case '`': goto yy177; - case '{': goto yy169; - case '|': goto yy133; - case '}': goto yy167; - case '~': goto yy175; - default: goto yy3; +yy39: + ++YYCURSOR; + switch ((yych = *YYCURSOR)) { + case ' ': goto yy134; + case '!': goto yy194; + case '"': goto yy184; + case '#': goto yy164; + case '$': goto yy162; + case '%': goto yy160; + case '&': goto yy148; + case '\'': goto yy182; + case '(': goto yy176; + case ')': goto yy174; + case '*': goto yy140; + case '+': goto yy158; + case ',': goto yy190; + case '-': goto yy156; + case '.': goto yy196; + case '/': goto yy144; + case ':': goto yy186; + case ';': goto yy188; + case '<': goto yy152; + case '=': goto yy154; + case '>': goto yy150; + case '?': goto yy192; + case '@': goto yy146; + case '[': goto yy168; + case '\\': goto yy132; + case ']': goto yy166; + case '^': goto yy142; + case '_': goto yy138; + case '`': goto yy180; + case '{': goto yy172; + case '|': goto yy136; + case '}': goto yy170; + case '~': goto yy178; + default: goto yy40; } -yy38: +yy40: + { return TEXT_BACKSLASH; } +yy41: ++YYCURSOR; switch ((yych = *YYCURSOR)) { - case '$': goto yy127; - default: goto yy39; + case '$': goto yy130; + default: goto yy42; } -yy39: +yy42: { return MATH_DOLLAR_SINGLE; } -yy40: +yy43: ++YYCURSOR; { return SUPERSCRIPT; } -yy42: +yy45: ++YYCURSOR; { return INDENT_TAB; } -yy44: +yy47: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy50; - case '\r': goto yy118; - case ' ': goto yy116; - default: goto yy3; + case '\n': goto yy53; + case '\r': goto yy121; + case ' ': goto yy119; + default: goto yy19; } -yy45: +yy48: YYCTXMARKER = YYCURSOR + 1; - yyaccept = 6; + yyaccept = 7; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { case '\t': case '\n': case '\r': - case ' ': goto yy77; - case '#': goto yy75; - default: goto yy46; + case ' ': goto yy80; + case '#': goto yy78; + default: goto yy49; } -yy46: +yy49: { return TEXT_HASH; } -yy47: +yy50: ++YYCURSOR; { return TEXT_PERCENT; } -yy49: +yy52: YYCTXMARKER = YYCURSOR + 1; - yyaccept = 0; + yyaccept = 5; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case '.': goto yy66; + case '.': goto yy69; case '0': case '1': case '2': @@ -352,66 +358,66 @@ yy49: case '6': case '7': case '8': - case '9': goto yy68; - default: goto yy3; + case '9': goto yy71; + default: goto yy19; } -yy50: +yy53: ++YYCURSOR; -yy51: +yy54: { return TEXT_NL; } -yy52: +yy55: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy50; - default: goto yy51; + case '\n': goto yy53; + default: goto yy54; } -yy53: +yy56: ++YYCURSOR; { return STAR; } -yy55: +yy58: ++YYCURSOR; { return UL; } -yy57: +yy60: ++YYCURSOR; yych = *YYCURSOR; - goto yy65; -yy58: + goto yy68; +yy61: { return BACKTICK; } -yy59: +yy62: ++YYCURSOR; yych = *YYCURSOR; - goto yy63; -yy60: + goto yy66; +yy63: { return PIPE; } -yy61: +yy64: yych = *++YYCURSOR; - goto yy3; -yy62: + goto yy19; +yy65: ++YYCURSOR; yych = *YYCURSOR; -yy63: +yy66: switch (yych) { - case '|': goto yy62; - default: goto yy60; + case '|': goto yy65; + default: goto yy63; } -yy64: +yy67: ++YYCURSOR; yych = *YYCURSOR; -yy65: +yy68: switch (yych) { - case '`': goto yy64; - default: goto yy58; + case '`': goto yy67; + default: goto yy61; } -yy66: +yy69: yych = *++YYCURSOR; switch (yych) { case '\t': - case ' ': goto yy73; - case '\n': goto yy70; - case '\r': goto yy72; - default: goto yy67; + case ' ': goto yy76; + case '\n': goto yy73; + case '\r': goto yy75; + default: goto yy70; } -yy67: +yy70: YYCURSOR = YYMARKER; switch (yyaccept) { case 0: goto yy3; @@ -419,18 +425,19 @@ yy67: case 2: goto yy9; case 3: goto yy11; case 4: goto yy13; - case 5: goto yy34; - case 6: goto yy46; - case 7: goto yy124; - case 8: goto yy209; - default: goto yy254; + case 5: goto yy19; + case 6: goto yy36; + case 7: goto yy49; + case 8: goto yy127; + case 9: goto yy212; + default: goto yy257; } -yy68: +yy71: YYCTXMARKER = YYCURSOR + 1; ++YYCURSOR; yych = *YYCURSOR; switch (yych) { - case '.': goto yy66; + case '.': goto yy69; case '0': case '1': case '2': @@ -440,627 +447,627 @@ yy68: case '6': case '7': case '8': - case '9': goto yy68; - default: goto yy67; + case '9': goto yy71; + default: goto yy70; } -yy70: +yy73: ++YYCURSOR; -yy71: +yy74: YYCURSOR = YYCTXMARKER; { return TEXT_NUMBER_POSS_LIST; } -yy72: +yy75: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy70; - default: goto yy71; + case '\n': goto yy73; + default: goto yy74; } -yy73: +yy76: ++YYCURSOR; yych = *YYCURSOR; switch (yych) { case '\t': - case ' ': goto yy73; - default: goto yy71; + case ' ': goto yy76; + default: goto yy74; } -yy75: +yy78: YYCTXMARKER = YYCURSOR + 1; yych = *++YYCURSOR; switch (yych) { case '\t': case '\n': case '\r': - case ' ': goto yy83; - case '#': goto yy88; - default: goto yy67; + case ' ': goto yy86; + case '#': goto yy91; + default: goto yy70; } -yy76: +yy79: ++YYCURSOR; yych = *YYCURSOR; -yy77: +yy80: switch (yych) { case '\t': - case ' ': goto yy76; - case '\n': goto yy79; - case '\r': goto yy81; - default: goto yy78; + case ' ': goto yy79; + case '\n': goto yy82; + case '\r': goto yy84; + default: goto yy81; } -yy78: +yy81: { return HASH1; } -yy79: +yy82: ++YYCURSOR; -yy80: +yy83: YYCURSOR = YYCTXMARKER; { return HASH1; } -yy81: +yy84: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy79; - default: goto yy80; + case '\n': goto yy82; + default: goto yy83; } -yy82: +yy85: ++YYCURSOR; yych = *YYCURSOR; -yy83: +yy86: switch (yych) { case '\t': - case ' ': goto yy82; - case '\n': goto yy85; - case '\r': goto yy87; - default: goto yy84; + case ' ': goto yy85; + case '\n': goto yy88; + case '\r': goto yy90; + default: goto yy87; } -yy84: +yy87: { return HASH2; } -yy85: +yy88: ++YYCURSOR; -yy86: +yy89: YYCURSOR = YYCTXMARKER; { return HASH2; } -yy87: +yy90: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy85; - default: goto yy86; + case '\n': goto yy88; + default: goto yy89; } -yy88: +yy91: YYCTXMARKER = YYCURSOR + 1; yych = *++YYCURSOR; switch (yych) { case '\t': case '\n': case '\r': - case ' ': goto yy91; - case '#': goto yy89; - default: goto yy67; + case ' ': goto yy94; + case '#': goto yy92; + default: goto yy70; } -yy89: +yy92: YYCTXMARKER = YYCURSOR + 1; yych = *++YYCURSOR; switch (yych) { case '\t': case '\n': case '\r': - case ' ': goto yy97; - case '#': goto yy102; - default: goto yy67; + case ' ': goto yy100; + case '#': goto yy105; + default: goto yy70; } -yy90: +yy93: ++YYCURSOR; yych = *YYCURSOR; -yy91: +yy94: switch (yych) { case '\t': - case ' ': goto yy90; - case '\n': goto yy93; - case '\r': goto yy95; - default: goto yy92; + case ' ': goto yy93; + case '\n': goto yy96; + case '\r': goto yy98; + default: goto yy95; } -yy92: +yy95: { return HASH3; } -yy93: +yy96: ++YYCURSOR; -yy94: +yy97: YYCURSOR = YYCTXMARKER; { return HASH3; } -yy95: +yy98: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy93; - default: goto yy94; + case '\n': goto yy96; + default: goto yy97; } -yy96: +yy99: ++YYCURSOR; yych = *YYCURSOR; -yy97: +yy100: switch (yych) { case '\t': - case ' ': goto yy96; - case '\n': goto yy99; - case '\r': goto yy101; - default: goto yy98; + case ' ': goto yy99; + case '\n': goto yy102; + case '\r': goto yy104; + default: goto yy101; } -yy98: +yy101: { return HASH4; } -yy99: +yy102: ++YYCURSOR; -yy100: +yy103: YYCURSOR = YYCTXMARKER; { return HASH4; } -yy101: +yy104: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy99; - default: goto yy100; + case '\n': goto yy102; + default: goto yy103; } -yy102: +yy105: YYCTXMARKER = YYCURSOR + 1; yych = *++YYCURSOR; switch (yych) { case '\t': case '\n': case '\r': - case ' ': goto yy105; - case '#': goto yy103; - default: goto yy67; + case ' ': goto yy108; + case '#': goto yy106; + default: goto yy70; } -yy103: +yy106: YYCTXMARKER = YYCURSOR + 1; yych = *++YYCURSOR; switch (yych) { case '\t': case '\n': case '\r': - case ' ': goto yy111; - default: goto yy67; + case ' ': goto yy114; + default: goto yy70; } -yy104: +yy107: ++YYCURSOR; yych = *YYCURSOR; -yy105: +yy108: switch (yych) { case '\t': - case ' ': goto yy104; - case '\n': goto yy107; - case '\r': goto yy109; - default: goto yy106; + case ' ': goto yy107; + case '\n': goto yy110; + case '\r': goto yy112; + default: goto yy109; } -yy106: +yy109: { return HASH5; } -yy107: +yy110: ++YYCURSOR; -yy108: +yy111: YYCURSOR = YYCTXMARKER; { return HASH5; } -yy109: +yy112: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy107; - default: goto yy108; + case '\n': goto yy110; + default: goto yy111; } -yy110: +yy113: ++YYCURSOR; yych = *YYCURSOR; -yy111: +yy114: switch (yych) { case '\t': - case ' ': goto yy110; - case '\n': goto yy113; - case '\r': goto yy115; - default: goto yy112; + case ' ': goto yy113; + case '\n': goto yy116; + case '\r': goto yy118; + default: goto yy115; } -yy112: +yy115: { return HASH6; } -yy113: +yy116: ++YYCURSOR; -yy114: +yy117: YYCURSOR = YYCTXMARKER; { return HASH6; } -yy115: +yy118: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy113; - default: goto yy114; + case '\n': goto yy116; + default: goto yy117; } -yy116: +yy119: ++YYCURSOR; switch ((yych = *YYCURSOR)) { - case '\n': goto yy120; - case '\r': goto yy122; - case ' ': goto yy119; - default: goto yy117; + case '\n': goto yy123; + case '\r': goto yy125; + case ' ': goto yy122; + default: goto yy120; } -yy117: +yy120: { return NON_INDENT_SPACE; } -yy118: +yy121: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy50; - default: goto yy51; + case '\n': goto yy53; + default: goto yy54; } -yy119: +yy122: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy120; - case '\r': goto yy122; - case ' ': goto yy123; - default: goto yy117; + case '\n': goto yy123; + case '\r': goto yy125; + case ' ': goto yy126; + default: goto yy120; } -yy120: +yy123: ++YYCURSOR; -yy121: +yy124: { return TEXT_LINEBREAK; } -yy122: +yy125: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy120; - default: goto yy121; + case '\n': goto yy123; + default: goto yy124; } -yy123: - yyaccept = 7; +yy126: + yyaccept = 8; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case '\n': goto yy120; - case '\r': goto yy122; - case ' ': goto yy125; - default: goto yy124; + case '\n': goto yy123; + case '\r': goto yy125; + case ' ': goto yy128; + default: goto yy127; } -yy124: +yy127: { return INDENT_SPACE; } -yy125: +yy128: ++YYCURSOR; yych = *YYCURSOR; switch (yych) { - case '\n': goto yy120; - case '\r': goto yy122; - case ' ': goto yy125; - default: goto yy67; + case '\n': goto yy123; + case '\r': goto yy125; + case ' ': goto yy128; + default: goto yy70; } -yy127: +yy130: ++YYCURSOR; { return MATH_DOLLAR_DOUBLE; } -yy129: +yy132: ++YYCURSOR; switch ((yych = *YYCURSOR)) { - case '(': goto yy195; - case ')': goto yy197; - case '[': goto yy199; - case ']': goto yy201; - default: goto yy130; + case '(': goto yy198; + case ')': goto yy200; + case '[': goto yy202; + case ']': goto yy204; + default: goto yy133; } -yy130: +yy133: { return ESCAPED_CHARACTER; } -yy131: +yy134: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy133: +yy136: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy135: +yy138: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy137: +yy140: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy139: +yy142: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy141: +yy144: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy143: +yy146: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy145: +yy148: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy147: +yy150: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy149: +yy152: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy151: +yy154: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy153: +yy156: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy155: +yy158: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy157: +yy160: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy159: +yy162: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy161: +yy164: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy163: +yy166: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy165: +yy168: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy167: +yy170: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy169: +yy172: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy171: +yy174: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy173: +yy176: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy175: +yy178: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy177: +yy180: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy179: +yy182: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy181: +yy184: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy183: +yy186: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy185: +yy188: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy187: +yy190: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy189: +yy192: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy191: +yy194: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy193: +yy196: ++YYCURSOR; { return ESCAPED_CHARACTER; } -yy195: +yy198: ++YYCURSOR; { return MATH_PAREN_OPEN; } -yy197: +yy200: ++YYCURSOR; { return MATH_PAREN_CLOSE; } -yy199: +yy202: ++YYCURSOR; { return MATH_BRACKET_OPEN; } -yy201: +yy204: ++YYCURSOR; { return MATH_BRACKET_CLOSE; } -yy203: +yy206: yych = *++YYCURSOR; switch (yych) { case 'M': - case 'm': goto yy204; - default: goto yy67; + case 'm': goto yy207; + default: goto yy70; } -yy204: +yy207: yych = *++YYCURSOR; switch (yych) { case 'P': - case 'p': goto yy205; - default: goto yy67; + case 'p': goto yy208; + default: goto yy70; } -yy205: +yy208: yych = *++YYCURSOR; switch (yych) { - case ';': goto yy206; - default: goto yy67; + case ';': goto yy209; + default: goto yy70; } -yy206: +yy209: ++YYCURSOR; { return AMPERSAND_LONG; } -yy208: +yy211: ++YYCURSOR; -yy209: +yy212: YYCURSOR = YYCTXMARKER; { return TEXT_PERIOD; } -yy210: +yy213: yych = *++YYCURSOR; switch (yych) { - case '\n': goto yy208; - default: goto yy209; + case '\n': goto yy211; + default: goto yy212; } -yy211: +yy214: ++YYCURSOR; yych = *YYCURSOR; -yy212: +yy215: switch (yych) { case '\t': - case ' ': goto yy211; - default: goto yy209; + case ' ': goto yy214; + default: goto yy212; } -yy213: - yyaccept = 8; +yy216: + yyaccept = 9; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case '.': goto yy217; - default: goto yy212; + case '.': goto yy220; + default: goto yy215; } -yy214: +yy217: yych = *++YYCURSOR; switch (yych) { - case '.': goto yy215; - default: goto yy67; + case '.': goto yy218; + default: goto yy70; } -yy215: +yy218: ++YYCURSOR; { return ELLIPSIS; } -yy217: +yy220: yych = *++YYCURSOR; switch (yych) { - case ' ': goto yy218; - default: goto yy67; + case ' ': goto yy221; + default: goto yy70; } -yy218: +yy221: yych = *++YYCURSOR; switch (yych) { - case '.': goto yy219; - default: goto yy67; + case '.': goto yy222; + default: goto yy70; } -yy219: +yy222: ++YYCURSOR; { return ELLIPSIS; } -yy221: +yy224: ++YYCURSOR; { return QUOTE_RIGHT_ALT; } -yy223: +yy226: ++YYCURSOR; { return BRACE_DOUBLE_RIGHT; } -yy225: +yy228: ++YYCURSOR; { return BRACKET_IMAGE_LEFT; } -yy227: +yy230: ++YYCURSOR; { return BRACKET_VARIABLE_LEFT; } -yy229: +yy232: ++YYCURSOR; { return BRACKET_CITATION_LEFT; } -yy231: +yy234: ++YYCURSOR; { return BRACKET_FOOTNOTE_LEFT; } -yy233: +yy236: yych = *++YYCURSOR; switch (yych) { - case '}': goto yy234; - default: goto yy67; + case '}': goto yy237; + default: goto yy70; } -yy234: +yy237: ++YYCURSOR; { return CRITIC_HI_CLOSE; } -yy236: +yy239: yych = *++YYCURSOR; switch (yych) { - case '}': goto yy239; - default: goto yy67; + case '}': goto yy242; + default: goto yy70; } -yy237: +yy240: ++YYCURSOR; { return CRITIC_SUB_DIV; } -yy239: +yy242: ++YYCURSOR; { return CRITIC_SUB_CLOSE; } -yy241: +yy244: yych = *++YYCURSOR; switch (yych) { - case '}': goto yy242; - default: goto yy67; + case '}': goto yy245; + default: goto yy70; } -yy242: +yy245: ++YYCURSOR; { return CRITIC_COM_CLOSE; } -yy244: +yy247: ++YYCURSOR; switch ((yych = *YYCURSOR)) { - case '-': goto yy248; - case '}': goto yy246; - default: goto yy245; + case '-': goto yy251; + case '}': goto yy249; + default: goto yy248; } -yy245: +yy248: { return DASH_N; } -yy246: +yy249: ++YYCURSOR; { return CRITIC_DEL_CLOSE; } -yy248: +yy251: ++YYCURSOR; { return DASH_M; } -yy250: +yy253: yych = *++YYCURSOR; switch (yych) { - case '}': goto yy251; - default: goto yy67; + case '}': goto yy254; + default: goto yy70; } -yy251: +yy254: ++YYCURSOR; { return CRITIC_ADD_CLOSE; } -yy253: - yyaccept = 9; +yy256: + yyaccept = 10; yych = *(YYMARKER = ++YYCURSOR); switch (yych) { - case 'T': goto yy270; - default: goto yy254; + case 'T': goto yy273; + default: goto yy257; } -yy254: +yy257: { return BRACE_DOUBLE_LEFT; } -yy255: +yy258: yych = *++YYCURSOR; switch (yych) { - case '=': goto yy268; - default: goto yy67; + case '=': goto yy271; + default: goto yy70; } -yy256: +yy259: yych = *++YYCURSOR; switch (yych) { - case '~': goto yy266; - default: goto yy67; + case '~': goto yy269; + default: goto yy70; } -yy257: +yy260: yych = *++YYCURSOR; switch (yych) { - case '>': goto yy264; - default: goto yy67; + case '>': goto yy267; + default: goto yy70; } -yy258: +yy261: yych = *++YYCURSOR; switch (yych) { - case '-': goto yy262; - default: goto yy67; + case '-': goto yy265; + default: goto yy70; } -yy259: +yy262: yych = *++YYCURSOR; switch (yych) { - case '+': goto yy260; - default: goto yy67; + case '+': goto yy263; + default: goto yy70; } -yy260: +yy263: ++YYCURSOR; { return CRITIC_ADD_OPEN; } -yy262: +yy265: ++YYCURSOR; { return CRITIC_DEL_OPEN; } -yy264: +yy267: ++YYCURSOR; { return CRITIC_COM_OPEN; } -yy266: +yy269: ++YYCURSOR; { return CRITIC_SUB_OPEN; } -yy268: +yy271: ++YYCURSOR; { return CRITIC_HI_OPEN; } -yy270: +yy273: yych = *++YYCURSOR; switch (yych) { - case 'O': goto yy271; - default: goto yy67; + case 'O': goto yy274; + default: goto yy70; } -yy271: +yy274: yych = *++YYCURSOR; switch (yych) { - case 'C': goto yy272; - default: goto yy67; + case 'C': goto yy275; + default: goto yy70; } -yy272: +yy275: yych = *++YYCURSOR; switch (yych) { - case '}': goto yy273; - default: goto yy67; + case '}': goto yy276; + default: goto yy70; } -yy273: +yy276: yych = *++YYCURSOR; switch (yych) { - case '}': goto yy274; - default: goto yy67; + case '}': goto yy277; + default: goto yy70; } -yy274: +yy277: ++YYCURSOR; { return TOC; } } diff --git a/src/lexer.re b/src/lexer.re index 6abfebf..4d4f8d8 100644 --- a/src/lexer.re +++ b/src/lexer.re @@ -192,7 +192,7 @@ int scan(Scanner * s, const char * stop) { "$$" { return MATH_DOLLAR_DOUBLE; } '^' { return SUPERSCRIPT; } - "~" { return SUBSCRIPT; } + '~' { return SUBSCRIPT; } INDENT_TAB { return INDENT_TAB; } INDENT_SPACE { return INDENT_SPACE; } @@ -212,6 +212,9 @@ int scan(Scanner * s, const char * stop) { '#' { return TEXT_HASH; } '%' { return TEXT_PERCENT; } + '{' { return TEXT_BRACE_LEFT; } + '}' { return TEXT_BRACE_RIGHT; } + '\\' { return TEXT_BACKSLASH; } [0-9]+ / ('.' (SP|NL)) { return TEXT_NUMBER_POSS_LIST; } '.' / (SP|NL) { return TEXT_PERIOD; } diff --git a/src/libMultiMarkdown.h b/src/libMultiMarkdown.h index 6ca1944..b4ceffb 100644 --- a/src/libMultiMarkdown.h +++ b/src/libMultiMarkdown.h @@ -273,6 +273,9 @@ enum token_types { TOC, + TEXT_BACKSLASH, + TEXT_BRACE_LEFT, + TEXT_BRACE_RIGHT, TEXT_EMPTY, TEXT_HASH, TEXT_LINEBREAK, diff --git a/tests/MMD6Tests/Math.tex b/tests/MMD6Tests/Math.tex new file mode 100644 index 0000000..f50203b --- /dev/null +++ b/tests/MMD6Tests/Math.tex @@ -0,0 +1,51 @@ +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\}\^{}\{i\textbackslash{}pi \}+1=0\$ bar + +\$\$ \{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\^{}\{2\}-4ac\}\}\{2a\}\$\$ + +foo \$\{e\}\^{}\{i\textbackslash{}pi \}+1=0 \$ bar + +\$\$\{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\^{}\{2\}-4ac\}\}\{2a\} \$\$ + +foo a\$\{e\}\^{}\{i\textbackslash{}pi \}+1=0\$ bar + +10 + +a\$\$\{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\^{}\{2\}-4ac\}\}\{2a\}\$\$ + +foo \$\{e\}\^{}\{i\textbackslash{}pi \}+1=0\$b bar + +\$\$\{x\}\_\{1,2\}=\textbackslash{}frac\{-b\textbackslash{}pm \textbackslash{}sqrt\{\{b\}\^{}\{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\}} -- 2.40.0