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