diff options
Diffstat (limited to 'src/lang/latex.cc')
| -rw-r--r-- | src/lang/latex.cc | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/src/lang/latex.cc b/src/lang/latex.cc new file mode 100644 index 0000000..d423230 --- /dev/null +++ b/src/lang/latex.cc | |||
| @@ -0,0 +1,152 @@ | |||
| 1 | /************************************************************************* | ||
| 2 | * | ||
| 3 | * HTCd - Copyright (C) 1998-2006 Henrik Rydberg | ||
| 4 | * | ||
| 5 | * This program is free software; you can redistribute it and/or modify | ||
| 6 | * it under the terms of the GNU General Public License as published by | ||
| 7 | * the Free Software Foundation; either version 2 of the License, or | ||
| 8 | * (at your option) any later version. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | * You should have received a copy of the GNU General Public License | ||
| 16 | * along with this program; if not, write to the Free Software | ||
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <lang/env.h> | ||
| 21 | using namespace std; | ||
| 22 | |||
| 23 | static opmap op_latex; | ||
| 24 | |||
| 25 | latex_env::latex_env(Env& p) : Env(p) { ops=&op_latex; } | ||
| 26 | |||
| 27 | ////////////////////////////////////////////////////// | ||
| 28 | |||
| 29 | TOK_IMPL(it) { | ||
| 30 | mstring s; env.parg(s,-1); | ||
| 31 | if(s.nempty()) { out<<"<i>"; out<<s.right_first_not_of(cset_ws); out<<"</i>"; } | ||
| 32 | else { out<<"<i>"; env.epilog=sref("</i>")+env.epilog; } | ||
| 33 | } | ||
| 34 | |||
| 35 | TOK_IMPL(em) { | ||
| 36 | mstring s; env.parg(s,-1); | ||
| 37 | if(s.nempty()) { out<<"<em>"; out<<s.right_first_not_of(cset_ws); out<<"</em>"; } | ||
| 38 | else { out<<"<em>"; env.epilog=sref("</em>")+env.epilog; } | ||
| 39 | } | ||
| 40 | |||
| 41 | TOK_IMPL(bf) { | ||
| 42 | mstring s; env.parg(s,-1); | ||
| 43 | if(s.nempty()) { out<<"<b>"; out<<s.right_first_not_of(cset_ws); out<<"</b>"; } | ||
| 44 | else { out<<"<b>"; env.epilog=sref("</b>")+env.epilog; } | ||
| 45 | } | ||
| 46 | |||
| 47 | TOK_IMPL(mathbf) { | ||
| 48 | mstring s; env.parg(s,-1); | ||
| 49 | if(s.nempty()) { out<<"<b>"; out<<s.right_first_not_of(cset_ws); out<<"</b>"; } | ||
| 50 | else { out<<"<b>"; env.epilog=sref("</b>")+env.epilog; } | ||
| 51 | } | ||
| 52 | |||
| 53 | TOK_IMPL(rm) { | ||
| 54 | mstring s; env.parg(s,-1); | ||
| 55 | if(s.nempty()) { out<<s.right_first_not_of(cset_ws); } | ||
| 56 | } | ||
| 57 | |||
| 58 | ////////////////////////////////////////////////////////// | ||
| 59 | |||
| 60 | TOK_IMPL(setpara) { | ||
| 61 | env.para=env[0]; | ||
| 62 | } | ||
| 63 | |||
| 64 | TOK_IMPL(epilog) { | ||
| 65 | env.epilog=env[0]+env.epilog; | ||
| 66 | } | ||
| 67 | |||
| 68 | ////////////////////////////////////////////////////////// | ||
| 69 | |||
| 70 | TOK_IMPL(equation) { | ||
| 71 | out<<env.para; | ||
| 72 | latex_env(env).expr(out,env.arg(0)->expr); | ||
| 73 | out<<env.para; | ||
| 74 | } | ||
| 75 | |||
| 76 | ////////////////////////////////////////////////////////// | ||
| 77 | |||
| 78 | void envAddLatex(tokmap& T) | ||
| 79 | { | ||
| 80 | static int init; if(!init) { init=1; opAddLatex(op_latex); } | ||
| 81 | |||
| 82 | ////////////////////////////////////////////////////////// | ||
| 83 | |||
| 84 | TOK_ADD(it,"?",tok_t::PUBLIC, | ||
| 85 | "%Set Italics mode\n" | ||
| 86 | "%Syntax: \\it<body>\n" | ||
| 87 | "%\n" | ||
| 88 | "%Note that the body is optional, just like in latex.\n" | ||
| 89 | ); | ||
| 90 | TOK_ADD(em,"?",tok_t::PUBLIC, | ||
| 91 | "%Set emph mode\n" | ||
| 92 | "%Syntax: \\em<body>\n" | ||
| 93 | "%\n" | ||
| 94 | "%Note that the body is optional, just like in latex.\n" | ||
| 95 | ); | ||
| 96 | TOK_ADD(bf,"?",tok_t::PUBLIC, | ||
| 97 | "%Set Boldface mode\n" | ||
| 98 | "%Syntax: \\bf<body>\n" | ||
| 99 | "%\n" | ||
| 100 | "%Note that the body is optional, just like in latex.\n" | ||
| 101 | ); | ||
| 102 | TOK_ADD(mathbf,"?",tok_t::PUBLIC, | ||
| 103 | "%Set Math boldface mode\n" | ||
| 104 | "%Syntax: \\mathbf<body>\n" | ||
| 105 | "%\n" | ||
| 106 | "%Note that the body is optional, just like in latex.\n" | ||
| 107 | ); | ||
| 108 | TOK_ADD(rm,"?",tok_t::PUBLIC, | ||
| 109 | "%Set rm face mode\n" | ||
| 110 | "%Syntax: \\rm<body>\n" | ||
| 111 | "%\n" | ||
| 112 | "%Note that the body is optional, just like in latex.\n" | ||
| 113 | ); | ||
| 114 | |||
| 115 | ////////////////////////////////////////////////////////// | ||
| 116 | |||
| 117 | TOK_ADD(setpara,"x",tok_t::PUBLIC, | ||
| 118 | "%Set paragraph string\n" | ||
| 119 | "%Syntax: \\setpara{string}\n" | ||
| 120 | "%\n" | ||
| 121 | "%Whenever a series of newlines is encountered, it is\n" | ||
| 122 | "%replaced by this string. The default is a newline.\n" | ||
| 123 | "%\n" | ||
| 124 | "%Operates on stack level (may be nested)\n" | ||
| 125 | ); | ||
| 126 | TOK_ADD(epilog,"x",tok_t::PUBLIC, | ||
| 127 | "%Add string to the epilog\n" | ||
| 128 | "%Syntax: \\epilog{string}\n" | ||
| 129 | "%\n" | ||
| 130 | "%The epilog string is output when the current stack frame\n" | ||
| 131 | "%goes out of scope. For functions like \\bf, which needs\n" | ||
| 132 | "%an end tag to be inserted at the right place.\n" | ||
| 133 | "%\n" | ||
| 134 | "%Operates on stack level (may be nested)\n" | ||
| 135 | ); | ||
| 136 | |||
| 137 | ////////////////////////////////////////////////////////// | ||
| 138 | |||
| 139 | TOK_ADD(equation,"r",tok_t::PUBLIC, | ||
| 140 | "%Evaluate equation (LaTeX)\n" | ||
| 141 | "%Syntax: \\equation{body}\n" | ||
| 142 | ); | ||
| 143 | |||
| 144 | ////////////////////////////////////////////////////////// | ||
| 145 | |||
| 146 | Const(T,sref("t"),sref("\t"),tok_t::PUBLIC); | ||
| 147 | Const(T,sref("n"),sref("\n"),tok_t::PUBLIC); | ||
| 148 | Const(T,sref("f"),sref("\f"),tok_t::PUBLIC); | ||
| 149 | |||
| 150 | ////////////////////////////////////////////////////////// | ||
| 151 | } | ||
| 152 | |||
