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