]> git.saurik.com Git - wxWidgets.git/blob - utils/tex2rtf/src/tex2any.cpp
Oops, forgot to return a value
[wxWidgets.git] / utils / tex2rtf / src / tex2any.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tex2any.cpp
3 // Purpose: Utilities for Latex conversion.
4 // Author: Julian Smart
5 // Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
6 // Ron Lee
7 // Created: 01/01/99
8 // RCS-ID: $Id$
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
19
20 #ifdef __BORLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WX_PRECOMP
25 #endif
26
27 #include <ctype.h>
28 #include "tex2any.h"
29 #include <stdlib.h>
30 #include <time.h>
31
32 #if !WXWIN_COMPATIBILITY_2_4
33 static inline wxChar* copystring(const wxChar* s)
34 { return wxStrcpy(new wxChar[wxStrlen(s) + 1], s); }
35 #endif
36
37 /*
38 * Variables accessible from clients
39 *
40 */
41
42 TexChunk * DocumentTitle = NULL;
43 TexChunk * DocumentAuthor = NULL;
44 TexChunk * DocumentDate = NULL;
45
46 // Header/footers/pagestyle
47 TexChunk * LeftHeaderEven = NULL;
48 TexChunk * LeftFooterEven = NULL;
49 TexChunk * CentreHeaderEven = NULL;
50 TexChunk * CentreFooterEven = NULL;
51 TexChunk * RightHeaderEven = NULL;
52 TexChunk * RightFooterEven = NULL;
53 TexChunk * LeftHeaderOdd = NULL;
54 TexChunk * LeftFooterOdd = NULL;
55 TexChunk * CentreHeaderOdd = NULL;
56 TexChunk * CentreFooterOdd = NULL;
57 TexChunk * RightHeaderOdd = NULL;
58 TexChunk * RightFooterOdd = NULL;
59 wxChar * PageStyle = copystring(_T("plain"));
60
61 int DocumentStyle = LATEX_REPORT;
62 int MinorDocumentStyle = 0;
63 wxPathList TexPathList;
64 wxChar * BibliographyStyleString = copystring(_T("plain"));
65 wxChar * DocumentStyleString = copystring(_T("report"));
66 wxChar * MinorDocumentStyleString = NULL;
67 int ParSkip = 0;
68 int ParIndent = 0;
69
70 int normalFont = 10;
71 int smallFont = 8;
72 int tinyFont = 6;
73 int largeFont1 = 12;
74 int LargeFont2 = 14;
75 int LARGEFont3 = 18;
76 int hugeFont1 = 20;
77 int HugeFont2 = 24;
78 int HUGEFont3 = 28;
79
80 // All of these tokens MUST be found on a line by themselves (no other
81 // text) and must start at the first character of the line, or tex2rtf
82 // will fail to process them correctly (a limitation of tex2rtf, not TeX)
83 static const wxString syntaxTokens[] =
84 { _T("\\begin{verbatim}"),
85 _T("\\begin{toocomplex}"),
86 _T("\\end{verbatim}"),
87 _T("\\end{toocomplex}"),
88 _T("\\verb"),
89 _T("\\begin{comment}"),
90 _T("\\end{comment}"),
91 _T("\\verbatiminput"),
92 // _T("\\par"),
93 _T("\\input"),
94 _T("\\helpinput"),
95 _T("\\include"),
96 wxEmptyString
97 };
98
99
100 /*
101 * USER-ADJUSTABLE SETTINGS
102 *
103 */
104
105 // Section font sizes
106 int chapterFont = 12; // LARGEFont3;
107 int sectionFont = 12; // LargeFont2;
108 int subsectionFont = 12; // largeFont1;
109 int titleFont = LARGEFont3;
110 int authorFont = LargeFont2;
111 int mirrorMargins = true;
112 bool winHelp = false; // Output in Windows Help format if TRUE, linear otherwise
113 bool isInteractive = false;
114 bool runTwice = false;
115 int convertMode = TEX_RTF;
116 bool checkCurleyBraces = false;
117 bool checkSyntax = false;
118 bool headerRule = false;
119 bool footerRule = false;
120 bool compatibilityMode = false; // If TRUE, maximum Latex compatibility
121 // (Quality of RTF generation deteriorate)
122 bool generateHPJ; // Generate WinHelp Help Project file
123 wxChar *winHelpTitle = NULL; // Windows Help title
124 int defaultTableColumnWidth = 2000;
125
126 int labelIndentTab = 18; // From left indent to item label (points)
127 int itemIndentTab = 40; // From left indent to item (points)
128
129 bool useUpButton = true;
130 int htmlBrowseButtons = HTML_BUTTONS_TEXT;
131
132 bool truncateFilenames = false; // Truncate for DOS
133 int winHelpVersion = 3; // WinHelp Version (3 for Windows 3.1, 4 for Win95)
134 bool winHelpContents = false; // Generate .cnt file for WinHelp 4
135 bool htmlIndex = false; // Generate .htx file for HTML
136 bool htmlFrameContents = false; // Use frames for HTML contents page
137 wxChar *htmlStylesheet = NULL; // Use this CSS stylesheet for HTML pages
138 bool useHeadingStyles = true; // Insert \s1, s2 etc.
139 bool useWord = true; // Insert proper Word table of contents, etc etc
140 int contentsDepth = 4; // Depth of Word table of contents
141 bool indexSubsections = true; // Index subsections in linear RTF
142 // Linear RTF method of including bitmaps. Can be "includepicture", "hex"
143 wxChar *bitmapMethod = copystring(_T("includepicture"));
144 bool upperCaseNames = false;
145 // HTML background and text colours
146 wxChar *backgroundImageString = NULL;
147 wxChar *backgroundColourString = copystring(_T("255;255;255"));
148 wxChar *textColourString = NULL;
149 wxChar *linkColourString = NULL;
150 wxChar *followedLinkColourString = NULL;
151 bool combineSubSections = false;
152 bool htmlWorkshopFiles = false;
153 bool ignoreBadRefs = false;
154 wxChar *htmlFaceName = NULL;
155
156 extern int passNumber;
157
158 extern wxHashTable TexReferences;
159
160 /*
161 * International support
162 */
163
164 // Names to help with internationalisation
165 wxChar *ContentsNameString = copystring(_T("Contents"));
166 wxChar *AbstractNameString = copystring(_T("Abstract"));
167 wxChar *GlossaryNameString = copystring(_T("Glossary"));
168 wxChar *ReferencesNameString = copystring(_T("References"));
169 wxChar *FiguresNameString = copystring(_T("List of Figures"));
170 wxChar *TablesNameString = copystring(_T("List of Tables"));
171 wxChar *FigureNameString = copystring(_T("Figure"));
172 wxChar *TableNameString = copystring(_T("Table"));
173 wxChar *IndexNameString = copystring(_T("Index"));
174 wxChar *ChapterNameString = copystring(_T("chapter"));
175 wxChar *SectionNameString = copystring(_T("section"));
176 wxChar *SubsectionNameString = copystring(_T("subsection"));
177 wxChar *SubsubsectionNameString = copystring(_T("subsubsection"));
178 wxChar *UpNameString = copystring(_T("Up"));
179
180 /*
181 * Section numbering
182 *
183 */
184
185 int chapterNo = 0;
186 int sectionNo = 0;
187 int subsectionNo = 0;
188 int subsubsectionNo = 0;
189 int figureNo = 0;
190 int tableNo = 0;
191
192 /*
193 * Other variables
194 *
195 */
196
197 FILE *CurrentOutput1 = NULL;
198 FILE *CurrentOutput2 = NULL;
199 FILE *Inputs[15];
200 unsigned long LineNumbers[15];
201 wxChar *FileNames[15];
202 int CurrentInputIndex = 0;
203
204 wxChar *TexFileRoot = NULL;
205 wxChar *TexBibName = NULL; // Bibliography output file name
206 wxChar *TexTmpBibName = NULL; // Temporary bibliography output file name
207 bool isSync = false; // If TRUE, should not yield to other processes.
208 bool stopRunning = false; // If TRUE, should abort.
209
210 static int currentColumn = 0;
211 wxChar *currentArgData = NULL;
212 bool haveArgData = false; // If TRUE, we're simulating the data.
213 TexChunk *currentArgument = NULL;
214 TexChunk *nextChunk = NULL;
215 bool isArgOptional = false;
216 int noArgs = 0;
217
218 TexChunk *TopLevel = NULL;
219 // wxList MacroDefs(wxKEY_STRING);
220 wxHashTable MacroDefs(wxKEY_STRING);
221 wxStringList IgnorableInputFiles; // Ignorable \input files, e.g. psbox.tex
222 wxChar *BigBuffer = NULL; // For reading in large chunks of text
223 TexMacroDef *SoloBlockDef = NULL;
224 TexMacroDef *VerbatimMacroDef = NULL;
225
226 #define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
227
228
229 TexRef::TexRef(const wxChar *label, const wxChar *file,
230 const wxChar *section, const wxChar *sectionN)
231 {
232 refLabel = copystring(label);
233 refFile = file ? copystring(file) : (wxChar*) NULL;
234 sectionNumber = section ? copystring(section) : copystring(_T("??"));
235 sectionName = sectionN ? copystring(sectionN) : copystring(_T("??"));
236 }
237
238 TexRef::~TexRef(void)
239 {
240 delete [] refLabel; refLabel = NULL;
241 delete [] refFile; refFile = NULL;
242 delete [] sectionNumber; sectionNumber = NULL;
243 delete [] sectionName; sectionName = NULL;
244 }
245
246
247 CustomMacro::~CustomMacro()
248 {
249 if (macroName)
250 delete [] macroName;
251 if (macroBody)
252 delete [] macroBody;
253 }
254
255 void TexOutput(const wxChar *s, bool ordinaryText)
256 {
257 int len = wxStrlen(s);
258
259 // Update current column, but only if we're guaranteed to
260 // be ordinary text (not mark-up stuff)
261 int i;
262 if (ordinaryText)
263 for (i = 0; i < len; i++)
264 {
265 if (s[i] == 13 || s[i] == 10)
266 currentColumn = 0;
267 else
268 currentColumn ++;
269 }
270
271 if (CurrentOutput1)
272 wxFprintf(CurrentOutput1, _T("%s"), s);
273 if (CurrentOutput2)
274 wxFprintf(CurrentOutput2, _T("%s"), s);
275 }
276
277 /*
278 * Try to find a Latex macro, in one of the following forms:
279 * (1) \begin{} ... \end{}
280 * (2) \macroname{arg1}...{argn}
281 * (3) {\bf arg1}
282 */
283
284 void ForbidWarning(TexMacroDef *def)
285 {
286 wxString informBuf;
287 switch (def->forbidden)
288 {
289 case FORBID_WARN:
290 {
291 informBuf.Printf(_T("Warning: it is recommended that command %s is not used."), def->name);
292 OnInform((const wxChar *)informBuf.c_str());
293 break;
294 }
295 case FORBID_ABSOLUTELY:
296 {
297 informBuf.Printf(_T("Error: command %s cannot be used and will lead to errors."), def->name);
298 OnInform((const wxChar *)informBuf.c_str());
299 break;
300 }
301 default:
302 break;
303 }
304 }
305
306 TexMacroDef *MatchMacro(wxChar *buffer, int *pos, wxChar **env, bool *parseToBrace)
307 {
308 *parseToBrace = true;
309 int i = (*pos);
310 TexMacroDef *def = NULL;
311 wxChar macroBuf[40];
312
313 // First, try to find begin{thing}
314 if (wxStrncmp(buffer+i, _T("begin{"), 6) == 0)
315 {
316 i += 6;
317
318 int j = i;
319 while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39))
320 {
321 macroBuf[j-i] = buffer[j];
322 j ++;
323 }
324 macroBuf[j-i] = 0;
325 def = (TexMacroDef *)MacroDefs.Get(macroBuf);
326
327 if (def)
328 {
329 *pos = j + 1; // BUGBUG Should this be + 1???
330 *env = def->name;
331 ForbidWarning(def);
332 return def;
333 }
334 else return NULL;
335 }
336
337 // Failed, so try to find macro from definition list
338 int j = i;
339
340 // First try getting a one-character macro, but ONLY
341 // if these TWO characters are not both alphabetical (could
342 // be a longer macro)
343 if (!(isalpha(buffer[i]) && isalpha(buffer[i+1])))
344 {
345 macroBuf[0] = buffer[i];
346 macroBuf[1] = 0;
347
348 def = (TexMacroDef *)MacroDefs.Get(macroBuf);
349 if (def) j ++;
350 }
351
352 if (!def)
353 {
354 while ((isalpha(buffer[j]) || buffer[j] == '*') && ((j - i) < 39))
355 {
356 macroBuf[j-i] = buffer[j];
357 j ++;
358 }
359 macroBuf[j-i] = 0;
360 def = (TexMacroDef *)MacroDefs.Get(macroBuf);
361 }
362
363 if (def)
364 {
365 i = j;
366
367 // We want to check whether this is a space-consuming macro
368 // (e.g. {\bf word})
369 // No brace, e.g. \input thing.tex instead of \input{thing};
370 // or a numeric argument, such as \parindent0pt
371 if ((def->no_args > 0) && ((buffer[i] == 32) || (buffer[i] == '=') || (isdigit(buffer[i]))))
372 {
373 if ((buffer[i] == 32) || (buffer[i] == '='))
374 i ++;
375
376 *parseToBrace = false;
377 }
378 *pos = i;
379 ForbidWarning(def);
380 return def;
381 }
382 return NULL;
383 }
384
385 void EatWhiteSpace(wxChar *buffer, int *pos)
386 {
387 int len = wxStrlen(buffer);
388 int j = *pos;
389 bool keepGoing = true;
390 bool moreLines = true;
391 while ((j < len) && keepGoing &&
392 (buffer[j] == 10 || buffer[j] == 13 || buffer[j] == ' ' || buffer[j] == 9))
393 {
394 j ++;
395 if (j >= len)
396 {
397 if (moreLines)
398 {
399 moreLines = read_a_line(buffer);
400 len = wxStrlen(buffer);
401 j = 0;
402 }
403 else
404 keepGoing = false;
405 }
406 }
407 *pos = j;
408 }
409
410 bool FindEndEnvironment(wxChar *buffer, int *pos, wxChar *env)
411 {
412 int i = (*pos);
413
414 // Try to find end{thing}
415 if ((wxStrncmp(buffer+i, _T("end{"), 4) == 0) &&
416 (wxStrncmp(buffer+i+4, env, wxStrlen(env)) == 0))
417 {
418 *pos = i + 5 + wxStrlen(env);
419 return true;
420 }
421 else return false;
422 }
423
424 bool readingVerbatim = false;
425 bool readInVerbatim = false; // Within a verbatim, but not nec. verbatiminput
426
427 // Switched this off because e.g. \verb${$ causes it to fail. There is no
428 // detection of \verb yet.
429 // #define CHECK_BRACES 1
430
431 unsigned long leftCurley = 0;
432 unsigned long rightCurley = 0;
433 static wxString currentFileName = _T("");
434
435 bool read_a_line(wxChar *buf)
436 {
437 if (CurrentInputIndex < 0)
438 {
439 buf[0] = 0;
440 return false;
441 }
442
443 int ch = -2;
444 unsigned long bufIndex = 0;
445 buf[0] = 0;
446 int lastChar;
447
448 while (ch != EOF && ch != 10)
449 {
450 if (bufIndex >= MAX_LINE_BUFFER_SIZE)
451 {
452 wxString errBuf;
453 errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
454 LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(), MAX_LINE_BUFFER_SIZE);
455 OnError((wxChar *)errBuf.c_str());
456 return false;
457 }
458
459 if (((bufIndex == 14) && (wxStrncmp(buf, _T("\\end{verbatim}"), 14) == 0)) ||
460 ((bufIndex == 16) && (wxStrncmp(buf, _T("\\end{toocomplex}"), 16) == 0)))
461 readInVerbatim = false;
462
463 lastChar = ch;
464 ch = getc(Inputs[CurrentInputIndex]);
465
466 if (checkCurleyBraces)
467 {
468 if (ch == '{' && !readInVerbatim && lastChar != _T('\\'))
469 leftCurley++;
470 if (ch == '}' && !readInVerbatim && lastChar != _T('\\'))
471 {
472 rightCurley++;
473 if (rightCurley > leftCurley)
474 {
475 wxString errBuf;
476 errBuf.Printf(_T("An extra right Curley brace ('}') was detected at line %lu inside file %s"), LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
477 OnError((wxChar *)errBuf.c_str());
478
479 // Reduce the count of right Curley braces, so the mismatched count
480 // isn't reported on every line that has a '}' after the first mismatch
481 rightCurley--;
482 }
483 }
484 }
485
486 if (ch != EOF)
487 {
488 // Check for 2 consecutive newlines and replace with \par
489 if (ch == 10 && !readInVerbatim)
490 {
491 int ch1 = getc(Inputs[CurrentInputIndex]);
492 if ((ch1 == 10) || (ch1 == 13))
493 {
494 // Eliminate newline (10) following DOS linefeed
495 if (ch1 == 13)
496 getc(Inputs[CurrentInputIndex]);
497 buf[bufIndex] = 0;
498 IncrementLineNumber();
499 // wxStrcat(buf, "\\par\n");
500 // i += 6;
501 if (bufIndex+5 >= MAX_LINE_BUFFER_SIZE)
502 {
503 wxString errBuf;
504 errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
505 LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
506 OnError((wxChar *)errBuf.c_str());
507 return false;
508 }
509 wxStrcat(buf, _T("\\par"));
510 bufIndex += 5;
511
512 }
513 else
514 {
515 ungetc(ch1, Inputs[CurrentInputIndex]);
516 if (bufIndex >= MAX_LINE_BUFFER_SIZE)
517 {
518 wxString errBuf;
519 errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
520 LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
521 OnError((wxChar *)errBuf.c_str());
522 return false;
523 }
524
525 buf[bufIndex] = ch;
526 bufIndex ++;
527 }
528 }
529 else
530 {
531
532 // Convert embedded characters to RTF equivalents
533 switch(ch)
534 {
535 case 0xf6: // ö
536 case 0xe4: // ü
537 case 0xfc: // ü
538 case 0xd6: // Ö
539 case 0xc4: // Ä
540 case 0xdc: // Ü
541 if (bufIndex+5 >= MAX_LINE_BUFFER_SIZE)
542 {
543 wxString errBuf;
544 errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
545 LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
546 OnError((wxChar *)errBuf.c_str());
547 return false;
548 }
549 buf[bufIndex++]='\\';
550 buf[bufIndex++]='"';
551 buf[bufIndex++]='{';
552 switch(ch)
553 {
554 case 0xf6:buf[bufIndex++]='o';break; // ö
555 case 0xe4:buf[bufIndex++]='a';break; // ä
556 case 0xfc:buf[bufIndex++]='u';break; // ü
557 case 0xd6:buf[bufIndex++]='O';break; // Ö
558 case 0xc4:buf[bufIndex++]='A';break; // Ä
559 case 0xdc:buf[bufIndex++]='U';break; // Ü
560 }
561 buf[bufIndex++]='}';
562 break;
563 case 0xdf: // ß
564 if (bufIndex+5 >= MAX_LINE_BUFFER_SIZE)
565 {
566 wxString errBuf;
567 errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
568 LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
569 OnError((wxChar *)errBuf.c_str());
570 return false;
571 }
572 buf[bufIndex++]='\\';
573 buf[bufIndex++]='s';
574 buf[bufIndex++]='s';
575 buf[bufIndex++]='\\';
576 buf[bufIndex++]='/';
577 break;
578 default:
579 if (bufIndex >= MAX_LINE_BUFFER_SIZE)
580 {
581 wxString errBuf;
582 errBuf.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
583 LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str(),MAX_LINE_BUFFER_SIZE);
584 OnError((wxChar *)errBuf.c_str());
585 return false;
586 }
587 // If the current character read in is a '_', we need to check
588 // whether there should be a '\' before it or not
589 if (ch != '_')
590 {
591 buf[bufIndex++] = ch;
592 break;
593 }
594
595 if (checkSyntax)
596 {
597 if (readInVerbatim)
598 {
599 // There should NOT be a '\' before the '_'
600 if ((bufIndex > 0 && (buf[bufIndex-1] == '\\')) && (buf[0] != '%'))
601 {
602 // wxString errBuf;
603 // errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that should NOT have a '\\' before it."),
604 // LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
605 // OnError((wxChar *)errBuf.c_str());
606 }
607 }
608 else
609 {
610 // There should be a '\' before the '_'
611 if (bufIndex == 0)
612 {
613 wxString errBuf;
614 errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
615 LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
616 OnError((wxChar *)errBuf.c_str());
617 }
618 else if ((buf[bufIndex-1] != '\\') && (buf[0] != '%') && // If it is a comment line, then no warnings
619 (wxStrncmp(buf, _T("\\input"), 6))) // do not report filenames that have underscores in them
620 {
621 wxString errBuf;
622 errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
623 LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
624 OnError((wxChar *)errBuf.c_str());
625 }
626 }
627 }
628 buf[bufIndex++] = ch;
629 break;
630 } // switch
631 } // else
632 }
633 else
634 {
635 buf[bufIndex] = 0;
636 fclose(Inputs[CurrentInputIndex]);
637 Inputs[CurrentInputIndex] = NULL;
638 if (CurrentInputIndex > 0)
639 ch = ' '; // No real end of file
640 CurrentInputIndex --;
641
642 if (checkCurleyBraces)
643 {
644 if (leftCurley != rightCurley)
645 {
646 wxString errBuf;
647 errBuf.Printf(_T("Curley braces do not match inside file %s\n%lu opens, %lu closes"),
648 (const wxChar*) currentFileName.c_str(),leftCurley,rightCurley);
649 OnError((wxChar *)errBuf.c_str());
650 }
651 leftCurley = 0;
652 rightCurley = 0;
653 }
654
655 if (readingVerbatim)
656 {
657 readingVerbatim = false;
658 readInVerbatim = false;
659 wxStrcat(buf, _T("\\end{verbatim}\n"));
660 return false;
661 }
662 }
663 if (ch == 10)
664 IncrementLineNumber();
665 }
666 buf[bufIndex] = 0;
667
668 // Strip out comment environment
669 if (wxStrncmp(buf, _T("\\begin{comment}"), 15) == 0)
670 {
671 while (wxStrncmp(buf, _T("\\end{comment}"), 13) != 0)
672 read_a_line(buf);
673 return read_a_line(buf);
674 }
675 // Read a verbatim input file as if it were a verbatim environment
676 else if (wxStrncmp(buf, _T("\\verbatiminput"), 14) == 0)
677 {
678 int wordLen = 14;
679 wxChar *fileName = buf + wordLen + 1;
680
681 int j = bufIndex - 1;
682 buf[j] = 0;
683
684 // thing}\par -- eliminate the \par!
685 if (wxStrncmp((buf + wxStrlen(buf)-5), _T("\\par"), 4) == 0)
686 {
687 j -= 5;
688 buf[j] = 0;
689 }
690
691 if (buf[j-1] == '}')
692 buf[j-1] = 0; // Ignore final brace
693
694 wxString actualFile = TexPathList.FindValidPath(fileName);
695 currentFileName = actualFile;
696 if (actualFile == _T(""))
697 {
698 wxString errBuf;
699 errBuf.Printf(_T("Could not find file: %s"),fileName);
700 OnError((wxChar *)errBuf.c_str());
701 }
702 else
703 {
704 wxString informStr;
705 informStr.Printf(_T("Processing: %s"),actualFile.c_str());
706 OnInform((wxChar *)informStr.c_str());
707 CurrentInputIndex ++;
708
709 Inputs[CurrentInputIndex] = wxFopen(actualFile, _T("r"));
710 LineNumbers[CurrentInputIndex] = 1;
711 if (FileNames[CurrentInputIndex])
712 delete[] FileNames[CurrentInputIndex];
713 FileNames[CurrentInputIndex] = copystring(actualFile);
714
715 if (!Inputs[CurrentInputIndex])
716 {
717 CurrentInputIndex --;
718 OnError(_T("Could not open verbatiminput file."));
719 }
720 else
721 {
722 readingVerbatim = true;
723 readInVerbatim = true;
724 wxStrcpy(buf, _T("\\begin{verbatim}\n"));
725 return false;
726 }
727 }
728 return false;
729 }
730 else if (wxStrncmp(buf, _T("\\input"), 6) == 0 || wxStrncmp(buf, _T("\\helpinput"), 10) == 0 ||
731 wxStrncmp(buf, _T("\\include"), 8) == 0)
732 {
733 int wordLen;
734 if (wxStrncmp(buf, _T("\\input"), 6) == 0)
735 wordLen = 6;
736 else
737 if (wxStrncmp(buf, _T("\\include"), 8) == 0)
738 wordLen = 8;
739 else
740 wordLen = 10;
741
742 wxChar *fileName = buf + wordLen + 1;
743
744 int j = bufIndex - 1;
745 buf[j] = 0;
746
747 // \input{thing}\par -- eliminate the \par!
748 // if (wxStrncmp((buf + wxStrlen(buf)-5), "\\par", 4) == 0)
749 if (wxStrncmp((buf + wxStrlen(buf)-4), _T("\\par"), 4) == 0) // Bug fix 8/2/95 Ulrich Leodolter
750 {
751 // j -= 5;
752 j -= 4; // Ditto
753 buf[j] = 0;
754 }
755
756 if (buf[j-1] == _T('}'))
757 buf[j-1] = 0; // Ignore final brace
758
759 // Remove backslashes from name
760 wxString fileNameStr(fileName);
761 fileNameStr.Replace(_T("\\"), _T(""));
762
763 // Ignore some types of input files (e.g. macro definition files)
764 wxChar *fileOnly = wxFileNameFromPath((wxChar*) (const wxChar*) fileNameStr);
765 currentFileName = fileOnly;
766 if (IgnorableInputFiles.Member(fileOnly))
767 return read_a_line(buf);
768
769 wxString actualFile = TexPathList.FindValidPath(fileNameStr);
770 if (actualFile == _T(""))
771 {
772 wxChar buf2[400];
773 wxSnprintf(buf2, sizeof(buf2), _T("%s.tex"), fileNameStr.c_str());
774 actualFile = TexPathList.FindValidPath(buf2);
775 }
776 currentFileName = actualFile;
777
778 if (actualFile == _T(""))
779 {
780 wxString errBuf;
781 errBuf.Printf(_T("Could not find file: %s"),fileName);
782 OnError((wxChar *)errBuf.c_str());
783 }
784 else
785 {
786 // Ensure that if this file includes another,
787 // then we look in the same directory as this one.
788 TexPathList.EnsureFileAccessible(actualFile);
789
790 wxString informStr;
791 informStr.Printf(_T("Processing: %s"),actualFile.c_str());
792 OnInform((wxChar *)informStr.c_str());
793 CurrentInputIndex ++;
794
795 Inputs[CurrentInputIndex] = wxFopen(actualFile, _T("r"));
796 LineNumbers[CurrentInputIndex] = 1;
797 if (FileNames[CurrentInputIndex])
798 delete[] FileNames[CurrentInputIndex];
799 FileNames[CurrentInputIndex] = copystring(actualFile);
800
801 if (!Inputs[CurrentInputIndex])
802 {
803 wxString errBuf;
804 errBuf.Printf(_T("Could not open include file %s"), (const wxChar*) actualFile);
805 CurrentInputIndex --;
806 OnError((wxChar *)errBuf.c_str());
807 }
808 }
809 bool succ = read_a_line(buf);
810 return succ;
811 }
812
813 if (checkSyntax)
814 {
815 wxString bufStr = buf;
816 for (int index=0; syntaxTokens[index] != wxEmptyString; index++)
817 {
818 size_t pos = bufStr.find(syntaxTokens[index]);
819 if (pos != wxString::npos && pos != 0)
820 {
821 size_t commentStart = bufStr.find(_T("%"));
822 if (commentStart == wxString::npos || commentStart > pos)
823 {
824 wxString errBuf;
825 if (syntaxTokens[index] == _T("\\verb"))
826 {
827 errBuf.Printf(_T("'%s$....$' was detected at line %lu inside file %s. Please replace this form with \\tt{....}"),
828 syntaxTokens[index].c_str(),
829 LineNumbers[CurrentInputIndex],
830 currentFileName.c_str());
831 }
832 else
833 {
834 errBuf.Printf(_T("'%s' was detected at line %lu inside file %s that is not the only text on the line, starting at column one."),
835 syntaxTokens[index].c_str(),
836 LineNumbers[CurrentInputIndex],
837 currentFileName.c_str());
838 }
839 OnError((wxChar *)errBuf.c_str());
840 }
841 }
842 }
843 } // checkSyntax
844
845 if (wxStrncmp(buf, _T("\\begin{verbatim}"), 16) == 0 ||
846 wxStrncmp(buf, _T("\\begin{toocomplex}"), 18) == 0)
847 readInVerbatim = true;
848 else if (wxStrncmp(buf, _T("\\end{verbatim}"), 14) == 0 ||
849 wxStrncmp(buf, _T("\\end{toocomplex}"), 16) == 0)
850 readInVerbatim = false;
851
852 if (checkCurleyBraces)
853 {
854 if (ch == EOF && leftCurley != rightCurley)
855 {
856 wxString errBuf;
857 errBuf.Printf(_T("Curley braces do not match inside file %s\n%lu opens, %lu closes"),
858 (const wxChar*) currentFileName.c_str(),leftCurley,rightCurley);
859 OnError((wxChar *)errBuf.c_str());
860 }
861 }
862
863 return (ch == EOF);
864 } // read_a_line
865
866 /*
867 * Parse newcommand
868 *
869 */
870
871 bool ParseNewCommand(wxChar *buffer, int *pos)
872 {
873 if ((wxStrncmp((buffer+(*pos)), _T("newcommand"), 10) == 0) ||
874 (wxStrncmp((buffer+(*pos)), _T("renewcommand"), 12) == 0))
875 {
876 if (wxStrncmp((buffer+(*pos)), _T("newcommand"), 10) == 0)
877 *pos = *pos + 12;
878 else
879 *pos = *pos + 14;
880
881 wxChar commandName[100];
882 wxChar commandValue[1000];
883 int noArgs = 0;
884 int i = 0;
885 while (buffer[*pos] != _T('}') && (buffer[*pos] != 0))
886 {
887 commandName[i] = buffer[*pos];
888 *pos += 1;
889 i ++;
890 }
891 commandName[i] = 0;
892 i = 0;
893 *pos += 1;
894 if (buffer[*pos] == _T('['))
895 {
896 *pos += 1;
897 noArgs = (int)(buffer[*pos]) - 48;
898 *pos += 2; // read past argument and '['
899 }
900 bool end = false;
901 int braceCount = 0;
902 while (!end)
903 {
904 char ch = buffer[*pos];
905 if (ch == _T('{'))
906 braceCount ++;
907 else if (ch == _T('}'))
908 {
909 braceCount --;
910 if (braceCount == 0)
911 end = true;
912 }
913 else if (ch == 0)
914 {
915 end = !read_a_line(buffer);
916 wxUnusedVar(end);
917 *pos = 0;
918 break;
919 }
920 commandValue[i] = ch;
921 i ++;
922 *pos += 1;
923 }
924 commandValue[i] = 0;
925
926 CustomMacro *macro = new CustomMacro(commandName, noArgs, NULL);
927 if (wxStrlen(commandValue) > 0)
928 macro->macroBody = copystring(commandValue);
929 if (!CustomMacroList.Find(commandName))
930 {
931 CustomMacroList.Append(commandName, macro);
932 AddMacroDef(ltCUSTOM_MACRO, commandName, noArgs);
933 }
934 return true;
935 }
936 else return false;
937 }
938
939 void MacroError(wxChar *buffer)
940 {
941 wxString errBuf;
942 wxChar macroBuf[200];
943 macroBuf[0] = '\\';
944 int i = 1;
945 char ch;
946 while (((ch = buffer[i-1]) != '\n') && (ch != 0))
947 {
948 macroBuf[i] = ch;
949 i ++;
950 }
951 macroBuf[i] = 0;
952 if (i > 20)
953 macroBuf[20] = 0;
954
955 errBuf.Printf(_T("Could not find macro: %s at line %d, file %s"),
956 macroBuf, (int)(LineNumbers[CurrentInputIndex]-1), FileNames[CurrentInputIndex]);
957 OnError((wxChar *)errBuf.c_str());
958
959 if (wxStrcmp(macroBuf,_T("\\end{document}")) == 0)
960 {
961 OnInform( _T("Halted build due to unrecoverable error.") );
962 stopRunning = true;
963 }
964 }
965
966 /*
967 * Parse an argument.
968 * 'environment' specifies the name of the macro IFF if we're looking for the end
969 * of an environment, e.g. \end{itemize}. Otherwise it's NULL.
970 * 'parseToBrace' is TRUE if the argument should extend to the next right brace,
971 * e.g. in {\bf an argument} as opposed to \vskip 30pt
972 *
973 */
974 int ParseArg(TexChunk *thisArg, wxList& children, wxChar *buffer, int pos, wxChar *environment, bool parseToBrace, TexChunk *customMacroArgs)
975 {
976 Tex2RTFYield();
977 if (stopRunning) return pos;
978
979 bool eof = false;
980 BigBuffer[0] = 0;
981 int buf_ptr = 0;
982 int len;
983
984 /*
985
986 // Consume leading brace or square bracket, but ONLY if not following
987 // a space, because this could be e.g. {\large {\bf thing}} where {\bf thing}
988 // is the argument of \large AS WELL as being a block in its
989 // own right.
990 if (!environment)
991 {
992 if ((pos > 0) && (buffer[pos-1] != ' ') && buffer[pos] == '{')
993 pos ++;
994 else
995
996 if ((pos > 0) && (buffer[pos-1] != ' ') && (buffer[pos] == '[' || buffer[pos] == '('))
997 {
998 isOptional = true;
999 pos ++;
1000 }
1001 else if ((pos > 1) && (buffer[pos-1] != ' ') && (buffer[pos+1] == '[' || buffer[pos+1] == '('))
1002 {
1003 isOptional = true;
1004 pos += 2;
1005 }
1006 }
1007 */
1008
1009 // If not parsing to brace, just read the next word
1010 // (e.g. \vskip 20pt)
1011 if (!parseToBrace)
1012 {
1013 int ch = buffer[pos];
1014 while (!eof && ch != 13 && ch != 32 && ch != 10 &&
1015 ch != 0 && ch != '{')
1016 {
1017 BigBuffer[buf_ptr] = ch;
1018 buf_ptr ++;
1019 pos ++;
1020 ch = buffer[pos];
1021 }
1022 if (buf_ptr > 0)
1023 {
1024 TexChunk *chunk = new TexChunk(CHUNK_TYPE_STRING);
1025 BigBuffer[buf_ptr] = 0;
1026 chunk->value = copystring(BigBuffer);
1027 children.Append((wxObject *)chunk);
1028 }
1029 return pos;
1030 }
1031
1032 while (!eof)
1033 {
1034 len = wxStrlen(buffer);
1035 if (pos >= len)
1036 {
1037 if (customMacroArgs) return 0;
1038
1039 eof = read_a_line(buffer);
1040 pos = 0;
1041 // Check for verbatim (or toocomplex, which comes to the same thing)
1042 wxString bufStr = buffer;
1043 // if (bufStr.find("\\begin{verbatim}") != wxString::npos ||
1044 // bufStr.find("\\begin{toocomplex}") != wxString::npos)
1045 if (wxStrncmp(buffer, _T("\\begin{verbatim}"), 16) == 0 ||
1046 wxStrncmp(buffer, _T("\\begin{toocomplex}"), 18) == 0)
1047 {
1048 if (buf_ptr > 0)
1049 {
1050 TexChunk *chunk = new TexChunk(CHUNK_TYPE_STRING);
1051 BigBuffer[buf_ptr] = 0;
1052 chunk->value = copystring(BigBuffer);
1053 children.Append((wxObject *)chunk);
1054 }
1055 BigBuffer[0] = 0;
1056 buf_ptr = 0;
1057
1058 eof = read_a_line(buffer);
1059 while (!eof && (wxStrncmp(buffer, _T("\\end{verbatim}"), 14) != 0) &&
1060 (wxStrncmp(buffer, _T("\\end{toocomplex}"), 16) != 0)
1061 )
1062 {
1063 wxStrcat(BigBuffer, buffer);
1064 buf_ptr += wxStrlen(buffer);
1065 eof = read_a_line(buffer);
1066 }
1067 eof = read_a_line(buffer);
1068 buf_ptr = 0;
1069
1070 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO, VerbatimMacroDef);
1071 chunk->no_args = 1;
1072 chunk->macroId = ltVERBATIM;
1073 TexChunk *arg = new TexChunk(CHUNK_TYPE_ARG, VerbatimMacroDef);
1074 arg->argn = 1;
1075 arg->macroId = ltVERBATIM;
1076 TexChunk *str = new TexChunk(CHUNK_TYPE_STRING);
1077 str->value = copystring(BigBuffer);
1078
1079 children.Append((wxObject *)chunk);
1080 chunk->children.Append((wxObject *)arg);
1081 arg->children.Append((wxObject *)str);
1082
1083 // Also want to include the following newline (is always a newline
1084 // after a verbatim): EXCEPT in HTML
1085 if (convertMode != TEX_HTML)
1086 {
1087 TexMacroDef *parDef = (TexMacroDef *)MacroDefs.Get(_T("\\"));
1088 TexChunk *parChunk = new TexChunk(CHUNK_TYPE_MACRO, parDef);
1089 parChunk->no_args = 0;
1090 parChunk->macroId = ltBACKSLASHCHAR;
1091 children.Append((wxObject *)parChunk);
1092 }
1093 }
1094 }
1095
1096 char ch = buffer[pos];
1097 // End of optional argument -- pretend it's right brace for simplicity
1098 if (thisArg->optional && (ch == ']'))
1099 ch = '}';
1100
1101 switch (ch)
1102 {
1103 case 0:
1104 case '}': // End of argument
1105 {
1106 if (buf_ptr > 0)
1107 {
1108 TexChunk *chunk = new TexChunk(CHUNK_TYPE_STRING);
1109 BigBuffer[buf_ptr] = 0;
1110 chunk->value = copystring(BigBuffer);
1111 children.Append((wxObject *)chunk);
1112 }
1113 if (ch == '}') pos ++;
1114 return pos;
1115 }
1116 case '\\':
1117 {
1118 if (buf_ptr > 0) // Finish off the string we've read so far
1119 {
1120 TexChunk *chunk = new TexChunk(CHUNK_TYPE_STRING);
1121 BigBuffer[buf_ptr] = 0;
1122 buf_ptr = 0;
1123 chunk->value = copystring(BigBuffer);
1124 children.Append((wxObject *)chunk);
1125 }
1126 pos ++;
1127
1128 // Try matching \end{environment}
1129 if (environment && FindEndEnvironment(buffer, &pos, environment))
1130 {
1131 // Eliminate newline after an \end{} if possible
1132 if (buffer[pos] == 13)
1133 {
1134 pos ++;
1135 if (buffer[pos] == 10)
1136 pos ++;
1137 }
1138 return pos;
1139 }
1140
1141 if (ParseNewCommand(buffer, &pos))
1142 break;
1143
1144 if (wxStrncmp(buffer+pos, _T("special"), 7) == 0)
1145 {
1146 pos += 7;
1147
1148 // Discard {
1149 pos ++;
1150 int noBraces = 1;
1151
1152 wxTex2RTFBuffer[0] = 0;
1153 int i = 0;
1154 bool end = false;
1155 while (!end)
1156 {
1157 int ch = buffer[pos];
1158 if (ch == '}')
1159 {
1160 noBraces --;
1161 if (noBraces == 0)
1162 {
1163 wxTex2RTFBuffer[i] = 0;
1164 end = true;
1165 }
1166 else
1167 {
1168 wxTex2RTFBuffer[i] = '}';
1169 i ++;
1170 }
1171 pos ++;
1172 }
1173 else if (ch == '{')
1174 {
1175 wxTex2RTFBuffer[i] = '{';
1176 i ++;
1177 pos ++;
1178 }
1179 else if (ch == '\\' && buffer[pos+1] == '}')
1180 {
1181 wxTex2RTFBuffer[i] = '}';
1182 pos += 2;
1183 i++;
1184 }
1185 else if (ch == '\\' && buffer[pos+1] == '{')
1186 {
1187 wxTex2RTFBuffer[i] = '{';
1188 pos += 2;
1189 i++;
1190 }
1191 else
1192 {
1193 wxTex2RTFBuffer[i] = ch;
1194 pos ++;
1195 i ++;
1196 if (ch == 0)
1197 end = true;
1198 }
1199 }
1200 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO);
1201 chunk->no_args = 1;
1202 chunk->macroId = ltSPECIAL;
1203 TexMacroDef *specialDef = (TexMacroDef *)MacroDefs.Get(_T("special"));
1204 chunk->def = specialDef;
1205 TexChunk *arg = new TexChunk(CHUNK_TYPE_ARG, specialDef);
1206 chunk->children.Append((wxObject *)arg);
1207 arg->argn = 1;
1208 arg->macroId = chunk->macroId;
1209
1210 // The value in the first argument.
1211 TexChunk *argValue = new TexChunk(CHUNK_TYPE_STRING);
1212 arg->children.Append((wxObject *)argValue);
1213 argValue->argn = 1;
1214 argValue->value = copystring(wxTex2RTFBuffer);
1215
1216 children.Append((wxObject *)chunk);
1217 }
1218 else if (wxStrncmp(buffer+pos, _T("verb"), 4) == 0)
1219 {
1220 pos += 4;
1221 if (buffer[pos] == '*')
1222 pos ++;
1223
1224 // Find the delimiter character
1225 int ch = buffer[pos];
1226 pos ++;
1227 // Now at start of verbatim text
1228 int j = pos;
1229 while ((buffer[pos] != ch) && buffer[pos] != 0)
1230 pos ++;
1231 wxChar *val = new wxChar[pos - j + 1];
1232 int i;
1233 for (i = j; i < pos; i++)
1234 {
1235 val[i-j] = buffer[i];
1236 }
1237 val[i-j] = 0;
1238
1239 pos ++;
1240
1241 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO);
1242 chunk->no_args = 1;
1243 chunk->macroId = ltVERB;
1244 TexMacroDef *verbDef = (TexMacroDef *)MacroDefs.Get(_T("verb"));
1245 chunk->def = verbDef;
1246 TexChunk *arg = new TexChunk(CHUNK_TYPE_ARG, verbDef);
1247 chunk->children.Append((wxObject *)arg);
1248 arg->argn = 1;
1249 arg->macroId = chunk->macroId;
1250
1251 // The value in the first argument.
1252 TexChunk *argValue = new TexChunk(CHUNK_TYPE_STRING);
1253 arg->children.Append((wxObject *)argValue);
1254 argValue->argn = 1;
1255 argValue->value = val;
1256
1257 children.Append((wxObject *)chunk);
1258 }
1259 else
1260 {
1261 wxChar *env = NULL;
1262 bool tmpParseToBrace = true;
1263 TexMacroDef *def = MatchMacro(buffer, &pos, &env, &tmpParseToBrace);
1264 if (def)
1265 {
1266 CustomMacro *customMacro = FindCustomMacro(def->name);
1267
1268 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO, def);
1269
1270 chunk->no_args = def->no_args;
1271 // chunk->name = copystring(def->name);
1272 chunk->macroId = def->macroId;
1273
1274 if (!customMacro)
1275 children.Append((wxObject *)chunk);
1276
1277 // Eliminate newline after a \begin{} or a \\ if possible
1278 if (env || wxStrcmp(def->name, _T("\\")) == 0)
1279 if (buffer[pos] == 13)
1280 {
1281 pos ++;
1282 if (buffer[pos] == 10)
1283 pos ++;
1284 }
1285
1286 pos = ParseMacroBody(def->name, chunk, chunk->no_args,
1287 buffer, pos, env, tmpParseToBrace, customMacroArgs);
1288
1289 // If custom macro, parse the body substituting the above found args.
1290 if (customMacro)
1291 {
1292 if (customMacro->macroBody)
1293 {
1294 wxChar macroBuf[300];
1295 // wxStrcpy(macroBuf, _T("{"));
1296 wxStrcpy(macroBuf, customMacro->macroBody);
1297 wxStrcat(macroBuf, _T("}"));
1298 ParseArg(thisArg, children, macroBuf, 0, NULL, true, chunk);
1299 }
1300
1301 // delete chunk; // Might delete children
1302 }
1303 }
1304 else
1305 {
1306 MacroError(buffer+pos);
1307 }
1308 }
1309 break;
1310 }
1311 // Parse constructs like {\bf thing} as if they were
1312 // \bf{thing}
1313 case '{':
1314 {
1315 pos ++;
1316 if (buffer[pos] == '\\')
1317 {
1318 if (buf_ptr > 0)
1319 {
1320 TexChunk *chunk = new TexChunk(CHUNK_TYPE_STRING);
1321 BigBuffer[buf_ptr] = 0;
1322 buf_ptr = 0;
1323 chunk->value = copystring(BigBuffer);
1324 children.Append((wxObject *)chunk);
1325 }
1326 pos ++;
1327
1328 wxChar *env;
1329 bool tmpParseToBrace;
1330 TexMacroDef *def = MatchMacro(buffer, &pos, &env, &tmpParseToBrace);
1331 if (def)
1332 {
1333 CustomMacro *customMacro = FindCustomMacro(def->name);
1334
1335 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO, def);
1336 chunk->no_args = def->no_args;
1337 // chunk->name = copystring(def->name);
1338 chunk->macroId = def->macroId;
1339 if (!customMacro)
1340 children.Append((wxObject *)chunk);
1341
1342 pos = ParseMacroBody(def->name, chunk, chunk->no_args,
1343 buffer, pos, NULL, true, customMacroArgs);
1344
1345 // If custom macro, parse the body substituting the above found args.
1346 if (customMacro)
1347 {
1348 if (customMacro->macroBody)
1349 {
1350 wxChar macroBuf[300];
1351 // wxStrcpy(macroBuf, _T("{"));
1352 wxStrcpy(macroBuf, customMacro->macroBody);
1353 wxStrcat(macroBuf, _T("}"));
1354 ParseArg(thisArg, children, macroBuf, 0, NULL, true, chunk);
1355 }
1356
1357 // delete chunk; // Might delete children
1358 }
1359 }
1360 else
1361 {
1362 MacroError(buffer+pos);
1363 }
1364 }
1365 else
1366 {
1367 /*
1368 * If all else fails, we assume that we have
1369 * a pair of braces on their own, so return a `dummy' macro
1370 * definition with just one argument to parse.
1371 */
1372 if (!SoloBlockDef)
1373 {
1374 SoloBlockDef = new TexMacroDef(ltSOLO_BLOCK, _T("solo block"), 1, false);
1375 }
1376 // Save text so far
1377 if (buf_ptr > 0)
1378 {
1379 TexChunk *chunk1 = new TexChunk(CHUNK_TYPE_STRING);
1380 BigBuffer[buf_ptr] = 0;
1381 buf_ptr = 0;
1382 chunk1->value = copystring(BigBuffer);
1383 children.Append((wxObject *)chunk1);
1384 }
1385 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO, SoloBlockDef);
1386 chunk->no_args = SoloBlockDef->no_args;
1387 // chunk->name = copystring(SoloBlockDef->name);
1388 chunk->macroId = SoloBlockDef->macroId;
1389 children.Append((wxObject *)chunk);
1390
1391 TexChunk *arg = new TexChunk(CHUNK_TYPE_ARG, SoloBlockDef);
1392
1393 chunk->children.Append((wxObject *)arg);
1394 // arg->name = copystring(SoloBlockDef->name);
1395 arg->argn = 1;
1396 arg->macroId = chunk->macroId;
1397
1398 pos = ParseArg(arg, arg->children, buffer, pos, NULL, true, customMacroArgs);
1399 }
1400 break;
1401 }
1402 case '$':
1403 {
1404 if (buf_ptr > 0)
1405 {
1406 TexChunk *chunk = new TexChunk(CHUNK_TYPE_STRING);
1407 BigBuffer[buf_ptr] = 0;
1408 buf_ptr = 0;
1409 chunk->value = copystring(BigBuffer);
1410 children.Append((wxObject *)chunk);
1411 }
1412
1413 pos ++;
1414
1415 if (buffer[pos] == '$')
1416 {
1417 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO);
1418 chunk->no_args = 0;
1419 // chunk->name = copystring(_T("$$"));
1420 chunk->macroId = ltSPECIALDOUBLEDOLLAR;
1421 children.Append((wxObject *)chunk);
1422 pos ++;
1423 }
1424 else
1425 {
1426 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO);
1427 chunk->no_args = 0;
1428 // chunk->name = copystring(_T("_$"));
1429 chunk->macroId = ltSPECIALDOLLAR;
1430 children.Append((wxObject *)chunk);
1431 }
1432 break;
1433 }
1434 case '~':
1435 {
1436 if (buf_ptr > 0)
1437 {
1438 TexChunk *chunk = new TexChunk(CHUNK_TYPE_STRING);
1439 BigBuffer[buf_ptr] = 0;
1440 buf_ptr = 0;
1441 chunk->value = copystring(BigBuffer);
1442 children.Append((wxObject *)chunk);
1443 }
1444
1445 pos ++;
1446 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO);
1447 chunk->no_args = 0;
1448 // chunk->name = copystring(_T("_~"));
1449 chunk->macroId = ltSPECIALTILDE;
1450 children.Append((wxObject *)chunk);
1451 break;
1452 }
1453 case '#': // Either treat as a special TeX character or as a macro arg
1454 {
1455 if (buf_ptr > 0)
1456 {
1457 TexChunk *chunk = new TexChunk(CHUNK_TYPE_STRING);
1458 BigBuffer[buf_ptr] = 0;
1459 buf_ptr = 0;
1460 chunk->value = copystring(BigBuffer);
1461 children.Append((wxObject *)chunk);
1462 }
1463
1464 pos ++;
1465 if (!customMacroArgs)
1466 {
1467 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO);
1468 chunk->no_args = 0;
1469 // chunk->name = copystring(_T("_#"));
1470 chunk->macroId = ltSPECIALHASH;
1471 children.Append((wxObject *)chunk);
1472 }
1473 else
1474 {
1475 if (isdigit(buffer[pos]))
1476 {
1477 int n = buffer[pos] - 48;
1478 pos ++;
1479 wxNode *node = customMacroArgs->children.Item(n-1);
1480 if (node)
1481 {
1482 TexChunk *argChunk = (TexChunk *)node->GetData();
1483 children.Append((wxObject *)new TexChunk(*argChunk));
1484 }
1485 }
1486 }
1487 break;
1488 }
1489 case '&':
1490 {
1491 // Remove white space before and after the ampersand,
1492 // since this is probably a table column separator with
1493 // some convenient -- but useless -- white space in the text.
1494 while ((buf_ptr > 0) && ((BigBuffer[buf_ptr-1] == ' ') || (BigBuffer[buf_ptr-1] == 9)))
1495 buf_ptr --;
1496
1497 if (buf_ptr > 0)
1498 {
1499 TexChunk *chunk = new TexChunk(CHUNK_TYPE_STRING);
1500 BigBuffer[buf_ptr] = 0;
1501 buf_ptr = 0;
1502 chunk->value = copystring(BigBuffer);
1503 children.Append((wxObject *)chunk);
1504 }
1505
1506 pos ++;
1507
1508 while (buffer[pos] == ' ' || buffer[pos] == 9)
1509 pos ++;
1510
1511 TexChunk *chunk = new TexChunk(CHUNK_TYPE_MACRO);
1512 chunk->no_args = 0;
1513 // chunk->name = copystring(_T("_&"));
1514 chunk->macroId = ltSPECIALAMPERSAND;
1515 children.Append((wxObject *)chunk);
1516 break;
1517 }
1518 // Eliminate end-of-line comment
1519 case '%':
1520 {
1521 ch = buffer[pos];
1522 while (ch != 10 && ch != 13 && ch != 0)
1523 {
1524 pos ++;
1525 ch = buffer[pos];
1526 }
1527 if (buffer[pos] == 10 || buffer[pos] == 13)
1528 {
1529 pos ++;
1530 if (buffer[pos] == 10) pos ++; // Eliminate newline following DOS line feed
1531 }
1532 break;
1533 }
1534 // Eliminate tab
1535 case 9:
1536 {
1537 BigBuffer[buf_ptr] = ' ';
1538 BigBuffer[buf_ptr+1] = 0;
1539 buf_ptr ++;
1540 pos ++;
1541 break;
1542 }
1543 default:
1544 {
1545 BigBuffer[buf_ptr] = ch;
1546 BigBuffer[buf_ptr+1] = 0;
1547 buf_ptr ++;
1548 pos ++;
1549 break;
1550 }
1551 }
1552 }
1553 return pos;
1554 }
1555
1556 /*
1557 * Consume as many arguments as the macro definition specifies
1558 *
1559 */
1560
1561 int ParseMacroBody(const wxChar *WXUNUSED(macro_name), TexChunk *parent,
1562 int no_args, wxChar *buffer, int pos,
1563 wxChar *environment, bool parseToBrace,
1564 TexChunk *customMacroArgs)
1565 {
1566 Tex2RTFYield();
1567 if (stopRunning) return pos;
1568
1569 // Check for a first optional argument
1570 if (buffer[pos] == ' ' && buffer[pos+1] == '[')
1571 {
1572 // Fool following code into thinking that this is definitely
1573 // an optional first argument. (If a space before a non-first argument,
1574 // [ is interpreted as a [, not an optional argument.)
1575 buffer[pos] = '!';
1576 pos ++;
1577 no_args ++;
1578 }
1579 else
1580 if (buffer[pos] == '[')
1581 no_args ++;
1582
1583 int maxArgs = 0;
1584
1585 int i;
1586 for (i = 0; i < no_args; i++)
1587 {
1588 maxArgs ++;
1589 TexChunk *arg = new TexChunk(CHUNK_TYPE_ARG, parent->def);
1590
1591 parent->children.Append((wxObject *)arg);
1592 // arg->name = copystring(macro_name);
1593 arg->argn = maxArgs;
1594 arg->macroId = parent->macroId;
1595
1596 // To parse the first arg of a 2 arg \begin{thing}{arg} ... \end{thing}
1597 // have to fool parser into thinking this is a regular kind of block.
1598 wxChar *actualEnv;
1599 if ((no_args == 2) && (i == 0))
1600 actualEnv = NULL;
1601 else
1602 actualEnv = environment;
1603
1604 bool isOptional = false;
1605
1606 // Remove the first { of the argument so it doesn't get recognized as { ... }
1607 // EatWhiteSpace(buffer, &pos);
1608 if (!actualEnv)
1609 {
1610 // The reason for these tests is to not consume braces that don't
1611 // belong to this macro.
1612 // E.g. {\bf {\small thing}}
1613 if ((pos > 0) && (buffer[pos-1] != ' ') && buffer[pos] == '{')
1614 pos ++;
1615 else
1616 if ((pos > 0) && (buffer[pos-1] != ' ') && (buffer[pos] == '['))
1617 {
1618 isOptional = true;
1619 pos ++;
1620 }
1621 else if ((pos > 1) && (buffer[pos-1] != ' ') && (buffer[pos+1] == '['))
1622 {
1623 isOptional = true;
1624 pos += 2;
1625 }
1626 else if (i > 0)
1627 {
1628 wxString errBuf;
1629 wxString tmpBuffer(buffer);
1630 if (tmpBuffer.length() > 4)
1631 {
1632 if (tmpBuffer.Right(4) == _T("\\par"))
1633 tmpBuffer = tmpBuffer.Mid(0,tmpBuffer.length()-4);
1634 }
1635 errBuf.Printf(_T("Missing macro argument in the line:\n\t%s\n"),tmpBuffer.c_str());
1636 OnError((wxChar *)errBuf.c_str());
1637 }
1638
1639 }
1640 arg->optional = isOptional;
1641
1642 pos = ParseArg(arg, arg->children, buffer, pos, actualEnv, parseToBrace, customMacroArgs);
1643
1644 // If we've encountered an OPTIONAL argument, go another time around
1645 // the loop, because we've got more than we thought.
1646 // Hopefully optional args don't occur at the end of a macro use
1647 // or we might miss it.
1648 // Don't increment no of times round loop if the first optional arg
1649 // -- we already did it before the loop.
1650 if (arg->optional && (i > 0))
1651 i --;
1652 }
1653 parent->no_args = maxArgs;
1654
1655 // Tell each argument how many args there are (useful when processing an arg)
1656 wxNode *node = parent->children.GetFirst();
1657 while (node)
1658 {
1659 TexChunk *chunk = (TexChunk *)node->GetData();
1660 chunk->no_args = maxArgs;
1661 node = node->GetNext();
1662 }
1663 return pos;
1664 }
1665
1666 bool TexLoadFile(wxChar *filename)
1667 {
1668 static wxChar *line_buffer;
1669 stopRunning = false;
1670 wxStrcpy(TexFileRoot, filename);
1671 StripExtension(TexFileRoot);
1672 wxSnprintf(TexBibName, 300, _T("%s.bb"), TexFileRoot);
1673 wxSnprintf(TexTmpBibName, 300, _T("%s.bb1"), TexFileRoot);
1674
1675 TexPathList.EnsureFileAccessible(filename);
1676
1677 if (line_buffer)
1678 delete line_buffer;
1679
1680 line_buffer = new wxChar[MAX_LINE_BUFFER_SIZE];
1681
1682 Inputs[0] = wxFopen(filename, _T("r"));
1683 LineNumbers[0] = 1;
1684 FileNames[0] = copystring(filename);
1685 if (Inputs[0])
1686 {
1687 read_a_line(line_buffer);
1688 ParseMacroBody(_T("toplevel"), TopLevel, 1, line_buffer, 0, NULL, true);
1689 if (Inputs[0]) fclose(Inputs[0]);
1690 return true;
1691 }
1692
1693 return false;
1694 }
1695
1696 TexMacroDef::TexMacroDef(int the_id, const wxChar *the_name, int n, bool ig, bool forbidLevel)
1697 {
1698 name = copystring(the_name);
1699 no_args = n;
1700 ignore = ig;
1701 macroId = the_id;
1702 forbidden = forbidLevel;
1703 }
1704
1705 TexMacroDef::~TexMacroDef(void)
1706 {
1707 if (name) delete[] name;
1708 }
1709
1710 TexChunk::TexChunk(int the_type, TexMacroDef *the_def)
1711 {
1712 type = the_type;
1713 no_args = 0;
1714 argn = 0;
1715 // name = NULL;
1716 def = the_def;
1717 macroId = 0;
1718 value = NULL;
1719 optional = false;
1720 }
1721
1722 TexChunk::TexChunk(TexChunk& toCopy)
1723 {
1724 type = toCopy.type;
1725 no_args = toCopy.no_args;
1726 argn = toCopy.argn;
1727 macroId = toCopy.macroId;
1728
1729 // if (toCopy.name)
1730 // name = copystring(toCopy.name);
1731 // else
1732 // name = NULL;
1733 def = toCopy.def;
1734
1735 if (toCopy.value)
1736 value = copystring(toCopy.value);
1737 else
1738 value = NULL;
1739
1740 optional = toCopy.optional;
1741 wxNode *node = toCopy.children.GetFirst();
1742 while (node)
1743 {
1744 TexChunk *child = (TexChunk *)node->GetData();
1745 children.Append((wxObject *)new TexChunk(*child));
1746 node = node->GetNext();
1747 }
1748 }
1749
1750 TexChunk::~TexChunk(void)
1751 {
1752 // if (name) delete[] name;
1753 if (value) delete[] value;
1754 wxNode *node = children.GetFirst();
1755 while (node)
1756 {
1757 TexChunk *child = (TexChunk *)node->GetData();
1758 delete child;
1759 wxNode *next = node->GetNext();
1760 delete node;
1761 node = next;
1762 }
1763 }
1764
1765 bool IsArgOptional(void) // Is this argument an optional argument?
1766 {
1767 return isArgOptional;
1768 }
1769
1770 int GetNoArgs(void) // Number of args for this macro
1771 {
1772 return noArgs;
1773 }
1774
1775 /* Gets the text of a chunk on request (must be for small arguments
1776 * only!)
1777 *
1778 */
1779
1780 void GetArgData1(TexChunk *chunk)
1781 {
1782 switch (chunk->type)
1783 {
1784 case CHUNK_TYPE_MACRO:
1785 {
1786 TexMacroDef *def = chunk->def;
1787 if (def && def->ignore)
1788 return;
1789
1790 if (def && (wxStrcmp(def->name, _T("solo block")) != 0))
1791 {
1792 wxStrcat(currentArgData, _T("\\"));
1793 wxStrcat(currentArgData, def->name);
1794 }
1795
1796 wxNode *node = chunk->children.GetFirst();
1797 while (node)
1798 {
1799 TexChunk *child_chunk = (TexChunk *)node->GetData();
1800 wxStrcat(currentArgData, _T("{"));
1801 GetArgData1(child_chunk);
1802 wxStrcat(currentArgData, _T("}"));
1803 node = node->GetNext();
1804 }
1805 break;
1806 }
1807 case CHUNK_TYPE_ARG:
1808 {
1809 wxNode *node = chunk->children.GetFirst();
1810 while (node)
1811 {
1812 TexChunk *child_chunk = (TexChunk *)node->GetData();
1813 GetArgData1(child_chunk);
1814 node = node->GetNext();
1815 }
1816 break;
1817 }
1818 case CHUNK_TYPE_STRING:
1819 {
1820 if (chunk->value)
1821 wxStrcat(currentArgData, chunk->value);
1822 break;
1823 }
1824 }
1825 }
1826
1827 wxChar *GetArgData(TexChunk *WXUNUSED(chunk))
1828 {
1829 currentArgData[0] = 0;
1830 GetArgData1(currentArgument);
1831 haveArgData = false;
1832 return currentArgData;
1833 }
1834
1835 wxChar *GetArgData(void)
1836 {
1837 if (!haveArgData)
1838 {
1839 currentArgData[0] = 0;
1840 GetArgData1(currentArgument);
1841 }
1842 return currentArgData;
1843 }
1844
1845 TexChunk *GetArgChunk(void)
1846 {
1847 return currentArgument;
1848 }
1849
1850 TexChunk *GetNextChunk(void) // Look ahead to the next chunk
1851 {
1852 return nextChunk;
1853 }
1854
1855 TexChunk *GetTopLevelChunk(void)
1856 {
1857 return TopLevel;
1858 }
1859
1860 int GetCurrentColumn(void)
1861 {
1862 return currentColumn;
1863 }
1864
1865 /*
1866 * Traverses document calling functions to allow the client to
1867 * write out the appropriate stuff
1868 */
1869
1870
1871 void TraverseFromChunk(TexChunk *chunk, wxNode *thisNode, bool childrenOnly)
1872 {
1873 Tex2RTFYield();
1874 if (stopRunning) return;
1875
1876 switch (chunk->type)
1877 {
1878 case CHUNK_TYPE_MACRO:
1879 {
1880 TexMacroDef *def = chunk->def;
1881 if (def && def->ignore)
1882 return;
1883
1884 if (!childrenOnly)
1885 OnMacro(chunk->macroId, chunk->no_args, true);
1886
1887 wxNode *node = chunk->children.GetFirst();
1888 while (node)
1889 {
1890 TexChunk *child_chunk = (TexChunk *)node->GetData();
1891 TraverseFromChunk(child_chunk, node);
1892 node = node->GetNext();
1893 }
1894
1895 if (thisNode && thisNode->GetNext())
1896 nextChunk = (TexChunk *)thisNode->GetNext()->GetData();
1897
1898 if (!childrenOnly)
1899 OnMacro(chunk->macroId, chunk->no_args, false);
1900 break;
1901 }
1902 case CHUNK_TYPE_ARG:
1903 {
1904 currentArgument = chunk;
1905
1906 isArgOptional = chunk->optional;
1907 noArgs = chunk->no_args;
1908
1909 // If OnArgument returns false, don't output.
1910
1911 if (childrenOnly || OnArgument(chunk->macroId, chunk->argn, true))
1912 {
1913 wxNode *node = chunk->children.GetFirst();
1914 while (node)
1915 {
1916 TexChunk *child_chunk = (TexChunk *)node->GetData();
1917 TraverseFromChunk(child_chunk, node);
1918 node = node->GetNext();
1919 }
1920 }
1921
1922 currentArgument = chunk;
1923
1924 if (thisNode && thisNode->GetNext())
1925 nextChunk = (TexChunk *)thisNode->GetNext()->GetData();
1926
1927 isArgOptional = chunk->optional;
1928 noArgs = chunk->no_args;
1929
1930 if (!childrenOnly)
1931 (void)OnArgument(chunk->macroId, chunk->argn, false);
1932 break;
1933 }
1934 case CHUNK_TYPE_STRING:
1935 {
1936 extern int issuedNewParagraph;
1937 extern int forbidResetPar;
1938 if (chunk->value && (forbidResetPar == 0))
1939 {
1940 // If non-whitespace text, we no longer have a new paragraph.
1941 if (issuedNewParagraph && !((chunk->value[0] == 10 || chunk->value[0] == 13 || chunk->value[0] == 32)
1942 && chunk->value[1] == 0))
1943 {
1944 issuedNewParagraph = false;
1945 }
1946 TexOutput(chunk->value, true);
1947 }
1948 break;
1949 }
1950 }
1951 }
1952
1953 void TraverseDocument(void)
1954 {
1955 TraverseFromChunk(TopLevel, NULL);
1956 }
1957
1958 void SetCurrentOutput(FILE *fd)
1959 {
1960 CurrentOutput1 = fd;
1961 CurrentOutput2 = NULL;
1962 }
1963
1964 void SetCurrentOutputs(FILE *fd1, FILE *fd2)
1965 {
1966 CurrentOutput1 = fd1;
1967 CurrentOutput2 = fd2;
1968 }
1969
1970 void AddMacroDef(int the_id, const wxChar *name, int n, bool ignore, bool forbid)
1971 {
1972 MacroDefs.Put(name, new TexMacroDef(the_id, name, n, ignore, forbid));
1973 }
1974
1975 void TexInitialize(int bufSize)
1976 {
1977 InitialiseColourTable();
1978 #ifdef __WXMSW__
1979 TexPathList.AddEnvList(_T("TEXINPUT"));
1980 #endif
1981 #ifdef __UNIX__
1982 TexPathList.AddEnvList(_T("TEXINPUTS"));
1983 #endif
1984 int i;
1985 for (i = 0; i < 15; i++)
1986 {
1987 Inputs[i] = NULL;
1988 LineNumbers[i] = 1;
1989 FileNames[i] = NULL;
1990 }
1991
1992 IgnorableInputFiles.Add(_T("psbox.tex"));
1993 BigBuffer = new wxChar[(bufSize*1000)];
1994 currentArgData = new wxChar[2000];
1995 TexFileRoot = new wxChar[300];
1996 TexBibName = new wxChar[300];
1997 TexTmpBibName = new wxChar[300];
1998 AddMacroDef(ltTOPLEVEL, _T("toplevel"), 1);
1999 TopLevel = new TexChunk(CHUNK_TYPE_MACRO);
2000 // TopLevel->name = copystring(_T("toplevel"));
2001 TopLevel->macroId = ltTOPLEVEL;
2002 TopLevel->no_args = 1;
2003 VerbatimMacroDef = (TexMacroDef *)MacroDefs.Get(_T("verbatim"));
2004 }
2005
2006 void TexCleanUp(void)
2007 {
2008 int i;
2009 for (i = 0; i < 15; i++)
2010 Inputs[i] = NULL;
2011
2012 chapterNo = 0;
2013 sectionNo = 0;
2014 subsectionNo = 0;
2015 subsubsectionNo = 0;
2016 figureNo = 0;
2017
2018 CurrentOutput1 = NULL;
2019 CurrentOutput2 = NULL;
2020 CurrentInputIndex = 0;
2021 haveArgData = false;
2022 noArgs = 0;
2023
2024 if (TopLevel)
2025 delete TopLevel;
2026 TopLevel = new TexChunk(CHUNK_TYPE_MACRO);
2027 // TopLevel->name = copystring(_T("toplevel"));
2028 TopLevel->macroId = ltTOPLEVEL;
2029 TopLevel->no_args = 1;
2030
2031 DocumentTitle = NULL;
2032 DocumentAuthor = NULL;
2033 DocumentDate = NULL;
2034 DocumentStyle = LATEX_REPORT;
2035 MinorDocumentStyle = 0;
2036 BibliographyStyleString = copystring(_T("plain"));
2037 DocumentStyleString = copystring(_T("report"));
2038 MinorDocumentStyleString = NULL;
2039
2040 // gt - Changed this so if this is the final pass
2041 // then we DO want to remove these macros, so that
2042 // memory is not MASSIVELY leaked if the user
2043 // does not exit the program, but instead runs
2044 // the program again
2045 if ((passNumber == 1 && !runTwice) ||
2046 (passNumber == 2 && runTwice))
2047 {
2048 /* Don't want to remove custom macros after each pass.*/
2049 SetFontSizes(10);
2050 wxNode *node = CustomMacroList.GetFirst();
2051 while (node)
2052 {
2053 CustomMacro *macro = (CustomMacro *)node->GetData();
2054 delete macro;
2055 delete node;
2056 node = CustomMacroList.GetFirst();
2057 }
2058 }
2059 /**/
2060 TexReferences.BeginFind();
2061 wxHashTable::Node *refNode = TexReferences.Next();
2062 while (refNode)
2063 {
2064 TexRef *ref = (TexRef *)refNode->GetData();
2065 delete ref;
2066 refNode = TexReferences.Next();
2067 }
2068 TexReferences.Clear();
2069
2070 wxNode* bibNode = BibList.GetFirst();
2071 while (bibNode)
2072 {
2073 BibEntry *entry = (BibEntry *)bibNode->GetData();
2074 delete entry;
2075 delete bibNode;
2076 bibNode = BibList.GetFirst();
2077 }
2078 CitationList.Clear();
2079 ResetTopicCounter();
2080 }
2081
2082 // There is likely to be one set of macros used by all utilities.
2083 void DefineDefaultMacros(void)
2084 {
2085 // Put names which subsume other names at the TOP
2086 // so they get recognized first
2087
2088 AddMacroDef(ltACCENT_GRAVE, _T("`"), 1);
2089 AddMacroDef(ltACCENT_ACUTE, _T("'"), 1);
2090 AddMacroDef(ltACCENT_CARET, _T("^"), 1);
2091 AddMacroDef(ltACCENT_UMLAUT, _T("\""), 1);
2092 AddMacroDef(ltACCENT_TILDE, _T("~"), 1);
2093 AddMacroDef(ltACCENT_DOT, _T("."), 1);
2094 AddMacroDef(ltACCENT_CADILLA, _T("c"), 1);
2095 AddMacroDef(ltSMALLSPACE1, _T(","), 0);
2096 AddMacroDef(ltSMALLSPACE2, _T(";"), 0);
2097
2098 AddMacroDef(ltABSTRACT, _T("abstract"), 1);
2099 AddMacroDef(ltADDCONTENTSLINE, _T("addcontentsline"), 3);
2100 AddMacroDef(ltADDTOCOUNTER, _T("addtocounter"), 2);
2101 AddMacroDef(ltALEPH, _T("aleph"), 0);
2102 AddMacroDef(ltALPHA, _T("alpha"), 0);
2103 AddMacroDef(ltALPH1, _T("alph"), 1);
2104 AddMacroDef(ltALPH2, _T("Alph"), 1);
2105 AddMacroDef(ltANGLE, _T("angle"), 0);
2106 AddMacroDef(ltAPPENDIX, _T("appendix"), 0);
2107 AddMacroDef(ltAPPROX, _T("approx"), 0);
2108 AddMacroDef(ltARABIC, _T("arabic"), 1);
2109 AddMacroDef(ltARRAY, _T("array"), 1);
2110 AddMacroDef(ltAST, _T("ast"), 0);
2111 AddMacroDef(ltASYMP, _T("asymp"), 0);
2112 AddMacroDef(ltAUTHOR, _T("author"), 1);
2113
2114 AddMacroDef(ltBACKGROUNDCOLOUR, _T("backgroundcolour"), 1);
2115 AddMacroDef(ltBACKGROUNDIMAGE, _T("backgroundimage"), 1);
2116 AddMacroDef(ltBACKGROUND, _T("background"), 1);
2117 AddMacroDef(ltBACKSLASHRAW, _T("backslashraw"), 0);
2118 AddMacroDef(ltBACKSLASH, _T("backslash"), 0);
2119 AddMacroDef(ltBASELINESKIP, _T("baselineskip"), 1);
2120 AddMacroDef(ltBCOL, _T("bcol"), 2);
2121 AddMacroDef(ltBETA, _T("beta"), 0);
2122 AddMacroDef(ltBFSERIES, _T("bfseries"), 1);
2123 AddMacroDef(ltBF, _T("bf"), 1);
2124 AddMacroDef(ltBIBITEM, _T("bibitem"), 2);
2125 // For convenience, bibitem has 2 args: label and item.
2126 // The Latex syntax permits writing as 2 args.
2127 AddMacroDef(ltBIBLIOGRAPHYSTYLE, _T("bibliographystyle"), 1);
2128 AddMacroDef(ltBIBLIOGRAPHY, _T("bibliography"), 1);
2129 AddMacroDef(ltBIGTRIANGLEDOWN, _T("bigtriangledown"), 0);
2130 AddMacroDef(ltBOT, _T("bot"), 0);
2131 AddMacroDef(ltBOXIT, _T("boxit"), 1);
2132 AddMacroDef(ltBOX, _T("box"), 0);
2133 AddMacroDef(ltBRCLEAR, _T("brclear"), 0);
2134 AddMacroDef(ltBULLET, _T("bullet"), 0);
2135
2136 AddMacroDef(ltCAPTIONSTAR, _T("caption*"), 1);
2137 AddMacroDef(ltCAPTION, _T("caption"), 1);
2138 AddMacroDef(ltCAP, _T("cap"), 0);
2139 AddMacroDef(ltCDOTS, _T("cdots"), 0);
2140 AddMacroDef(ltCDOT, _T("cdot"), 0);
2141 AddMacroDef(ltCENTERLINE, _T("centerline"), 1);
2142 AddMacroDef(ltCENTERING, _T("centering"), 0);
2143 AddMacroDef(ltCENTER, _T("center"), 1);
2144 AddMacroDef(ltCEXTRACT, _T("cextract"), 0);
2145 AddMacroDef(ltCHAPTERHEADING, _T("chapterheading"), 1);
2146 AddMacroDef(ltCHAPTERSTAR, _T("chapter*"), 1);
2147 AddMacroDef(ltCHAPTER, _T("chapter"), 1);
2148 AddMacroDef(ltCHI, _T("chi"), 0);
2149 AddMacroDef(ltCINSERT, _T("cinsert"), 0);
2150 AddMacroDef(ltCIRC, _T("circ"), 0);
2151 AddMacroDef(ltCITE, _T("cite"), 1);
2152 AddMacroDef(ltCLASS, _T("class"), 1);
2153 AddMacroDef(ltCLEARDOUBLEPAGE, _T("cleardoublepage"), 0);
2154 AddMacroDef(ltCLEARPAGE, _T("clearpage"), 0);
2155 AddMacroDef(ltCLINE, _T("cline"), 1);
2156 AddMacroDef(ltCLIPSFUNC, _T("clipsfunc"), 3);
2157 AddMacroDef(ltCLUBSUIT, _T("clubsuit"), 0);
2158 AddMacroDef(ltCOLUMNSEP, _T("columnsep"), 1);
2159 AddMacroDef(ltCOMMENT, _T("comment"), 1, true);
2160 AddMacroDef(ltCONG, _T("cong"), 0);
2161 AddMacroDef(ltCOPYRIGHT, _T("copyright"), 0);
2162 AddMacroDef(ltCPARAM, _T("cparam"), 2);
2163 AddMacroDef(ltCHEAD, _T("chead"), 1);
2164 AddMacroDef(ltCFOOT, _T("cfoot"), 1);
2165 AddMacroDef(ltCUP, _T("cup"), 0);
2166
2167 AddMacroDef(ltDASHV, _T("dashv"), 0);
2168 AddMacroDef(ltDATE, _T("date"), 1);
2169 AddMacroDef(ltDELTA, _T("delta"), 0);
2170 AddMacroDef(ltCAP_DELTA, _T("Delta"), 0);
2171 AddMacroDef(ltDEFINECOLOUR, _T("definecolour"), 4);
2172 AddMacroDef(ltDEFINECOLOR, _T("definecolor"), 4);
2173 AddMacroDef(ltDESCRIPTION, _T("description"), 1);
2174 AddMacroDef(ltDESTRUCT, _T("destruct"), 1);
2175 AddMacroDef(ltDIAMOND2, _T("diamond2"), 0);
2176 AddMacroDef(ltDIAMOND, _T("diamond"), 0);
2177 AddMacroDef(ltDIV, _T("div"), 0);
2178 AddMacroDef(ltDOCUMENTCLASS, _T("documentclass"), 1);
2179 AddMacroDef(ltDOCUMENTSTYLE, _T("documentstyle"), 1);
2180 AddMacroDef(ltDOCUMENT, _T("document"), 1);
2181 AddMacroDef(ltDOUBLESPACE, _T("doublespace"), 1);
2182 AddMacroDef(ltDOTEQ, _T("doteq"), 0);
2183 AddMacroDef(ltDOWNARROW, _T("downarrow"), 0);
2184 AddMacroDef(ltDOWNARROW2, _T("Downarrow"), 0);
2185
2186 AddMacroDef(ltEMPTYSET, _T("emptyset"), 0);
2187 AddMacroDef(ltEMPH, _T("emph"), 1);
2188 AddMacroDef(ltEM, _T("em"), 1);
2189 AddMacroDef(ltENUMERATE, _T("enumerate"), 1);
2190 AddMacroDef(ltEPSILON, _T("epsilon"), 0);
2191 AddMacroDef(ltEQUATION, _T("equation"), 1);
2192 AddMacroDef(ltEQUIV, _T("equiv"), 0);
2193 AddMacroDef(ltETA, _T("eta"), 0);
2194 AddMacroDef(ltEVENSIDEMARGIN, _T("evensidemargin"), 1);
2195 AddMacroDef(ltEXISTS, _T("exists"), 0);
2196
2197 AddMacroDef(ltFBOX, _T("fbox"), 1);
2198 AddMacroDef(ltFCOL, _T("fcol"), 2);
2199 AddMacroDef(ltFIGURE, _T("figure"), 1);
2200 AddMacroDef(ltFIGURESTAR, _T("figure*"), 1);
2201 AddMacroDef(ltFLUSHLEFT, _T("flushleft"), 1);
2202 AddMacroDef(ltFLUSHRIGHT, _T("flushright"), 1);
2203 AddMacroDef(ltFOLLOWEDLINKCOLOUR, _T("followedlinkcolour"), 1);
2204 AddMacroDef(ltFOOTHEIGHT, _T("footheight"), 1);
2205 AddMacroDef(ltFOOTNOTEPOPUP, _T("footnotepopup"), 2);
2206 AddMacroDef(ltFOOTNOTE, _T("footnote"), 1);
2207 AddMacroDef(ltFOOTSKIP, _T("footskip"), 1);
2208 AddMacroDef(ltFORALL, _T("forall"), 0);
2209 AddMacroDef(ltFRAMEBOX, _T("framebox"), 1);
2210 AddMacroDef(ltFROWN, _T("frown"), 0);
2211 AddMacroDef(ltFUNCTIONSECTION, _T("functionsection"), 1);
2212 AddMacroDef(ltFUNC, _T("func"), 3);
2213 AddMacroDef(ltFOOTNOTESIZE, _T("footnotesize"), 0);
2214 AddMacroDef(ltFANCYPLAIN, _T("fancyplain"), 2);
2215
2216 AddMacroDef(ltGAMMA, _T("gamma"), 0);
2217 AddMacroDef(ltCAP_GAMMA, _T("Gamma"), 0);
2218 AddMacroDef(ltGEQ, _T("geq"), 0);
2219 AddMacroDef(ltGE, _T("ge"), 0);
2220 AddMacroDef(ltGG, _T("gg"), 0);
2221 AddMacroDef(ltGLOSSARY, _T("glossary"), 1);
2222 AddMacroDef(ltGLOSS, _T("gloss"), 1);
2223
2224 AddMacroDef(ltHEADHEIGHT, _T("headheight"), 1);
2225 AddMacroDef(ltHEARTSUIT, _T("heartsuit"), 0);
2226 AddMacroDef(ltHELPGLOSSARY, _T("helpglossary"), 1);
2227 AddMacroDef(ltHELPIGNORE, _T("helpignore"), 1, true);
2228 AddMacroDef(ltHELPONLY, _T("helponly"), 1);
2229 AddMacroDef(ltHELPINPUT, _T("helpinput"), 1);
2230 AddMacroDef(ltHELPFONTFAMILY, _T("helpfontfamily"), 1);
2231 AddMacroDef(ltHELPFONTSIZE, _T("helpfontsize"), 1);
2232 AddMacroDef(ltHELPREFN, _T("helprefn"), 2);
2233 AddMacroDef(ltHELPREF, _T("helpref"), 2);
2234 AddMacroDef(ltHFILL, _T("hfill"), 0);
2235 AddMacroDef(ltHLINE, _T("hline"), 0);
2236 AddMacroDef(ltHRULE, _T("hrule"), 0);
2237 AddMacroDef(ltHSPACESTAR, _T("hspace*"), 1);
2238 AddMacroDef(ltHSPACE, _T("hspace"), 1);
2239 AddMacroDef(ltHSKIPSTAR, _T("hskip*"), 1);
2240 AddMacroDef(ltHSKIP, _T("hskip"), 1);
2241 AddMacroDef(lthuge, _T("huge"), 1);
2242 AddMacroDef(ltHuge, _T("Huge"), 1);
2243 AddMacroDef(ltHUGE, _T("HUGE"), 1);
2244 AddMacroDef(ltHTMLIGNORE, _T("htmlignore"), 1);
2245 AddMacroDef(ltHTMLONLY, _T("htmlonly"), 1);
2246
2247 AddMacroDef(ltIM, _T("im"), 0);
2248 AddMacroDef(ltINCLUDEONLY, _T("includeonly"), 1);
2249 AddMacroDef(ltINCLUDE, _T("include"), 1);
2250 AddMacroDef(ltINDENTED, _T("indented"), 2);
2251 AddMacroDef(ltINDEX, _T("index"), 1);
2252 AddMacroDef(ltINPUT, _T("input"), 1, true);
2253 AddMacroDef(ltIOTA, _T("iota"), 0);
2254 AddMacroDef(ltITEMIZE, _T("itemize"), 1);
2255 AddMacroDef(ltITEM, _T("item"), 0);
2256 AddMacroDef(ltIMAGEMAP, _T("imagemap"), 3);
2257 AddMacroDef(ltIMAGEL, _T("imagel"), 2);
2258 AddMacroDef(ltIMAGER, _T("imager"), 2);
2259 AddMacroDef(ltIMAGE, _T("image"), 2);
2260 AddMacroDef(ltIN, _T("in"), 0);
2261 AddMacroDef(ltINFTY, _T("infty"), 0);
2262 AddMacroDef(ltITSHAPE, _T("itshape"), 1);
2263 AddMacroDef(ltIT, _T("it"), 1);
2264 AddMacroDef(ltITEMSEP, _T("itemsep"), 1);
2265 AddMacroDef(ltINSERTATLEVEL, _T("insertatlevel"), 2);
2266
2267 AddMacroDef(ltKAPPA, _T("kappa"), 0);
2268 AddMacroDef(ltKILL, _T("kill"), 0);
2269
2270 AddMacroDef(ltLABEL, _T("label"), 1);
2271 AddMacroDef(ltLAMBDA, _T("lambda"), 0);
2272 AddMacroDef(ltCAP_LAMBDA, _T("Lambda"), 0);
2273 AddMacroDef(ltlarge, _T("large"), 1);
2274 AddMacroDef(ltLarge, _T("Large"), 1);
2275 AddMacroDef(ltLARGE, _T("LARGE"), 1);
2276 AddMacroDef(ltLATEXIGNORE, _T("latexignore"), 1);
2277 AddMacroDef(ltLATEXONLY, _T("latexonly"), 1);
2278 AddMacroDef(ltLATEX, _T("LaTeX"), 0);
2279 AddMacroDef(ltLBOX, _T("lbox"), 1);
2280 AddMacroDef(ltLBRACERAW, _T("lbraceraw"), 0);
2281 AddMacroDef(ltLDOTS, _T("ldots"), 0);
2282 AddMacroDef(ltLEQ, _T("leq"), 0);
2283 AddMacroDef(ltLE, _T("le"), 0);
2284 AddMacroDef(ltLEFTARROW, _T("leftarrow"), 0);
2285 AddMacroDef(ltLEFTRIGHTARROW, _T("leftrightarrow"), 0);
2286 AddMacroDef(ltLEFTARROW2, _T("Leftarrow"), 0);
2287 AddMacroDef(ltLEFTRIGHTARROW2, _T("Leftrightarrow"), 0);
2288 AddMacroDef(ltLINEBREAK, _T("linebreak"), 0);
2289 AddMacroDef(ltLINKCOLOUR, _T("linkcolour"), 1);
2290 AddMacroDef(ltLISTOFFIGURES, _T("listoffigures"), 0);
2291 AddMacroDef(ltLISTOFTABLES, _T("listoftables"), 0);
2292 AddMacroDef(ltLHEAD, _T("lhead"), 1);
2293 AddMacroDef(ltLFOOT, _T("lfoot"), 1);
2294 AddMacroDef(ltLOWERCASE, _T("lowercase"), 1);
2295 AddMacroDef(ltLL, _T("ll"), 0);
2296
2297 AddMacroDef(ltMAKEGLOSSARY, _T("makeglossary"), 0);
2298 AddMacroDef(ltMAKEINDEX, _T("makeindex"), 0);
2299 AddMacroDef(ltMAKETITLE, _T("maketitle"), 0);
2300 AddMacroDef(ltMARKRIGHT, _T("markright"), 1);
2301 AddMacroDef(ltMARKBOTH, _T("markboth"), 2);
2302 AddMacroDef(ltMARGINPARWIDTH, _T("marginparwidth"), 1);
2303 AddMacroDef(ltMARGINPARSEP, _T("marginparsep"), 1);
2304 AddMacroDef(ltMARGINPARODD, _T("marginparodd"), 1);
2305 AddMacroDef(ltMARGINPAREVEN, _T("marginpareven"), 1);
2306 AddMacroDef(ltMARGINPAR, _T("marginpar"), 1);
2307 AddMacroDef(ltMBOX, _T("mbox"), 1);
2308 AddMacroDef(ltMDSERIES, _T("mdseries"), 1);
2309 AddMacroDef(ltMEMBERSECTION, _T("membersection"), 1);
2310 AddMacroDef(ltMEMBER, _T("member"), 2);
2311 AddMacroDef(ltMID, _T("mid"), 0);
2312 AddMacroDef(ltMODELS, _T("models"), 0);
2313 AddMacroDef(ltMP, _T("mp"), 0);
2314 AddMacroDef(ltMULTICOLUMN, _T("multicolumn"), 3);
2315 AddMacroDef(ltMU, _T("mu"), 0);
2316
2317 AddMacroDef(ltNABLA, _T("nabla"), 0);
2318 AddMacroDef(ltNEG, _T("neg"), 0);
2319 AddMacroDef(ltNEQ, _T("neq"), 0);
2320 AddMacroDef(ltNEWCOUNTER, _T("newcounter"), 1, false, (bool)FORBID_ABSOLUTELY);
2321 AddMacroDef(ltNEWLINE, _T("newline"), 0);
2322 AddMacroDef(ltNEWPAGE, _T("newpage"), 0);
2323 AddMacroDef(ltNI, _T("ni"), 0);
2324 AddMacroDef(ltNOCITE, _T("nocite"), 1);
2325 AddMacroDef(ltNOINDENT, _T("noindent"), 0);
2326 AddMacroDef(ltNOLINEBREAK, _T("nolinebreak"), 0);
2327 AddMacroDef(ltNOPAGEBREAK, _T("nopagebreak"), 0);
2328 AddMacroDef(ltNORMALSIZE, _T("normalsize"), 1);
2329 AddMacroDef(ltNORMALBOX, _T("normalbox"), 1);
2330 AddMacroDef(ltNORMALBOXD, _T("normalboxd"), 1);
2331 AddMacroDef(ltNOTEQ, _T("noteq"), 0);
2332 AddMacroDef(ltNOTIN, _T("notin"), 0);
2333 AddMacroDef(ltNOTSUBSET, _T("notsubset"), 0);
2334 AddMacroDef(ltNU, _T("nu"), 0);
2335
2336 AddMacroDef(ltODDSIDEMARGIN, _T("oddsidemargin"), 1);
2337 AddMacroDef(ltOMEGA, _T("omega"), 0);
2338 AddMacroDef(ltCAP_OMEGA, _T("Omega"), 0);
2339 AddMacroDef(ltONECOLUMN, _T("onecolumn"), 0);
2340 AddMacroDef(ltOPLUS, _T("oplus"), 0);
2341 AddMacroDef(ltOSLASH, _T("oslash"), 0);
2342 AddMacroDef(ltOTIMES, _T("otimes"), 0);
2343
2344 AddMacroDef(ltPAGEBREAK, _T("pagebreak"), 0);
2345 AddMacroDef(ltPAGEREF, _T("pageref"), 1);
2346 AddMacroDef(ltPAGESTYLE, _T("pagestyle"), 1);
2347 AddMacroDef(ltPAGENUMBERING, _T("pagenumbering"), 1);
2348 AddMacroDef(ltPARAGRAPHSTAR, _T("paragraph*"), 1);
2349 AddMacroDef(ltPARAGRAPH, _T("paragraph"), 1);
2350 AddMacroDef(ltPARALLEL, _T("parallel"), 0);
2351 AddMacroDef(ltPARAM, _T("param"), 2);
2352 AddMacroDef(ltPARINDENT, _T("parindent"), 1);
2353 AddMacroDef(ltPARSKIP, _T("parskip"), 1);
2354 AddMacroDef(ltPARTIAL, _T("partial"), 0);
2355 AddMacroDef(ltPARTSTAR, _T("part*"), 1);
2356 AddMacroDef(ltPART, _T("part"), 1);
2357 AddMacroDef(ltPAR, _T("par"), 0);
2358 AddMacroDef(ltPERP, _T("perp"), 0);
2359 AddMacroDef(ltPHI, _T("phi"), 0);
2360 AddMacroDef(ltCAP_PHI, _T("Phi"), 0);
2361 AddMacroDef(ltPFUNC, _T("pfunc"), 3);
2362 AddMacroDef(ltPICTURE, _T("picture"), 1);
2363 AddMacroDef(ltPI, _T("pi"), 0);
2364 AddMacroDef(ltCAP_PI, _T("Pi"), 0);
2365 AddMacroDef(ltPM, _T("pm"), 0);
2366 AddMacroDef(ltPOPREFONLY, _T("poprefonly"), 1);
2367 AddMacroDef(ltPOPREF, _T("popref"), 2);
2368 AddMacroDef(ltPOUNDS, _T("pounds"), 0);
2369 AddMacroDef(ltPREC, _T("prec"), 0);
2370 AddMacroDef(ltPRECEQ, _T("preceq"), 0);
2371 AddMacroDef(ltPRINTINDEX, _T("printindex"), 0);
2372 AddMacroDef(ltPROPTO, _T("propto"), 0);
2373 AddMacroDef(ltPSBOXTO, _T("psboxto"), 1, false, (bool)FORBID_ABSOLUTELY);
2374 AddMacroDef(ltPSBOX, _T("psbox"), 1, false, (bool)FORBID_ABSOLUTELY);
2375 AddMacroDef(ltPSI, _T("psi"), 0);
2376 AddMacroDef(ltCAP_PSI, _T("Psi"), 0);
2377
2378 AddMacroDef(ltQUOTE, _T("quote"), 1);
2379 AddMacroDef(ltQUOTATION, _T("quotation"), 1);
2380
2381 AddMacroDef(ltRAGGEDBOTTOM, _T("raggedbottom"), 0);
2382 AddMacroDef(ltRAGGEDLEFT, _T("raggedleft"), 0);
2383 AddMacroDef(ltRAGGEDRIGHT, _T("raggedright"), 0);
2384 AddMacroDef(ltRBRACERAW, _T("rbraceraw"), 0);
2385 AddMacroDef(ltREF, _T("ref"), 1);
2386 AddMacroDef(ltREGISTERED, _T("registered"), 0);
2387 AddMacroDef(ltRE, _T("we"), 0);
2388 AddMacroDef(ltRHO, _T("rho"), 0);
2389 AddMacroDef(ltRIGHTARROW, _T("rightarrow"), 0);
2390 AddMacroDef(ltRIGHTARROW2, _T("rightarrow2"), 0);
2391 AddMacroDef(ltRMFAMILY, _T("rmfamily"), 1);
2392 AddMacroDef(ltRM, _T("rm"), 1);
2393 AddMacroDef(ltROMAN, _T("roman"), 1);
2394 AddMacroDef(ltROMAN2, _T("Roman"), 1);
2395 // AddMacroDef(lt"row", 1);
2396 AddMacroDef(ltRTFSP, _T("rtfsp"), 0);
2397 AddMacroDef(ltRTFIGNORE, _T("rtfignore"), 1);
2398 AddMacroDef(ltRTFONLY, _T("rtfonly"), 1);
2399 AddMacroDef(ltRULEDROW, _T("ruledrow"), 1);
2400 AddMacroDef(ltDRULED, _T("druled"), 1);
2401 AddMacroDef(ltRULE, _T("rule"), 2);
2402 AddMacroDef(ltRHEAD, _T("rhead"), 1);
2403 AddMacroDef(ltRFOOT, _T("rfoot"), 1);
2404 AddMacroDef(ltROW, _T("row"), 1);
2405
2406 AddMacroDef(ltSCSHAPE, _T("scshape"), 1);
2407 AddMacroDef(ltSC, _T("sc"), 1);
2408 AddMacroDef(ltSECTIONHEADING, _T("sectionheading"), 1);
2409 AddMacroDef(ltSECTIONSTAR, _T("section*"), 1);
2410 AddMacroDef(ltSECTION, _T("section"), 1);
2411 AddMacroDef(ltSETCOUNTER, _T("setcounter"), 2);
2412 AddMacroDef(ltSFFAMILY, _T("sffamily"), 1);
2413 AddMacroDef(ltSF, _T("sf"), 1);
2414 AddMacroDef(ltSHARP, _T("sharp"), 0);
2415 AddMacroDef(ltSHORTCITE, _T("shortcite"), 1);
2416 AddMacroDef(ltSIGMA, _T("sigma"), 0);
2417 AddMacroDef(ltCAP_SIGMA, _T("Sigma"), 0);
2418 AddMacroDef(ltSIM, _T("sim"), 0);
2419 AddMacroDef(ltSIMEQ, _T("simeq"), 0);
2420 AddMacroDef(ltSINGLESPACE, _T("singlespace"), 1);
2421 AddMacroDef(ltSIZEDBOX, _T("sizedbox"), 2);
2422 AddMacroDef(ltSIZEDBOXD, _T("sizedboxd"), 2);
2423 AddMacroDef(ltSLOPPYPAR, _T("sloppypar"), 1);
2424 AddMacroDef(ltSLOPPY, _T("sloppy"), 0);
2425 AddMacroDef(ltSLSHAPE, _T("slshape"), 1);
2426 AddMacroDef(ltSL, _T("sl"), 1);
2427 AddMacroDef(ltSMALL, _T("small"), 1);
2428 AddMacroDef(ltSMILE, _T("smile"), 0);
2429 AddMacroDef(ltSS, _T("ss"), 0);
2430 AddMacroDef(ltSTAR, _T("star"), 0);
2431 AddMacroDef(ltSUBITEM, _T("subitem"), 0);
2432 AddMacroDef(ltSUBPARAGRAPHSTAR, _T("subparagraph*"), 1);
2433 AddMacroDef(ltSUBPARAGRAPH, _T("subparagraph"), 1);
2434 AddMacroDef(ltSPECIAL, _T("special"), 1);
2435 AddMacroDef(ltSUBSECTIONSTAR, _T("subsection*"), 1);
2436 AddMacroDef(ltSUBSECTION, _T("subsection"), 1);
2437 AddMacroDef(ltSUBSETEQ, _T("subseteq"), 0);
2438 AddMacroDef(ltSUBSET, _T("subset"), 0);
2439 AddMacroDef(ltSUCC, _T("succ"), 0);
2440 AddMacroDef(ltSUCCEQ, _T("succeq"), 0);
2441 AddMacroDef(ltSUPSETEQ, _T("supseteq"), 0);
2442 AddMacroDef(ltSUPSET, _T("supset"), 0);
2443 AddMacroDef(ltSUBSUBSECTIONSTAR, _T("subsubsection*"), 1);
2444 AddMacroDef(ltSUBSUBSECTION, _T("subsubsection"), 1);
2445 AddMacroDef(ltSUPERTABULAR, _T("supertabular"), 2, false);
2446 AddMacroDef(ltSURD, _T("surd"), 0);
2447 AddMacroDef(ltSCRIPTSIZE, _T("scriptsize"), 1);
2448 AddMacroDef(ltSETHEADER, _T("setheader"), 6);
2449 AddMacroDef(ltSETFOOTER, _T("setfooter"), 6);
2450 AddMacroDef(ltSETHOTSPOTCOLOUR, _T("sethotspotcolour"), 1);
2451 AddMacroDef(ltSETHOTSPOTCOLOR, _T("sethotspotcolor"), 1);
2452 AddMacroDef(ltSETHOTSPOTUNDERLINE, _T("sethotspotunderline"), 1);
2453 AddMacroDef(ltSETTRANSPARENCY, _T("settransparency"), 1);
2454 AddMacroDef(ltSPADESUIT, _T("spadesuit"), 0);
2455
2456 AddMacroDef(ltTABBING, _T("tabbing"), 2);
2457 AddMacroDef(ltTABLEOFCONTENTS, _T("tableofcontents"), 0);
2458 AddMacroDef(ltTABLE, _T("table"), 1);
2459 AddMacroDef(ltTABULAR, _T("tabular"), 2, false);
2460 AddMacroDef(ltTAB, _T("tab"), 0);
2461 AddMacroDef(ltTAU, _T("tau"), 0);
2462 AddMacroDef(ltTEXTRM, _T("textrm"), 1);
2463 AddMacroDef(ltTEXTSF, _T("textsf"), 1);
2464 AddMacroDef(ltTEXTTT, _T("texttt"), 1);
2465 AddMacroDef(ltTEXTBF, _T("textbf"), 1);
2466 AddMacroDef(ltTEXTIT, _T("textit"), 1);
2467 AddMacroDef(ltTEXTSL, _T("textsl"), 1);
2468 AddMacroDef(ltTEXTSC, _T("textsc"), 1);
2469 AddMacroDef(ltTEXTWIDTH, _T("textwidth"), 1);
2470 AddMacroDef(ltTEXTHEIGHT, _T("textheight"), 1);
2471 AddMacroDef(ltTEXTCOLOUR, _T("textcolour"), 1);
2472 AddMacroDef(ltTEX, _T("TeX"), 0);
2473 AddMacroDef(ltTHEBIBLIOGRAPHY, _T("thebibliography"), 2);
2474 AddMacroDef(ltTHETA, _T("theta"), 0);
2475 AddMacroDef(ltTIMES, _T("times"), 0);
2476 AddMacroDef(ltCAP_THETA, _T("Theta"), 0);
2477 AddMacroDef(ltTITLEPAGE, _T("titlepage"), 1);
2478 AddMacroDef(ltTITLE, _T("title"), 1);
2479 AddMacroDef(ltTINY, _T("tiny"), 1);
2480 AddMacroDef(ltTODAY, _T("today"), 0);
2481 AddMacroDef(ltTOPMARGIN, _T("topmargin"), 1);
2482 AddMacroDef(ltTOPSKIP, _T("topskip"), 1);
2483 AddMacroDef(ltTRIANGLE, _T("triangle"), 0);
2484 AddMacroDef(ltTTFAMILY, _T("ttfamily"), 1);
2485 AddMacroDef(ltTT, _T("tt"), 1);
2486 AddMacroDef(ltTYPEIN, _T("typein"), 1);
2487 AddMacroDef(ltTYPEOUT, _T("typeout"), 1);
2488 AddMacroDef(ltTWOCOLWIDTHA, _T("twocolwidtha"), 1);
2489 AddMacroDef(ltTWOCOLWIDTHB, _T("twocolwidthb"), 1);
2490 AddMacroDef(ltTWOCOLSPACING, _T("twocolspacing"), 1);
2491 AddMacroDef(ltTWOCOLITEMRULED, _T("twocolitemruled"), 2);
2492 AddMacroDef(ltTWOCOLITEM, _T("twocolitem"), 2);
2493 AddMacroDef(ltTWOCOLLIST, _T("twocollist"), 1);
2494 AddMacroDef(ltTWOCOLUMN, _T("twocolumn"), 0);
2495 AddMacroDef(ltTHEPAGE, _T("thepage"), 0);
2496 AddMacroDef(ltTHECHAPTER, _T("thechapter"), 0);
2497 AddMacroDef(ltTHESECTION, _T("thesection"), 0);
2498 AddMacroDef(ltTHISPAGESTYLE, _T("thispagestyle"), 1);
2499
2500 AddMacroDef(ltUNDERLINE, _T("underline"), 1);
2501 AddMacroDef(ltUPSILON, _T("upsilon"), 0);
2502 AddMacroDef(ltCAP_UPSILON, _T("Upsilon"), 0);
2503 AddMacroDef(ltUPARROW, _T("uparrow"), 0);
2504 AddMacroDef(ltUPARROW2, _T("Uparrow"), 0);
2505 AddMacroDef(ltUPPERCASE, _T("uppercase"), 1);
2506 AddMacroDef(ltUPSHAPE, _T("upshape"), 1);
2507 AddMacroDef(ltURLREF, _T("urlref"), 2);
2508 AddMacroDef(ltUSEPACKAGE, _T("usepackage"), 1);
2509
2510 AddMacroDef(ltVAREPSILON, _T("varepsilon"), 0);
2511 AddMacroDef(ltVARPHI, _T("varphi"), 0);
2512 AddMacroDef(ltVARPI, _T("varpi"), 0);
2513 AddMacroDef(ltVARRHO, _T("varrho"), 0);
2514 AddMacroDef(ltVARSIGMA, _T("varsigma"), 0);
2515 AddMacroDef(ltVARTHETA, _T("vartheta"), 0);
2516 AddMacroDef(ltVDOTS, _T("vdots"), 0);
2517 AddMacroDef(ltVEE, _T("vee"), 0);
2518 AddMacroDef(ltVERBATIMINPUT, _T("verbatiminput"), 1);
2519 AddMacroDef(ltVERBATIM, _T("verbatim"), 1);
2520 AddMacroDef(ltVERBSTAR, _T("verb*"), 1);
2521 AddMacroDef(ltVERB, _T("verb"), 1);
2522 AddMacroDef(ltVERSE, _T("verse"), 1);
2523 AddMacroDef(ltVFILL, _T("vfill"), 0);
2524 AddMacroDef(ltVLINE, _T("vline"), 0);
2525 AddMacroDef(ltVOID, _T("void"), 0);
2526 AddMacroDef(ltVDASH, _T("vdash"), 0);
2527 AddMacroDef(ltVRULE, _T("vrule"), 0);
2528 AddMacroDef(ltVSPACESTAR, _T("vspace*"), 1);
2529 AddMacroDef(ltVSKIPSTAR, _T("vskip*"), 1);
2530 AddMacroDef(ltVSPACE, _T("vspace"), 1);
2531 AddMacroDef(ltVSKIP, _T("vskip"), 1);
2532
2533 AddMacroDef(ltWEDGE, _T("wedge"), 0);
2534 AddMacroDef(ltWXCLIPS, _T("wxclips"), 0);
2535 AddMacroDef(ltWINHELPIGNORE, _T("winhelpignore"), 1);
2536 AddMacroDef(ltWINHELPONLY, _T("winhelponly"), 1);
2537 AddMacroDef(ltWP, _T("wp"), 0);
2538
2539 AddMacroDef(ltXI, _T("xi"), 0);
2540 AddMacroDef(ltCAP_XI, _T("Xi"), 0);
2541 AddMacroDef(ltXLPIGNORE, _T("xlpignore"), 1);
2542 AddMacroDef(ltXLPONLY, _T("xlponly"), 1);
2543
2544 AddMacroDef(ltZETA, _T("zeta"), 0);
2545
2546 AddMacroDef(ltSPACE, _T(" "), 0);
2547 AddMacroDef(ltBACKSLASHCHAR, _T("\\"), 0);
2548 AddMacroDef(ltPIPE, _T("|"), 0);
2549 AddMacroDef(ltFORWARDSLASH, _T("/"), 0);
2550 AddMacroDef(ltUNDERSCORE, _T("_"), 0);
2551 AddMacroDef(ltAMPERSAND, _T("&"), 0);
2552 AddMacroDef(ltPERCENT, _T("%"), 0);
2553 AddMacroDef(ltDOLLAR, _T("$"), 0);
2554 AddMacroDef(ltHASH, _T("#"), 0);
2555 AddMacroDef(ltLPARENTH, _T("("), 0);
2556 AddMacroDef(ltRPARENTH, _T(")"), 0);
2557 AddMacroDef(ltLBRACE, _T("{"), 0);
2558 AddMacroDef(ltRBRACE, _T("}"), 0);
2559 // AddMacroDef(ltEQUALS, _T("="), 0);
2560 AddMacroDef(ltRANGLEBRA, _T(">"), 0);
2561 AddMacroDef(ltLANGLEBRA, _T("<"), 0);
2562 AddMacroDef(ltPLUS, _T("+"), 0);
2563 AddMacroDef(ltDASH, _T("-"), 0);
2564 AddMacroDef(ltAT_SYMBOL, _T("@"), 0);
2565 // AddMacroDef(ltSINGLEQUOTE, _T("'"), 0);
2566 // AddMacroDef(ltBACKQUOTE, _T("`"), 0);
2567 }
2568
2569 /*
2570 * Default behaviour, should be called by client if can't match locally.
2571 *
2572 */
2573
2574 // Called on start/end of macro examination
2575 void DefaultOnMacro(int macroId, int no_args, bool start)
2576 {
2577 switch (macroId)
2578 {
2579 // Default behaviour for abstract
2580 case ltABSTRACT:
2581 {
2582 if (start)
2583 {
2584 // Write the heading
2585 FakeCurrentSection(AbstractNameString);
2586 OnMacro(ltPAR, 0, true);
2587 OnMacro(ltPAR, 0, false);
2588 }
2589 else
2590 {
2591 if (DocumentStyle == LATEX_ARTICLE)
2592 sectionNo --;
2593 else
2594 chapterNo --;
2595 }
2596 break;
2597 }
2598
2599 // Default behaviour for glossary
2600 case ltHELPGLOSSARY:
2601 {
2602 if (start)
2603 {
2604 // Write the heading
2605 FakeCurrentSection(GlossaryNameString);
2606 OnMacro(ltPAR, 0, true);
2607 OnMacro(ltPAR, 0, false);
2608 if ((convertMode == TEX_RTF) && !winHelp)
2609 {
2610 OnMacro(ltPAR, 0, true);
2611 OnMacro(ltPAR, 0, false);
2612 }
2613 }
2614 break;
2615 }
2616 case ltSPECIALAMPERSAND:
2617 if (start)
2618 TexOutput(_T(" "));
2619 break;
2620
2621 case ltCINSERT:
2622 if (start)
2623 TexOutput(_T("<<"), true);
2624 break;
2625 case ltCEXTRACT:
2626 if (start)
2627 TexOutput(_T(">>"), true);
2628 break;
2629 case ltDESTRUCT:
2630 if (start)
2631 TexOutput(_T("~"), true);
2632 break;
2633 case ltTILDE:
2634 if (start)
2635 TexOutput(_T("~"), true);
2636 break;
2637 case ltSPECIALTILDE:
2638 if (start)
2639 TexOutput(_T(" "), true);
2640 break;
2641 case ltUNDERSCORE:
2642 if (start)
2643 TexOutput(_T("_"), true);
2644 break;
2645 case ltHASH:
2646 if (start)
2647 TexOutput(_T("#"), true);
2648 break;
2649 case ltAMPERSAND:
2650 if (start)
2651 TexOutput(_T("&"), true);
2652 break;
2653 case ltSPACE:
2654 if (start)
2655 TexOutput(_T(" "), true);
2656 break;
2657 case ltPIPE:
2658 if (start)
2659 TexOutput(_T("|"), true);
2660 break;
2661 case ltPERCENT:
2662 if (start)
2663 TexOutput(_T("%"), true);
2664 break;
2665 case ltDOLLAR:
2666 if (start)
2667 TexOutput(_T("$"), true);
2668 break;
2669 case ltLPARENTH:
2670 if (start)
2671 TexOutput(_T(""), true);
2672 break;
2673 case ltRPARENTH:
2674 if (start)
2675 TexOutput(_T(""), true);
2676 break;
2677 case ltLBRACE:
2678 if (start)
2679 TexOutput(_T("{"), true);
2680 break;
2681 case ltRBRACE:
2682 if (start)
2683 TexOutput(_T("}"), true);
2684 break;
2685 case ltCOPYRIGHT:
2686 if (start)
2687 TexOutput(_T("(c)"), true);
2688 break;
2689 case ltREGISTERED:
2690 if (start)
2691 TexOutput(_T("(r)"), true);
2692 break;
2693 case ltBACKSLASH:
2694 if (start)
2695 TexOutput(_T("\\"), true);
2696 break;
2697 case ltLDOTS:
2698 case ltCDOTS:
2699 if (start)
2700 TexOutput(_T("..."), true);
2701 break;
2702 case ltVDOTS:
2703 if (start)
2704 TexOutput(_T("|"), true);
2705 break;
2706 case ltLATEX:
2707 if (start)
2708 TexOutput(_T("LaTeX"), true);
2709 break;
2710 case ltTEX:
2711 if (start)
2712 TexOutput(_T("TeX"), true);
2713 break;
2714 case ltPOUNDS:
2715 if (start)
2716 TexOutput(_T("£"), true);
2717 break;
2718 case ltSPECIALDOUBLEDOLLAR: // Interpret as center
2719 OnMacro(ltCENTER, no_args, start);
2720 break;
2721 case ltEMPH:
2722 case ltTEXTSL:
2723 case ltSLSHAPE:
2724 case ltSL:
2725 OnMacro(ltIT, no_args, start);
2726 break;
2727 case ltPARAGRAPH:
2728 case ltPARAGRAPHSTAR:
2729 case ltSUBPARAGRAPH:
2730 case ltSUBPARAGRAPHSTAR:
2731 OnMacro(ltSUBSUBSECTION, no_args, start);
2732 break;
2733 case ltTODAY:
2734 {
2735 if (start)
2736 {
2737 time_t when;
2738 (void) time(&when);
2739 TexOutput(wxCtime(&when), true);
2740 }
2741 break;
2742 }
2743 case ltNOINDENT:
2744 if (start)
2745 ParIndent = 0;
2746 break;
2747
2748 // Symbols
2749 case ltALPHA:
2750 if (start) TexOutput(_T("alpha"));
2751 break;
2752 case ltBETA:
2753 if (start) TexOutput(_T("beta"));
2754 break;
2755 case ltGAMMA:
2756 if (start) TexOutput(_T("gamma"));
2757 break;
2758 case ltDELTA:
2759 if (start) TexOutput(_T("delta"));
2760 break;
2761 case ltEPSILON:
2762 case ltVAREPSILON:
2763 if (start) TexOutput(_T("epsilon"));
2764 break;
2765 case ltZETA:
2766 if (start) TexOutput(_T("zeta"));
2767 break;
2768 case ltETA:
2769 if (start) TexOutput(_T("eta"));
2770 break;
2771 case ltTHETA:
2772 case ltVARTHETA:
2773 if (start) TexOutput(_T("theta"));
2774 break;
2775 case ltIOTA:
2776 if (start) TexOutput(_T("iota"));
2777 break;
2778 case ltKAPPA:
2779 if (start) TexOutput(_T("kappa"));
2780 break;
2781 case ltLAMBDA:
2782 if (start) TexOutput(_T("lambda"));
2783 break;
2784 case ltMU:
2785 if (start) TexOutput(_T("mu"));
2786 break;
2787 case ltNU:
2788 if (start) TexOutput(_T("nu"));
2789 break;
2790 case ltXI:
2791 if (start) TexOutput(_T("xi"));
2792 break;
2793 case ltPI:
2794 case ltVARPI:
2795 if (start) TexOutput(_T("pi"));
2796 break;
2797 case ltRHO:
2798 case ltVARRHO:
2799 if (start) TexOutput(_T("rho"));
2800 break;
2801 case ltSIGMA:
2802 case ltVARSIGMA:
2803 if (start) TexOutput(_T("sigma"));
2804 break;
2805 case ltTAU:
2806 if (start) TexOutput(_T("tau"));
2807 break;
2808 case ltUPSILON:
2809 if (start) TexOutput(_T("upsilon"));
2810 break;
2811 case ltPHI:
2812 case ltVARPHI:
2813 if (start) TexOutput(_T("phi"));
2814 break;
2815 case ltCHI:
2816 if (start) TexOutput(_T("chi"));
2817 break;
2818 case ltPSI:
2819 if (start) TexOutput(_T("psi"));
2820 break;
2821 case ltOMEGA:
2822 if (start) TexOutput(_T("omega"));
2823 break;
2824 case ltCAP_GAMMA:
2825 if (start) TexOutput(_T("GAMMA"));
2826 break;
2827 case ltCAP_DELTA:
2828 if (start) TexOutput(_T("DELTA"));
2829 break;
2830 case ltCAP_THETA:
2831 if (start) TexOutput(_T("THETA"));
2832 break;
2833 case ltCAP_LAMBDA:
2834 if (start) TexOutput(_T("LAMBDA"));
2835 break;
2836 case ltCAP_XI:
2837 if (start) TexOutput(_T("XI"));
2838 break;
2839 case ltCAP_PI:
2840 if (start) TexOutput(_T("PI"));
2841 break;
2842 case ltCAP_SIGMA:
2843 if (start) TexOutput(_T("SIGMA"));
2844 break;
2845 case ltCAP_UPSILON:
2846 if (start) TexOutput(_T("UPSILON"));
2847 break;
2848 case ltCAP_PHI:
2849 if (start) TexOutput(_T("PHI"));
2850 break;
2851 case ltCAP_PSI:
2852 if (start) TexOutput(_T("PSI"));
2853 break;
2854 case ltCAP_OMEGA:
2855 if (start) TexOutput(_T("OMEGA"));
2856 break;
2857
2858 // Binary operation symbols
2859 case ltLE:
2860 case ltLEQ:
2861 if (start) TexOutput(_T("<="));
2862 break;
2863 case ltLL:
2864 if (start) TexOutput(_T("<<"));
2865 break;
2866 case ltSUBSET:
2867 if (start) TexOutput(_T("SUBSET"));
2868 break;
2869 case ltSUBSETEQ:
2870 if (start) TexOutput(_T("SUBSETEQ"));
2871 break;
2872 case ltIN:
2873 if (start) TexOutput(_T("IN"));
2874 break;
2875 case ltVDASH:
2876 if (start) TexOutput(_T("VDASH"));
2877 break;
2878 case ltMODELS:
2879 if (start) TexOutput(_T("MODELS"));
2880 break;
2881 case ltGE:
2882 case ltGEQ:
2883 if (start) TexOutput(_T(">="));
2884 break;
2885 case ltGG:
2886 if (start) TexOutput(_T(">>"));
2887 break;
2888 case ltSUPSET:
2889 if (start) TexOutput(_T("SUPSET"));
2890 break;
2891 case ltSUPSETEQ:
2892 if (start) TexOutput(_T("SUPSETEQ"));
2893 break;
2894 case ltNI:
2895 if (start) TexOutput(_T("NI"));
2896 break;
2897 case ltDASHV:
2898 if (start) TexOutput(_T("DASHV"));
2899 break;
2900 case ltPERP:
2901 if (start) TexOutput(_T("PERP"));
2902 break;
2903 case ltNEQ:
2904 if (start) TexOutput(_T("NEQ"));
2905 break;
2906 case ltDOTEQ:
2907 if (start) TexOutput(_T("DOTEQ"));
2908 break;
2909 case ltAPPROX:
2910 if (start) TexOutput(_T("APPROX"));
2911 break;
2912 case ltCONG:
2913 if (start) TexOutput(_T("CONG"));
2914 break;
2915 case ltEQUIV:
2916 if (start) TexOutput(_T("EQUIV"));
2917 break;
2918 case ltPROPTO:
2919 if (start) TexOutput(_T("PROPTO"));
2920 break;
2921 case ltPREC:
2922 if (start) TexOutput(_T("PREC"));
2923 break;
2924 case ltPRECEQ:
2925 if (start) TexOutput(_T("PRECEQ"));
2926 break;
2927 case ltPARALLEL:
2928 if (start) TexOutput(_T("|"));
2929 break;
2930 case ltSIM:
2931 if (start) TexOutput(_T("~"));
2932 break;
2933 case ltSIMEQ:
2934 if (start) TexOutput(_T("SIMEQ"));
2935 break;
2936 case ltASYMP:
2937 if (start) TexOutput(_T("ASYMP"));
2938 break;
2939 case ltSMILE:
2940 if (start) TexOutput(_T(":-)"));
2941 break;
2942 case ltFROWN:
2943 if (start) TexOutput(_T(":-("));
2944 break;
2945 case ltSUCC:
2946 if (start) TexOutput(_T("SUCC"));
2947 break;
2948 case ltSUCCEQ:
2949 if (start) TexOutput(_T("SUCCEQ"));
2950 break;
2951 case ltMID:
2952 if (start) TexOutput(_T("|"));
2953 break;
2954
2955 // Negated relation symbols
2956 case ltNOTEQ:
2957 if (start) TexOutput(_T("!="));
2958 break;
2959 case ltNOTIN:
2960 if (start) TexOutput(_T("NOTIN"));
2961 break;
2962 case ltNOTSUBSET:
2963 if (start) TexOutput(_T("NOTSUBSET"));
2964 break;
2965
2966 // Arrows
2967 case ltLEFTARROW:
2968 if (start) TexOutput(_T("<--"));
2969 break;
2970 case ltLEFTARROW2:
2971 if (start) TexOutput(_T("<=="));
2972 break;
2973 case ltRIGHTARROW:
2974 if (start) TexOutput(_T("-->"));
2975 break;
2976 case ltRIGHTARROW2:
2977 if (start) TexOutput(_T("==>"));
2978 break;
2979 case ltLEFTRIGHTARROW:
2980 if (start) TexOutput(_T("<-->"));
2981 break;
2982 case ltLEFTRIGHTARROW2:
2983 if (start) TexOutput(_T("<==>"));
2984 break;
2985 case ltUPARROW:
2986 if (start) TexOutput(_T("UPARROW"));
2987 break;
2988 case ltUPARROW2:
2989 if (start) TexOutput(_T("UPARROW2"));
2990 break;
2991 case ltDOWNARROW:
2992 if (start) TexOutput(_T("DOWNARROW"));
2993 break;
2994 case ltDOWNARROW2:
2995 if (start) TexOutput(_T("DOWNARROW2"));
2996 break;
2997 // Miscellaneous symbols
2998 case ltALEPH:
2999 if (start) TexOutput(_T("ALEPH"));
3000 break;
3001 case ltWP:
3002 if (start) TexOutput(_T("WP"));
3003 break;
3004 case ltRE:
3005 if (start) TexOutput(_T("RE"));
3006 break;
3007 case ltIM:
3008 if (start) TexOutput(_T("IM"));
3009 break;
3010 case ltEMPTYSET:
3011 if (start) TexOutput(_T("EMPTYSET"));
3012 break;
3013 case ltNABLA:
3014 if (start) TexOutput(_T("NABLA"));
3015 break;
3016 case ltSURD:
3017 if (start) TexOutput(_T("SURD"));
3018 break;
3019 case ltPARTIAL:
3020 if (start) TexOutput(_T("PARTIAL"));
3021 break;
3022 case ltBOT:
3023 if (start) TexOutput(_T("BOT"));
3024 break;
3025 case ltFORALL:
3026 if (start) TexOutput(_T("FORALL"));
3027 break;
3028 case ltEXISTS:
3029 if (start) TexOutput(_T("EXISTS"));
3030 break;
3031 case ltNEG:
3032 if (start) TexOutput(_T("NEG"));
3033 break;
3034 case ltSHARP:
3035 if (start) TexOutput(_T("SHARP"));
3036 break;
3037 case ltANGLE:
3038 if (start) TexOutput(_T("ANGLE"));
3039 break;
3040 case ltTRIANGLE:
3041 if (start) TexOutput(_T("TRIANGLE"));
3042 break;
3043 case ltCLUBSUIT:
3044 if (start) TexOutput(_T("CLUBSUIT"));
3045 break;
3046 case ltDIAMONDSUIT:
3047 if (start) TexOutput(_T("DIAMONDSUIT"));
3048 break;
3049 case ltHEARTSUIT:
3050 if (start) TexOutput(_T("HEARTSUIT"));
3051 break;
3052 case ltSPADESUIT:
3053 if (start) TexOutput(_T("SPADESUIT"));
3054 break;
3055 case ltINFTY:
3056 if (start) TexOutput(_T("INFTY"));
3057 break;
3058 case ltPM:
3059 if (start) TexOutput(_T("PM"));
3060 break;
3061 case ltMP:
3062 if (start) TexOutput(_T("MP"));
3063 break;
3064 case ltTIMES:
3065 if (start) TexOutput(_T("TIMES"));
3066 break;
3067 case ltDIV:
3068 if (start) TexOutput(_T("DIV"));
3069 break;
3070 case ltCDOT:
3071 if (start) TexOutput(_T("CDOT"));
3072 break;
3073 case ltAST:
3074 if (start) TexOutput(_T("AST"));
3075 break;
3076 case ltSTAR:
3077 if (start) TexOutput(_T("STAR"));
3078 break;
3079 case ltCAP:
3080 if (start) TexOutput(_T("CAP"));
3081 break;
3082 case ltCUP:
3083 if (start) TexOutput(_T("CUP"));
3084 break;
3085 case ltVEE:
3086 if (start) TexOutput(_T("VEE"));
3087 break;
3088 case ltWEDGE:
3089 if (start) TexOutput(_T("WEDGE"));
3090 break;
3091 case ltCIRC:
3092 if (start) TexOutput(_T("CIRC"));
3093 break;
3094 case ltBULLET:
3095 if (start) TexOutput(_T("BULLET"));
3096 break;
3097 case ltDIAMOND:
3098 if (start) TexOutput(_T("DIAMOND"));
3099 break;
3100 case ltOSLASH:
3101 if (start) TexOutput(_T("OSLASH"));
3102 break;
3103 case ltBOX:
3104 if (start) TexOutput(_T("BOX"));
3105 break;
3106 case ltDIAMOND2:
3107 if (start) TexOutput(_T("DIAMOND2"));
3108 break;
3109 case ltBIGTRIANGLEDOWN:
3110 if (start) TexOutput(_T("BIGTRIANGLEDOWN"));
3111 break;
3112 case ltOPLUS:
3113 if (start) TexOutput(_T("OPLUS"));
3114 break;
3115 case ltOTIMES:
3116 if (start) TexOutput(_T("OTIMES"));
3117 break;
3118 case ltSS:
3119 if (start) TexOutput(_T("s"));
3120 break;
3121 case ltBACKSLASHRAW:
3122 if (start) TexOutput(_T("\\"));
3123 break;
3124 case ltLBRACERAW:
3125 if (start) TexOutput(_T("{"));
3126 break;
3127 case ltRBRACERAW:
3128 if (start) TexOutput(_T("}"));
3129 break;
3130 case ltSMALLSPACE1:
3131 case ltSMALLSPACE2:
3132 if (start) TexOutput(_T(" "));
3133 break;
3134 default:
3135 break;
3136 }
3137 }
3138
3139 // Called on start/end of argument examination
3140 bool DefaultOnArgument(int macroId, int arg_no, bool start)
3141 {
3142 switch (macroId)
3143 {
3144 case ltREF:
3145 {
3146 if (arg_no == 1 && start)
3147 {
3148 wxChar *refName = GetArgData();
3149 if (refName)
3150 {
3151 TexRef *texRef = FindReference(refName);
3152 if (texRef)
3153 {
3154 // Must strip the 'section' or 'chapter' or 'figure' text
3155 // from a normal 'ref' reference
3156 wxChar buf[150];
3157 wxStrcpy(buf, texRef->sectionNumber);
3158 int len = wxStrlen(buf);
3159 int i = 0;
3160 if (wxStrcmp(buf, _T("??")) != 0)
3161 {
3162 while (i < len)
3163 {
3164 if (buf[i] == ' ')
3165 {
3166 i ++;
3167 break;
3168 }
3169 else i ++;
3170 }
3171 }
3172 TexOutput(texRef->sectionNumber + i, true);
3173 }
3174 else
3175 {
3176 wxString informBuf;
3177 informBuf.Printf(_T("Warning: unresolved reference '%s'"), refName);
3178 OnInform((wxChar *)informBuf.c_str());
3179 }
3180 }
3181 else TexOutput(_T("??"), true);
3182 return false;
3183 }
3184 break;
3185 }
3186 case ltLABEL:
3187 {
3188 return false;
3189 }
3190 case ltAUTHOR:
3191 {
3192 if (start && (arg_no == 1))
3193 DocumentAuthor = GetArgChunk();
3194 return false;
3195 }
3196 case ltDATE:
3197 {
3198 if (start && (arg_no == 1))
3199 DocumentDate = GetArgChunk();
3200 return false;
3201 }
3202 case ltTITLE:
3203 {
3204 if (start && (arg_no == 1))
3205 DocumentTitle = GetArgChunk();
3206 return false;
3207 }
3208 case ltDOCUMENTCLASS:
3209 case ltDOCUMENTSTYLE:
3210 {
3211 if (start && !IsArgOptional())
3212 {
3213 DocumentStyleString = copystring(GetArgData());
3214 if (wxStrncmp(DocumentStyleString, _T("art"), 3) == 0)
3215 DocumentStyle = LATEX_ARTICLE;
3216 else if (wxStrncmp(DocumentStyleString, _T("rep"), 3) == 0)
3217 DocumentStyle = LATEX_REPORT;
3218 else if (wxStrncmp(DocumentStyleString, _T("book"), 4) == 0 ||
3219 wxStrncmp(DocumentStyleString, _T("thesis"), 6) == 0)
3220 DocumentStyle = LATEX_BOOK;
3221 else if (wxStrncmp(DocumentStyleString, _T("letter"), 6) == 0)
3222 DocumentStyle = LATEX_LETTER;
3223 else if (wxStrncmp(DocumentStyleString, _T("slides"), 6) == 0)
3224 DocumentStyle = LATEX_SLIDES;
3225
3226 if (StringMatch(_T("10"), DocumentStyleString))
3227 SetFontSizes(10);
3228 else if (StringMatch(_T("11"), DocumentStyleString))
3229 SetFontSizes(11);
3230 else if (StringMatch(_T("12"), DocumentStyleString))
3231 SetFontSizes(12);
3232
3233 OnMacro(ltHELPFONTSIZE, 1, true);
3234 wxSnprintf(currentArgData, 2000, _T("%d"), normalFont);
3235 haveArgData = true;
3236 OnArgument(ltHELPFONTSIZE, 1, true);
3237 OnArgument(ltHELPFONTSIZE, 1, false);
3238 haveArgData = false;
3239 OnMacro(ltHELPFONTSIZE, 1, false);
3240 }
3241 else if (start && IsArgOptional())
3242 {
3243 MinorDocumentStyleString = copystring(GetArgData());
3244
3245 if (StringMatch(_T("10"), MinorDocumentStyleString))
3246 SetFontSizes(10);
3247 else if (StringMatch(_T("11"), MinorDocumentStyleString))
3248 SetFontSizes(11);
3249 else if (StringMatch(_T("12"), MinorDocumentStyleString))
3250 SetFontSizes(12);
3251 }
3252 return false;
3253 }
3254 case ltBIBLIOGRAPHYSTYLE:
3255 {
3256 if (start && !IsArgOptional())
3257 BibliographyStyleString = copystring(GetArgData());
3258 return false;
3259 }
3260 case ltPAGESTYLE:
3261 {
3262 if (start && !IsArgOptional())
3263 {
3264 if (PageStyle) delete[] PageStyle;
3265 PageStyle = copystring(GetArgData());
3266 }
3267 return false;
3268 }
3269 /*
3270 case ltLHEAD:
3271 {
3272 if (start && !IsArgOptional())
3273 LeftHeader = GetArgChunk();
3274 return false;
3275 break;
3276 }
3277 case ltLFOOT:
3278 {
3279 if (start && !IsArgOptional())
3280 LeftFooter = GetArgChunk();
3281 return false;
3282 break;
3283 }
3284 case ltCHEAD:
3285 {
3286 if (start && !IsArgOptional())
3287 CentreHeader = GetArgChunk();
3288 return false;
3289 break;
3290 }
3291 case ltCFOOT:
3292 {
3293 if (start && !IsArgOptional())
3294 CentreFooter = GetArgChunk();
3295 return false;
3296 break;
3297 }
3298 case ltRHEAD:
3299 {
3300 if (start && !IsArgOptional())
3301 RightHeader = GetArgChunk();
3302 return false;
3303 break;
3304 }
3305 case ltRFOOT:
3306 {
3307 if (start && !IsArgOptional())
3308 RightFooter = GetArgChunk();
3309 return false;
3310 break;
3311 }
3312 */
3313 case ltCITE:
3314 case ltSHORTCITE:
3315 {
3316 if (start && !IsArgOptional())
3317 {
3318 wxChar *citeKeys = GetArgData();
3319 int pos = 0;
3320 wxChar *citeKey = ParseMultifieldString(citeKeys, &pos);
3321 while (citeKey)
3322 {
3323 AddCitation(citeKey);
3324 TexRef *ref = FindReference(citeKey);
3325 if (ref)
3326 {
3327 TexOutput(ref->sectionNumber, true);
3328 if (wxStrcmp(ref->sectionNumber, _T("??")) == 0)
3329 {
3330 wxString informBuf;
3331 informBuf.Printf(_T("Warning: unresolved citation %s."), citeKey);
3332 OnInform((wxChar *)informBuf.c_str());
3333 }
3334 }
3335 citeKey = ParseMultifieldString(citeKeys, &pos);
3336 if (citeKey)
3337 {
3338 TexOutput(_T(", "), true);
3339 }
3340 }
3341 return false;
3342 }
3343 break;
3344 }
3345 case ltNOCITE:
3346 {
3347 if (start && !IsArgOptional())
3348 {
3349 wxChar *citeKey = GetArgData();
3350 AddCitation(citeKey);
3351 return false;
3352 }
3353 break;
3354 }
3355 case ltHELPFONTSIZE:
3356 {
3357 if (start)
3358 {
3359 wxChar *data = GetArgData();
3360 if (wxStrcmp(data, _T("10")) == 0)
3361 SetFontSizes(10);
3362 else if (wxStrcmp(data, _T("11")) == 0)
3363 SetFontSizes(11);
3364 else if (wxStrcmp(data, _T("12")) == 0)
3365 SetFontSizes(12);
3366 return false;
3367 }
3368 break;
3369 }
3370 case ltPAGEREF:
3371 {
3372 if (start)
3373 {
3374 TexOutput(_T(" ??"), true);
3375 return false;
3376 }
3377 break;
3378 }
3379 case ltPARSKIP:
3380 {
3381 if (start && arg_no == 1)
3382 {
3383 wxChar *data = GetArgData();
3384 ParSkip = ParseUnitArgument(data);
3385 return false;
3386 }
3387 break;
3388 }
3389 case ltPARINDENT:
3390 {
3391 if (start && arg_no == 1)
3392 {
3393 wxChar *data = GetArgData();
3394 ParIndent = ParseUnitArgument(data);
3395 return false;
3396 }
3397 break;
3398 }
3399 case ltSL:
3400 {
3401 return OnArgument(ltIT, arg_no, start);
3402 }
3403 case ltSPECIALDOUBLEDOLLAR:
3404 {
3405 return OnArgument(ltCENTER, arg_no, start);
3406 }
3407 case ltPARAGRAPH:
3408 case ltPARAGRAPHSTAR:
3409 case ltSUBPARAGRAPH:
3410 case ltSUBPARAGRAPHSTAR:
3411 {
3412 return OnArgument(ltSUBSUBSECTION, arg_no, start);
3413 }
3414 case ltTYPEOUT:
3415 {
3416 if (start)
3417 OnInform(GetArgData());
3418 break;
3419 }
3420 case ltFOOTNOTE:
3421 {
3422 if (start)
3423 TexOutput(_T(" ("), true);
3424 else
3425 TexOutput(_T(")"), true);
3426 break;
3427 }
3428 case ltBIBLIOGRAPHY:
3429 {
3430 if (start)
3431 {
3432 int ch;
3433 wxChar smallBuf[2];
3434 smallBuf[1] = 0;
3435 FILE *fd = wxFopen(TexBibName, _T("r"));
3436 if (fd)
3437 {
3438 ch = getc(fd);
3439 smallBuf[0] = ch;
3440 while (ch != EOF)
3441 {
3442 TexOutput(smallBuf);
3443 ch = getc(fd);
3444 smallBuf[0] = ch;
3445 }
3446 fclose(fd);
3447 }
3448 else
3449 {
3450 OnInform(_T("Run Tex2RTF again to include bibliography."));
3451 }
3452
3453 // Read in the .bib file, resolve all known references, write out the RTF.
3454 wxChar *allFiles = GetArgData();
3455 int pos = 0;
3456 wxChar *bibFile = ParseMultifieldString(allFiles, &pos);
3457 while (bibFile)
3458 {
3459 wxChar fileBuf[300];
3460 wxStrcpy(fileBuf, bibFile);
3461 wxString actualFile = TexPathList.FindValidPath(fileBuf);
3462 if (actualFile == _T(""))
3463 {
3464 wxStrcat(fileBuf, _T(".bib"));
3465 actualFile = TexPathList.FindValidPath(fileBuf);
3466 }
3467 if (actualFile != _T(""))
3468 {
3469 if (!ReadBib((wxChar*) (const wxChar*) actualFile))
3470 {
3471 wxString errBuf;
3472 errBuf.Printf(_T(".bib file %s not found or malformed"), (const wxChar*) actualFile);
3473 OnError((wxChar *)errBuf.c_str());
3474 }
3475 }
3476 else
3477 {
3478 wxString errBuf;
3479 errBuf.Printf(_T(".bib file %s not found"), fileBuf);
3480 OnError((wxChar *)errBuf.c_str());
3481 }
3482 bibFile = ParseMultifieldString(allFiles, &pos);
3483 }
3484
3485 ResolveBibReferences();
3486
3487 // Write it a new bib section in the appropriate format.
3488 FILE *save1 = CurrentOutput1;
3489 FILE *save2 = CurrentOutput2;
3490 FILE *Biblio = wxFopen(TexTmpBibName, _T("w"));
3491 SetCurrentOutput(Biblio);
3492 OutputBib();
3493 fclose(Biblio);
3494 if (wxFileExists(TexTmpBibName))
3495 {
3496 if (wxFileExists(TexBibName)) wxRemoveFile(TexBibName);
3497 wxRenameFile(TexTmpBibName, TexBibName);
3498 }
3499 SetCurrentOutputs(save1, save2);
3500 return false;
3501 }
3502 break;
3503 }
3504 case ltMULTICOLUMN:
3505 return (start && (arg_no == 3));
3506 case ltSCSHAPE:
3507 case ltTEXTSC:
3508 case ltSC:
3509 {
3510 if (start && (arg_no == 1))
3511 {
3512 wxChar *s = GetArgData();
3513 if (s)
3514 {
3515 wxChar *s1 = copystring(s);
3516 int i;
3517 for (i = 0; i < (int)wxStrlen(s); i++)
3518 s1[i] = wxToupper(s[i]);
3519 TexOutput(s1);
3520 delete[] s1;
3521 return false;
3522 }
3523 else return true;
3524
3525 }
3526 return true;
3527 }
3528 case ltLOWERCASE:
3529 {
3530 if (start && (arg_no == 1))
3531 {
3532 wxChar *s = GetArgData();
3533 if (s)
3534 {
3535 wxChar *s1 = copystring(s);
3536 int i;
3537 for (i = 0; i < (int)wxStrlen(s); i++)
3538 s1[i] = wxTolower(s[i]);
3539 TexOutput(s1);
3540 delete[] s1;
3541 return false;
3542 }
3543 else return true;
3544
3545 }
3546 return true;
3547 }
3548 case ltUPPERCASE:
3549 {
3550 if (start && (arg_no == 1))
3551 {
3552 wxChar *s = GetArgData();
3553 if (s)
3554 {
3555 wxChar *s1 = copystring(s);
3556 int i;
3557 for (i = 0; i < (int)wxStrlen(s); i++)
3558 s1[i] = wxToupper(s[i]);
3559 TexOutput(s1);
3560 delete[] s1;
3561 return false;
3562 }
3563 else return true;
3564
3565 }
3566 return true;
3567 }
3568 case ltPOPREF: // Ignore second argument by default
3569 return (start && (arg_no == 1));
3570 case ltTWOCOLUMN:
3571 return true;
3572 case ltXLPIGNORE:
3573 return ((convertMode == TEX_XLP) ? false : true);
3574 case ltXLPONLY:
3575 return ((convertMode != TEX_XLP) ? false : true);
3576 case ltHTMLIGNORE:
3577 return ((convertMode == TEX_HTML) ? false : true);
3578 case ltHTMLONLY:
3579 return ((convertMode != TEX_HTML) ? false : true);
3580 case ltRTFIGNORE:
3581 return (((convertMode == TEX_RTF) && !winHelp) ? false : true);
3582 case ltRTFONLY:
3583 return (!((convertMode == TEX_RTF) && !winHelp) ? false : true);
3584 case ltWINHELPIGNORE:
3585 return (winHelp ? false : true);
3586 case ltWINHELPONLY:
3587 return (!winHelp ? false : true);
3588 case ltLATEXIGNORE:
3589 return true;
3590 case ltLATEXONLY:
3591 return false;
3592 case ltCLINE:
3593 case ltARABIC:
3594 case ltALPH1:
3595 case ltALPH2:
3596 case ltROMAN:
3597 case ltROMAN2:
3598 case ltSETCOUNTER:
3599 case ltADDTOCOUNTER:
3600 case ltADDCONTENTSLINE:
3601 case ltNEWCOUNTER:
3602 case ltTEXTWIDTH:
3603 case ltTEXTHEIGHT:
3604 case ltBASELINESKIP:
3605 case ltVSPACESTAR:
3606 case ltHSPACESTAR:
3607 case ltVSPACE:
3608 case ltHSPACE:
3609 case ltVSKIPSTAR:
3610 case ltHSKIPSTAR:
3611 case ltVSKIP:
3612 case ltHSKIP:
3613 case ltPAGENUMBERING:
3614 case ltTHEPAGE:
3615 case ltTHECHAPTER:
3616 case ltTHESECTION:
3617 case ltITEMSEP:
3618 case ltFANCYPLAIN:
3619 case ltCHEAD:
3620 case ltRHEAD:
3621 case ltLHEAD:
3622 case ltCFOOT:
3623 case ltRFOOT:
3624 case ltLFOOT:
3625 case ltTHISPAGESTYLE:
3626 case ltMARKRIGHT:
3627 case ltMARKBOTH:
3628 case ltEVENSIDEMARGIN:
3629 case ltODDSIDEMARGIN:
3630 case ltMARGINPAR:
3631 case ltMARGINPARWIDTH:
3632 case ltMARGINPARSEP:
3633 case ltMARGINPAREVEN:
3634 case ltMARGINPARODD:
3635 case ltTWOCOLWIDTHA:
3636 case ltTWOCOLWIDTHB:
3637 case ltTWOCOLSPACING:
3638 case ltSETHEADER:
3639 case ltSETFOOTER:
3640 case ltINDEX:
3641 case ltITEM:
3642 case ltBCOL:
3643 case ltFCOL:
3644 case ltSETHOTSPOTCOLOUR:
3645 case ltSETHOTSPOTCOLOR:
3646 case ltSETHOTSPOTUNDERLINE:
3647 case ltSETTRANSPARENCY:
3648 case ltUSEPACKAGE:
3649 case ltBACKGROUND:
3650 case ltBACKGROUNDCOLOUR:
3651 case ltBACKGROUNDIMAGE:
3652 case ltLINKCOLOUR:
3653 case ltFOLLOWEDLINKCOLOUR:
3654 case ltTEXTCOLOUR:
3655 case ltIMAGE:
3656 case ltIMAGEMAP:
3657 case ltIMAGEL:
3658 case ltIMAGER:
3659 case ltPOPREFONLY:
3660 case ltINSERTATLEVEL:
3661 return false;
3662 case ltTABULAR:
3663 case ltSUPERTABULAR:
3664 case ltINDENTED:
3665 case ltSIZEDBOX:
3666 case ltSIZEDBOXD:
3667 return (arg_no == 2);
3668 case ltDEFINECOLOUR:
3669 case ltDEFINECOLOR:
3670 {
3671 static int redVal = 0;
3672 static int greenVal = 0;
3673 static int blueVal = 0;
3674 static wxChar *colourName = NULL;
3675 if (start)
3676 {
3677 switch (arg_no)
3678 {
3679 case 1:
3680 {
3681 if (colourName) delete[] colourName;
3682 colourName = copystring(GetArgData());
3683 break;
3684 }
3685 case 2:
3686 {
3687 redVal = wxAtoi(GetArgData());
3688 break;
3689 }
3690 case 3:
3691 {
3692 greenVal = wxAtoi(GetArgData());
3693 break;
3694 }
3695 case 4:
3696 {
3697 blueVal = wxAtoi(GetArgData());
3698 AddColour(colourName, redVal, greenVal, blueVal);
3699 break;
3700 }
3701 default:
3702 break;
3703 }
3704 }
3705 return false;
3706 }
3707 case ltFIGURE:
3708 case ltFIGURESTAR:
3709 case ltNORMALBOX:
3710 case ltNORMALBOXD:
3711 default:
3712 return (!IsArgOptional());
3713 }
3714 return true;
3715 }
3716