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