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