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