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