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