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