summaryrefslogtreecommitdiff
path: root/src/lang/latex.cc
blob: d423230d33ca903a13d37576956a5d3d315dfaf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*************************************************************************
 *
 * HTCd - Copyright (C) 1998-2006 Henrik Rydberg
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

#include <lang/env.h>
using namespace std;

static opmap op_latex;

latex_env::latex_env(Env& p) : Env(p) { ops=&op_latex; }

//////////////////////////////////////////////////////

TOK_IMPL(it) {
  mstring s; env.parg(s,-1);
  if(s.nempty()) { out<<"<i>"; out<<s.right_first_not_of(cset_ws); out<<"</i>"; }
  else { out<<"<i>"; env.epilog=sref("</i>")+env.epilog; }
}

TOK_IMPL(em) {
  mstring s; env.parg(s,-1);
  if(s.nempty()) { out<<"<em>"; out<<s.right_first_not_of(cset_ws); out<<"</em>"; }
  else { out<<"<em>"; env.epilog=sref("</em>")+env.epilog; }
}

TOK_IMPL(bf) {
  mstring s; env.parg(s,-1);
  if(s.nempty()) { out<<"<b>"; out<<s.right_first_not_of(cset_ws); out<<"</b>"; }
  else { out<<"<b>"; env.epilog=sref("</b>")+env.epilog; }
}

TOK_IMPL(mathbf) {
  mstring s; env.parg(s,-1);
  if(s.nempty()) { out<<"<b>"; out<<s.right_first_not_of(cset_ws); out<<"</b>"; }
  else { out<<"<b>"; env.epilog=sref("</b>")+env.epilog; }
}

TOK_IMPL(rm) {
  mstring s; env.parg(s,-1);
  if(s.nempty()) { out<<s.right_first_not_of(cset_ws); }
}

//////////////////////////////////////////////////////////

TOK_IMPL(setpara) {
  env.para=env[0];
}

TOK_IMPL(epilog) {
  env.epilog=env[0]+env.epilog;
}

//////////////////////////////////////////////////////////

TOK_IMPL(equation) {
  out<<env.para;
  latex_env(env).expr(out,env.arg(0)->expr);
  out<<env.para;
}

//////////////////////////////////////////////////////////

void envAddLatex(tokmap& T)
{
  static int init; if(!init) { init=1; opAddLatex(op_latex); }

  //////////////////////////////////////////////////////////

  TOK_ADD(it,"?",tok_t::PUBLIC,
          "%Set Italics mode\n"
          "%Syntax: \\it<body>\n"
          "%\n"
          "%Note that the body is optional, just like in latex.\n"
          );
  TOK_ADD(em,"?",tok_t::PUBLIC,
          "%Set emph mode\n"
          "%Syntax: \\em<body>\n"
          "%\n"
          "%Note that the body is optional, just like in latex.\n"
          );
  TOK_ADD(bf,"?",tok_t::PUBLIC,
          "%Set Boldface mode\n"
          "%Syntax: \\bf<body>\n"
          "%\n"
          "%Note that the body is optional, just like in latex.\n"
          );
  TOK_ADD(mathbf,"?",tok_t::PUBLIC,
          "%Set Math boldface mode\n"
          "%Syntax: \\mathbf<body>\n"
          "%\n"
          "%Note that the body is optional, just like in latex.\n"
          );
  TOK_ADD(rm,"?",tok_t::PUBLIC,
          "%Set rm face mode\n"
          "%Syntax: \\rm<body>\n"
          "%\n"
          "%Note that the body is optional, just like in latex.\n"
          );

  //////////////////////////////////////////////////////////
  
  TOK_ADD(setpara,"x",tok_t::PUBLIC,
          "%Set paragraph string\n"
          "%Syntax: \\setpara{string}\n"
          "%\n"
          "%Whenever a series of newlines is encountered, it is\n"
          "%replaced by this string. The default is a newline.\n"
          "%\n"
          "%Operates on stack level (may be nested)\n"
          );
  TOK_ADD(epilog,"x",tok_t::PUBLIC,
          "%Add string to the epilog\n"
          "%Syntax: \\epilog{string}\n"
          "%\n"
          "%The epilog string is output when the current stack frame\n"
          "%goes out of scope. For functions like \\bf, which needs\n"
          "%an end tag to be inserted at the right place.\n"
          "%\n"
          "%Operates on stack level (may be nested)\n"
          );

  //////////////////////////////////////////////////////////

  TOK_ADD(equation,"r",tok_t::PUBLIC,
          "%Evaluate equation (LaTeX)\n"
          "%Syntax: \\equation{body}\n"
          );
  
  //////////////////////////////////////////////////////////

  Const(T,sref("t"),sref("\t"),tok_t::PUBLIC);
  Const(T,sref("n"),sref("\n"),tok_t::PUBLIC);
  Const(T,sref("f"),sref("\f"),tok_t::PUBLIC);

  //////////////////////////////////////////////////////////
}