1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Utilities for Latex conversion.
4 // Author: Julian Smart
5 // Modified by: Wlodzimiez ABX Skiba 2003/2004 Unicode support
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
14 #pragma implementation
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
32 #if !WXWIN_COMPATIBILITY_2_4
33 static inline wxChar
* copystring(const wxChar
* s
)
34 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
38 * Variables accessible from clients
42 TexChunk
* DocumentTitle
= NULL
;
43 TexChunk
* DocumentAuthor
= NULL
;
44 TexChunk
* DocumentDate
= NULL
;
46 // Header/footers/pagestyle
47 TexChunk
* LeftHeaderEven
= NULL
;
48 TexChunk
* LeftFooterEven
= NULL
;
49 TexChunk
* CentreHeaderEven
= NULL
;
50 TexChunk
* CentreFooterEven
= NULL
;
51 TexChunk
* RightHeaderEven
= NULL
;
52 TexChunk
* RightFooterEven
= NULL
;
53 TexChunk
* LeftHeaderOdd
= NULL
;
54 TexChunk
* LeftFooterOdd
= NULL
;
55 TexChunk
* CentreHeaderOdd
= NULL
;
56 TexChunk
* CentreFooterOdd
= NULL
;
57 TexChunk
* RightHeaderOdd
= NULL
;
58 TexChunk
* RightFooterOdd
= NULL
;
59 wxChar
* PageStyle
= copystring(_T("plain"));
61 int DocumentStyle
= LATEX_REPORT
;
62 int MinorDocumentStyle
= 0;
63 wxPathList TexPathList
;
64 wxChar
* BibliographyStyleString
= copystring(_T("plain"));
65 wxChar
* DocumentStyleString
= copystring(_T("report"));
66 wxChar
* MinorDocumentStyleString
= NULL
;
80 // All of these tokens MUST be found on a line by themselves (no other
81 // text) and must start at the first character of the line, or tex2rtf
82 // will fail to process them correctly (a limitation of tex2rtf, not TeX)
83 static const wxString syntaxTokens
[] =
84 { _T("\\begin{verbatim}"),
85 _T("\\begin{toocomplex}"),
86 _T("\\end{verbatim}"),
87 _T("\\end{toocomplex}"),
89 _T("\\begin{comment}"),
91 _T("\\verbatiminput"),
101 * USER-ADJUSTABLE SETTINGS
105 // Section font sizes
106 int chapterFont
= 12; // LARGEFont3;
107 int sectionFont
= 12; // LargeFont2;
108 int subsectionFont
= 12; // largeFont1;
109 int titleFont
= LARGEFont3
;
110 int authorFont
= LargeFont2
;
111 int mirrorMargins
= true;
112 bool winHelp
= false; // Output in Windows Help format if true, linear otherwise
113 bool isInteractive
= false;
114 bool runTwice
= false;
115 int convertMode
= TEX_RTF
;
116 bool checkCurleyBraces
= false;
117 bool checkSyntax
= false;
118 bool headerRule
= false;
119 bool footerRule
= false;
120 bool compatibilityMode
= false; // If true, maximum Latex compatibility
121 // (Quality of RTF generation deteriorate)
122 bool generateHPJ
; // Generate WinHelp Help Project file
123 wxChar
*winHelpTitle
= NULL
; // Windows Help title
124 int defaultTableColumnWidth
= 2000;
126 int labelIndentTab
= 18; // From left indent to item label (points)
127 int itemIndentTab
= 40; // From left indent to item (points)
129 bool useUpButton
= true;
130 int htmlBrowseButtons
= HTML_BUTTONS_TEXT
;
132 bool truncateFilenames
= false; // Truncate for DOS
133 int winHelpVersion
= 3; // WinHelp Version (3 for Windows 3.1, 4 for Win95)
134 bool winHelpContents
= false; // Generate .cnt file for WinHelp 4
135 bool htmlIndex
= false; // Generate .htx file for HTML
136 bool htmlFrameContents
= false; // Use frames for HTML contents page
137 wxChar
*htmlStylesheet
= NULL
; // Use this CSS stylesheet for HTML pages
138 bool useHeadingStyles
= true; // Insert \s1, s2 etc.
139 bool useWord
= true; // Insert proper Word table of contents, etc etc
140 int contentsDepth
= 4; // Depth of Word table of contents
141 bool indexSubsections
= true; // Index subsections in linear RTF
142 // Linear RTF method of including bitmaps. Can be "includepicture", "hex"
143 wxChar
*bitmapMethod
= copystring(_T("includepicture"));
144 bool upperCaseNames
= false;
145 // HTML background and text colours
146 wxChar
*backgroundImageString
= NULL
;
147 wxChar
*backgroundColourString
= copystring(_T("255;255;255"));
148 wxChar
*textColourString
= NULL
;
149 wxChar
*linkColourString
= NULL
;
150 wxChar
*followedLinkColourString
= NULL
;
151 bool combineSubSections
= false;
152 bool htmlWorkshopFiles
= false;
153 bool ignoreBadRefs
= false;
154 wxChar
*htmlFaceName
= NULL
;
156 extern int passNumber
;
158 extern wxHashTable TexReferences
;
161 * International support
164 // Names to help with internationalisation
165 wxChar
*ContentsNameString
= copystring(_T("Contents"));
166 wxChar
*AbstractNameString
= copystring(_T("Abstract"));
167 wxChar
*GlossaryNameString
= copystring(_T("Glossary"));
168 wxChar
*ReferencesNameString
= copystring(_T("References"));
169 wxChar
*FiguresNameString
= copystring(_T("List of Figures"));
170 wxChar
*TablesNameString
= copystring(_T("List of Tables"));
171 wxChar
*FigureNameString
= copystring(_T("Figure"));
172 wxChar
*TableNameString
= copystring(_T("Table"));
173 wxChar
*IndexNameString
= copystring(_T("Index"));
174 wxChar
*ChapterNameString
= copystring(_T("chapter"));
175 wxChar
*SectionNameString
= copystring(_T("section"));
176 wxChar
*SubsectionNameString
= copystring(_T("subsection"));
177 wxChar
*SubsubsectionNameString
= copystring(_T("subsubsection"));
178 wxChar
*UpNameString
= copystring(_T("Up"));
187 int subsectionNo
= 0;
188 int subsubsectionNo
= 0;
197 FILE *CurrentOutput1
= NULL
;
198 FILE *CurrentOutput2
= NULL
;
200 unsigned long LineNumbers
[15];
201 wxChar
*FileNames
[15];
202 int CurrentInputIndex
= 0;
204 wxChar
*TexFileRoot
= NULL
;
205 wxChar
*TexBibName
= NULL
; // Bibliography output file name
206 wxChar
*TexTmpBibName
= NULL
; // Temporary bibliography output file name
207 bool isSync
= false; // If true, should not yield to other processes.
208 bool stopRunning
= false; // If true, should abort.
210 static int currentColumn
= 0;
211 wxChar
*currentArgData
= NULL
;
212 bool haveArgData
= false; // If true, we're simulating the data.
213 TexChunk
*currentArgument
= NULL
;
214 TexChunk
*nextChunk
= NULL
;
215 bool isArgOptional
= false;
218 TexChunk
*TopLevel
= NULL
;
219 // wxList MacroDefs(wxKEY_STRING);
220 wxHashTable
MacroDefs(wxKEY_STRING
);
221 wxStringList IgnorableInputFiles
; // Ignorable \input files, e.g. psbox.tex
222 wxChar
*BigBuffer
= NULL
; // For reading in large chunks of text
223 TexMacroDef
*SoloBlockDef
= NULL
;
224 TexMacroDef
*VerbatimMacroDef
= NULL
;
226 #define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
229 TexRef::TexRef(const wxChar
*label
, const wxChar
*file
,
230 const wxChar
*section
, const wxChar
*sectionN
)
232 refLabel
= copystring(label
);
233 refFile
= file
? copystring(file
) : (wxChar
*) NULL
;
234 sectionNumber
= section
? copystring(section
) : copystring(_T("??"));
235 sectionName
= sectionN
? copystring(sectionN
) : copystring(_T("??"));
238 TexRef::~TexRef(void)
240 delete [] refLabel
; refLabel
= NULL
;
241 delete [] refFile
; refFile
= NULL
;
242 delete [] sectionNumber
; sectionNumber
= NULL
;
243 delete [] sectionName
; sectionName
= NULL
;
247 CustomMacro::~CustomMacro()
255 void TexOutput(const wxChar
*s
, bool ordinaryText
)
257 int len
= wxStrlen(s
);
259 // Update current column, but only if we're guaranteed to
260 // be ordinary text (not mark-up stuff)
263 for (i
= 0; i
< len
; i
++)
265 if (s
[i
] == 13 || s
[i
] == 10)
272 wxFprintf(CurrentOutput1
, _T("%s"), s
);
274 wxFprintf(CurrentOutput2
, _T("%s"), s
);
278 * Try to find a Latex macro, in one of the following forms:
279 * (1) \begin{} ... \end{}
280 * (2) \macroname{arg1}...{argn}
284 void ForbidWarning(TexMacroDef
*def
)
287 switch (def
->forbidden
)
291 informBuf
.Printf(_T("Warning: it is recommended that command %s is not used."), def
->name
);
292 OnInform((const wxChar
*)informBuf
.c_str());
295 case FORBID_ABSOLUTELY
:
297 informBuf
.Printf(_T("Error: command %s cannot be used and will lead to errors."), def
->name
);
298 OnInform((const wxChar
*)informBuf
.c_str());
306 TexMacroDef
*MatchMacro(wxChar
*buffer
, int *pos
, wxChar
**env
, bool *parseToBrace
)
308 *parseToBrace
= true;
310 TexMacroDef
*def
= NULL
;
313 // First, try to find begin{thing}
314 if (wxStrncmp(buffer
+i
, _T("begin{"), 6) == 0)
319 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
321 macroBuf
[j
-i
] = buffer
[j
];
325 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
329 *pos
= j
+ 1; // BUGBUG Should this be + 1???
337 // Failed, so try to find macro from definition list
340 // First try getting a one-character macro, but ONLY
341 // if these TWO characters are not both alphabetical (could
342 // be a longer macro)
343 if (!(isalpha(buffer
[i
]) && isalpha(buffer
[i
+1])))
345 macroBuf
[0] = buffer
[i
];
348 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
354 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
356 macroBuf
[j
-i
] = buffer
[j
];
360 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
367 // We want to check whether this is a space-consuming macro
369 // No brace, e.g. \input thing.tex instead of \input{thing};
370 // or a numeric argument, such as \parindent0pt
371 if ((def
->no_args
> 0) && ((buffer
[i
] == 32) || (buffer
[i
] == '=') || (isdigit(buffer
[i
]))))
373 if ((buffer
[i
] == 32) || (buffer
[i
] == '='))
376 *parseToBrace
= false;
385 void EatWhiteSpace(wxChar
*buffer
, int *pos
)
387 int len
= wxStrlen(buffer
);
389 bool keepGoing
= true;
390 bool moreLines
= true;
391 while ((j
< len
) && keepGoing
&&
392 (buffer
[j
] == 10 || buffer
[j
] == 13 || buffer
[j
] == ' ' || buffer
[j
] == 9))
399 moreLines
= read_a_line(buffer
);
400 len
= wxStrlen(buffer
);
410 bool FindEndEnvironment(wxChar
*buffer
, int *pos
, wxChar
*env
)
414 // Try to find end{thing}
415 if ((wxStrncmp(buffer
+i
, _T("end{"), 4) == 0) &&
416 (wxStrncmp(buffer
+i
+4, env
, wxStrlen(env
)) == 0))
418 *pos
= i
+ 5 + wxStrlen(env
);
424 bool readingVerbatim
= false;
425 bool readInVerbatim
= false; // Within a verbatim, but not nec. verbatiminput
427 // Switched this off because e.g. \verb${$ causes it to fail. There is no
428 // detection of \verb yet.
429 // #define CHECK_BRACES 1
431 unsigned long leftCurley
= 0;
432 unsigned long rightCurley
= 0;
433 static wxString currentFileName
= _T("");
435 bool read_a_line(wxChar
*buf
)
437 if (CurrentInputIndex
< 0)
444 unsigned long bufIndex
= 0;
448 while (ch
!= EOF
&& ch
!= 10)
450 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
453 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
454 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(), MAX_LINE_BUFFER_SIZE
);
455 OnError((wxChar
*)errBuf
.c_str());
459 if (((bufIndex
== 14) && (wxStrncmp(buf
, _T("\\end{verbatim}"), 14) == 0)) ||
460 ((bufIndex
== 16) && (wxStrncmp(buf
, _T("\\end{toocomplex}"), 16) == 0)))
461 readInVerbatim
= false;
464 ch
= getc(Inputs
[CurrentInputIndex
]);
466 if (checkCurleyBraces
)
468 if (ch
== '{' && !readInVerbatim
&& lastChar
!= _T('\\'))
470 if (ch
== '}' && !readInVerbatim
&& lastChar
!= _T('\\'))
473 if (rightCurley
> leftCurley
)
476 errBuf
.Printf(_T("An extra right Curley brace ('}') was detected at line %lu inside file %s"), LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
477 OnError((wxChar
*)errBuf
.c_str());
479 // Reduce the count of right Curley braces, so the mismatched count
480 // isn't reported on every line that has a '}' after the first mismatch
488 // Check for 2 consecutive newlines and replace with \par
489 if (ch
== 10 && !readInVerbatim
)
491 int ch1
= getc(Inputs
[CurrentInputIndex
]);
492 if ((ch1
== 10) || (ch1
== 13))
494 // Eliminate newline (10) following DOS linefeed
496 getc(Inputs
[CurrentInputIndex
]);
498 IncrementLineNumber();
499 // wxStrcat(buf, "\\par\n");
501 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
504 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
505 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
506 OnError((wxChar
*)errBuf
.c_str());
509 wxStrcat(buf
, _T("\\par"));
515 ungetc(ch1
, Inputs
[CurrentInputIndex
]);
516 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
519 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
520 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
521 OnError((wxChar
*)errBuf
.c_str());
532 // Convert embedded characters to RTF equivalents
541 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
544 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
545 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
546 OnError((wxChar
*)errBuf
.c_str());
549 buf
[bufIndex
++]='\\';
554 case 0xf6:buf
[bufIndex
++]='o';break; // ö
555 case 0xe4:buf
[bufIndex
++]='a';break; // ä
556 case 0xfc:buf
[bufIndex
++]='u';break; // ü
557 case 0xd6:buf
[bufIndex
++]='O';break; // Ö
558 case 0xc4:buf
[bufIndex
++]='A';break; // Ä
559 case 0xdc:buf
[bufIndex
++]='U';break; // Ü
564 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
567 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
568 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
569 OnError((wxChar
*)errBuf
.c_str());
572 buf
[bufIndex
++]='\\';
575 buf
[bufIndex
++]='\\';
579 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
582 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
583 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
584 OnError((wxChar
*)errBuf
.c_str());
587 // If the current character read in is a '_', we need to check
588 // whether there should be a '\' before it or not
591 buf
[bufIndex
++] = ch
;
599 // There should NOT be a '\' before the '_'
600 if ((bufIndex
> 0 && (buf
[bufIndex
-1] == '\\')) && (buf
[0] != '%'))
603 // errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that should NOT have a '\\' before it."),
604 // LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
605 // OnError((wxChar *)errBuf.c_str());
610 // There should be a '\' before the '_'
614 errBuf
.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
615 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
616 OnError((wxChar
*)errBuf
.c_str());
618 else if ((buf
[bufIndex
-1] != '\\') && (buf
[0] != '%') && // If it is a comment line, then no warnings
619 (wxStrncmp(buf
, _T("\\input"), 6))) // do not report filenames that have underscores in them
622 errBuf
.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
623 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
624 OnError((wxChar
*)errBuf
.c_str());
628 buf
[bufIndex
++] = ch
;
636 fclose(Inputs
[CurrentInputIndex
]);
637 Inputs
[CurrentInputIndex
] = NULL
;
638 if (CurrentInputIndex
> 0)
639 ch
= ' '; // No real end of file
640 CurrentInputIndex
--;
642 if (checkCurleyBraces
)
644 if (leftCurley
!= rightCurley
)
647 errBuf
.Printf(_T("Curley braces do not match inside file %s\n%lu opens, %lu closes"),
648 (const wxChar
*) currentFileName
.c_str(),leftCurley
,rightCurley
);
649 OnError((wxChar
*)errBuf
.c_str());
657 readingVerbatim
= false;
658 readInVerbatim
= false;
659 wxStrcat(buf
, _T("\\end{verbatim}\n"));
664 IncrementLineNumber();
668 // Strip out comment environment
669 if (wxStrncmp(buf
, _T("\\begin{comment}"), 15) == 0)
671 while (wxStrncmp(buf
, _T("\\end{comment}"), 13) != 0)
673 return read_a_line(buf
);
675 // Read a verbatim input file as if it were a verbatim environment
676 else if (wxStrncmp(buf
, _T("\\verbatiminput"), 14) == 0)
679 wxChar
*fileName
= buf
+ wordLen
+ 1;
681 int j
= bufIndex
- 1;
684 // thing}\par -- eliminate the \par!
685 if (wxStrncmp((buf
+ wxStrlen(buf
)-5), _T("\\par"), 4) == 0)
692 buf
[j
-1] = 0; // Ignore final brace
694 wxString actualFile
= TexPathList
.FindValidPath(fileName
);
695 currentFileName
= actualFile
;
696 if (actualFile
== _T(""))
699 errBuf
.Printf(_T("Could not find file: %s"),fileName
);
700 OnError((wxChar
*)errBuf
.c_str());
705 informStr
.Printf(_T("Processing: %s"),actualFile
.c_str());
706 OnInform((wxChar
*)informStr
.c_str());
707 CurrentInputIndex
++;
709 Inputs
[CurrentInputIndex
] = wxFopen(actualFile
, _T("r"));
710 LineNumbers
[CurrentInputIndex
] = 1;
711 if (FileNames
[CurrentInputIndex
])
712 delete[] FileNames
[CurrentInputIndex
];
713 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
715 if (!Inputs
[CurrentInputIndex
])
717 CurrentInputIndex
--;
718 OnError(_T("Could not open verbatiminput file."));
722 readingVerbatim
= true;
723 readInVerbatim
= true;
724 wxStrcpy(buf
, _T("\\begin{verbatim}\n"));
730 else if (wxStrncmp(buf
, _T("\\input"), 6) == 0 || wxStrncmp(buf
, _T("\\helpinput"), 10) == 0 ||
731 wxStrncmp(buf
, _T("\\include"), 8) == 0)
734 if (wxStrncmp(buf
, _T("\\input"), 6) == 0)
737 if (wxStrncmp(buf
, _T("\\include"), 8) == 0)
742 wxChar
*fileName
= buf
+ wordLen
+ 1;
744 int j
= bufIndex
- 1;
747 // \input{thing}\par -- eliminate the \par!
748 // if (wxStrncmp((buf + wxStrlen(buf)-5), "\\par", 4) == 0)
749 if (wxStrncmp((buf
+ wxStrlen(buf
)-4), _T("\\par"), 4) == 0) // Bug fix 8/2/95 Ulrich Leodolter
756 if (buf
[j
-1] == _T('}'))
757 buf
[j
-1] = 0; // Ignore final brace
759 // Remove backslashes from name
760 wxString
fileNameStr(fileName
);
761 fileNameStr
.Replace(_T("\\"), _T(""));
763 // Ignore some types of input files (e.g. macro definition files)
764 wxChar
*fileOnly
= wxFileNameFromPath((wxChar
*) (const wxChar
*) fileNameStr
);
765 currentFileName
= fileOnly
;
766 if (IgnorableInputFiles
.Member(fileOnly
))
767 return read_a_line(buf
);
769 wxString actualFile
= TexPathList
.FindValidPath(fileNameStr
);
770 if (actualFile
== _T(""))
773 wxSnprintf(buf2
, sizeof(buf2
), _T("%s.tex"), fileNameStr
.c_str());
774 actualFile
= TexPathList
.FindValidPath(buf2
);
776 currentFileName
= actualFile
;
778 if (actualFile
== _T(""))
781 errBuf
.Printf(_T("Could not find file: %s"),fileName
);
782 OnError((wxChar
*)errBuf
.c_str());
786 // Ensure that if this file includes another,
787 // then we look in the same directory as this one.
788 TexPathList
.EnsureFileAccessible(actualFile
);
791 informStr
.Printf(_T("Processing: %s"),actualFile
.c_str());
792 OnInform((wxChar
*)informStr
.c_str());
793 CurrentInputIndex
++;
795 Inputs
[CurrentInputIndex
] = wxFopen(actualFile
, _T("r"));
796 LineNumbers
[CurrentInputIndex
] = 1;
797 if (FileNames
[CurrentInputIndex
])
798 delete[] FileNames
[CurrentInputIndex
];
799 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
801 if (!Inputs
[CurrentInputIndex
])
804 errBuf
.Printf(_T("Could not open include file %s"), (const wxChar
*) actualFile
);
805 CurrentInputIndex
--;
806 OnError((wxChar
*)errBuf
.c_str());
809 bool succ
= read_a_line(buf
);
815 wxString bufStr
= buf
;
816 for (int index
=0; syntaxTokens
[index
] != wxEmptyString
; index
++)
818 size_t pos
= bufStr
.find(syntaxTokens
[index
]);
819 if (pos
!= wxString::npos
&& pos
!= 0)
821 size_t commentStart
= bufStr
.find(_T("%"));
822 if (commentStart
== wxString::npos
|| commentStart
> pos
)
825 if (syntaxTokens
[index
] == _T("\\verb"))
827 errBuf
.Printf(_T("'%s$....$' was detected at line %lu inside file %s. Please replace this form with \\tt{....}"),
828 syntaxTokens
[index
].c_str(),
829 LineNumbers
[CurrentInputIndex
],
830 currentFileName
.c_str());
834 errBuf
.Printf(_T("'%s' was detected at line %lu inside file %s that is not the only text on the line, starting at column one."),
835 syntaxTokens
[index
].c_str(),
836 LineNumbers
[CurrentInputIndex
],
837 currentFileName
.c_str());
839 OnError((wxChar
*)errBuf
.c_str());
845 if (wxStrncmp(buf
, _T("\\begin{verbatim}"), 16) == 0 ||
846 wxStrncmp(buf
, _T("\\begin{toocomplex}"), 18) == 0)
847 readInVerbatim
= true;
848 else if (wxStrncmp(buf
, _T("\\end{verbatim}"), 14) == 0 ||
849 wxStrncmp(buf
, _T("\\end{toocomplex}"), 16) == 0)
850 readInVerbatim
= false;
852 if (checkCurleyBraces
)
854 if (ch
== EOF
&& leftCurley
!= rightCurley
)
857 errBuf
.Printf(_T("Curley braces do not match inside file %s\n%lu opens, %lu closes"),
858 (const wxChar
*) currentFileName
.c_str(),leftCurley
,rightCurley
);
859 OnError((wxChar
*)errBuf
.c_str());
871 bool ParseNewCommand(wxChar
*buffer
, int *pos
)
873 if ((wxStrncmp((buffer
+(*pos
)), _T("newcommand"), 10) == 0) ||
874 (wxStrncmp((buffer
+(*pos
)), _T("renewcommand"), 12) == 0))
876 if (wxStrncmp((buffer
+(*pos
)), _T("newcommand"), 10) == 0)
881 wxChar commandName
[100];
882 wxChar commandValue
[1000];
885 while (buffer
[*pos
] != _T('}') && (buffer
[*pos
] != 0))
887 commandName
[i
] = buffer
[*pos
];
894 if (buffer
[*pos
] == _T('['))
897 noArgs
= (int)(buffer
[*pos
]) - 48;
898 *pos
+= 2; // read past argument and '['
904 char ch
= buffer
[*pos
];
907 else if (ch
== _T('}'))
915 end
= !read_a_line(buffer
);
920 commandValue
[i
] = ch
;
926 CustomMacro
*macro
= new CustomMacro(commandName
, noArgs
, NULL
);
927 if (wxStrlen(commandValue
) > 0)
928 macro
->macroBody
= copystring(commandValue
);
929 if (!CustomMacroList
.Find(commandName
))
931 CustomMacroList
.Append(commandName
, macro
);
932 AddMacroDef(ltCUSTOM_MACRO
, commandName
, noArgs
);
939 void MacroError(wxChar
*buffer
)
942 wxChar macroBuf
[200];
946 while (((ch
= buffer
[i
-1]) != '\n') && (ch
!= 0))
955 errBuf
.Printf(_T("Could not find macro: %s at line %d, file %s"),
956 macroBuf
, (int)(LineNumbers
[CurrentInputIndex
]-1), FileNames
[CurrentInputIndex
]);
957 OnError((wxChar
*)errBuf
.c_str());
959 if (wxStrcmp(macroBuf
,_T("\\end{document}")) == 0)
961 OnInform( _T("Halted build due to unrecoverable error.") );
968 * 'environment' specifies the name of the macro IFF if we're looking for the end
969 * of an environment, e.g. \end{itemize}. Otherwise it's NULL.
970 * 'parseToBrace' is true if the argument should extend to the next right brace,
971 * e.g. in {\bf an argument} as opposed to \vskip 30pt
974 int ParseArg(TexChunk
*thisArg
, wxList
& children
, wxChar
*buffer
, int pos
, wxChar
*environment
, bool parseToBrace
, TexChunk
*customMacroArgs
)
977 if (stopRunning
) return pos
;
986 // Consume leading brace or square bracket, but ONLY if not following
987 // a space, because this could be e.g. {\large {\bf thing}} where {\bf thing}
988 // is the argument of \large AS WELL as being a block in its
992 if ((pos > 0) && (buffer[pos-1] != ' ') && buffer[pos] == '{')
996 if ((pos > 0) && (buffer[pos-1] != ' ') && (buffer[pos] == '[' || buffer[pos] == '('))
1001 else if ((pos > 1) && (buffer[pos-1] != ' ') && (buffer[pos+1] == '[' || buffer[pos+1] == '('))
1009 // If not parsing to brace, just read the next word
1010 // (e.g. \vskip 20pt)
1013 int ch
= buffer
[pos
];
1014 while (!eof
&& ch
!= 13 && ch
!= 32 && ch
!= 10 &&
1015 ch
!= 0 && ch
!= '{')
1017 BigBuffer
[buf_ptr
] = ch
;
1024 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1025 BigBuffer
[buf_ptr
] = 0;
1026 chunk
->value
= copystring(BigBuffer
);
1027 children
.Append((wxObject
*)chunk
);
1034 len
= wxStrlen(buffer
);
1037 if (customMacroArgs
) return 0;
1039 eof
= read_a_line(buffer
);
1041 // Check for verbatim (or toocomplex, which comes to the same thing)
1042 wxString bufStr
= buffer
;
1043 // if (bufStr.find("\\begin{verbatim}") != wxString::npos ||
1044 // bufStr.find("\\begin{toocomplex}") != wxString::npos)
1045 if (wxStrncmp(buffer
, _T("\\begin{verbatim}"), 16) == 0 ||
1046 wxStrncmp(buffer
, _T("\\begin{toocomplex}"), 18) == 0)
1050 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1051 BigBuffer
[buf_ptr
] = 0;
1052 chunk
->value
= copystring(BigBuffer
);
1053 children
.Append((wxObject
*)chunk
);
1058 eof
= read_a_line(buffer
);
1059 while (!eof
&& (wxStrncmp(buffer
, _T("\\end{verbatim}"), 14) != 0) &&
1060 (wxStrncmp(buffer
, _T("\\end{toocomplex}"), 16) != 0)
1063 wxStrcat(BigBuffer
, buffer
);
1064 buf_ptr
+= wxStrlen(buffer
);
1065 eof
= read_a_line(buffer
);
1067 eof
= read_a_line(buffer
);
1070 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, VerbatimMacroDef
);
1072 chunk
->macroId
= ltVERBATIM
;
1073 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, VerbatimMacroDef
);
1075 arg
->macroId
= ltVERBATIM
;
1076 TexChunk
*str
= new TexChunk(CHUNK_TYPE_STRING
);
1077 str
->value
= copystring(BigBuffer
);
1079 children
.Append((wxObject
*)chunk
);
1080 chunk
->children
.Append((wxObject
*)arg
);
1081 arg
->children
.Append((wxObject
*)str
);
1083 // Also want to include the following newline (is always a newline
1084 // after a verbatim): EXCEPT in HTML
1085 if (convertMode
!= TEX_HTML
)
1087 TexMacroDef
*parDef
= (TexMacroDef
*)MacroDefs
.Get(_T("\\"));
1088 TexChunk
*parChunk
= new TexChunk(CHUNK_TYPE_MACRO
, parDef
);
1089 parChunk
->no_args
= 0;
1090 parChunk
->macroId
= ltBACKSLASHCHAR
;
1091 children
.Append((wxObject
*)parChunk
);
1096 char ch
= buffer
[pos
];
1097 // End of optional argument -- pretend it's right brace for simplicity
1098 if (thisArg
->optional
&& (ch
== ']'))
1104 case '}': // End of argument
1108 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1109 BigBuffer
[buf_ptr
] = 0;
1110 chunk
->value
= copystring(BigBuffer
);
1111 children
.Append((wxObject
*)chunk
);
1113 if (ch
== '}') pos
++;
1118 if (buf_ptr
> 0) // Finish off the string we've read so far
1120 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1121 BigBuffer
[buf_ptr
] = 0;
1123 chunk
->value
= copystring(BigBuffer
);
1124 children
.Append((wxObject
*)chunk
);
1128 // Try matching \end{environment}
1129 if (environment
&& FindEndEnvironment(buffer
, &pos
, environment
))
1131 // Eliminate newline after an \end{} if possible
1132 if (buffer
[pos
] == 13)
1135 if (buffer
[pos
] == 10)
1141 if (ParseNewCommand(buffer
, &pos
))
1144 if (wxStrncmp(buffer
+pos
, _T("special"), 7) == 0)
1152 wxTex2RTFBuffer
[0] = 0;
1157 int ch
= buffer
[pos
];
1163 wxTex2RTFBuffer
[i
] = 0;
1168 wxTex2RTFBuffer
[i
] = '}';
1175 wxTex2RTFBuffer
[i
] = '{';
1179 else if (ch
== '\\' && buffer
[pos
+1] == '}')
1181 wxTex2RTFBuffer
[i
] = '}';
1185 else if (ch
== '\\' && buffer
[pos
+1] == '{')
1187 wxTex2RTFBuffer
[i
] = '{';
1193 wxTex2RTFBuffer
[i
] = ch
;
1200 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1202 chunk
->macroId
= ltSPECIAL
;
1203 TexMacroDef
*specialDef
= (TexMacroDef
*)MacroDefs
.Get(_T("special"));
1204 chunk
->def
= specialDef
;
1205 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, specialDef
);
1206 chunk
->children
.Append((wxObject
*)arg
);
1208 arg
->macroId
= chunk
->macroId
;
1210 // The value in the first argument.
1211 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1212 arg
->children
.Append((wxObject
*)argValue
);
1214 argValue
->value
= copystring(wxTex2RTFBuffer
);
1216 children
.Append((wxObject
*)chunk
);
1218 else if (wxStrncmp(buffer
+pos
, _T("verb"), 4) == 0)
1221 if (buffer
[pos
] == '*')
1224 // Find the delimiter character
1225 int ch
= buffer
[pos
];
1227 // Now at start of verbatim text
1229 while ((buffer
[pos
] != ch
) && buffer
[pos
] != 0)
1231 wxChar
*val
= new wxChar
[pos
- j
+ 1];
1233 for (i
= j
; i
< pos
; i
++)
1235 val
[i
-j
] = buffer
[i
];
1241 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1243 chunk
->macroId
= ltVERB
;
1244 TexMacroDef
*verbDef
= (TexMacroDef
*)MacroDefs
.Get(_T("verb"));
1245 chunk
->def
= verbDef
;
1246 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, verbDef
);
1247 chunk
->children
.Append((wxObject
*)arg
);
1249 arg
->macroId
= chunk
->macroId
;
1251 // The value in the first argument.
1252 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1253 arg
->children
.Append((wxObject
*)argValue
);
1255 argValue
->value
= val
;
1257 children
.Append((wxObject
*)chunk
);
1262 bool tmpParseToBrace
= true;
1263 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1266 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1268 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1270 chunk
->no_args
= def
->no_args
;
1271 // chunk->name = copystring(def->name);
1272 chunk
->macroId
= def
->macroId
;
1275 children
.Append((wxObject
*)chunk
);
1277 // Eliminate newline after a \begin{} or a \\ if possible
1278 if (env
|| wxStrcmp(def
->name
, _T("\\")) == 0)
1279 if (buffer
[pos
] == 13)
1282 if (buffer
[pos
] == 10)
1286 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1287 buffer
, pos
, env
, tmpParseToBrace
, customMacroArgs
);
1289 // If custom macro, parse the body substituting the above found args.
1292 if (customMacro
->macroBody
)
1294 wxChar macroBuf
[300];
1295 // wxStrcpy(macroBuf, _T("{"));
1296 wxStrcpy(macroBuf
, customMacro
->macroBody
);
1297 wxStrcat(macroBuf
, _T("}"));
1298 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, true, chunk
);
1301 // delete chunk; // Might delete children
1306 MacroError(buffer
+pos
);
1311 // Parse constructs like {\bf thing} as if they were
1316 if (buffer
[pos
] == '\\')
1320 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1321 BigBuffer
[buf_ptr
] = 0;
1323 chunk
->value
= copystring(BigBuffer
);
1324 children
.Append((wxObject
*)chunk
);
1329 bool tmpParseToBrace
;
1330 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1333 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1335 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1336 chunk
->no_args
= def
->no_args
;
1337 // chunk->name = copystring(def->name);
1338 chunk
->macroId
= def
->macroId
;
1340 children
.Append((wxObject
*)chunk
);
1342 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1343 buffer
, pos
, NULL
, true, customMacroArgs
);
1345 // If custom macro, parse the body substituting the above found args.
1348 if (customMacro
->macroBody
)
1350 wxChar macroBuf
[300];
1351 // wxStrcpy(macroBuf, _T("{"));
1352 wxStrcpy(macroBuf
, customMacro
->macroBody
);
1353 wxStrcat(macroBuf
, _T("}"));
1354 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, true, chunk
);
1357 // delete chunk; // Might delete children
1362 MacroError(buffer
+pos
);
1368 * If all else fails, we assume that we have
1369 * a pair of braces on their own, so return a `dummy' macro
1370 * definition with just one argument to parse.
1374 SoloBlockDef
= new TexMacroDef(ltSOLO_BLOCK
, _T("solo block"), 1, false);
1379 TexChunk
*chunk1
= new TexChunk(CHUNK_TYPE_STRING
);
1380 BigBuffer
[buf_ptr
] = 0;
1382 chunk1
->value
= copystring(BigBuffer
);
1383 children
.Append((wxObject
*)chunk1
);
1385 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, SoloBlockDef
);
1386 chunk
->no_args
= SoloBlockDef
->no_args
;
1387 // chunk->name = copystring(SoloBlockDef->name);
1388 chunk
->macroId
= SoloBlockDef
->macroId
;
1389 children
.Append((wxObject
*)chunk
);
1391 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, SoloBlockDef
);
1393 chunk
->children
.Append((wxObject
*)arg
);
1394 // arg->name = copystring(SoloBlockDef->name);
1396 arg
->macroId
= chunk
->macroId
;
1398 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, NULL
, true, customMacroArgs
);
1406 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1407 BigBuffer
[buf_ptr
] = 0;
1409 chunk
->value
= copystring(BigBuffer
);
1410 children
.Append((wxObject
*)chunk
);
1415 if (buffer
[pos
] == '$')
1417 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1419 // chunk->name = copystring(_T("$$"));
1420 chunk
->macroId
= ltSPECIALDOUBLEDOLLAR
;
1421 children
.Append((wxObject
*)chunk
);
1426 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1428 // chunk->name = copystring(_T("_$"));
1429 chunk
->macroId
= ltSPECIALDOLLAR
;
1430 children
.Append((wxObject
*)chunk
);
1438 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1439 BigBuffer
[buf_ptr
] = 0;
1441 chunk
->value
= copystring(BigBuffer
);
1442 children
.Append((wxObject
*)chunk
);
1446 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1448 // chunk->name = copystring(_T("_~"));
1449 chunk
->macroId
= ltSPECIALTILDE
;
1450 children
.Append((wxObject
*)chunk
);
1453 case '#': // Either treat as a special TeX character or as a macro arg
1457 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1458 BigBuffer
[buf_ptr
] = 0;
1460 chunk
->value
= copystring(BigBuffer
);
1461 children
.Append((wxObject
*)chunk
);
1465 if (!customMacroArgs
)
1467 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1469 // chunk->name = copystring(_T("_#"));
1470 chunk
->macroId
= ltSPECIALHASH
;
1471 children
.Append((wxObject
*)chunk
);
1475 if (isdigit(buffer
[pos
]))
1477 int n
= buffer
[pos
] - 48;
1479 wxNode
*node
= customMacroArgs
->children
.Item(n
-1);
1482 TexChunk
*argChunk
= (TexChunk
*)node
->GetData();
1483 children
.Append((wxObject
*)new TexChunk(*argChunk
));
1491 // Remove white space before and after the ampersand,
1492 // since this is probably a table column separator with
1493 // some convenient -- but useless -- white space in the text.
1494 while ((buf_ptr
> 0) && ((BigBuffer
[buf_ptr
-1] == ' ') || (BigBuffer
[buf_ptr
-1] == 9)))
1499 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1500 BigBuffer
[buf_ptr
] = 0;
1502 chunk
->value
= copystring(BigBuffer
);
1503 children
.Append((wxObject
*)chunk
);
1508 while (buffer
[pos
] == ' ' || buffer
[pos
] == 9)
1511 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1513 // chunk->name = copystring(_T("_&"));
1514 chunk
->macroId
= ltSPECIALAMPERSAND
;
1515 children
.Append((wxObject
*)chunk
);
1518 // Eliminate end-of-line comment
1522 while (ch
!= 10 && ch
!= 13 && ch
!= 0)
1527 if (buffer
[pos
] == 10 || buffer
[pos
] == 13)
1530 if (buffer
[pos
] == 10) pos
++; // Eliminate newline following DOS line feed
1537 BigBuffer
[buf_ptr
] = ' ';
1538 BigBuffer
[buf_ptr
+1] = 0;
1545 BigBuffer
[buf_ptr
] = ch
;
1546 BigBuffer
[buf_ptr
+1] = 0;
1557 * Consume as many arguments as the macro definition specifies
1561 int ParseMacroBody(const wxChar
*WXUNUSED(macro_name
), TexChunk
*parent
,
1562 int no_args
, wxChar
*buffer
, int pos
,
1563 wxChar
*environment
, bool parseToBrace
,
1564 TexChunk
*customMacroArgs
)
1567 if (stopRunning
) return pos
;
1569 // Check for a first optional argument
1570 if (buffer
[pos
] == ' ' && buffer
[pos
+1] == '[')
1572 // Fool following code into thinking that this is definitely
1573 // an optional first argument. (If a space before a non-first argument,
1574 // [ is interpreted as a [, not an optional argument.)
1580 if (buffer
[pos
] == '[')
1586 for (i
= 0; i
< no_args
; i
++)
1589 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, parent
->def
);
1591 parent
->children
.Append((wxObject
*)arg
);
1592 // arg->name = copystring(macro_name);
1593 arg
->argn
= maxArgs
;
1594 arg
->macroId
= parent
->macroId
;
1596 // To parse the first arg of a 2 arg \begin{thing}{arg} ... \end{thing}
1597 // have to fool parser into thinking this is a regular kind of block.
1599 if ((no_args
== 2) && (i
== 0))
1602 actualEnv
= environment
;
1604 bool isOptional
= false;
1606 // Remove the first { of the argument so it doesn't get recognized as { ... }
1607 // EatWhiteSpace(buffer, &pos);
1610 // The reason for these tests is to not consume braces that don't
1611 // belong to this macro.
1612 // E.g. {\bf {\small thing}}
1613 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && buffer
[pos
] == '{')
1616 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && (buffer
[pos
] == '['))
1621 else if ((pos
> 1) && (buffer
[pos
-1] != ' ') && (buffer
[pos
+1] == '['))
1629 wxString
tmpBuffer(buffer
);
1630 if (tmpBuffer
.length() > 4)
1632 if (tmpBuffer
.Right(4) == _T("\\par"))
1633 tmpBuffer
= tmpBuffer
.Mid(0,tmpBuffer
.length()-4);
1635 errBuf
.Printf(_T("Missing macro argument in the line:\n\t%s\n"),tmpBuffer
.c_str());
1636 OnError((wxChar
*)errBuf
.c_str());
1640 arg
->optional
= isOptional
;
1642 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, actualEnv
, parseToBrace
, customMacroArgs
);
1644 // If we've encountered an OPTIONAL argument, go another time around
1645 // the loop, because we've got more than we thought.
1646 // Hopefully optional args don't occur at the end of a macro use
1647 // or we might miss it.
1648 // Don't increment no of times round loop if the first optional arg
1649 // -- we already did it before the loop.
1650 if (arg
->optional
&& (i
> 0))
1653 parent
->no_args
= maxArgs
;
1655 // Tell each argument how many args there are (useful when processing an arg)
1656 wxNode
*node
= parent
->children
.GetFirst();
1659 TexChunk
*chunk
= (TexChunk
*)node
->GetData();
1660 chunk
->no_args
= maxArgs
;
1661 node
= node
->GetNext();
1666 bool TexLoadFile(wxChar
*filename
)
1668 static wxChar
*line_buffer
;
1669 stopRunning
= false;
1670 wxStrcpy(TexFileRoot
, filename
);
1671 StripExtension(TexFileRoot
);
1672 wxSnprintf(TexBibName
, 300, _T("%s.bb"), TexFileRoot
);
1673 wxSnprintf(TexTmpBibName
, 300, _T("%s.bb1"), TexFileRoot
);
1675 TexPathList
.EnsureFileAccessible(filename
);
1680 line_buffer
= new wxChar
[MAX_LINE_BUFFER_SIZE
];
1682 Inputs
[0] = wxFopen(filename
, _T("r"));
1684 FileNames
[0] = copystring(filename
);
1687 read_a_line(line_buffer
);
1688 ParseMacroBody(_T("toplevel"), TopLevel
, 1, line_buffer
, 0, NULL
, true);
1689 if (Inputs
[0]) fclose(Inputs
[0]);
1696 TexMacroDef::TexMacroDef(int the_id
, const wxChar
*the_name
, int n
, bool ig
, bool forbidLevel
)
1698 name
= copystring(the_name
);
1702 forbidden
= forbidLevel
;
1705 TexMacroDef::~TexMacroDef(void)
1707 if (name
) delete[] name
;
1710 TexChunk::TexChunk(int the_type
, TexMacroDef
*the_def
)
1722 TexChunk::TexChunk(TexChunk
& toCopy
)
1725 no_args
= toCopy
.no_args
;
1727 macroId
= toCopy
.macroId
;
1730 // name = copystring(toCopy.name);
1736 value
= copystring(toCopy
.value
);
1740 optional
= toCopy
.optional
;
1741 wxNode
*node
= toCopy
.children
.GetFirst();
1744 TexChunk
*child
= (TexChunk
*)node
->GetData();
1745 children
.Append((wxObject
*)new TexChunk(*child
));
1746 node
= node
->GetNext();
1750 TexChunk::~TexChunk(void)
1752 // if (name) delete[] name;
1753 if (value
) delete[] value
;
1754 wxNode
*node
= children
.GetFirst();
1757 TexChunk
*child
= (TexChunk
*)node
->GetData();
1759 wxNode
*next
= node
->GetNext();
1765 bool IsArgOptional(void) // Is this argument an optional argument?
1767 return isArgOptional
;
1770 int GetNoArgs(void) // Number of args for this macro
1775 /* Gets the text of a chunk on request (must be for small arguments
1780 void GetArgData1(TexChunk
*chunk
)
1782 switch (chunk
->type
)
1784 case CHUNK_TYPE_MACRO
:
1786 TexMacroDef
*def
= chunk
->def
;
1787 if (def
&& def
->ignore
)
1790 if (def
&& (wxStrcmp(def
->name
, _T("solo block")) != 0))
1792 wxStrcat(currentArgData
, _T("\\"));
1793 wxStrcat(currentArgData
, def
->name
);
1796 wxNode
*node
= chunk
->children
.GetFirst();
1799 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1800 wxStrcat(currentArgData
, _T("{"));
1801 GetArgData1(child_chunk
);
1802 wxStrcat(currentArgData
, _T("}"));
1803 node
= node
->GetNext();
1807 case CHUNK_TYPE_ARG
:
1809 wxNode
*node
= chunk
->children
.GetFirst();
1812 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1813 GetArgData1(child_chunk
);
1814 node
= node
->GetNext();
1818 case CHUNK_TYPE_STRING
:
1821 wxStrcat(currentArgData
, chunk
->value
);
1827 wxChar
*GetArgData(TexChunk
*WXUNUSED(chunk
))
1829 currentArgData
[0] = 0;
1830 GetArgData1(currentArgument
);
1831 haveArgData
= false;
1832 return currentArgData
;
1835 wxChar
*GetArgData(void)
1839 currentArgData
[0] = 0;
1840 GetArgData1(currentArgument
);
1842 return currentArgData
;
1845 TexChunk
*GetArgChunk(void)
1847 return currentArgument
;
1850 TexChunk
*GetNextChunk(void) // Look ahead to the next chunk
1855 TexChunk
*GetTopLevelChunk(void)
1860 int GetCurrentColumn(void)
1862 return currentColumn
;
1866 * Traverses document calling functions to allow the client to
1867 * write out the appropriate stuff
1871 void TraverseFromChunk(TexChunk
*chunk
, wxNode
*thisNode
, bool childrenOnly
)
1874 if (stopRunning
) return;
1876 switch (chunk
->type
)
1878 case CHUNK_TYPE_MACRO
:
1880 TexMacroDef
*def
= chunk
->def
;
1881 if (def
&& def
->ignore
)
1885 OnMacro(chunk
->macroId
, chunk
->no_args
, true);
1887 wxNode
*node
= chunk
->children
.GetFirst();
1890 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1891 TraverseFromChunk(child_chunk
, node
);
1892 node
= node
->GetNext();
1895 if (thisNode
&& thisNode
->GetNext())
1896 nextChunk
= (TexChunk
*)thisNode
->GetNext()->GetData();
1899 OnMacro(chunk
->macroId
, chunk
->no_args
, false);
1902 case CHUNK_TYPE_ARG
:
1904 currentArgument
= chunk
;
1906 isArgOptional
= chunk
->optional
;
1907 noArgs
= chunk
->no_args
;
1909 // If OnArgument returns false, don't output.
1911 if (childrenOnly
|| OnArgument(chunk
->macroId
, chunk
->argn
, true))
1913 wxNode
*node
= chunk
->children
.GetFirst();
1916 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1917 TraverseFromChunk(child_chunk
, node
);
1918 node
= node
->GetNext();
1922 currentArgument
= chunk
;
1924 if (thisNode
&& thisNode
->GetNext())
1925 nextChunk
= (TexChunk
*)thisNode
->GetNext()->GetData();
1927 isArgOptional
= chunk
->optional
;
1928 noArgs
= chunk
->no_args
;
1931 (void)OnArgument(chunk
->macroId
, chunk
->argn
, false);
1934 case CHUNK_TYPE_STRING
:
1936 extern int issuedNewParagraph
;
1937 extern int forbidResetPar
;
1938 if (chunk
->value
&& (forbidResetPar
== 0))
1940 // If non-whitespace text, we no longer have a new paragraph.
1941 if (issuedNewParagraph
&& !((chunk
->value
[0] == 10 || chunk
->value
[0] == 13 || chunk
->value
[0] == 32)
1942 && chunk
->value
[1] == 0))
1944 issuedNewParagraph
= false;
1946 TexOutput(chunk
->value
, true);
1953 void TraverseDocument(void)
1955 TraverseFromChunk(TopLevel
, NULL
);
1958 void SetCurrentOutput(FILE *fd
)
1960 CurrentOutput1
= fd
;
1961 CurrentOutput2
= NULL
;
1964 void SetCurrentOutputs(FILE *fd1
, FILE *fd2
)
1966 CurrentOutput1
= fd1
;
1967 CurrentOutput2
= fd2
;
1970 void AddMacroDef(int the_id
, const wxChar
*name
, int n
, bool ignore
, bool forbid
)
1972 MacroDefs
.Put(name
, new TexMacroDef(the_id
, name
, n
, ignore
, forbid
));
1975 void TexInitialize(int bufSize
)
1977 InitialiseColourTable();
1979 TexPathList
.AddEnvList(_T("TEXINPUT"));
1982 TexPathList
.AddEnvList(_T("TEXINPUTS"));
1985 for (i
= 0; i
< 15; i
++)
1989 FileNames
[i
] = NULL
;
1992 IgnorableInputFiles
.Add(_T("psbox.tex"));
1993 BigBuffer
= new wxChar
[(bufSize
*1000)];
1994 currentArgData
= new wxChar
[2000];
1995 TexFileRoot
= new wxChar
[300];
1996 TexBibName
= new wxChar
[300];
1997 TexTmpBibName
= new wxChar
[300];
1998 AddMacroDef(ltTOPLEVEL
, _T("toplevel"), 1);
1999 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
2000 // TopLevel->name = copystring(_T("toplevel"));
2001 TopLevel
->macroId
= ltTOPLEVEL
;
2002 TopLevel
->no_args
= 1;
2003 VerbatimMacroDef
= (TexMacroDef
*)MacroDefs
.Get(_T("verbatim"));
2006 void TexCleanUp(void)
2009 for (i
= 0; i
< 15; i
++)
2015 subsubsectionNo
= 0;
2018 CurrentOutput1
= NULL
;
2019 CurrentOutput2
= NULL
;
2020 CurrentInputIndex
= 0;
2021 haveArgData
= false;
2026 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
2027 // TopLevel->name = copystring(_T("toplevel"));
2028 TopLevel
->macroId
= ltTOPLEVEL
;
2029 TopLevel
->no_args
= 1;
2031 DocumentTitle
= NULL
;
2032 DocumentAuthor
= NULL
;
2033 DocumentDate
= NULL
;
2034 DocumentStyle
= LATEX_REPORT
;
2035 MinorDocumentStyle
= 0;
2036 BibliographyStyleString
= copystring(_T("plain"));
2037 DocumentStyleString
= copystring(_T("report"));
2038 MinorDocumentStyleString
= NULL
;
2040 // gt - Changed this so if this is the final pass
2041 // then we DO want to remove these macros, so that
2042 // memory is not MASSIVELY leaked if the user
2043 // does not exit the program, but instead runs
2044 // the program again
2045 if ((passNumber
== 1 && !runTwice
) ||
2046 (passNumber
== 2 && runTwice
))
2048 /* Don't want to remove custom macros after each pass.*/
2050 wxNode
*node
= CustomMacroList
.GetFirst();
2053 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
2056 node
= CustomMacroList
.GetFirst();
2060 TexReferences
.BeginFind();
2061 wxHashTable::Node
*refNode
= TexReferences
.Next();
2064 TexRef
*ref
= (TexRef
*)refNode
->GetData();
2066 refNode
= TexReferences
.Next();
2068 TexReferences
.Clear();
2070 wxNode
* bibNode
= BibList
.GetFirst();
2073 BibEntry
*entry
= (BibEntry
*)bibNode
->GetData();
2076 bibNode
= BibList
.GetFirst();
2078 CitationList
.Clear();
2079 ResetTopicCounter();
2082 // There is likely to be one set of macros used by all utilities.
2083 void DefineDefaultMacros(void)
2085 // Put names which subsume other names at the TOP
2086 // so they get recognized first
2088 AddMacroDef(ltACCENT_GRAVE
, _T("`"), 1);
2089 AddMacroDef(ltACCENT_ACUTE
, _T("'"), 1);
2090 AddMacroDef(ltACCENT_CARET
, _T("^"), 1);
2091 AddMacroDef(ltACCENT_UMLAUT
, _T("\""), 1);
2092 AddMacroDef(ltACCENT_TILDE
, _T("~"), 1);
2093 AddMacroDef(ltACCENT_DOT
, _T("."), 1);
2094 AddMacroDef(ltACCENT_CADILLA
, _T("c"), 1);
2095 AddMacroDef(ltSMALLSPACE1
, _T(","), 0);
2096 AddMacroDef(ltSMALLSPACE2
, _T(";"), 0);
2098 AddMacroDef(ltABSTRACT
, _T("abstract"), 1);
2099 AddMacroDef(ltADDCONTENTSLINE
, _T("addcontentsline"), 3);
2100 AddMacroDef(ltADDTOCOUNTER
, _T("addtocounter"), 2);
2101 AddMacroDef(ltALEPH
, _T("aleph"), 0);
2102 AddMacroDef(ltALPHA
, _T("alpha"), 0);
2103 AddMacroDef(ltALPH1
, _T("alph"), 1);
2104 AddMacroDef(ltALPH2
, _T("Alph"), 1);
2105 AddMacroDef(ltANGLE
, _T("angle"), 0);
2106 AddMacroDef(ltAPPENDIX
, _T("appendix"), 0);
2107 AddMacroDef(ltAPPROX
, _T("approx"), 0);
2108 AddMacroDef(ltARABIC
, _T("arabic"), 1);
2109 AddMacroDef(ltARRAY
, _T("array"), 1);
2110 AddMacroDef(ltAST
, _T("ast"), 0);
2111 AddMacroDef(ltASYMP
, _T("asymp"), 0);
2112 AddMacroDef(ltAUTHOR
, _T("author"), 1);
2114 AddMacroDef(ltBACKGROUNDCOLOUR
, _T("backgroundcolour"), 1);
2115 AddMacroDef(ltBACKGROUNDIMAGE
, _T("backgroundimage"), 1);
2116 AddMacroDef(ltBACKGROUND
, _T("background"), 1);
2117 AddMacroDef(ltBACKSLASHRAW
, _T("backslashraw"), 0);
2118 AddMacroDef(ltBACKSLASH
, _T("backslash"), 0);
2119 AddMacroDef(ltBASELINESKIP
, _T("baselineskip"), 1);
2120 AddMacroDef(ltBCOL
, _T("bcol"), 2);
2121 AddMacroDef(ltBETA
, _T("beta"), 0);
2122 AddMacroDef(ltBFSERIES
, _T("bfseries"), 1);
2123 AddMacroDef(ltBF
, _T("bf"), 1);
2124 AddMacroDef(ltBIBITEM
, _T("bibitem"), 2);
2125 // For convenience, bibitem has 2 args: label and item.
2126 // The Latex syntax permits writing as 2 args.
2127 AddMacroDef(ltBIBLIOGRAPHYSTYLE
, _T("bibliographystyle"), 1);
2128 AddMacroDef(ltBIBLIOGRAPHY
, _T("bibliography"), 1);
2129 AddMacroDef(ltBIGTRIANGLEDOWN
, _T("bigtriangledown"), 0);
2130 AddMacroDef(ltBOT
, _T("bot"), 0);
2131 AddMacroDef(ltBOXIT
, _T("boxit"), 1);
2132 AddMacroDef(ltBOX
, _T("box"), 0);
2133 AddMacroDef(ltBRCLEAR
, _T("brclear"), 0);
2134 AddMacroDef(ltBULLET
, _T("bullet"), 0);
2136 AddMacroDef(ltCAPTIONSTAR
, _T("caption*"), 1);
2137 AddMacroDef(ltCAPTION
, _T("caption"), 1);
2138 AddMacroDef(ltCAP
, _T("cap"), 0);
2139 AddMacroDef(ltCDOTS
, _T("cdots"), 0);
2140 AddMacroDef(ltCDOT
, _T("cdot"), 0);
2141 AddMacroDef(ltCENTERLINE
, _T("centerline"), 1);
2142 AddMacroDef(ltCENTERING
, _T("centering"), 0);
2143 AddMacroDef(ltCENTER
, _T("center"), 1);
2144 AddMacroDef(ltCEXTRACT
, _T("cextract"), 0);
2145 AddMacroDef(ltCHAPTERHEADING
, _T("chapterheading"), 1);
2146 AddMacroDef(ltCHAPTERSTAR
, _T("chapter*"), 1);
2147 AddMacroDef(ltCHAPTER
, _T("chapter"), 1);
2148 AddMacroDef(ltCHI
, _T("chi"), 0);
2149 AddMacroDef(ltCINSERT
, _T("cinsert"), 0);
2150 AddMacroDef(ltCIRC
, _T("circ"), 0);
2151 AddMacroDef(ltCITE
, _T("cite"), 1);
2152 AddMacroDef(ltCLASS
, _T("class"), 1);
2153 AddMacroDef(ltCLEARDOUBLEPAGE
, _T("cleardoublepage"), 0);
2154 AddMacroDef(ltCLEARPAGE
, _T("clearpage"), 0);
2155 AddMacroDef(ltCLINE
, _T("cline"), 1);
2156 AddMacroDef(ltCLIPSFUNC
, _T("clipsfunc"), 3);
2157 AddMacroDef(ltCLUBSUIT
, _T("clubsuit"), 0);
2158 AddMacroDef(ltCOLUMNSEP
, _T("columnsep"), 1);
2159 AddMacroDef(ltCOMMENT
, _T("comment"), 1, true);
2160 AddMacroDef(ltCONG
, _T("cong"), 0);
2161 AddMacroDef(ltCOPYRIGHT
, _T("copyright"), 0);
2162 AddMacroDef(ltCPARAM
, _T("cparam"), 2);
2163 AddMacroDef(ltCHEAD
, _T("chead"), 1);
2164 AddMacroDef(ltCFOOT
, _T("cfoot"), 1);
2165 AddMacroDef(ltCUP
, _T("cup"), 0);
2167 AddMacroDef(ltDASHV
, _T("dashv"), 0);
2168 AddMacroDef(ltDATE
, _T("date"), 1);
2169 AddMacroDef(ltDELTA
, _T("delta"), 0);
2170 AddMacroDef(ltCAP_DELTA
, _T("Delta"), 0);
2171 AddMacroDef(ltDEFINECOLOUR
, _T("definecolour"), 4);
2172 AddMacroDef(ltDEFINECOLOR
, _T("definecolor"), 4);
2173 AddMacroDef(ltDESCRIPTION
, _T("description"), 1);
2174 AddMacroDef(ltDESTRUCT
, _T("destruct"), 1);
2175 AddMacroDef(ltDIAMOND2
, _T("diamond2"), 0);
2176 AddMacroDef(ltDIAMOND
, _T("diamond"), 0);
2177 AddMacroDef(ltDIV
, _T("div"), 0);
2178 AddMacroDef(ltDOCUMENTCLASS
, _T("documentclass"), 1);
2179 AddMacroDef(ltDOCUMENTSTYLE
, _T("documentstyle"), 1);
2180 AddMacroDef(ltDOCUMENT
, _T("document"), 1);
2181 AddMacroDef(ltDOUBLESPACE
, _T("doublespace"), 1);
2182 AddMacroDef(ltDOTEQ
, _T("doteq"), 0);
2183 AddMacroDef(ltDOWNARROW
, _T("downarrow"), 0);
2184 AddMacroDef(ltDOWNARROW2
, _T("Downarrow"), 0);
2186 AddMacroDef(ltEMPTYSET
, _T("emptyset"), 0);
2187 AddMacroDef(ltEMPH
, _T("emph"), 1);
2188 AddMacroDef(ltEM
, _T("em"), 1);
2189 AddMacroDef(ltENUMERATE
, _T("enumerate"), 1);
2190 AddMacroDef(ltEPSILON
, _T("epsilon"), 0);
2191 AddMacroDef(ltEQUATION
, _T("equation"), 1);
2192 AddMacroDef(ltEQUIV
, _T("equiv"), 0);
2193 AddMacroDef(ltETA
, _T("eta"), 0);
2194 AddMacroDef(ltEVENSIDEMARGIN
, _T("evensidemargin"), 1);
2195 AddMacroDef(ltEXISTS
, _T("exists"), 0);
2197 AddMacroDef(ltFBOX
, _T("fbox"), 1);
2198 AddMacroDef(ltFCOL
, _T("fcol"), 2);
2199 AddMacroDef(ltFIGURE
, _T("figure"), 1);
2200 AddMacroDef(ltFIGURESTAR
, _T("figure*"), 1);
2201 AddMacroDef(ltFLUSHLEFT
, _T("flushleft"), 1);
2202 AddMacroDef(ltFLUSHRIGHT
, _T("flushright"), 1);
2203 AddMacroDef(ltFOLLOWEDLINKCOLOUR
, _T("followedlinkcolour"), 1);
2204 AddMacroDef(ltFOOTHEIGHT
, _T("footheight"), 1);
2205 AddMacroDef(ltFOOTNOTEPOPUP
, _T("footnotepopup"), 2);
2206 AddMacroDef(ltFOOTNOTE
, _T("footnote"), 1);
2207 AddMacroDef(ltFOOTSKIP
, _T("footskip"), 1);
2208 AddMacroDef(ltFORALL
, _T("forall"), 0);
2209 AddMacroDef(ltFRAMEBOX
, _T("framebox"), 1);
2210 AddMacroDef(ltFROWN
, _T("frown"), 0);
2211 AddMacroDef(ltFUNCTIONSECTION
, _T("functionsection"), 1);
2212 AddMacroDef(ltFUNC
, _T("func"), 3);
2213 AddMacroDef(ltFOOTNOTESIZE
, _T("footnotesize"), 0);
2214 AddMacroDef(ltFANCYPLAIN
, _T("fancyplain"), 2);
2216 AddMacroDef(ltGAMMA
, _T("gamma"), 0);
2217 AddMacroDef(ltCAP_GAMMA
, _T("Gamma"), 0);
2218 AddMacroDef(ltGEQ
, _T("geq"), 0);
2219 AddMacroDef(ltGE
, _T("ge"), 0);
2220 AddMacroDef(ltGG
, _T("gg"), 0);
2221 AddMacroDef(ltGLOSSARY
, _T("glossary"), 1);
2222 AddMacroDef(ltGLOSS
, _T("gloss"), 1);
2224 AddMacroDef(ltHEADHEIGHT
, _T("headheight"), 1);
2225 AddMacroDef(ltHEARTSUIT
, _T("heartsuit"), 0);
2226 AddMacroDef(ltHELPGLOSSARY
, _T("helpglossary"), 1);
2227 AddMacroDef(ltHELPIGNORE
, _T("helpignore"), 1, true);
2228 AddMacroDef(ltHELPONLY
, _T("helponly"), 1);
2229 AddMacroDef(ltHELPINPUT
, _T("helpinput"), 1);
2230 AddMacroDef(ltHELPFONTFAMILY
, _T("helpfontfamily"), 1);
2231 AddMacroDef(ltHELPFONTSIZE
, _T("helpfontsize"), 1);
2232 AddMacroDef(ltHELPREFN
, _T("helprefn"), 2);
2233 AddMacroDef(ltHELPREF
, _T("helpref"), 2);
2234 AddMacroDef(ltHFILL
, _T("hfill"), 0);
2235 AddMacroDef(ltHLINE
, _T("hline"), 0);
2236 AddMacroDef(ltHRULE
, _T("hrule"), 0);
2237 AddMacroDef(ltHSPACESTAR
, _T("hspace*"), 1);
2238 AddMacroDef(ltHSPACE
, _T("hspace"), 1);
2239 AddMacroDef(ltHSKIPSTAR
, _T("hskip*"), 1);
2240 AddMacroDef(ltHSKIP
, _T("hskip"), 1);
2241 AddMacroDef(lthuge
, _T("huge"), 1);
2242 AddMacroDef(ltHuge
, _T("Huge"), 1);
2243 AddMacroDef(ltHUGE
, _T("HUGE"), 1);
2244 AddMacroDef(ltHTMLIGNORE
, _T("htmlignore"), 1);
2245 AddMacroDef(ltHTMLONLY
, _T("htmlonly"), 1);
2247 AddMacroDef(ltIM
, _T("im"), 0);
2248 AddMacroDef(ltINCLUDEONLY
, _T("includeonly"), 1);
2249 AddMacroDef(ltINCLUDE
, _T("include"), 1);
2250 AddMacroDef(ltINDENTED
, _T("indented"), 2);
2251 AddMacroDef(ltINDEX
, _T("index"), 1);
2252 AddMacroDef(ltINPUT
, _T("input"), 1, true);
2253 AddMacroDef(ltIOTA
, _T("iota"), 0);
2254 AddMacroDef(ltITEMIZE
, _T("itemize"), 1);
2255 AddMacroDef(ltITEM
, _T("item"), 0);
2256 AddMacroDef(ltIMAGEMAP
, _T("imagemap"), 3);
2257 AddMacroDef(ltIMAGEL
, _T("imagel"), 2);
2258 AddMacroDef(ltIMAGER
, _T("imager"), 2);
2259 AddMacroDef(ltIMAGE
, _T("image"), 2);
2260 AddMacroDef(ltIN
, _T("in"), 0);
2261 AddMacroDef(ltINFTY
, _T("infty"), 0);
2262 AddMacroDef(ltITSHAPE
, _T("itshape"), 1);
2263 AddMacroDef(ltIT
, _T("it"), 1);
2264 AddMacroDef(ltITEMSEP
, _T("itemsep"), 1);
2265 AddMacroDef(ltINSERTATLEVEL
, _T("insertatlevel"), 2);
2267 AddMacroDef(ltKAPPA
, _T("kappa"), 0);
2268 AddMacroDef(ltKILL
, _T("kill"), 0);
2270 AddMacroDef(ltLABEL
, _T("label"), 1);
2271 AddMacroDef(ltLAMBDA
, _T("lambda"), 0);
2272 AddMacroDef(ltCAP_LAMBDA
, _T("Lambda"), 0);
2273 AddMacroDef(ltlarge
, _T("large"), 1);
2274 AddMacroDef(ltLarge
, _T("Large"), 1);
2275 AddMacroDef(ltLARGE
, _T("LARGE"), 1);
2276 AddMacroDef(ltLATEXIGNORE
, _T("latexignore"), 1);
2277 AddMacroDef(ltLATEXONLY
, _T("latexonly"), 1);
2278 AddMacroDef(ltLATEX
, _T("LaTeX"), 0);
2279 AddMacroDef(ltLBOX
, _T("lbox"), 1);
2280 AddMacroDef(ltLBRACERAW
, _T("lbraceraw"), 0);
2281 AddMacroDef(ltLDOTS
, _T("ldots"), 0);
2282 AddMacroDef(ltLEQ
, _T("leq"), 0);
2283 AddMacroDef(ltLE
, _T("le"), 0);
2284 AddMacroDef(ltLEFTARROW
, _T("leftarrow"), 0);
2285 AddMacroDef(ltLEFTRIGHTARROW
, _T("leftrightarrow"), 0);
2286 AddMacroDef(ltLEFTARROW2
, _T("Leftarrow"), 0);
2287 AddMacroDef(ltLEFTRIGHTARROW2
, _T("Leftrightarrow"), 0);
2288 AddMacroDef(ltLINEBREAK
, _T("linebreak"), 0);
2289 AddMacroDef(ltLINKCOLOUR
, _T("linkcolour"), 1);
2290 AddMacroDef(ltLISTOFFIGURES
, _T("listoffigures"), 0);
2291 AddMacroDef(ltLISTOFTABLES
, _T("listoftables"), 0);
2292 AddMacroDef(ltLHEAD
, _T("lhead"), 1);
2293 AddMacroDef(ltLFOOT
, _T("lfoot"), 1);
2294 AddMacroDef(ltLOWERCASE
, _T("lowercase"), 1);
2295 AddMacroDef(ltLL
, _T("ll"), 0);
2297 AddMacroDef(ltMAKEGLOSSARY
, _T("makeglossary"), 0);
2298 AddMacroDef(ltMAKEINDEX
, _T("makeindex"), 0);
2299 AddMacroDef(ltMAKETITLE
, _T("maketitle"), 0);
2300 AddMacroDef(ltMARKRIGHT
, _T("markright"), 1);
2301 AddMacroDef(ltMARKBOTH
, _T("markboth"), 2);
2302 AddMacroDef(ltMARGINPARWIDTH
, _T("marginparwidth"), 1);
2303 AddMacroDef(ltMARGINPARSEP
, _T("marginparsep"), 1);
2304 AddMacroDef(ltMARGINPARODD
, _T("marginparodd"), 1);
2305 AddMacroDef(ltMARGINPAREVEN
, _T("marginpareven"), 1);
2306 AddMacroDef(ltMARGINPAR
, _T("marginpar"), 1);
2307 AddMacroDef(ltMBOX
, _T("mbox"), 1);
2308 AddMacroDef(ltMDSERIES
, _T("mdseries"), 1);
2309 AddMacroDef(ltMEMBERSECTION
, _T("membersection"), 1);
2310 AddMacroDef(ltMEMBER
, _T("member"), 2);
2311 AddMacroDef(ltMID
, _T("mid"), 0);
2312 AddMacroDef(ltMODELS
, _T("models"), 0);
2313 AddMacroDef(ltMP
, _T("mp"), 0);
2314 AddMacroDef(ltMULTICOLUMN
, _T("multicolumn"), 3);
2315 AddMacroDef(ltMU
, _T("mu"), 0);
2317 AddMacroDef(ltNABLA
, _T("nabla"), 0);
2318 AddMacroDef(ltNEG
, _T("neg"), 0);
2319 AddMacroDef(ltNEQ
, _T("neq"), 0);
2320 AddMacroDef(ltNEWCOUNTER
, _T("newcounter"), 1, false, (bool)FORBID_ABSOLUTELY
);
2321 AddMacroDef(ltNEWLINE
, _T("newline"), 0);
2322 AddMacroDef(ltNEWPAGE
, _T("newpage"), 0);
2323 AddMacroDef(ltNI
, _T("ni"), 0);
2324 AddMacroDef(ltNOCITE
, _T("nocite"), 1);
2325 AddMacroDef(ltNOINDENT
, _T("noindent"), 0);
2326 AddMacroDef(ltNOLINEBREAK
, _T("nolinebreak"), 0);
2327 AddMacroDef(ltNOPAGEBREAK
, _T("nopagebreak"), 0);
2328 AddMacroDef(ltNORMALSIZE
, _T("normalsize"), 1);
2329 AddMacroDef(ltNORMALBOX
, _T("normalbox"), 1);
2330 AddMacroDef(ltNORMALBOXD
, _T("normalboxd"), 1);
2331 AddMacroDef(ltNOTEQ
, _T("noteq"), 0);
2332 AddMacroDef(ltNOTIN
, _T("notin"), 0);
2333 AddMacroDef(ltNOTSUBSET
, _T("notsubset"), 0);
2334 AddMacroDef(ltNU
, _T("nu"), 0);
2336 AddMacroDef(ltODDSIDEMARGIN
, _T("oddsidemargin"), 1);
2337 AddMacroDef(ltOMEGA
, _T("omega"), 0);
2338 AddMacroDef(ltCAP_OMEGA
, _T("Omega"), 0);
2339 AddMacroDef(ltONECOLUMN
, _T("onecolumn"), 0);
2340 AddMacroDef(ltOPLUS
, _T("oplus"), 0);
2341 AddMacroDef(ltOSLASH
, _T("oslash"), 0);
2342 AddMacroDef(ltOTIMES
, _T("otimes"), 0);
2344 AddMacroDef(ltPAGEBREAK
, _T("pagebreak"), 0);
2345 AddMacroDef(ltPAGEREF
, _T("pageref"), 1);
2346 AddMacroDef(ltPAGESTYLE
, _T("pagestyle"), 1);
2347 AddMacroDef(ltPAGENUMBERING
, _T("pagenumbering"), 1);
2348 AddMacroDef(ltPARAGRAPHSTAR
, _T("paragraph*"), 1);
2349 AddMacroDef(ltPARAGRAPH
, _T("paragraph"), 1);
2350 AddMacroDef(ltPARALLEL
, _T("parallel"), 0);
2351 AddMacroDef(ltPARAM
, _T("param"), 2);
2352 AddMacroDef(ltPARINDENT
, _T("parindent"), 1);
2353 AddMacroDef(ltPARSKIP
, _T("parskip"), 1);
2354 AddMacroDef(ltPARTIAL
, _T("partial"), 0);
2355 AddMacroDef(ltPARTSTAR
, _T("part*"), 1);
2356 AddMacroDef(ltPART
, _T("part"), 1);
2357 AddMacroDef(ltPAR
, _T("par"), 0);
2358 AddMacroDef(ltPERP
, _T("perp"), 0);
2359 AddMacroDef(ltPHI
, _T("phi"), 0);
2360 AddMacroDef(ltCAP_PHI
, _T("Phi"), 0);
2361 AddMacroDef(ltPFUNC
, _T("pfunc"), 3);
2362 AddMacroDef(ltPICTURE
, _T("picture"), 1);
2363 AddMacroDef(ltPI
, _T("pi"), 0);
2364 AddMacroDef(ltCAP_PI
, _T("Pi"), 0);
2365 AddMacroDef(ltPM
, _T("pm"), 0);
2366 AddMacroDef(ltPOPREFONLY
, _T("poprefonly"), 1);
2367 AddMacroDef(ltPOPREF
, _T("popref"), 2);
2368 AddMacroDef(ltPOUNDS
, _T("pounds"), 0);
2369 AddMacroDef(ltPREC
, _T("prec"), 0);
2370 AddMacroDef(ltPRECEQ
, _T("preceq"), 0);
2371 AddMacroDef(ltPRINTINDEX
, _T("printindex"), 0);
2372 AddMacroDef(ltPROPTO
, _T("propto"), 0);
2373 AddMacroDef(ltPSBOXTO
, _T("psboxto"), 1, false, (bool)FORBID_ABSOLUTELY
);
2374 AddMacroDef(ltPSBOX
, _T("psbox"), 1, false, (bool)FORBID_ABSOLUTELY
);
2375 AddMacroDef(ltPSI
, _T("psi"), 0);
2376 AddMacroDef(ltCAP_PSI
, _T("Psi"), 0);
2378 AddMacroDef(ltQUOTE
, _T("quote"), 1);
2379 AddMacroDef(ltQUOTATION
, _T("quotation"), 1);
2381 AddMacroDef(ltRAGGEDBOTTOM
, _T("raggedbottom"), 0);
2382 AddMacroDef(ltRAGGEDLEFT
, _T("raggedleft"), 0);
2383 AddMacroDef(ltRAGGEDRIGHT
, _T("raggedright"), 0);
2384 AddMacroDef(ltRBRACERAW
, _T("rbraceraw"), 0);
2385 AddMacroDef(ltREF
, _T("ref"), 1);
2386 AddMacroDef(ltREGISTERED
, _T("registered"), 0);
2387 AddMacroDef(ltRE
, _T("we"), 0);
2388 AddMacroDef(ltRHO
, _T("rho"), 0);
2389 AddMacroDef(ltRIGHTARROW
, _T("rightarrow"), 0);
2390 AddMacroDef(ltRIGHTARROW2
, _T("rightarrow2"), 0);
2391 AddMacroDef(ltRMFAMILY
, _T("rmfamily"), 1);
2392 AddMacroDef(ltRM
, _T("rm"), 1);
2393 AddMacroDef(ltROMAN
, _T("roman"), 1);
2394 AddMacroDef(ltROMAN2
, _T("Roman"), 1);
2395 // AddMacroDef(lt"row", 1);
2396 AddMacroDef(ltRTFSP
, _T("rtfsp"), 0);
2397 AddMacroDef(ltRTFIGNORE
, _T("rtfignore"), 1);
2398 AddMacroDef(ltRTFONLY
, _T("rtfonly"), 1);
2399 AddMacroDef(ltRULEDROW
, _T("ruledrow"), 1);
2400 AddMacroDef(ltDRULED
, _T("druled"), 1);
2401 AddMacroDef(ltRULE
, _T("rule"), 2);
2402 AddMacroDef(ltRHEAD
, _T("rhead"), 1);
2403 AddMacroDef(ltRFOOT
, _T("rfoot"), 1);
2404 AddMacroDef(ltROW
, _T("row"), 1);
2406 AddMacroDef(ltSCSHAPE
, _T("scshape"), 1);
2407 AddMacroDef(ltSC
, _T("sc"), 1);
2408 AddMacroDef(ltSECTIONHEADING
, _T("sectionheading"), 1);
2409 AddMacroDef(ltSECTIONSTAR
, _T("section*"), 1);
2410 AddMacroDef(ltSECTION
, _T("section"), 1);
2411 AddMacroDef(ltSETCOUNTER
, _T("setcounter"), 2);
2412 AddMacroDef(ltSFFAMILY
, _T("sffamily"), 1);
2413 AddMacroDef(ltSF
, _T("sf"), 1);
2414 AddMacroDef(ltSHARP
, _T("sharp"), 0);
2415 AddMacroDef(ltSHORTCITE
, _T("shortcite"), 1);
2416 AddMacroDef(ltSIGMA
, _T("sigma"), 0);
2417 AddMacroDef(ltCAP_SIGMA
, _T("Sigma"), 0);
2418 AddMacroDef(ltSIM
, _T("sim"), 0);
2419 AddMacroDef(ltSIMEQ
, _T("simeq"), 0);
2420 AddMacroDef(ltSINGLESPACE
, _T("singlespace"), 1);
2421 AddMacroDef(ltSIZEDBOX
, _T("sizedbox"), 2);
2422 AddMacroDef(ltSIZEDBOXD
, _T("sizedboxd"), 2);
2423 AddMacroDef(ltSLOPPYPAR
, _T("sloppypar"), 1);
2424 AddMacroDef(ltSLOPPY
, _T("sloppy"), 0);
2425 AddMacroDef(ltSLSHAPE
, _T("slshape"), 1);
2426 AddMacroDef(ltSL
, _T("sl"), 1);
2427 AddMacroDef(ltSMALL
, _T("small"), 1);
2428 AddMacroDef(ltSMILE
, _T("smile"), 0);
2429 AddMacroDef(ltSS
, _T("ss"), 0);
2430 AddMacroDef(ltSTAR
, _T("star"), 0);
2431 AddMacroDef(ltSUBITEM
, _T("subitem"), 0);
2432 AddMacroDef(ltSUBPARAGRAPHSTAR
, _T("subparagraph*"), 1);
2433 AddMacroDef(ltSUBPARAGRAPH
, _T("subparagraph"), 1);
2434 AddMacroDef(ltSPECIAL
, _T("special"), 1);
2435 AddMacroDef(ltSUBSECTIONSTAR
, _T("subsection*"), 1);
2436 AddMacroDef(ltSUBSECTION
, _T("subsection"), 1);
2437 AddMacroDef(ltSUBSETEQ
, _T("subseteq"), 0);
2438 AddMacroDef(ltSUBSET
, _T("subset"), 0);
2439 AddMacroDef(ltSUCC
, _T("succ"), 0);
2440 AddMacroDef(ltSUCCEQ
, _T("succeq"), 0);
2441 AddMacroDef(ltSUPSETEQ
, _T("supseteq"), 0);
2442 AddMacroDef(ltSUPSET
, _T("supset"), 0);
2443 AddMacroDef(ltSUBSUBSECTIONSTAR
, _T("subsubsection*"), 1);
2444 AddMacroDef(ltSUBSUBSECTION
, _T("subsubsection"), 1);
2445 AddMacroDef(ltSUPERTABULAR
, _T("supertabular"), 2, false);
2446 AddMacroDef(ltSURD
, _T("surd"), 0);
2447 AddMacroDef(ltSCRIPTSIZE
, _T("scriptsize"), 1);
2448 AddMacroDef(ltSETHEADER
, _T("setheader"), 6);
2449 AddMacroDef(ltSETFOOTER
, _T("setfooter"), 6);
2450 AddMacroDef(ltSETHOTSPOTCOLOUR
, _T("sethotspotcolour"), 1);
2451 AddMacroDef(ltSETHOTSPOTCOLOR
, _T("sethotspotcolor"), 1);
2452 AddMacroDef(ltSETHOTSPOTUNDERLINE
, _T("sethotspotunderline"), 1);
2453 AddMacroDef(ltSETTRANSPARENCY
, _T("settransparency"), 1);
2454 AddMacroDef(ltSPADESUIT
, _T("spadesuit"), 0);
2456 AddMacroDef(ltTABBING
, _T("tabbing"), 2);
2457 AddMacroDef(ltTABLEOFCONTENTS
, _T("tableofcontents"), 0);
2458 AddMacroDef(ltTABLE
, _T("table"), 1);
2459 AddMacroDef(ltTABULAR
, _T("tabular"), 2, false);
2460 AddMacroDef(ltTAB
, _T("tab"), 0);
2461 AddMacroDef(ltTAU
, _T("tau"), 0);
2462 AddMacroDef(ltTEXTRM
, _T("textrm"), 1);
2463 AddMacroDef(ltTEXTSF
, _T("textsf"), 1);
2464 AddMacroDef(ltTEXTTT
, _T("texttt"), 1);
2465 AddMacroDef(ltTEXTBF
, _T("textbf"), 1);
2466 AddMacroDef(ltTEXTIT
, _T("textit"), 1);
2467 AddMacroDef(ltTEXTSL
, _T("textsl"), 1);
2468 AddMacroDef(ltTEXTSC
, _T("textsc"), 1);
2469 AddMacroDef(ltTEXTWIDTH
, _T("textwidth"), 1);
2470 AddMacroDef(ltTEXTHEIGHT
, _T("textheight"), 1);
2471 AddMacroDef(ltTEXTCOLOUR
, _T("textcolour"), 1);
2472 AddMacroDef(ltTEX
, _T("TeX"), 0);
2473 AddMacroDef(ltTHEBIBLIOGRAPHY
, _T("thebibliography"), 2);
2474 AddMacroDef(ltTHETA
, _T("theta"), 0);
2475 AddMacroDef(ltTIMES
, _T("times"), 0);
2476 AddMacroDef(ltCAP_THETA
, _T("Theta"), 0);
2477 AddMacroDef(ltTITLEPAGE
, _T("titlepage"), 1);
2478 AddMacroDef(ltTITLE
, _T("title"), 1);
2479 AddMacroDef(ltTINY
, _T("tiny"), 1);
2480 AddMacroDef(ltTODAY
, _T("today"), 0);
2481 AddMacroDef(ltTOPMARGIN
, _T("topmargin"), 1);
2482 AddMacroDef(ltTOPSKIP
, _T("topskip"), 1);
2483 AddMacroDef(ltTRIANGLE
, _T("triangle"), 0);
2484 AddMacroDef(ltTTFAMILY
, _T("ttfamily"), 1);
2485 AddMacroDef(ltTT
, _T("tt"), 1);
2486 AddMacroDef(ltTYPEIN
, _T("typein"), 1);
2487 AddMacroDef(ltTYPEOUT
, _T("typeout"), 1);
2488 AddMacroDef(ltTWOCOLWIDTHA
, _T("twocolwidtha"), 1);
2489 AddMacroDef(ltTWOCOLWIDTHB
, _T("twocolwidthb"), 1);
2490 AddMacroDef(ltTWOCOLSPACING
, _T("twocolspacing"), 1);
2491 AddMacroDef(ltTWOCOLITEMRULED
, _T("twocolitemruled"), 2);
2492 AddMacroDef(ltTWOCOLITEM
, _T("twocolitem"), 2);
2493 AddMacroDef(ltTWOCOLLIST
, _T("twocollist"), 1);
2494 AddMacroDef(ltTWOCOLUMN
, _T("twocolumn"), 0);
2495 AddMacroDef(ltTHEPAGE
, _T("thepage"), 0);
2496 AddMacroDef(ltTHECHAPTER
, _T("thechapter"), 0);
2497 AddMacroDef(ltTHESECTION
, _T("thesection"), 0);
2498 AddMacroDef(ltTHISPAGESTYLE
, _T("thispagestyle"), 1);
2500 AddMacroDef(ltUNDERLINE
, _T("underline"), 1);
2501 AddMacroDef(ltUPSILON
, _T("upsilon"), 0);
2502 AddMacroDef(ltCAP_UPSILON
, _T("Upsilon"), 0);
2503 AddMacroDef(ltUPARROW
, _T("uparrow"), 0);
2504 AddMacroDef(ltUPARROW2
, _T("Uparrow"), 0);
2505 AddMacroDef(ltUPPERCASE
, _T("uppercase"), 1);
2506 AddMacroDef(ltUPSHAPE
, _T("upshape"), 1);
2507 AddMacroDef(ltURLREF
, _T("urlref"), 2);
2508 AddMacroDef(ltUSEPACKAGE
, _T("usepackage"), 1);
2510 AddMacroDef(ltVAREPSILON
, _T("varepsilon"), 0);
2511 AddMacroDef(ltVARPHI
, _T("varphi"), 0);
2512 AddMacroDef(ltVARPI
, _T("varpi"), 0);
2513 AddMacroDef(ltVARRHO
, _T("varrho"), 0);
2514 AddMacroDef(ltVARSIGMA
, _T("varsigma"), 0);
2515 AddMacroDef(ltVARTHETA
, _T("vartheta"), 0);
2516 AddMacroDef(ltVDOTS
, _T("vdots"), 0);
2517 AddMacroDef(ltVEE
, _T("vee"), 0);
2518 AddMacroDef(ltVERBATIMINPUT
, _T("verbatiminput"), 1);
2519 AddMacroDef(ltVERBATIM
, _T("verbatim"), 1);
2520 AddMacroDef(ltVERBSTAR
, _T("verb*"), 1);
2521 AddMacroDef(ltVERB
, _T("verb"), 1);
2522 AddMacroDef(ltVERSE
, _T("verse"), 1);
2523 AddMacroDef(ltVFILL
, _T("vfill"), 0);
2524 AddMacroDef(ltVLINE
, _T("vline"), 0);
2525 AddMacroDef(ltVOID
, _T("void"), 0);
2526 AddMacroDef(ltVDASH
, _T("vdash"), 0);
2527 AddMacroDef(ltVRULE
, _T("vrule"), 0);
2528 AddMacroDef(ltVSPACESTAR
, _T("vspace*"), 1);
2529 AddMacroDef(ltVSKIPSTAR
, _T("vskip*"), 1);
2530 AddMacroDef(ltVSPACE
, _T("vspace"), 1);
2531 AddMacroDef(ltVSKIP
, _T("vskip"), 1);
2533 AddMacroDef(ltWEDGE
, _T("wedge"), 0);
2534 AddMacroDef(ltWXCLIPS
, _T("wxclips"), 0);
2535 AddMacroDef(ltWINHELPIGNORE
, _T("winhelpignore"), 1);
2536 AddMacroDef(ltWINHELPONLY
, _T("winhelponly"), 1);
2537 AddMacroDef(ltWP
, _T("wp"), 0);
2539 AddMacroDef(ltXI
, _T("xi"), 0);
2540 AddMacroDef(ltCAP_XI
, _T("Xi"), 0);
2541 AddMacroDef(ltXLPIGNORE
, _T("xlpignore"), 1);
2542 AddMacroDef(ltXLPONLY
, _T("xlponly"), 1);
2544 AddMacroDef(ltZETA
, _T("zeta"), 0);
2546 AddMacroDef(ltSPACE
, _T(" "), 0);
2547 AddMacroDef(ltBACKSLASHCHAR
, _T("\\"), 0);
2548 AddMacroDef(ltPIPE
, _T("|"), 0);
2549 AddMacroDef(ltFORWARDSLASH
, _T("/"), 0);
2550 AddMacroDef(ltUNDERSCORE
, _T("_"), 0);
2551 AddMacroDef(ltAMPERSAND
, _T("&"), 0);
2552 AddMacroDef(ltPERCENT
, _T("%"), 0);
2553 AddMacroDef(ltDOLLAR
, _T("$"), 0);
2554 AddMacroDef(ltHASH
, _T("#"), 0);
2555 AddMacroDef(ltLPARENTH
, _T("("), 0);
2556 AddMacroDef(ltRPARENTH
, _T(")"), 0);
2557 AddMacroDef(ltLBRACE
, _T("{"), 0);
2558 AddMacroDef(ltRBRACE
, _T("}"), 0);
2559 // AddMacroDef(ltEQUALS, _T("="), 0);
2560 AddMacroDef(ltRANGLEBRA
, _T(">"), 0);
2561 AddMacroDef(ltLANGLEBRA
, _T("<"), 0);
2562 AddMacroDef(ltPLUS
, _T("+"), 0);
2563 AddMacroDef(ltDASH
, _T("-"), 0);
2564 AddMacroDef(ltAT_SYMBOL
, _T("@"), 0);
2565 // AddMacroDef(ltSINGLEQUOTE, _T("'"), 0);
2566 // AddMacroDef(ltBACKQUOTE, _T("`"), 0);
2570 * Default behaviour, should be called by client if can't match locally.
2574 // Called on start/end of macro examination
2575 void DefaultOnMacro(int macroId
, int no_args
, bool start
)
2579 // Default behaviour for abstract
2584 // Write the heading
2585 FakeCurrentSection(AbstractNameString
);
2586 OnMacro(ltPAR
, 0, true);
2587 OnMacro(ltPAR
, 0, false);
2591 if (DocumentStyle
== LATEX_ARTICLE
)
2599 // Default behaviour for glossary
2600 case ltHELPGLOSSARY
:
2604 // Write the heading
2605 FakeCurrentSection(GlossaryNameString
);
2606 OnMacro(ltPAR
, 0, true);
2607 OnMacro(ltPAR
, 0, false);
2608 if ((convertMode
== TEX_RTF
) && !winHelp
)
2610 OnMacro(ltPAR
, 0, true);
2611 OnMacro(ltPAR
, 0, false);
2616 case ltSPECIALAMPERSAND
:
2623 TexOutput(_T("<<"), true);
2627 TexOutput(_T(">>"), true);
2631 TexOutput(_T("~"), true);
2635 TexOutput(_T("~"), true);
2637 case ltSPECIALTILDE
:
2639 TexOutput(_T(" "), true);
2643 TexOutput(_T("_"), true);
2647 TexOutput(_T("#"), true);
2651 TexOutput(_T("&"), true);
2655 TexOutput(_T(" "), true);
2659 TexOutput(_T("|"), true);
2663 TexOutput(_T("%"), true);
2667 TexOutput(_T("$"), true);
2671 TexOutput(_T(""), true);
2675 TexOutput(_T(""), true);
2679 TexOutput(_T("{"), true);
2683 TexOutput(_T("}"), true);
2687 TexOutput(_T("(c)"), true);
2691 TexOutput(_T("(r)"), true);
2695 TexOutput(_T("\\"), true);
2700 TexOutput(_T("..."), true);
2704 TexOutput(_T("|"), true);
2708 TexOutput(_T("LaTeX"), true);
2712 TexOutput(_T("TeX"), true);
2716 TexOutput(_T("£"), true);
2718 case ltSPECIALDOUBLEDOLLAR
: // Interpret as center
2719 OnMacro(ltCENTER
, no_args
, start
);
2725 OnMacro(ltIT
, no_args
, start
);
2728 case ltPARAGRAPHSTAR
:
2729 case ltSUBPARAGRAPH
:
2730 case ltSUBPARAGRAPHSTAR
:
2731 OnMacro(ltSUBSUBSECTION
, no_args
, start
);
2739 TexOutput(wxCtime(&when
), true);
2750 if (start
) TexOutput(_T("alpha"));
2753 if (start
) TexOutput(_T("beta"));
2756 if (start
) TexOutput(_T("gamma"));
2759 if (start
) TexOutput(_T("delta"));
2763 if (start
) TexOutput(_T("epsilon"));
2766 if (start
) TexOutput(_T("zeta"));
2769 if (start
) TexOutput(_T("eta"));
2773 if (start
) TexOutput(_T("theta"));
2776 if (start
) TexOutput(_T("iota"));
2779 if (start
) TexOutput(_T("kappa"));
2782 if (start
) TexOutput(_T("lambda"));
2785 if (start
) TexOutput(_T("mu"));
2788 if (start
) TexOutput(_T("nu"));
2791 if (start
) TexOutput(_T("xi"));
2795 if (start
) TexOutput(_T("pi"));
2799 if (start
) TexOutput(_T("rho"));
2803 if (start
) TexOutput(_T("sigma"));
2806 if (start
) TexOutput(_T("tau"));
2809 if (start
) TexOutput(_T("upsilon"));
2813 if (start
) TexOutput(_T("phi"));
2816 if (start
) TexOutput(_T("chi"));
2819 if (start
) TexOutput(_T("psi"));
2822 if (start
) TexOutput(_T("omega"));
2825 if (start
) TexOutput(_T("GAMMA"));
2828 if (start
) TexOutput(_T("DELTA"));
2831 if (start
) TexOutput(_T("THETA"));
2834 if (start
) TexOutput(_T("LAMBDA"));
2837 if (start
) TexOutput(_T("XI"));
2840 if (start
) TexOutput(_T("PI"));
2843 if (start
) TexOutput(_T("SIGMA"));
2846 if (start
) TexOutput(_T("UPSILON"));
2849 if (start
) TexOutput(_T("PHI"));
2852 if (start
) TexOutput(_T("PSI"));
2855 if (start
) TexOutput(_T("OMEGA"));
2858 // Binary operation symbols
2861 if (start
) TexOutput(_T("<="));
2864 if (start
) TexOutput(_T("<<"));
2867 if (start
) TexOutput(_T("SUBSET"));
2870 if (start
) TexOutput(_T("SUBSETEQ"));
2873 if (start
) TexOutput(_T("IN"));
2876 if (start
) TexOutput(_T("VDASH"));
2879 if (start
) TexOutput(_T("MODELS"));
2883 if (start
) TexOutput(_T(">="));
2886 if (start
) TexOutput(_T(">>"));
2889 if (start
) TexOutput(_T("SUPSET"));
2892 if (start
) TexOutput(_T("SUPSETEQ"));
2895 if (start
) TexOutput(_T("NI"));
2898 if (start
) TexOutput(_T("DASHV"));
2901 if (start
) TexOutput(_T("PERP"));
2904 if (start
) TexOutput(_T("NEQ"));
2907 if (start
) TexOutput(_T("DOTEQ"));
2910 if (start
) TexOutput(_T("APPROX"));
2913 if (start
) TexOutput(_T("CONG"));
2916 if (start
) TexOutput(_T("EQUIV"));
2919 if (start
) TexOutput(_T("PROPTO"));
2922 if (start
) TexOutput(_T("PREC"));
2925 if (start
) TexOutput(_T("PRECEQ"));
2928 if (start
) TexOutput(_T("|"));
2931 if (start
) TexOutput(_T("~"));
2934 if (start
) TexOutput(_T("SIMEQ"));
2937 if (start
) TexOutput(_T("ASYMP"));
2940 if (start
) TexOutput(_T(":-)"));
2943 if (start
) TexOutput(_T(":-("));
2946 if (start
) TexOutput(_T("SUCC"));
2949 if (start
) TexOutput(_T("SUCCEQ"));
2952 if (start
) TexOutput(_T("|"));
2955 // Negated relation symbols
2957 if (start
) TexOutput(_T("!="));
2960 if (start
) TexOutput(_T("NOTIN"));
2963 if (start
) TexOutput(_T("NOTSUBSET"));
2968 if (start
) TexOutput(_T("<--"));
2971 if (start
) TexOutput(_T("<=="));
2974 if (start
) TexOutput(_T("-->"));
2977 if (start
) TexOutput(_T("==>"));
2979 case ltLEFTRIGHTARROW
:
2980 if (start
) TexOutput(_T("<-->"));
2982 case ltLEFTRIGHTARROW2
:
2983 if (start
) TexOutput(_T("<==>"));
2986 if (start
) TexOutput(_T("UPARROW"));
2989 if (start
) TexOutput(_T("UPARROW2"));
2992 if (start
) TexOutput(_T("DOWNARROW"));
2995 if (start
) TexOutput(_T("DOWNARROW2"));
2997 // Miscellaneous symbols
2999 if (start
) TexOutput(_T("ALEPH"));
3002 if (start
) TexOutput(_T("WP"));
3005 if (start
) TexOutput(_T("RE"));
3008 if (start
) TexOutput(_T("IM"));
3011 if (start
) TexOutput(_T("EMPTYSET"));
3014 if (start
) TexOutput(_T("NABLA"));
3017 if (start
) TexOutput(_T("SURD"));
3020 if (start
) TexOutput(_T("PARTIAL"));
3023 if (start
) TexOutput(_T("BOT"));
3026 if (start
) TexOutput(_T("FORALL"));
3029 if (start
) TexOutput(_T("EXISTS"));
3032 if (start
) TexOutput(_T("NEG"));
3035 if (start
) TexOutput(_T("SHARP"));
3038 if (start
) TexOutput(_T("ANGLE"));
3041 if (start
) TexOutput(_T("TRIANGLE"));
3044 if (start
) TexOutput(_T("CLUBSUIT"));
3047 if (start
) TexOutput(_T("DIAMONDSUIT"));
3050 if (start
) TexOutput(_T("HEARTSUIT"));
3053 if (start
) TexOutput(_T("SPADESUIT"));
3056 if (start
) TexOutput(_T("INFTY"));
3059 if (start
) TexOutput(_T("PM"));
3062 if (start
) TexOutput(_T("MP"));
3065 if (start
) TexOutput(_T("TIMES"));
3068 if (start
) TexOutput(_T("DIV"));
3071 if (start
) TexOutput(_T("CDOT"));
3074 if (start
) TexOutput(_T("AST"));
3077 if (start
) TexOutput(_T("STAR"));
3080 if (start
) TexOutput(_T("CAP"));
3083 if (start
) TexOutput(_T("CUP"));
3086 if (start
) TexOutput(_T("VEE"));
3089 if (start
) TexOutput(_T("WEDGE"));
3092 if (start
) TexOutput(_T("CIRC"));
3095 if (start
) TexOutput(_T("BULLET"));
3098 if (start
) TexOutput(_T("DIAMOND"));
3101 if (start
) TexOutput(_T("OSLASH"));
3104 if (start
) TexOutput(_T("BOX"));
3107 if (start
) TexOutput(_T("DIAMOND2"));
3109 case ltBIGTRIANGLEDOWN
:
3110 if (start
) TexOutput(_T("BIGTRIANGLEDOWN"));
3113 if (start
) TexOutput(_T("OPLUS"));
3116 if (start
) TexOutput(_T("OTIMES"));
3119 if (start
) TexOutput(_T("s"));
3121 case ltBACKSLASHRAW
:
3122 if (start
) TexOutput(_T("\\"));
3125 if (start
) TexOutput(_T("{"));
3128 if (start
) TexOutput(_T("}"));
3132 if (start
) TexOutput(_T(" "));
3139 // Called on start/end of argument examination
3140 bool DefaultOnArgument(int macroId
, int arg_no
, bool start
)
3146 if (arg_no
== 1 && start
)
3148 wxChar
*refName
= GetArgData();
3151 TexRef
*texRef
= FindReference(refName
);
3154 // Must strip the 'section' or 'chapter' or 'figure' text
3155 // from a normal 'ref' reference
3157 wxStrcpy(buf
, texRef
->sectionNumber
);
3158 int len
= wxStrlen(buf
);
3160 if (wxStrcmp(buf
, _T("??")) != 0)
3172 TexOutput(texRef
->sectionNumber
+ i
, true);
3177 informBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
3178 OnInform((wxChar
*)informBuf
.c_str());
3181 else TexOutput(_T("??"), true);
3192 if (start
&& (arg_no
== 1))
3193 DocumentAuthor
= GetArgChunk();
3198 if (start
&& (arg_no
== 1))
3199 DocumentDate
= GetArgChunk();
3204 if (start
&& (arg_no
== 1))
3205 DocumentTitle
= GetArgChunk();
3208 case ltDOCUMENTCLASS
:
3209 case ltDOCUMENTSTYLE
:
3211 if (start
&& !IsArgOptional())
3213 DocumentStyleString
= copystring(GetArgData());
3214 if (wxStrncmp(DocumentStyleString
, _T("art"), 3) == 0)
3215 DocumentStyle
= LATEX_ARTICLE
;
3216 else if (wxStrncmp(DocumentStyleString
, _T("rep"), 3) == 0)
3217 DocumentStyle
= LATEX_REPORT
;
3218 else if (wxStrncmp(DocumentStyleString
, _T("book"), 4) == 0 ||
3219 wxStrncmp(DocumentStyleString
, _T("thesis"), 6) == 0)
3220 DocumentStyle
= LATEX_BOOK
;
3221 else if (wxStrncmp(DocumentStyleString
, _T("letter"), 6) == 0)
3222 DocumentStyle
= LATEX_LETTER
;
3223 else if (wxStrncmp(DocumentStyleString
, _T("slides"), 6) == 0)
3224 DocumentStyle
= LATEX_SLIDES
;
3226 if (StringMatch(_T("10"), DocumentStyleString
))
3228 else if (StringMatch(_T("11"), DocumentStyleString
))
3230 else if (StringMatch(_T("12"), DocumentStyleString
))
3233 OnMacro(ltHELPFONTSIZE
, 1, true);
3234 wxSnprintf(currentArgData
, 2000, _T("%d"), normalFont
);
3236 OnArgument(ltHELPFONTSIZE
, 1, true);
3237 OnArgument(ltHELPFONTSIZE
, 1, false);
3238 haveArgData
= false;
3239 OnMacro(ltHELPFONTSIZE
, 1, false);
3241 else if (start
&& IsArgOptional())
3243 MinorDocumentStyleString
= copystring(GetArgData());
3245 if (StringMatch(_T("10"), MinorDocumentStyleString
))
3247 else if (StringMatch(_T("11"), MinorDocumentStyleString
))
3249 else if (StringMatch(_T("12"), MinorDocumentStyleString
))
3254 case ltBIBLIOGRAPHYSTYLE
:
3256 if (start
&& !IsArgOptional())
3257 BibliographyStyleString
= copystring(GetArgData());
3262 if (start
&& !IsArgOptional())
3264 if (PageStyle
) delete[] PageStyle
;
3265 PageStyle
= copystring(GetArgData());
3272 if (start && !IsArgOptional())
3273 LeftHeader = GetArgChunk();
3279 if (start && !IsArgOptional())
3280 LeftFooter = GetArgChunk();
3286 if (start && !IsArgOptional())
3287 CentreHeader = GetArgChunk();
3293 if (start && !IsArgOptional())
3294 CentreFooter = GetArgChunk();
3300 if (start && !IsArgOptional())
3301 RightHeader = GetArgChunk();
3307 if (start && !IsArgOptional())
3308 RightFooter = GetArgChunk();
3316 if (start
&& !IsArgOptional())
3318 wxChar
*citeKeys
= GetArgData();
3320 wxChar
*citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3323 AddCitation(citeKey
);
3324 TexRef
*ref
= FindReference(citeKey
);
3327 TexOutput(ref
->sectionNumber
, true);
3328 if (wxStrcmp(ref
->sectionNumber
, _T("??")) == 0)
3331 informBuf
.Printf(_T("Warning: unresolved citation %s."), citeKey
);
3332 OnInform((wxChar
*)informBuf
.c_str());
3335 citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3338 TexOutput(_T(", "), true);
3347 if (start
&& !IsArgOptional())
3349 wxChar
*citeKey
= GetArgData();
3350 AddCitation(citeKey
);
3355 case ltHELPFONTSIZE
:
3359 wxChar
*data
= GetArgData();
3360 if (wxStrcmp(data
, _T("10")) == 0)
3362 else if (wxStrcmp(data
, _T("11")) == 0)
3364 else if (wxStrcmp(data
, _T("12")) == 0)
3374 TexOutput(_T(" ??"), true);
3381 if (start
&& arg_no
== 1)
3383 wxChar
*data
= GetArgData();
3384 ParSkip
= ParseUnitArgument(data
);
3391 if (start
&& arg_no
== 1)
3393 wxChar
*data
= GetArgData();
3394 ParIndent
= ParseUnitArgument(data
);
3401 return OnArgument(ltIT
, arg_no
, start
);
3403 case ltSPECIALDOUBLEDOLLAR
:
3405 return OnArgument(ltCENTER
, arg_no
, start
);
3408 case ltPARAGRAPHSTAR
:
3409 case ltSUBPARAGRAPH
:
3410 case ltSUBPARAGRAPHSTAR
:
3412 return OnArgument(ltSUBSUBSECTION
, arg_no
, start
);
3417 OnInform(GetArgData());
3423 TexOutput(_T(" ("), true);
3425 TexOutput(_T(")"), true);
3428 case ltBIBLIOGRAPHY
:
3435 FILE *fd
= wxFopen(TexBibName
, _T("r"));
3442 TexOutput(smallBuf
);
3450 OnInform(_T("Run Tex2RTF again to include bibliography."));
3453 // Read in the .bib file, resolve all known references, write out the RTF.
3454 wxChar
*allFiles
= GetArgData();
3456 wxChar
*bibFile
= ParseMultifieldString(allFiles
, &pos
);
3459 wxChar fileBuf
[300];
3460 wxStrcpy(fileBuf
, bibFile
);
3461 wxString actualFile
= TexPathList
.FindValidPath(fileBuf
);
3462 if (actualFile
== _T(""))
3464 wxStrcat(fileBuf
, _T(".bib"));
3465 actualFile
= TexPathList
.FindValidPath(fileBuf
);
3467 if (actualFile
!= _T(""))
3469 if (!ReadBib((wxChar
*) (const wxChar
*) actualFile
))
3472 errBuf
.Printf(_T(".bib file %s not found or malformed"), (const wxChar
*) actualFile
);
3473 OnError((wxChar
*)errBuf
.c_str());
3479 errBuf
.Printf(_T(".bib file %s not found"), fileBuf
);
3480 OnError((wxChar
*)errBuf
.c_str());
3482 bibFile
= ParseMultifieldString(allFiles
, &pos
);
3485 ResolveBibReferences();
3487 // Write it a new bib section in the appropriate format.
3488 FILE *save1
= CurrentOutput1
;
3489 FILE *save2
= CurrentOutput2
;
3490 FILE *Biblio
= wxFopen(TexTmpBibName
, _T("w"));
3491 SetCurrentOutput(Biblio
);
3494 if (wxFileExists(TexTmpBibName
))
3496 if (wxFileExists(TexBibName
)) wxRemoveFile(TexBibName
);
3497 wxRenameFile(TexTmpBibName
, TexBibName
);
3499 SetCurrentOutputs(save1
, save2
);
3505 return (start
&& (arg_no
== 3));
3510 if (start
&& (arg_no
== 1))
3512 wxChar
*s
= GetArgData();
3515 wxChar
*s1
= copystring(s
);
3517 for (i
= 0; i
< (int)wxStrlen(s
); i
++)
3518 s1
[i
] = wxToupper(s
[i
]);
3530 if (start
&& (arg_no
== 1))
3532 wxChar
*s
= GetArgData();
3535 wxChar
*s1
= copystring(s
);
3537 for (i
= 0; i
< (int)wxStrlen(s
); i
++)
3538 s1
[i
] = wxTolower(s
[i
]);
3550 if (start
&& (arg_no
== 1))
3552 wxChar
*s
= GetArgData();
3555 wxChar
*s1
= copystring(s
);
3557 for (i
= 0; i
< (int)wxStrlen(s
); i
++)
3558 s1
[i
] = wxToupper(s
[i
]);
3568 case ltPOPREF
: // Ignore second argument by default
3569 return (start
&& (arg_no
== 1));
3573 return ((convertMode
== TEX_XLP
) ? false : true);
3575 return ((convertMode
!= TEX_XLP
) ? false : true);
3577 return ((convertMode
== TEX_HTML
) ? false : true);
3579 return ((convertMode
!= TEX_HTML
) ? false : true);
3581 return (((convertMode
== TEX_RTF
) && !winHelp
) ? false : true);
3583 return (!((convertMode
== TEX_RTF
) && !winHelp
) ? false : true);
3584 case ltWINHELPIGNORE
:
3585 return (winHelp
? false : true);
3587 return (!winHelp
? false : true);
3599 case ltADDTOCOUNTER
:
3600 case ltADDCONTENTSLINE
:
3604 case ltBASELINESKIP
:
3613 case ltPAGENUMBERING
:
3625 case ltTHISPAGESTYLE
:
3628 case ltEVENSIDEMARGIN
:
3629 case ltODDSIDEMARGIN
:
3631 case ltMARGINPARWIDTH
:
3632 case ltMARGINPARSEP
:
3633 case ltMARGINPAREVEN
:
3634 case ltMARGINPARODD
:
3635 case ltTWOCOLWIDTHA
:
3636 case ltTWOCOLWIDTHB
:
3637 case ltTWOCOLSPACING
:
3644 case ltSETHOTSPOTCOLOUR
:
3645 case ltSETHOTSPOTCOLOR
:
3646 case ltSETHOTSPOTUNDERLINE
:
3647 case ltSETTRANSPARENCY
:
3650 case ltBACKGROUNDCOLOUR
:
3651 case ltBACKGROUNDIMAGE
:
3653 case ltFOLLOWEDLINKCOLOUR
:
3660 case ltINSERTATLEVEL
:
3663 case ltSUPERTABULAR
:
3667 return (arg_no
== 2);
3668 case ltDEFINECOLOUR
:
3671 static int redVal
= 0;
3672 static int greenVal
= 0;
3673 static int blueVal
= 0;
3674 static wxChar
*colourName
= NULL
;
3681 if (colourName
) delete[] colourName
;
3682 colourName
= copystring(GetArgData());
3687 redVal
= wxAtoi(GetArgData());
3692 greenVal
= wxAtoi(GetArgData());
3697 blueVal
= wxAtoi(GetArgData());
3698 AddColour(colourName
, redVal
, greenVal
, blueVal
);
3712 return (!IsArgOptional());