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