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