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