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