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