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