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