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