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