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