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