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