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