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