1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Utilities for Latex conversion.
4 // Author: Julian Smart
5 // Modified by: Wlodzimierz ABX Skiba 2003/2004 Unicode support
9 // Copyright: (c) Julian Smart
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 // For compilers that support precompilation, includes "wx.h".
14 #include "wx/wxprec.h"
28 static inline wxChar
* copystring(const wxChar
* s
)
29 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
32 * Variables accessible from clients
36 TexChunk
* DocumentTitle
= NULL
;
37 TexChunk
* DocumentAuthor
= NULL
;
38 TexChunk
* DocumentDate
= NULL
;
40 // Header/footers/pagestyle
41 TexChunk
* LeftHeaderEven
= NULL
;
42 TexChunk
* LeftFooterEven
= NULL
;
43 TexChunk
* CentreHeaderEven
= NULL
;
44 TexChunk
* CentreFooterEven
= NULL
;
45 TexChunk
* RightHeaderEven
= NULL
;
46 TexChunk
* RightFooterEven
= NULL
;
47 TexChunk
* LeftHeaderOdd
= NULL
;
48 TexChunk
* LeftFooterOdd
= NULL
;
49 TexChunk
* CentreHeaderOdd
= NULL
;
50 TexChunk
* CentreFooterOdd
= NULL
;
51 TexChunk
* RightHeaderOdd
= NULL
;
52 TexChunk
* RightFooterOdd
= NULL
;
53 wxChar
* PageStyle
= copystring(_T("plain"));
55 int DocumentStyle
= LATEX_REPORT
;
56 int MinorDocumentStyle
= 0;
57 wxPathList TexPathList
;
58 wxChar
* BibliographyStyleString
= copystring(_T("plain"));
59 wxChar
* DocumentStyleString
= copystring(_T("report"));
60 wxChar
* MinorDocumentStyleString
= NULL
;
74 // All of these tokens MUST be found on a line by themselves (no other
75 // text) and must start at the first character of the line, or tex2rtf
76 // will fail to process them correctly (a limitation of tex2rtf, not TeX)
77 static const wxString syntaxTokens
[] =
78 { _T("\\begin{verbatim}"),
79 _T("\\begin{toocomplex}"),
80 _T("\\end{verbatim}"),
81 _T("\\end{toocomplex}"),
83 _T("\\begin{comment}"),
85 _T("\\verbatiminput"),
95 * USER-ADJUSTABLE SETTINGS
100 int chapterFont
= 12; // LARGEFont3;
101 int sectionFont
= 12; // LargeFont2;
102 int subsectionFont
= 12; // largeFont1;
103 int titleFont
= LARGEFont3
;
104 int authorFont
= LargeFont2
;
105 int mirrorMargins
= true;
106 bool winHelp
= false; // Output in Windows Help format if true, linear otherwise
107 bool isInteractive
= false;
108 bool runTwice
= false;
109 int convertMode
= TEX_RTF
;
110 bool checkCurlyBraces
= false;
111 bool checkSyntax
= false;
112 bool headerRule
= false;
113 bool footerRule
= false;
114 bool compatibilityMode
= false; // If true, maximum Latex compatibility
115 // (Quality of RTF generation deteriorate)
116 bool generateHPJ
; // Generate WinHelp Help Project file
117 wxChar
*winHelpTitle
= NULL
; // Windows Help title
118 int defaultTableColumnWidth
= 2000;
120 int labelIndentTab
= 18; // From left indent to item label (points)
121 int itemIndentTab
= 40; // From left indent to item (points)
123 bool useUpButton
= true;
124 int htmlBrowseButtons
= HTML_BUTTONS_TEXT
;
126 bool truncateFilenames
= false; // Truncate for DOS
127 int winHelpVersion
= 3; // WinHelp Version (3 for Windows 3.1, 4 for Win95)
128 bool winHelpContents
= false; // Generate .cnt file for WinHelp 4
129 bool htmlIndex
= false; // Generate .htx file for HTML
130 bool htmlFrameContents
= false; // Use frames for HTML contents page
131 wxChar
*htmlStylesheet
= NULL
; // Use this CSS stylesheet for HTML pages
132 bool useHeadingStyles
= true; // Insert \s1, s2 etc.
133 bool useWord
= true; // Insert proper Word table of contents, etc etc
134 int contentsDepth
= 4; // Depth of Word table of contents
135 bool indexSubsections
= true; // Index subsections in linear RTF
136 // Linear RTF method of including bitmaps. Can be "includepicture", "hex"
137 wxChar
*bitmapMethod
= copystring(_T("includepicture"));
138 bool upperCaseNames
= false;
139 // HTML background and text colours
140 wxChar
*backgroundImageString
= NULL
;
141 wxChar
*backgroundColourString
= copystring(_T("255;255;255"));
142 wxChar
*textColourString
= NULL
;
143 wxChar
*linkColourString
= NULL
;
144 wxChar
*followedLinkColourString
= NULL
;
145 bool combineSubSections
= false;
146 bool htmlWorkshopFiles
= false;
147 bool ignoreBadRefs
= false;
148 wxChar
*htmlFaceName
= NULL
;
150 extern int passNumber
;
152 extern wxHashTable TexReferences
;
155 * International support
158 // Names to help with internationalisation
159 wxChar
*ContentsNameString
= copystring(_T("Contents"));
160 wxChar
*AbstractNameString
= copystring(_T("Abstract"));
161 wxChar
*GlossaryNameString
= copystring(_T("Glossary"));
162 wxChar
*ReferencesNameString
= copystring(_T("References"));
163 wxChar
*FiguresNameString
= copystring(_T("List of Figures"));
164 wxChar
*TablesNameString
= copystring(_T("List of Tables"));
165 wxChar
*FigureNameString
= copystring(_T("Figure"));
166 wxChar
*TableNameString
= copystring(_T("Table"));
167 wxChar
*IndexNameString
= copystring(_T("Index"));
168 wxChar
*ChapterNameString
= copystring(_T("chapter"));
169 wxChar
*SectionNameString
= copystring(_T("section"));
170 wxChar
*SubsectionNameString
= copystring(_T("subsection"));
171 wxChar
*SubsubsectionNameString
= copystring(_T("subsubsection"));
172 wxChar
*UpNameString
= copystring(_T("Up"));
181 int subsectionNo
= 0;
182 int subsubsectionNo
= 0;
191 FILE *CurrentOutput1
= NULL
;
192 FILE *CurrentOutput2
= NULL
;
194 unsigned long LineNumbers
[15];
195 wxChar
*FileNames
[15];
196 int CurrentInputIndex
= 0;
198 wxChar
*TexFileRoot
= NULL
;
199 wxChar
*TexBibName
= NULL
; // Bibliography output file name
200 wxChar
*TexTmpBibName
= NULL
; // Temporary bibliography output file name
201 bool isSync
= false; // If true, should not yield to other processes.
202 bool stopRunning
= false; // If true, should abort.
204 static int currentColumn
= 0;
205 wxChar
*currentArgData
= NULL
;
206 bool haveArgData
= false; // If true, we're simulating the data.
207 TexChunk
*currentArgument
= NULL
;
208 TexChunk
*nextChunk
= NULL
;
209 bool isArgOptional
= false;
212 TexChunk
*TopLevel
= NULL
;
213 // wxList MacroDefs(wxKEY_STRING);
214 wxHashTable
MacroDefs(wxKEY_STRING
);
215 wxStringList IgnorableInputFiles
; // Ignorable \input files, e.g. psbox.tex
216 wxChar
*BigBuffer
= NULL
; // For reading in large chunks of text
217 TexMacroDef
*SoloBlockDef
= NULL
;
218 TexMacroDef
*VerbatimMacroDef
= NULL
;
220 #define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
223 TexRef::TexRef(const wxChar
*label
, const wxChar
*file
,
224 const wxChar
*section
, const wxChar
*sectionN
)
226 refLabel
= copystring(label
);
227 refFile
= file
? copystring(file
) : (wxChar
*) NULL
;
228 sectionNumber
= section
? copystring(section
) : copystring(_T("??"));
229 sectionName
= sectionN
? copystring(sectionN
) : copystring(_T("??"));
232 TexRef::~TexRef(void)
234 delete [] refLabel
; refLabel
= NULL
;
235 delete [] refFile
; refFile
= NULL
;
236 delete [] sectionNumber
; sectionNumber
= NULL
;
237 delete [] sectionName
; sectionName
= NULL
;
241 CustomMacro::~CustomMacro()
249 void TexOutput(const wxString
& s
, bool ordinaryText
)
251 // Update current column, but only if we're guaranteed to
252 // be ordinary text (not mark-up stuff)
255 for (wxString::const_iterator i
= s
.begin(); i
!= s
.end(); ++i
)
257 if (*i
== 13 || *i
== 10)
264 wxFprintf(CurrentOutput1
, _T("%s"), s
);
266 wxFprintf(CurrentOutput2
, _T("%s"), s
);
270 * Try to find a Latex macro, in one of the following forms:
271 * (1) \begin{} ... \end{}
272 * (2) \macroname{arg1}...{argn}
276 void ForbidWarning(TexMacroDef
*def
)
279 switch (def
->forbidden
)
283 informBuf
.Printf(_T("Warning: it is recommended that command %s is not used."), def
->name
);
287 case FORBID_ABSOLUTELY
:
289 informBuf
.Printf(_T("Error: command %s cannot be used and will lead to errors."), def
->name
);
298 TexMacroDef
*MatchMacro(wxChar
*buffer
, int *pos
, wxChar
**env
, bool *parseToBrace
)
300 *parseToBrace
= true;
302 TexMacroDef
*def
= NULL
;
305 // First, try to find begin{thing}
306 if (wxStrncmp(buffer
+i
, _T("begin{"), 6) == 0)
311 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
313 macroBuf
[j
-i
] = buffer
[j
];
317 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
321 *pos
= j
+ 1; // BUGBUG Should this be + 1???
332 // Failed, so try to find macro from definition list
335 // First try getting a one-character macro, but ONLY
336 // if these TWO characters are not both alphabetical (could
337 // be a longer macro)
338 if (!(isalpha(buffer
[i
]) && isalpha(buffer
[i
+1])))
340 macroBuf
[0] = buffer
[i
];
343 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
349 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
351 macroBuf
[j
-i
] = buffer
[j
];
355 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
362 // We want to check whether this is a space-consuming macro
364 // No brace, e.g. \input thing.tex instead of \input{thing};
365 // or a numeric argument, such as \parindent0pt
366 if ((def
->no_args
> 0) && ((buffer
[i
] == 32) || (buffer
[i
] == '=') || (isdigit(buffer
[i
]))))
368 if ((buffer
[i
] == 32) || (buffer
[i
] == '='))
371 *parseToBrace
= false;
380 void EatWhiteSpace(wxChar
*buffer
, int *pos
)
382 int len
= wxStrlen(buffer
);
384 bool keepGoing
= true;
385 bool moreLines
= true;
386 while ((j
< len
) && keepGoing
&&
387 (buffer
[j
] == 10 || buffer
[j
] == 13 || buffer
[j
] == ' ' || buffer
[j
] == 9))
394 moreLines
= read_a_line(buffer
);
395 len
= wxStrlen(buffer
);
405 bool FindEndEnvironment(wxChar
*buffer
, int *pos
, wxChar
*env
)
409 // Try to find end{thing}
410 if ((wxStrncmp(buffer
+i
, _T("end{"), 4) == 0) &&
411 (wxStrncmp(buffer
+i
+4, env
, wxStrlen(env
)) == 0))
413 *pos
= i
+ 5 + wxStrlen(env
);
419 bool readingVerbatim
= false;
420 bool readInVerbatim
= false; // Within a verbatim, but not nec. verbatiminput
422 // Switched this off because e.g. \verb${$ causes it to fail. There is no
423 // detection of \verb yet.
424 // #define CHECK_BRACES 1
426 unsigned long leftCurly
= 0;
427 unsigned long rightCurly
= 0;
428 static wxString currentFileName
= wxEmptyString
;
430 bool read_a_line(wxChar
*buf
)
432 if (CurrentInputIndex
< 0)
439 unsigned long bufIndex
= 0;
443 while (ch
!= EOF
&& ch
!= 10)
445 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
448 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
449 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(), MAX_LINE_BUFFER_SIZE
);
454 if (((bufIndex
== 14) && (wxStrncmp(buf
, _T("\\end{verbatim}"), 14) == 0)) ||
455 ((bufIndex
== 16) && (wxStrncmp(buf
, _T("\\end{toocomplex}"), 16) == 0)))
456 readInVerbatim
= false;
459 ch
= getc(Inputs
[CurrentInputIndex
]);
461 if (checkCurlyBraces
)
463 if (ch
== '{' && !readInVerbatim
&& lastChar
!= _T('\\'))
465 if (ch
== '}' && !readInVerbatim
&& lastChar
!= _T('\\'))
468 if (rightCurly
> leftCurly
)
471 errBuf
.Printf(_T("An extra right Curly brace ('}') was detected at line %lu inside file %s"), LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
474 // Reduce the count of right Curly braces, so the mismatched count
475 // isn't reported on every line that has a '}' after the first mismatch
483 // Check for 2 consecutive newlines and replace with \par
484 if (ch
== 10 && !readInVerbatim
)
486 int ch1
= getc(Inputs
[CurrentInputIndex
]);
487 if ((ch1
== 10) || (ch1
== 13))
489 // Eliminate newline (10) following DOS linefeed
491 getc(Inputs
[CurrentInputIndex
]);
493 IncrementLineNumber();
494 // wxStrcat(buf, "\\par\n");
496 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
499 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
500 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
504 wxStrcat(buf
, _T("\\par"));
510 ungetc(ch1
, Inputs
[CurrentInputIndex
]);
511 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
514 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
515 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
520 buf
[bufIndex
] = (wxChar
)ch
;
527 // Convert embedded characters to RTF equivalents
536 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
539 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
540 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
544 buf
[bufIndex
++]='\\';
549 case 0xf6:buf
[bufIndex
++]='o';break; // ö
550 case 0xe4:buf
[bufIndex
++]='a';break; // ä
551 case 0xfc:buf
[bufIndex
++]='u';break; // ü
552 case 0xd6:buf
[bufIndex
++]='O';break; // Ö
553 case 0xc4:buf
[bufIndex
++]='A';break; // Ä
554 case 0xdc:buf
[bufIndex
++]='U';break; // Ü
559 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
562 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
563 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
567 buf
[bufIndex
++]='\\';
570 buf
[bufIndex
++]='\\';
574 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
577 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
578 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
582 // If the current character read in is a '_', we need to check
583 // whether there should be a '\' before it or not
586 buf
[bufIndex
++] = (wxChar
)ch
;
594 // There should NOT be a '\' before the '_'
595 if ((bufIndex
> 0 && (buf
[bufIndex
-1] == '\\')) && (buf
[0] != '%'))
598 // errBuf.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that should NOT have a '\\' before it."),
599 // LineNumbers[CurrentInputIndex], (const wxChar*) currentFileName.c_str());
605 // There should be a '\' before the '_'
609 errBuf
.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
610 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
613 else if ((buf
[bufIndex
-1] != '\\') && (buf
[0] != '%') && // If it is a comment line, then no warnings
614 (wxStrncmp(buf
, _T("\\input"), 6))) // do not report filenames that have underscores in them
617 errBuf
.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
618 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
623 buf
[bufIndex
++] = (wxChar
)ch
;
631 fclose(Inputs
[CurrentInputIndex
]);
632 Inputs
[CurrentInputIndex
] = NULL
;
633 if (CurrentInputIndex
> 0)
634 ch
= ' '; // No real end of file
635 CurrentInputIndex
--;
637 if (checkCurlyBraces
)
639 if (leftCurly
!= rightCurly
)
642 errBuf
.Printf(_T("Curly braces do not match inside file %s\n%lu opens, %lu closes"),
643 (const wxChar
*) currentFileName
.c_str(),leftCurly
,rightCurly
);
652 readingVerbatim
= false;
653 readInVerbatim
= false;
654 wxStrcat(buf
, _T("\\end{verbatim}\n"));
659 IncrementLineNumber();
663 // Strip out comment environment
664 if (wxStrncmp(buf
, _T("\\begin{comment}"), 15) == 0)
666 while (wxStrncmp(buf
, _T("\\end{comment}"), 13) != 0)
668 return read_a_line(buf
);
670 // Read a verbatim input file as if it were a verbatim environment
671 else if (wxStrncmp(buf
, _T("\\verbatiminput"), 14) == 0)
674 wxChar
*fileName
= buf
+ wordLen
+ 1;
676 int j
= bufIndex
- 1;
679 // thing}\par -- eliminate the \par!
680 if (wxStrncmp((buf
+ wxStrlen(buf
)-5), _T("\\par"), 4) == 0)
687 buf
[j
-1] = 0; // Ignore final brace
689 wxString actualFile
= TexPathList
.FindValidPath(fileName
);
690 currentFileName
= actualFile
;
691 if (actualFile
.empty())
694 errBuf
.Printf(_T("Could not find file: %s"),fileName
);
700 informStr
.Printf(_T("Processing: %s"),actualFile
.c_str());
702 CurrentInputIndex
++;
704 Inputs
[CurrentInputIndex
] = wxFopen(actualFile
, _T("r"));
705 LineNumbers
[CurrentInputIndex
] = 1;
706 if (FileNames
[CurrentInputIndex
])
707 delete[] FileNames
[CurrentInputIndex
];
708 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
710 if (!Inputs
[CurrentInputIndex
])
712 CurrentInputIndex
--;
713 OnError(_T("Could not open verbatiminput file."));
717 readingVerbatim
= true;
718 readInVerbatim
= true;
719 wxStrcpy(buf
, _T("\\begin{verbatim}\n"));
725 else if (wxStrncmp(buf
, _T("\\input"), 6) == 0 || wxStrncmp(buf
, _T("\\helpinput"), 10) == 0 ||
726 wxStrncmp(buf
, _T("\\include"), 8) == 0)
729 if (wxStrncmp(buf
, _T("\\input"), 6) == 0)
732 if (wxStrncmp(buf
, _T("\\include"), 8) == 0)
737 wxChar
*fileName
= buf
+ wordLen
+ 1;
739 int j
= bufIndex
- 1;
742 // \input{thing}\par -- eliminate the \par!
743 // if (wxStrncmp((buf + wxStrlen(buf)-5), "\\par", 4) == 0)
744 if (wxStrncmp((buf
+ wxStrlen(buf
)-4), _T("\\par"), 4) == 0) // Bug fix 8/2/95 Ulrich Leodolter
751 if (buf
[j
-1] == _T('}'))
752 buf
[j
-1] = 0; // Ignore final brace
754 // Remove backslashes from name
755 wxString
fileNameStr(fileName
);
756 fileNameStr
.Replace(_T("\\"), _T(""));
758 // Ignore some types of input files (e.g. macro definition files)
759 wxString fileOnly
= wxFileNameFromPath(fileNameStr
);
760 currentFileName
= fileOnly
;
761 if (IgnorableInputFiles
.Member(fileOnly
))
762 return read_a_line(buf
);
764 wxString actualFile
= TexPathList
.FindValidPath(fileNameStr
);
765 if (actualFile
.empty())
768 wxSnprintf(buf2
, sizeof(buf2
), _T("%s.tex"), fileNameStr
.c_str());
769 actualFile
= TexPathList
.FindValidPath(buf2
);
771 currentFileName
= actualFile
;
773 if (actualFile
.empty())
776 errBuf
.Printf(_T("Could not find file: %s"),fileName
);
781 // Ensure that if this file includes another,
782 // then we look in the same directory as this one.
783 TexPathList
.EnsureFileAccessible(actualFile
);
786 informStr
.Printf(_T("Processing: %s"),actualFile
.c_str());
788 CurrentInputIndex
++;
790 Inputs
[CurrentInputIndex
] = wxFopen(actualFile
, _T("r"));
791 LineNumbers
[CurrentInputIndex
] = 1;
792 if (FileNames
[CurrentInputIndex
])
793 delete[] FileNames
[CurrentInputIndex
];
794 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
796 if (!Inputs
[CurrentInputIndex
])
799 errBuf
.Printf(_T("Could not open include file %s"), (const wxChar
*) actualFile
);
800 CurrentInputIndex
--;
804 bool succ
= read_a_line(buf
);
810 wxString bufStr
= buf
;
811 for (int index
=0; !syntaxTokens
[index
].empty(); index
++)
813 size_t pos
= bufStr
.find(syntaxTokens
[index
]);
814 if (pos
!= wxString::npos
&& pos
!= 0)
816 size_t commentStart
= bufStr
.find(_T("%"));
817 if (commentStart
== wxString::npos
|| commentStart
> pos
)
820 if (syntaxTokens
[index
] == _T("\\verb"))
822 errBuf
.Printf(_T("'%s$....$' was detected at line %lu inside file %s. Please replace this form with \\tt{....}"),
823 syntaxTokens
[index
].c_str(),
824 LineNumbers
[CurrentInputIndex
],
825 currentFileName
.c_str());
829 errBuf
.Printf(_T("'%s' was detected at line %lu inside file %s that is not the only text on the line, starting at column one."),
830 syntaxTokens
[index
].c_str(),
831 LineNumbers
[CurrentInputIndex
],
832 currentFileName
.c_str());
840 if (wxStrncmp(buf
, _T("\\begin{verbatim}"), 16) == 0 ||
841 wxStrncmp(buf
, _T("\\begin{toocomplex}"), 18) == 0)
842 readInVerbatim
= true;
843 else if (wxStrncmp(buf
, _T("\\end{verbatim}"), 14) == 0 ||
844 wxStrncmp(buf
, _T("\\end{toocomplex}"), 16) == 0)
845 readInVerbatim
= false;
847 if (checkCurlyBraces
)
849 if (ch
== EOF
&& leftCurly
!= rightCurly
)
852 errBuf
.Printf(_T("Curly braces do not match inside file %s\n%lu opens, %lu closes"),
853 (const wxChar
*) currentFileName
.c_str(),leftCurly
,rightCurly
);
866 bool ParseNewCommand(wxChar
*buffer
, int *pos
)
868 if ((wxStrncmp((buffer
+(*pos
)), _T("newcommand"), 10) == 0) ||
869 (wxStrncmp((buffer
+(*pos
)), _T("renewcommand"), 12) == 0))
871 if (wxStrncmp((buffer
+(*pos
)), _T("newcommand"), 10) == 0)
876 wxChar commandName
[100];
877 wxChar commandValue
[1000];
880 while (buffer
[*pos
] != _T('}') && (buffer
[*pos
] != 0))
882 commandName
[i
] = buffer
[*pos
];
889 if (buffer
[*pos
] == _T('['))
892 noArgs
= (int)(buffer
[*pos
]) - 48;
893 *pos
+= 2; // read past argument and '['
899 wxChar ch
= buffer
[*pos
];
902 else if (ch
== _T('}'))
910 end
= !read_a_line(buffer
);
915 commandValue
[i
] = ch
;
921 CustomMacro
*macro
= new CustomMacro(commandName
, noArgs
, NULL
);
922 if (wxStrlen(commandValue
) > 0)
923 macro
->macroBody
= copystring(commandValue
);
924 if (!CustomMacroList
.Find(commandName
))
926 CustomMacroList
.Append(commandName
, macro
);
927 AddMacroDef(ltCUSTOM_MACRO
, commandName
, noArgs
);
934 void MacroError(wxChar
*buffer
)
937 wxChar macroBuf
[200];
941 while (((ch
= buffer
[i
-1]) != '\n') && (ch
!= 0))
950 errBuf
.Printf(_T("Could not find macro: %s at line %d, file %s"),
951 macroBuf
, (int)(LineNumbers
[CurrentInputIndex
]-1), FileNames
[CurrentInputIndex
]);
954 if (wxStrcmp(macroBuf
,_T("\\end{document}")) == 0)
956 OnInform( _T("Halted build due to unrecoverable error.") );
963 * 'environment' specifies the name of the macro IFF if we're looking for the end
964 * of an environment, e.g. \end{itemize}. Otherwise it's NULL.
965 * 'parseToBrace' is true if the argument should extend to the next right brace,
966 * e.g. in {\bf an argument} as opposed to \vskip 30pt
969 int ParseArg(TexChunk
*thisArg
, wxList
& children
, wxChar
*buffer
, int pos
, wxChar
*environment
, bool parseToBrace
, TexChunk
*customMacroArgs
)
972 if (stopRunning
) return pos
;
981 // Consume leading brace or square bracket, but ONLY if not following
982 // a space, because this could be e.g. {\large {\bf thing}} where {\bf thing}
983 // is the argument of \large AS WELL as being a block in its
987 if ((pos > 0) && (buffer[pos-1] != ' ') && buffer[pos] == '{')
991 if ((pos > 0) && (buffer[pos-1] != ' ') && (buffer[pos] == '[' || buffer[pos] == '('))
996 else if ((pos > 1) && (buffer[pos-1] != ' ') && (buffer[pos+1] == '[' || buffer[pos+1] == '('))
1004 // If not parsing to brace, just read the next word
1005 // (e.g. \vskip 20pt)
1008 int ch
= buffer
[pos
];
1009 while (!eof
&& ch
!= 13 && ch
!= 32 && ch
!= 10 &&
1010 ch
!= 0 && ch
!= '{')
1012 BigBuffer
[buf_ptr
] = (wxChar
)ch
;
1019 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1020 BigBuffer
[buf_ptr
] = 0;
1021 chunk
->value
= copystring(BigBuffer
);
1022 children
.Append((wxObject
*)chunk
);
1029 len
= wxStrlen(buffer
);
1032 if (customMacroArgs
) return 0;
1034 eof
= read_a_line(buffer
);
1036 // Check for verbatim (or toocomplex, which comes to the same thing)
1037 wxString bufStr
= buffer
;
1038 // if (bufStr.find("\\begin{verbatim}") != wxString::npos ||
1039 // bufStr.find("\\begin{toocomplex}") != wxString::npos)
1040 if (wxStrncmp(buffer
, _T("\\begin{verbatim}"), 16) == 0 ||
1041 wxStrncmp(buffer
, _T("\\begin{toocomplex}"), 18) == 0)
1045 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1046 BigBuffer
[buf_ptr
] = 0;
1047 chunk
->value
= copystring(BigBuffer
);
1048 children
.Append((wxObject
*)chunk
);
1053 eof
= read_a_line(buffer
);
1054 while (!eof
&& (wxStrncmp(buffer
, _T("\\end{verbatim}"), 14) != 0) &&
1055 (wxStrncmp(buffer
, _T("\\end{toocomplex}"), 16) != 0)
1058 wxStrcat(BigBuffer
, buffer
);
1059 buf_ptr
+= wxStrlen(buffer
);
1060 eof
= read_a_line(buffer
);
1062 eof
= read_a_line(buffer
);
1065 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, VerbatimMacroDef
);
1067 chunk
->macroId
= ltVERBATIM
;
1068 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, VerbatimMacroDef
);
1070 arg
->macroId
= ltVERBATIM
;
1071 TexChunk
*str
= new TexChunk(CHUNK_TYPE_STRING
);
1072 str
->value
= copystring(BigBuffer
);
1074 children
.Append((wxObject
*)chunk
);
1075 chunk
->children
.Append((wxObject
*)arg
);
1076 arg
->children
.Append((wxObject
*)str
);
1078 // Also want to include the following newline (is always a newline
1079 // after a verbatim): EXCEPT in HTML
1080 if (convertMode
!= TEX_HTML
)
1082 TexMacroDef
*parDef
= (TexMacroDef
*)MacroDefs
.Get(_T("\\"));
1083 TexChunk
*parChunk
= new TexChunk(CHUNK_TYPE_MACRO
, parDef
);
1084 parChunk
->no_args
= 0;
1085 parChunk
->macroId
= ltBACKSLASHCHAR
;
1086 children
.Append((wxObject
*)parChunk
);
1091 wxChar wxCh
= buffer
[pos
];
1092 // End of optional argument -- pretend it's right brace for simplicity
1093 if (thisArg
->optional
&& (wxCh
== _T(']')))
1099 case _T('}'): // End of argument
1103 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1104 BigBuffer
[buf_ptr
] = 0;
1105 chunk
->value
= copystring(BigBuffer
);
1106 children
.Append((wxObject
*)chunk
);
1108 if (wxCh
== _T('}')) pos
++;
1113 if (buf_ptr
> 0) // Finish off the string we've read so far
1115 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1116 BigBuffer
[buf_ptr
] = 0;
1118 chunk
->value
= copystring(BigBuffer
);
1119 children
.Append((wxObject
*)chunk
);
1123 // Try matching \end{environment}
1124 if (environment
&& FindEndEnvironment(buffer
, &pos
, environment
))
1126 // Eliminate newline after an \end{} if possible
1127 if (buffer
[pos
] == 13)
1130 if (buffer
[pos
] == 10)
1136 if (ParseNewCommand(buffer
, &pos
))
1139 if (wxStrncmp(buffer
+pos
, _T("special"), 7) == 0)
1147 wxTex2RTFBuffer
[0] = 0;
1152 wxChar ch
= buffer
[pos
];
1158 wxTex2RTFBuffer
[i
] = 0;
1163 wxTex2RTFBuffer
[i
] = _T('}');
1168 else if (ch
== _T('{'))
1170 wxTex2RTFBuffer
[i
] = _T('{');
1174 else if (ch
== _T('\\') && buffer
[pos
+1] == _T('}'))
1176 wxTex2RTFBuffer
[i
] = _T('}');
1180 else if (ch
== _T('\\') && buffer
[pos
+1] == _T('{'))
1182 wxTex2RTFBuffer
[i
] = _T('{');
1188 wxTex2RTFBuffer
[i
] = ch
;
1195 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1197 chunk
->macroId
= ltSPECIAL
;
1198 TexMacroDef
*specialDef
= (TexMacroDef
*)MacroDefs
.Get(_T("special"));
1199 chunk
->def
= specialDef
;
1200 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, specialDef
);
1201 chunk
->children
.Append((wxObject
*)arg
);
1203 arg
->macroId
= chunk
->macroId
;
1205 // The value in the first argument.
1206 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1207 arg
->children
.Append((wxObject
*)argValue
);
1209 argValue
->value
= copystring(wxTex2RTFBuffer
);
1211 children
.Append((wxObject
*)chunk
);
1213 else if (wxStrncmp(buffer
+pos
, _T("verb"), 4) == 0)
1216 if (buffer
[pos
] == _T('*'))
1219 // Find the delimiter character
1220 wxChar ch
= buffer
[pos
];
1222 // Now at start of verbatim text
1224 while ((buffer
[pos
] != ch
) && buffer
[pos
] != 0)
1226 wxChar
*val
= new wxChar
[pos
- j
+ 1];
1228 for (i
= j
; i
< pos
; i
++)
1230 val
[i
-j
] = buffer
[i
];
1236 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1238 chunk
->macroId
= ltVERB
;
1239 TexMacroDef
*verbDef
= (TexMacroDef
*)MacroDefs
.Get(_T("verb"));
1240 chunk
->def
= verbDef
;
1241 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, verbDef
);
1242 chunk
->children
.Append((wxObject
*)arg
);
1244 arg
->macroId
= chunk
->macroId
;
1246 // The value in the first argument.
1247 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1248 arg
->children
.Append((wxObject
*)argValue
);
1250 argValue
->value
= val
;
1252 children
.Append((wxObject
*)chunk
);
1257 bool tmpParseToBrace
= true;
1258 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1261 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1263 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1265 chunk
->no_args
= def
->no_args
;
1266 // chunk->name = copystring(def->name);
1267 chunk
->macroId
= def
->macroId
;
1270 children
.Append((wxObject
*)chunk
);
1272 // Eliminate newline after a \begin{} or a \\ if possible
1273 if ((env
|| wxStrcmp(def
->name
, _T("\\")) == 0) && (buffer
[pos
] == 13))
1276 if (buffer
[pos
] == 10)
1280 pos
= ParseMacroBody(def
->name
,
1281 chunk
, chunk
->no_args
,
1288 // If custom macro, parse the body substituting the above found args.
1291 if (customMacro
->macroBody
)
1293 wxChar macroBuf
[300];
1294 // wxStrcpy(macroBuf, _T("{"));
1295 wxStrcpy(macroBuf
, customMacro
->macroBody
);
1296 wxStrcat(macroBuf
, _T("}"));
1297 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, true, chunk
);
1300 // delete chunk; // Might delete children
1305 MacroError(buffer
+pos
);
1310 // Parse constructs like {\bf thing} as if they were
1315 if (buffer
[pos
] == _T('\\'))
1319 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1320 BigBuffer
[buf_ptr
] = 0;
1322 chunk
->value
= copystring(BigBuffer
);
1323 children
.Append((wxObject
*)chunk
);
1328 bool tmpParseToBrace
;
1329 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1332 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1334 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1335 chunk
->no_args
= def
->no_args
;
1336 // chunk->name = copystring(def->name);
1337 chunk
->macroId
= def
->macroId
;
1339 children
.Append((wxObject
*)chunk
);
1341 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1342 buffer
, pos
, NULL
, true, customMacroArgs
);
1344 // If custom macro, parse the body substituting the above found args.
1347 if (customMacro
->macroBody
)
1349 wxChar macroBuf
[300];
1350 // wxStrcpy(macroBuf, _T("{"));
1351 wxStrcpy(macroBuf
, customMacro
->macroBody
);
1352 wxStrcat(macroBuf
, _T("}"));
1353 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, true, chunk
);
1356 // delete chunk; // Might delete children
1361 MacroError(buffer
+pos
);
1367 * If all else fails, we assume that we have
1368 * a pair of braces on their own, so return a `dummy' macro
1369 * definition with just one argument to parse.
1373 SoloBlockDef
= new TexMacroDef(ltSOLO_BLOCK
, _T("solo block"), 1, false);
1378 TexChunk
*chunk1
= new TexChunk(CHUNK_TYPE_STRING
);
1379 BigBuffer
[buf_ptr
] = 0;
1381 chunk1
->value
= copystring(BigBuffer
);
1382 children
.Append((wxObject
*)chunk1
);
1384 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, SoloBlockDef
);
1385 chunk
->no_args
= SoloBlockDef
->no_args
;
1386 // chunk->name = copystring(SoloBlockDef->name);
1387 chunk
->macroId
= SoloBlockDef
->macroId
;
1388 children
.Append((wxObject
*)chunk
);
1390 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, SoloBlockDef
);
1392 chunk
->children
.Append((wxObject
*)arg
);
1393 // arg->name = copystring(SoloBlockDef->name);
1395 arg
->macroId
= chunk
->macroId
;
1397 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, NULL
, true, customMacroArgs
);
1405 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1406 BigBuffer
[buf_ptr
] = 0;
1408 chunk
->value
= copystring(BigBuffer
);
1409 children
.Append((wxObject
*)chunk
);
1414 if (buffer
[pos
] == _T('$'))
1416 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1418 // chunk->name = copystring(_T("$$"));
1419 chunk
->macroId
= ltSPECIALDOUBLEDOLLAR
;
1420 children
.Append((wxObject
*)chunk
);
1425 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1427 // chunk->name = copystring(_T("_$"));
1428 chunk
->macroId
= ltSPECIALDOLLAR
;
1429 children
.Append((wxObject
*)chunk
);
1437 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1438 BigBuffer
[buf_ptr
] = 0;
1440 chunk
->value
= copystring(BigBuffer
);
1441 children
.Append((wxObject
*)chunk
);
1445 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1447 // chunk->name = copystring(_T("_~"));
1448 chunk
->macroId
= ltSPECIALTILDE
;
1449 children
.Append((wxObject
*)chunk
);
1452 case _T('#'): // Either treat as a special TeX character or as a macro arg
1456 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1457 BigBuffer
[buf_ptr
] = 0;
1459 chunk
->value
= copystring(BigBuffer
);
1460 children
.Append((wxObject
*)chunk
);
1464 if (!customMacroArgs
)
1466 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1468 // chunk->name = copystring(_T("_#"));
1469 chunk
->macroId
= ltSPECIALHASH
;
1470 children
.Append((wxObject
*)chunk
);
1474 if (isdigit(buffer
[pos
]))
1476 int n
= buffer
[pos
] - 48;
1478 wxNode
*node
= customMacroArgs
->children
.Item(n
-1);
1481 TexChunk
*argChunk
= (TexChunk
*)node
->GetData();
1482 children
.Append((wxObject
*)new TexChunk(*argChunk
));
1490 // Remove white space before and after the ampersand,
1491 // since this is probably a table column separator with
1492 // some convenient -- but useless -- white space in the text.
1493 while ((buf_ptr
> 0) && ((BigBuffer
[buf_ptr
-1] == _T(' ')) || (BigBuffer
[buf_ptr
-1] == 9)))
1498 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1499 BigBuffer
[buf_ptr
] = 0;
1501 chunk
->value
= copystring(BigBuffer
);
1502 children
.Append((wxObject
*)chunk
);
1507 while (buffer
[pos
] == _T(' ') || buffer
[pos
] == 9)
1510 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1512 // chunk->name = copystring(_T("_&"));
1513 chunk
->macroId
= ltSPECIALAMPERSAND
;
1514 children
.Append((wxObject
*)chunk
);
1517 // Eliminate end-of-line comment
1521 while (wxCh
!= 10 && wxCh
!= 13 && wxCh
!= 0)
1526 if (buffer
[pos
] == 10 || buffer
[pos
] == 13)
1529 if (buffer
[pos
] == 10) pos
++; // Eliminate newline following DOS line feed
1536 BigBuffer
[buf_ptr
] = _T(' ');
1537 BigBuffer
[buf_ptr
+1] = 0;
1544 BigBuffer
[buf_ptr
] = wxCh
;
1545 BigBuffer
[buf_ptr
+1] = 0;
1556 * Consume as many arguments as the macro definition specifies
1560 int ParseMacroBody(const wxChar
*WXUNUSED(macro_name
), TexChunk
*parent
,
1561 int no_args
, wxChar
*buffer
, int pos
,
1562 wxChar
*environment
, bool parseToBrace
,
1563 TexChunk
*customMacroArgs
)
1566 if (stopRunning
) return pos
;
1568 // Check for a first optional argument
1569 if (buffer
[pos
] == ' ' && buffer
[pos
+1] == '[')
1571 // Fool following code into thinking that this is definitely
1572 // an optional first argument. (If a space before a non-first argument,
1573 // [ is interpreted as a [, not an optional argument.)
1579 if (buffer
[pos
] == '[')
1585 for (i
= 0; i
< no_args
; i
++)
1588 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, parent
->def
);
1590 parent
->children
.Append((wxObject
*)arg
);
1591 // arg->name = copystring(macro_name);
1592 arg
->argn
= maxArgs
;
1593 arg
->macroId
= parent
->macroId
;
1595 // To parse the first arg of a 2 arg \begin{thing}{arg} ... \end{thing}
1596 // have to fool parser into thinking this is a regular kind of block.
1598 if ((no_args
== 2) && (i
== 0))
1601 actualEnv
= environment
;
1603 bool isOptional
= false;
1605 // Remove the first { of the argument so it doesn't get recognized as { ... }
1606 // EatWhiteSpace(buffer, &pos);
1609 // The reason for these tests is to not consume braces that don't
1610 // belong to this macro.
1611 // E.g. {\bf {\small thing}}
1612 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && buffer
[pos
] == '{')
1615 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && (buffer
[pos
] == '['))
1620 else if ((pos
> 1) && (buffer
[pos
-1] != ' ') && (buffer
[pos
+1] == '['))
1628 wxString
tmpBuffer(buffer
);
1629 if (tmpBuffer
.length() > 4)
1631 if (tmpBuffer
.Right(4) == _T("\\par"))
1632 tmpBuffer
= tmpBuffer
.Mid(0,tmpBuffer
.length()-4);
1634 errBuf
.Printf(_T("Missing macro argument in the line:\n\t%s\n"),tmpBuffer
.c_str());
1639 arg
->optional
= isOptional
;
1641 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, actualEnv
, parseToBrace
, customMacroArgs
);
1643 // If we've encountered an OPTIONAL argument, go another time around
1644 // the loop, because we've got more than we thought.
1645 // Hopefully optional args don't occur at the end of a macro use
1646 // or we might miss it.
1647 // Don't increment no of times round loop if the first optional arg
1648 // -- we already did it before the loop.
1649 if (arg
->optional
&& (i
> 0))
1652 parent
->no_args
= maxArgs
;
1654 // Tell each argument how many args there are (useful when processing an arg)
1655 wxNode
*node
= parent
->children
.GetFirst();
1658 TexChunk
*chunk
= (TexChunk
*)node
->GetData();
1659 chunk
->no_args
= maxArgs
;
1660 node
= node
->GetNext();
1665 bool TexLoadFile(const wxString
& filename
)
1667 static wxChar
*line_buffer
;
1668 stopRunning
= false;
1669 wxStrcpy(TexFileRoot
, filename
);
1670 StripExtension(TexFileRoot
);
1671 wxSnprintf(TexBibName
, 300, _T("%s.bb"), TexFileRoot
);
1672 wxSnprintf(TexTmpBibName
, 300, _T("%s.bb1"), TexFileRoot
);
1674 TexPathList
.EnsureFileAccessible(filename
);
1679 line_buffer
= new wxChar
[MAX_LINE_BUFFER_SIZE
];
1681 Inputs
[0] = wxFopen(filename
, _T("r"));
1683 FileNames
[0] = copystring(filename
);
1686 read_a_line(line_buffer
);
1687 ParseMacroBody(_T("toplevel"), TopLevel
, 1, line_buffer
, 0, NULL
, true);
1688 if (Inputs
[0]) fclose(Inputs
[0]);
1695 TexMacroDef::TexMacroDef(int the_id
, const wxChar
*the_name
, int n
, bool ig
, bool forbidLevel
)
1697 name
= copystring(the_name
);
1701 forbidden
= forbidLevel
;
1704 TexMacroDef::~TexMacroDef(void)
1706 if (name
) delete[] name
;
1709 TexChunk::TexChunk(int the_type
, TexMacroDef
*the_def
)
1721 TexChunk::TexChunk(TexChunk
& toCopy
)
1724 no_args
= toCopy
.no_args
;
1726 macroId
= toCopy
.macroId
;
1729 // name = copystring(toCopy.name);
1735 value
= copystring(toCopy
.value
);
1739 optional
= toCopy
.optional
;
1740 wxNode
*node
= toCopy
.children
.GetFirst();
1743 TexChunk
*child
= (TexChunk
*)node
->GetData();
1744 children
.Append((wxObject
*)new TexChunk(*child
));
1745 node
= node
->GetNext();
1749 TexChunk::~TexChunk(void)
1751 // if (name) delete[] name;
1752 if (value
) delete[] value
;
1753 wxNode
*node
= children
.GetFirst();
1756 TexChunk
*child
= (TexChunk
*)node
->GetData();
1758 wxNode
*next
= node
->GetNext();
1764 bool IsArgOptional(void) // Is this argument an optional argument?
1766 return isArgOptional
;
1769 int GetNoArgs(void) // Number of args for this macro
1774 /* Gets the text of a chunk on request (must be for small arguments
1779 void GetArgData1(TexChunk
*chunk
)
1781 switch (chunk
->type
)
1783 case CHUNK_TYPE_MACRO
:
1785 TexMacroDef
*def
= chunk
->def
;
1786 if (def
&& def
->ignore
)
1789 if (def
&& (wxStrcmp(def
->name
, _T("solo block")) != 0))
1791 wxStrcat(currentArgData
, _T("\\"));
1792 wxStrcat(currentArgData
, def
->name
);
1795 wxNode
*node
= chunk
->children
.GetFirst();
1798 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1799 wxStrcat(currentArgData
, _T("{"));
1800 GetArgData1(child_chunk
);
1801 wxStrcat(currentArgData
, _T("}"));
1802 node
= node
->GetNext();
1806 case CHUNK_TYPE_ARG
:
1808 wxNode
*node
= chunk
->children
.GetFirst();
1811 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1812 GetArgData1(child_chunk
);
1813 node
= node
->GetNext();
1817 case CHUNK_TYPE_STRING
:
1820 wxStrcat(currentArgData
, chunk
->value
);
1826 wxChar
*GetArgData(TexChunk
*WXUNUSED(chunk
))
1828 currentArgData
[0] = 0;
1829 GetArgData1(currentArgument
);
1830 haveArgData
= false;
1831 return currentArgData
;
1834 wxChar
*GetArgData(void)
1838 currentArgData
[0] = 0;
1839 GetArgData1(currentArgument
);
1841 return currentArgData
;
1844 TexChunk
*GetArgChunk(void)
1846 return currentArgument
;
1849 TexChunk
*GetNextChunk(void) // Look ahead to the next chunk
1854 TexChunk
*GetTopLevelChunk(void)
1859 int GetCurrentColumn(void)
1861 return currentColumn
;
1865 * Traverses document calling functions to allow the client to
1866 * write out the appropriate stuff
1870 void TraverseFromChunk(TexChunk
*chunk
, wxNode
*thisNode
, bool childrenOnly
)
1873 if (stopRunning
) return;
1875 switch (chunk
->type
)
1877 case CHUNK_TYPE_MACRO
:
1879 TexMacroDef
*def
= chunk
->def
;
1880 if (def
&& def
->ignore
)
1884 OnMacro(chunk
->macroId
, chunk
->no_args
, true);
1886 wxNode
*node
= chunk
->children
.GetFirst();
1889 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1890 TraverseFromChunk(child_chunk
, node
);
1891 node
= node
->GetNext();
1894 if (thisNode
&& thisNode
->GetNext())
1895 nextChunk
= (TexChunk
*)thisNode
->GetNext()->GetData();
1898 OnMacro(chunk
->macroId
, chunk
->no_args
, false);
1901 case CHUNK_TYPE_ARG
:
1903 currentArgument
= chunk
;
1905 isArgOptional
= chunk
->optional
;
1906 noArgs
= chunk
->no_args
;
1908 // If OnArgument returns false, don't output.
1910 if (childrenOnly
|| OnArgument(chunk
->macroId
, chunk
->argn
, true))
1912 wxNode
*node
= chunk
->children
.GetFirst();
1915 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1916 TraverseFromChunk(child_chunk
, node
);
1917 node
= node
->GetNext();
1921 currentArgument
= chunk
;
1923 if (thisNode
&& thisNode
->GetNext())
1924 nextChunk
= (TexChunk
*)thisNode
->GetNext()->GetData();
1926 isArgOptional
= chunk
->optional
;
1927 noArgs
= chunk
->no_args
;
1930 (void)OnArgument(chunk
->macroId
, chunk
->argn
, false);
1933 case CHUNK_TYPE_STRING
:
1935 extern int issuedNewParagraph
;
1936 extern int forbidResetPar
;
1937 if (chunk
->value
&& (forbidResetPar
== 0))
1939 // If non-whitespace text, we no longer have a new paragraph.
1940 if (issuedNewParagraph
&& !((chunk
->value
[0] == 10 || chunk
->value
[0] == 13 || chunk
->value
[0] == 32)
1941 && chunk
->value
[1] == 0))
1943 issuedNewParagraph
= false;
1945 TexOutput(chunk
->value
, true);
1952 void TraverseDocument(void)
1954 TraverseFromChunk(TopLevel
, NULL
);
1957 void SetCurrentOutput(FILE *fd
)
1959 CurrentOutput1
= fd
;
1960 CurrentOutput2
= NULL
;
1963 void SetCurrentOutputs(FILE *fd1
, FILE *fd2
)
1965 CurrentOutput1
= fd1
;
1966 CurrentOutput2
= fd2
;
1969 void AddMacroDef(int the_id
, const wxChar
*name
, int n
, bool ignore
, bool forbid
)
1971 MacroDefs
.Put(name
, new TexMacroDef(the_id
, name
, n
, ignore
, forbid
));
1974 void TexInitialize(int bufSize
)
1976 InitialiseColourTable();
1978 TexPathList
.AddEnvList(_T("TEXINPUT"));
1981 TexPathList
.AddEnvList(_T("TEXINPUTS"));
1984 for (i
= 0; i
< 15; i
++)
1988 FileNames
[i
] = NULL
;
1991 IgnorableInputFiles
.Add(_T("psbox.tex"));
1992 BigBuffer
= new wxChar
[(bufSize
*1000)];
1993 currentArgData
= new wxChar
[2000];
1994 TexFileRoot
= new wxChar
[300];
1995 TexBibName
= new wxChar
[300];
1996 TexTmpBibName
= new wxChar
[300];
1997 AddMacroDef(ltTOPLEVEL
, _T("toplevel"), 1);
1998 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
1999 // TopLevel->name = copystring(_T("toplevel"));
2000 TopLevel
->macroId
= ltTOPLEVEL
;
2001 TopLevel
->no_args
= 1;
2002 VerbatimMacroDef
= (TexMacroDef
*)MacroDefs
.Get(_T("verbatim"));
2005 void TexCleanUp(void)
2008 for (i
= 0; i
< 15; i
++)
2014 subsubsectionNo
= 0;
2017 CurrentOutput1
= NULL
;
2018 CurrentOutput2
= NULL
;
2019 CurrentInputIndex
= 0;
2020 haveArgData
= false;
2025 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
2026 // TopLevel->name = copystring(_T("toplevel"));
2027 TopLevel
->macroId
= ltTOPLEVEL
;
2028 TopLevel
->no_args
= 1;
2030 DocumentTitle
= NULL
;
2031 DocumentAuthor
= NULL
;
2032 DocumentDate
= NULL
;
2033 DocumentStyle
= LATEX_REPORT
;
2034 MinorDocumentStyle
= 0;
2035 BibliographyStyleString
= copystring(_T("plain"));
2036 DocumentStyleString
= copystring(_T("report"));
2037 MinorDocumentStyleString
= NULL
;
2039 // gt - Changed this so if this is the final pass
2040 // then we DO want to remove these macros, so that
2041 // memory is not MASSIVELY leaked if the user
2042 // does not exit the program, but instead runs
2043 // the program again
2044 if ((passNumber
== 1 && !runTwice
) ||
2045 (passNumber
== 2 && runTwice
))
2047 /* Don't want to remove custom macros after each pass.*/
2049 wxNode
*node
= CustomMacroList
.GetFirst();
2052 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
2055 node
= CustomMacroList
.GetFirst();
2059 TexReferences
.BeginFind();
2060 wxHashTable::Node
*refNode
= TexReferences
.Next();
2063 TexRef
*ref
= (TexRef
*)refNode
->GetData();
2065 refNode
= TexReferences
.Next();
2067 TexReferences
.Clear();
2069 wxNode
* bibNode
= BibList
.GetFirst();
2072 BibEntry
*entry
= (BibEntry
*)bibNode
->GetData();
2075 bibNode
= BibList
.GetFirst();
2077 CitationList
.Clear();
2078 ResetTopicCounter();
2081 // There is likely to be one set of macros used by all utilities.
2082 void DefineDefaultMacros(void)
2084 // Put names which subsume other names at the TOP
2085 // so they get recognized first
2087 AddMacroDef(ltACCENT_GRAVE
, _T("`"), 1);
2088 AddMacroDef(ltACCENT_ACUTE
, _T("'"), 1);
2089 AddMacroDef(ltACCENT_CARET
, _T("^"), 1);
2090 AddMacroDef(ltACCENT_UMLAUT
, _T("\""), 1);
2091 AddMacroDef(ltACCENT_TILDE
, _T("~"), 1);
2092 AddMacroDef(ltACCENT_DOT
, _T("."), 1);
2093 AddMacroDef(ltACCENT_CADILLA
, _T("c"), 1);
2094 AddMacroDef(ltSMALLSPACE1
, _T(","), 0);
2095 AddMacroDef(ltSMALLSPACE2
, _T(";"), 0);
2097 AddMacroDef(ltABSTRACT
, _T("abstract"), 1);
2098 AddMacroDef(ltADDCONTENTSLINE
, _T("addcontentsline"), 3);
2099 AddMacroDef(ltADDTOCOUNTER
, _T("addtocounter"), 2);
2100 AddMacroDef(ltALEPH
, _T("aleph"), 0);
2101 AddMacroDef(ltALPHA
, _T("alpha"), 0);
2102 AddMacroDef(ltALPH1
, _T("alph"), 1);
2103 AddMacroDef(ltALPH2
, _T("Alph"), 1);
2104 AddMacroDef(ltANGLE
, _T("angle"), 0);
2105 AddMacroDef(ltAPPENDIX
, _T("appendix"), 0);
2106 AddMacroDef(ltAPPROX
, _T("approx"), 0);
2107 AddMacroDef(ltARABIC
, _T("arabic"), 1);
2108 AddMacroDef(ltARRAY
, _T("array"), 1);
2109 AddMacroDef(ltAST
, _T("ast"), 0);
2110 AddMacroDef(ltASYMP
, _T("asymp"), 0);
2111 AddMacroDef(ltAUTHOR
, _T("author"), 1);
2113 AddMacroDef(ltBACKGROUNDCOLOUR
, _T("backgroundcolour"), 1);
2114 AddMacroDef(ltBACKGROUNDIMAGE
, _T("backgroundimage"), 1);
2115 AddMacroDef(ltBACKGROUND
, _T("background"), 1);
2116 AddMacroDef(ltBACKSLASHRAW
, _T("backslashraw"), 0);
2117 AddMacroDef(ltBACKSLASH
, _T("backslash"), 0);
2118 AddMacroDef(ltBASELINESKIP
, _T("baselineskip"), 1);
2119 AddMacroDef(ltBCOL
, _T("bcol"), 2);
2120 AddMacroDef(ltBETA
, _T("beta"), 0);
2121 AddMacroDef(ltBFSERIES
, _T("bfseries"), 1);
2122 AddMacroDef(ltBF
, _T("bf"), 1);
2123 AddMacroDef(ltBIBITEM
, _T("bibitem"), 2);
2124 // For convenience, bibitem has 2 args: label and item.
2125 // The Latex syntax permits writing as 2 args.
2126 AddMacroDef(ltBIBLIOGRAPHYSTYLE
, _T("bibliographystyle"), 1);
2127 AddMacroDef(ltBIBLIOGRAPHY
, _T("bibliography"), 1);
2128 AddMacroDef(ltBIGTRIANGLEDOWN
, _T("bigtriangledown"), 0);
2129 AddMacroDef(ltBOT
, _T("bot"), 0);
2130 AddMacroDef(ltBOXIT
, _T("boxit"), 1);
2131 AddMacroDef(ltBOX
, _T("box"), 0);
2132 AddMacroDef(ltBRCLEAR
, _T("brclear"), 0);
2133 AddMacroDef(ltBULLET
, _T("bullet"), 0);
2135 AddMacroDef(ltCAPTIONSTAR
, _T("caption*"), 1);
2136 AddMacroDef(ltCAPTION
, _T("caption"), 1);
2137 AddMacroDef(ltCAP
, _T("cap"), 0);
2138 AddMacroDef(ltCDOTS
, _T("cdots"), 0);
2139 AddMacroDef(ltCDOT
, _T("cdot"), 0);
2140 AddMacroDef(ltCENTERLINE
, _T("centerline"), 1);
2141 AddMacroDef(ltCENTERING
, _T("centering"), 0);
2142 AddMacroDef(ltCENTER
, _T("center"), 1);
2143 AddMacroDef(ltCEXTRACT
, _T("cextract"), 0);
2144 AddMacroDef(ltCHAPTERHEADING
, _T("chapterheading"), 1);
2145 AddMacroDef(ltCHAPTERSTAR
, _T("chapter*"), 1);
2146 AddMacroDef(ltCHAPTER
, _T("chapter"), 1);
2147 AddMacroDef(ltCHI
, _T("chi"), 0);
2148 AddMacroDef(ltCINSERT
, _T("cinsert"), 0);
2149 AddMacroDef(ltCIRC
, _T("circ"), 0);
2150 AddMacroDef(ltCITE
, _T("cite"), 1);
2151 AddMacroDef(ltCLASS
, _T("class"), 1);
2152 AddMacroDef(ltCLEARDOUBLEPAGE
, _T("cleardoublepage"), 0);
2153 AddMacroDef(ltCLEARPAGE
, _T("clearpage"), 0);
2154 AddMacroDef(ltCLINE
, _T("cline"), 1);
2155 AddMacroDef(ltCLIPSFUNC
, _T("clipsfunc"), 3);
2156 AddMacroDef(ltCLUBSUIT
, _T("clubsuit"), 0);
2157 AddMacroDef(ltCOLUMNSEP
, _T("columnsep"), 1);
2158 AddMacroDef(ltCOMMENT
, _T("comment"), 1, true);
2159 AddMacroDef(ltCONG
, _T("cong"), 0);
2160 AddMacroDef(ltCOPYRIGHT
, _T("copyright"), 0);
2161 AddMacroDef(ltCPARAM
, _T("cparam"), 2);
2162 AddMacroDef(ltCHEAD
, _T("chead"), 1);
2163 AddMacroDef(ltCFOOT
, _T("cfoot"), 1);
2164 AddMacroDef(ltCUP
, _T("cup"), 0);
2166 AddMacroDef(ltDASHV
, _T("dashv"), 0);
2167 AddMacroDef(ltDATE
, _T("date"), 1);
2168 AddMacroDef(ltDELTA
, _T("delta"), 0);
2169 AddMacroDef(ltCAP_DELTA
, _T("Delta"), 0);
2170 AddMacroDef(ltDEFINECOLOUR
, _T("definecolour"), 4);
2171 AddMacroDef(ltDEFINECOLOR
, _T("definecolor"), 4);
2172 AddMacroDef(ltDESCRIPTION
, _T("description"), 1);
2173 AddMacroDef(ltDESTRUCT
, _T("destruct"), 1);
2174 AddMacroDef(ltDIAMOND2
, _T("diamond2"), 0);
2175 AddMacroDef(ltDIAMOND
, _T("diamond"), 0);
2176 AddMacroDef(ltDIV
, _T("div"), 0);
2177 AddMacroDef(ltDOCUMENTCLASS
, _T("documentclass"), 1);
2178 AddMacroDef(ltDOCUMENTSTYLE
, _T("documentstyle"), 1);
2179 AddMacroDef(ltDOCUMENT
, _T("document"), 1);
2180 AddMacroDef(ltDOUBLESPACE
, _T("doublespace"), 1);
2181 AddMacroDef(ltDOTEQ
, _T("doteq"), 0);
2182 AddMacroDef(ltDOWNARROW
, _T("downarrow"), 0);
2183 AddMacroDef(ltDOWNARROW2
, _T("Downarrow"), 0);
2185 AddMacroDef(ltEMPTYSET
, _T("emptyset"), 0);
2186 AddMacroDef(ltEMPH
, _T("emph"), 1);
2187 AddMacroDef(ltEM
, _T("em"), 1);
2188 AddMacroDef(ltENUMERATE
, _T("enumerate"), 1);
2189 AddMacroDef(ltEPSILON
, _T("epsilon"), 0);
2190 AddMacroDef(ltEQUATION
, _T("equation"), 1);
2191 AddMacroDef(ltEQUIV
, _T("equiv"), 0);
2192 AddMacroDef(ltETA
, _T("eta"), 0);
2193 AddMacroDef(ltEVENSIDEMARGIN
, _T("evensidemargin"), 1);
2194 AddMacroDef(ltEXISTS
, _T("exists"), 0);
2196 AddMacroDef(ltFBOX
, _T("fbox"), 1);
2197 AddMacroDef(ltFCOL
, _T("fcol"), 2);
2198 AddMacroDef(ltFIGURE
, _T("figure"), 1);
2199 AddMacroDef(ltFIGURESTAR
, _T("figure*"), 1);
2200 AddMacroDef(ltFLUSHLEFT
, _T("flushleft"), 1);
2201 AddMacroDef(ltFLUSHRIGHT
, _T("flushright"), 1);
2202 AddMacroDef(ltFOLLOWEDLINKCOLOUR
, _T("followedlinkcolour"), 1);
2203 AddMacroDef(ltFOOTHEIGHT
, _T("footheight"), 1);
2204 AddMacroDef(ltFOOTNOTEPOPUP
, _T("footnotepopup"), 2);
2205 AddMacroDef(ltFOOTNOTE
, _T("footnote"), 1);
2206 AddMacroDef(ltFOOTSKIP
, _T("footskip"), 1);
2207 AddMacroDef(ltFORALL
, _T("forall"), 0);
2208 AddMacroDef(ltFRAMEBOX
, _T("framebox"), 1);
2209 AddMacroDef(ltFROWN
, _T("frown"), 0);
2210 AddMacroDef(ltFUNCTIONSECTION
, _T("functionsection"), 1);
2211 AddMacroDef(ltFUNC
, _T("func"), 3);
2212 AddMacroDef(ltFOOTNOTESIZE
, _T("footnotesize"), 0);
2213 AddMacroDef(ltFANCYPLAIN
, _T("fancyplain"), 2);
2215 AddMacroDef(ltGAMMA
, _T("gamma"), 0);
2216 AddMacroDef(ltCAP_GAMMA
, _T("Gamma"), 0);
2217 AddMacroDef(ltGEQ
, _T("geq"), 0);
2218 AddMacroDef(ltGE
, _T("ge"), 0);
2219 AddMacroDef(ltGG
, _T("gg"), 0);
2220 AddMacroDef(ltGLOSSARY
, _T("glossary"), 1);
2221 AddMacroDef(ltGLOSS
, _T("gloss"), 1);
2223 AddMacroDef(ltHEADHEIGHT
, _T("headheight"), 1);
2224 AddMacroDef(ltHEARTSUIT
, _T("heartsuit"), 0);
2225 AddMacroDef(ltHELPGLOSSARY
, _T("helpglossary"), 1);
2226 AddMacroDef(ltHELPIGNORE
, _T("helpignore"), 1, true);
2227 AddMacroDef(ltHELPONLY
, _T("helponly"), 1);
2228 AddMacroDef(ltHELPINPUT
, _T("helpinput"), 1);
2229 AddMacroDef(ltHELPFONTFAMILY
, _T("helpfontfamily"), 1);
2230 AddMacroDef(ltHELPFONTSIZE
, _T("helpfontsize"), 1);
2231 AddMacroDef(ltHELPREFN
, _T("helprefn"), 2);
2232 AddMacroDef(ltHELPREF
, _T("helpref"), 2);
2233 AddMacroDef(ltHFILL
, _T("hfill"), 0);
2234 AddMacroDef(ltHLINE
, _T("hline"), 0);
2235 AddMacroDef(ltHRULE
, _T("hrule"), 0);
2236 AddMacroDef(ltHSPACESTAR
, _T("hspace*"), 1);
2237 AddMacroDef(ltHSPACE
, _T("hspace"), 1);
2238 AddMacroDef(ltHSKIPSTAR
, _T("hskip*"), 1);
2239 AddMacroDef(ltHSKIP
, _T("hskip"), 1);
2240 AddMacroDef(lthuge
, _T("huge"), 1);
2241 AddMacroDef(ltHuge
, _T("Huge"), 1);
2242 AddMacroDef(ltHUGE
, _T("HUGE"), 1);
2243 AddMacroDef(ltHTMLIGNORE
, _T("htmlignore"), 1);
2244 AddMacroDef(ltHTMLONLY
, _T("htmlonly"), 1);
2246 AddMacroDef(ltIM
, _T("im"), 0);
2247 AddMacroDef(ltINCLUDEONLY
, _T("includeonly"), 1);
2248 AddMacroDef(ltINCLUDE
, _T("include"), 1);
2249 AddMacroDef(ltINDENTED
, _T("indented"), 2);
2250 AddMacroDef(ltINDEX
, _T("index"), 1);
2251 AddMacroDef(ltINPUT
, _T("input"), 1, true);
2252 AddMacroDef(ltIOTA
, _T("iota"), 0);
2253 AddMacroDef(ltITEMIZE
, _T("itemize"), 1);
2254 AddMacroDef(ltITEM
, _T("item"), 0);
2255 AddMacroDef(ltIMAGEMAP
, _T("imagemap"), 3);
2256 AddMacroDef(ltIMAGEL
, _T("imagel"), 2);
2257 AddMacroDef(ltIMAGER
, _T("imager"), 2);
2258 AddMacroDef(ltIMAGE
, _T("image"), 2);
2259 AddMacroDef(ltIN
, _T("in"), 0);
2260 AddMacroDef(ltINFTY
, _T("infty"), 0);
2261 AddMacroDef(ltITSHAPE
, _T("itshape"), 1);
2262 AddMacroDef(ltIT
, _T("it"), 1);
2263 AddMacroDef(ltITEMSEP
, _T("itemsep"), 1);
2264 AddMacroDef(ltINSERTATLEVEL
, _T("insertatlevel"), 2);
2266 AddMacroDef(ltKAPPA
, _T("kappa"), 0);
2267 AddMacroDef(ltKILL
, _T("kill"), 0);
2269 AddMacroDef(ltLABEL
, _T("label"), 1);
2270 AddMacroDef(ltLAMBDA
, _T("lambda"), 0);
2271 AddMacroDef(ltCAP_LAMBDA
, _T("Lambda"), 0);
2272 AddMacroDef(ltlarge
, _T("large"), 1);
2273 AddMacroDef(ltLarge
, _T("Large"), 1);
2274 AddMacroDef(ltLARGE
, _T("LARGE"), 1);
2275 AddMacroDef(ltLATEXIGNORE
, _T("latexignore"), 1);
2276 AddMacroDef(ltLATEXONLY
, _T("latexonly"), 1);
2277 AddMacroDef(ltLATEX
, _T("LaTeX"), 0);
2278 AddMacroDef(ltLBOX
, _T("lbox"), 1);
2279 AddMacroDef(ltLBRACERAW
, _T("lbraceraw"), 0);
2280 AddMacroDef(ltLDOTS
, _T("ldots"), 0);
2281 AddMacroDef(ltLEQ
, _T("leq"), 0);
2282 AddMacroDef(ltLE
, _T("le"), 0);
2283 AddMacroDef(ltLEFTARROW
, _T("leftarrow"), 0);
2284 AddMacroDef(ltLEFTRIGHTARROW
, _T("leftrightarrow"), 0);
2285 AddMacroDef(ltLEFTARROW2
, _T("Leftarrow"), 0);
2286 AddMacroDef(ltLEFTRIGHTARROW2
, _T("Leftrightarrow"), 0);
2287 AddMacroDef(ltLINEBREAK
, _T("linebreak"), 0);
2288 AddMacroDef(ltLINKCOLOUR
, _T("linkcolour"), 1);
2289 AddMacroDef(ltLISTOFFIGURES
, _T("listoffigures"), 0);
2290 AddMacroDef(ltLISTOFTABLES
, _T("listoftables"), 0);
2291 AddMacroDef(ltLHEAD
, _T("lhead"), 1);
2292 AddMacroDef(ltLFOOT
, _T("lfoot"), 1);
2293 AddMacroDef(ltLOWERCASE
, _T("lowercase"), 1);
2294 AddMacroDef(ltLL
, _T("ll"), 0);
2296 AddMacroDef(ltMAKEGLOSSARY
, _T("makeglossary"), 0);
2297 AddMacroDef(ltMAKEINDEX
, _T("makeindex"), 0);
2298 AddMacroDef(ltMAKETITLE
, _T("maketitle"), 0);
2299 AddMacroDef(ltMARKRIGHT
, _T("markright"), 1);
2300 AddMacroDef(ltMARKBOTH
, _T("markboth"), 2);
2301 AddMacroDef(ltMARGINPARWIDTH
, _T("marginparwidth"), 1);
2302 AddMacroDef(ltMARGINPARSEP
, _T("marginparsep"), 1);
2303 AddMacroDef(ltMARGINPARODD
, _T("marginparodd"), 1);
2304 AddMacroDef(ltMARGINPAREVEN
, _T("marginpareven"), 1);
2305 AddMacroDef(ltMARGINPAR
, _T("marginpar"), 1);
2306 AddMacroDef(ltMBOX
, _T("mbox"), 1);
2307 AddMacroDef(ltMDSERIES
, _T("mdseries"), 1);
2308 AddMacroDef(ltMEMBERSECTION
, _T("membersection"), 1);
2309 AddMacroDef(ltMEMBER
, _T("member"), 2);
2310 AddMacroDef(ltMID
, _T("mid"), 0);
2311 AddMacroDef(ltMODELS
, _T("models"), 0);
2312 AddMacroDef(ltMP
, _T("mp"), 0);
2313 AddMacroDef(ltMULTICOLUMN
, _T("multicolumn"), 3);
2314 AddMacroDef(ltMU
, _T("mu"), 0);
2316 AddMacroDef(ltNABLA
, _T("nabla"), 0);
2317 AddMacroDef(ltNEG
, _T("neg"), 0);
2318 AddMacroDef(ltNEQ
, _T("neq"), 0);
2319 AddMacroDef(ltNEWCOUNTER
, _T("newcounter"), 1, false, (bool)FORBID_ABSOLUTELY
);
2320 AddMacroDef(ltNEWLINE
, _T("newline"), 0);
2321 AddMacroDef(ltNEWPAGE
, _T("newpage"), 0);
2322 AddMacroDef(ltNI
, _T("ni"), 0);
2323 AddMacroDef(ltNOCITE
, _T("nocite"), 1);
2324 AddMacroDef(ltNOINDENT
, _T("noindent"), 0);
2325 AddMacroDef(ltNOLINEBREAK
, _T("nolinebreak"), 0);
2326 AddMacroDef(ltNOPAGEBREAK
, _T("nopagebreak"), 0);
2327 AddMacroDef(ltNORMALSIZE
, _T("normalsize"), 1);
2328 AddMacroDef(ltNORMALBOX
, _T("normalbox"), 1);
2329 AddMacroDef(ltNORMALBOXD
, _T("normalboxd"), 1);
2330 AddMacroDef(ltNOTEQ
, _T("noteq"), 0);
2331 AddMacroDef(ltNOTIN
, _T("notin"), 0);
2332 AddMacroDef(ltNOTSUBSET
, _T("notsubset"), 0);
2333 AddMacroDef(ltNU
, _T("nu"), 0);
2335 AddMacroDef(ltODDSIDEMARGIN
, _T("oddsidemargin"), 1);
2336 AddMacroDef(ltOMEGA
, _T("omega"), 0);
2337 AddMacroDef(ltCAP_OMEGA
, _T("Omega"), 0);
2338 AddMacroDef(ltONECOLUMN
, _T("onecolumn"), 0);
2339 AddMacroDef(ltOPLUS
, _T("oplus"), 0);
2340 AddMacroDef(ltOSLASH
, _T("oslash"), 0);
2341 AddMacroDef(ltOTIMES
, _T("otimes"), 0);
2343 AddMacroDef(ltPAGEBREAK
, _T("pagebreak"), 0);
2344 AddMacroDef(ltPAGEREF
, _T("pageref"), 1);
2345 AddMacroDef(ltPAGESTYLE
, _T("pagestyle"), 1);
2346 AddMacroDef(ltPAGENUMBERING
, _T("pagenumbering"), 1);
2347 AddMacroDef(ltPARAGRAPHSTAR
, _T("paragraph*"), 1);
2348 AddMacroDef(ltPARAGRAPH
, _T("paragraph"), 1);
2349 AddMacroDef(ltPARALLEL
, _T("parallel"), 0);
2350 AddMacroDef(ltPARAM
, _T("param"), 2);
2351 AddMacroDef(ltPARINDENT
, _T("parindent"), 1);
2352 AddMacroDef(ltPARSKIP
, _T("parskip"), 1);
2353 AddMacroDef(ltPARTIAL
, _T("partial"), 0);
2354 AddMacroDef(ltPARTSTAR
, _T("part*"), 1);
2355 AddMacroDef(ltPART
, _T("part"), 1);
2356 AddMacroDef(ltPAR
, _T("par"), 0);
2357 AddMacroDef(ltPERP
, _T("perp"), 0);
2358 AddMacroDef(ltPHI
, _T("phi"), 0);
2359 AddMacroDef(ltCAP_PHI
, _T("Phi"), 0);
2360 AddMacroDef(ltPFUNC
, _T("pfunc"), 3);
2361 AddMacroDef(ltPICTURE
, _T("picture"), 1);
2362 AddMacroDef(ltPI
, _T("pi"), 0);
2363 AddMacroDef(ltCAP_PI
, _T("Pi"), 0);
2364 AddMacroDef(ltPM
, _T("pm"), 0);
2365 AddMacroDef(ltPOPREFONLY
, _T("poprefonly"), 1);
2366 AddMacroDef(ltPOPREF
, _T("popref"), 2);
2367 AddMacroDef(ltPOUNDS
, _T("pounds"), 0);
2368 AddMacroDef(ltPREC
, _T("prec"), 0);
2369 AddMacroDef(ltPRECEQ
, _T("preceq"), 0);
2370 AddMacroDef(ltPRINTINDEX
, _T("printindex"), 0);
2371 AddMacroDef(ltPROPTO
, _T("propto"), 0);
2372 AddMacroDef(ltPSBOXTO
, _T("psboxto"), 1, false, (bool)FORBID_ABSOLUTELY
);
2373 AddMacroDef(ltPSBOX
, _T("psbox"), 1, false, (bool)FORBID_ABSOLUTELY
);
2374 AddMacroDef(ltPSI
, _T("psi"), 0);
2375 AddMacroDef(ltCAP_PSI
, _T("Psi"), 0);
2377 AddMacroDef(ltQUOTE
, _T("quote"), 1);
2378 AddMacroDef(ltQUOTATION
, _T("quotation"), 1);
2380 AddMacroDef(ltRAGGEDBOTTOM
, _T("raggedbottom"), 0);
2381 AddMacroDef(ltRAGGEDLEFT
, _T("raggedleft"), 0);
2382 AddMacroDef(ltRAGGEDRIGHT
, _T("raggedright"), 0);
2383 AddMacroDef(ltRBRACERAW
, _T("rbraceraw"), 0);
2384 AddMacroDef(ltREF
, _T("ref"), 1);
2385 AddMacroDef(ltREGISTERED
, _T("registered"), 0);
2386 AddMacroDef(ltRE
, _T("we"), 0);
2387 AddMacroDef(ltRHO
, _T("rho"), 0);
2388 AddMacroDef(ltRIGHTARROW
, _T("rightarrow"), 0);
2389 AddMacroDef(ltRIGHTARROW2
, _T("rightarrow2"), 0);
2390 AddMacroDef(ltRMFAMILY
, _T("rmfamily"), 1);
2391 AddMacroDef(ltRM
, _T("rm"), 1);
2392 AddMacroDef(ltROMAN
, _T("roman"), 1);
2393 AddMacroDef(ltROMAN2
, _T("Roman"), 1);
2394 // AddMacroDef(lt"row", 1);
2395 AddMacroDef(ltRTFSP
, _T("rtfsp"), 0);
2396 AddMacroDef(ltRTFIGNORE
, _T("rtfignore"), 1);
2397 AddMacroDef(ltRTFONLY
, _T("rtfonly"), 1);
2398 AddMacroDef(ltRULEDROW
, _T("ruledrow"), 1);
2399 AddMacroDef(ltDRULED
, _T("druled"), 1);
2400 AddMacroDef(ltRULE
, _T("rule"), 2);
2401 AddMacroDef(ltRHEAD
, _T("rhead"), 1);
2402 AddMacroDef(ltRFOOT
, _T("rfoot"), 1);
2403 AddMacroDef(ltROW
, _T("row"), 1);
2405 AddMacroDef(ltSCSHAPE
, _T("scshape"), 1);
2406 AddMacroDef(ltSC
, _T("sc"), 1);
2407 AddMacroDef(ltSECTIONHEADING
, _T("sectionheading"), 1);
2408 AddMacroDef(ltSECTIONSTAR
, _T("section*"), 1);
2409 AddMacroDef(ltSECTION
, _T("section"), 1);
2410 AddMacroDef(ltSETCOUNTER
, _T("setcounter"), 2);
2411 AddMacroDef(ltSFFAMILY
, _T("sffamily"), 1);
2412 AddMacroDef(ltSF
, _T("sf"), 1);
2413 AddMacroDef(ltSHARP
, _T("sharp"), 0);
2414 AddMacroDef(ltSHORTCITE
, _T("shortcite"), 1);
2415 AddMacroDef(ltSIGMA
, _T("sigma"), 0);
2416 AddMacroDef(ltCAP_SIGMA
, _T("Sigma"), 0);
2417 AddMacroDef(ltSIM
, _T("sim"), 0);
2418 AddMacroDef(ltSIMEQ
, _T("simeq"), 0);
2419 AddMacroDef(ltSINGLESPACE
, _T("singlespace"), 1);
2420 AddMacroDef(ltSIZEDBOX
, _T("sizedbox"), 2);
2421 AddMacroDef(ltSIZEDBOXD
, _T("sizedboxd"), 2);
2422 AddMacroDef(ltSLOPPYPAR
, _T("sloppypar"), 1);
2423 AddMacroDef(ltSLOPPY
, _T("sloppy"), 0);
2424 AddMacroDef(ltSLSHAPE
, _T("slshape"), 1);
2425 AddMacroDef(ltSL
, _T("sl"), 1);
2426 AddMacroDef(ltSMALL
, _T("small"), 1);
2427 AddMacroDef(ltSMILE
, _T("smile"), 0);
2428 AddMacroDef(ltSS
, _T("ss"), 0);
2429 AddMacroDef(ltSTAR
, _T("star"), 0);
2430 AddMacroDef(ltSUBITEM
, _T("subitem"), 0);
2431 AddMacroDef(ltSUBPARAGRAPHSTAR
, _T("subparagraph*"), 1);
2432 AddMacroDef(ltSUBPARAGRAPH
, _T("subparagraph"), 1);
2433 AddMacroDef(ltSPECIAL
, _T("special"), 1);
2434 AddMacroDef(ltSUBSECTIONSTAR
, _T("subsection*"), 1);
2435 AddMacroDef(ltSUBSECTION
, _T("subsection"), 1);
2436 AddMacroDef(ltSUBSETEQ
, _T("subseteq"), 0);
2437 AddMacroDef(ltSUBSET
, _T("subset"), 0);
2438 AddMacroDef(ltSUCC
, _T("succ"), 0);
2439 AddMacroDef(ltSUCCEQ
, _T("succeq"), 0);
2440 AddMacroDef(ltSUPSETEQ
, _T("supseteq"), 0);
2441 AddMacroDef(ltSUPSET
, _T("supset"), 0);
2442 AddMacroDef(ltSUBSUBSECTIONSTAR
, _T("subsubsection*"), 1);
2443 AddMacroDef(ltSUBSUBSECTION
, _T("subsubsection"), 1);
2444 AddMacroDef(ltSUPERTABULAR
, _T("supertabular"), 2, false);
2445 AddMacroDef(ltSURD
, _T("surd"), 0);
2446 AddMacroDef(ltSCRIPTSIZE
, _T("scriptsize"), 1);
2447 AddMacroDef(ltSETHEADER
, _T("setheader"), 6);
2448 AddMacroDef(ltSETFOOTER
, _T("setfooter"), 6);
2449 AddMacroDef(ltSETHOTSPOTCOLOUR
, _T("sethotspotcolour"), 1);
2450 AddMacroDef(ltSETHOTSPOTCOLOR
, _T("sethotspotcolor"), 1);
2451 AddMacroDef(ltSETHOTSPOTUNDERLINE
, _T("sethotspotunderline"), 1);
2452 AddMacroDef(ltSETTRANSPARENCY
, _T("settransparency"), 1);
2453 AddMacroDef(ltSPADESUIT
, _T("spadesuit"), 0);
2455 AddMacroDef(ltTABBING
, _T("tabbing"), 2);
2456 AddMacroDef(ltTABLEOFCONTENTS
, _T("tableofcontents"), 0);
2457 AddMacroDef(ltTABLE
, _T("table"), 1);
2458 AddMacroDef(ltTABULAR
, _T("tabular"), 2, false);
2459 AddMacroDef(ltTAB
, _T("tab"), 0);
2460 AddMacroDef(ltTAU
, _T("tau"), 0);
2461 AddMacroDef(ltTEXTRM
, _T("textrm"), 1);
2462 AddMacroDef(ltTEXTSF
, _T("textsf"), 1);
2463 AddMacroDef(ltTEXTTT
, _T("texttt"), 1);
2464 AddMacroDef(ltTEXTBF
, _T("textbf"), 1);
2465 AddMacroDef(ltTEXTIT
, _T("textit"), 1);
2466 AddMacroDef(ltTEXTSL
, _T("textsl"), 1);
2467 AddMacroDef(ltTEXTSC
, _T("textsc"), 1);
2468 AddMacroDef(ltTEXTWIDTH
, _T("textwidth"), 1);
2469 AddMacroDef(ltTEXTHEIGHT
, _T("textheight"), 1);
2470 AddMacroDef(ltTEXTCOLOUR
, _T("textcolour"), 1);
2471 AddMacroDef(ltTEX
, _T("TeX"), 0);
2472 AddMacroDef(ltTHEBIBLIOGRAPHY
, _T("thebibliography"), 2);
2473 AddMacroDef(ltTHETA
, _T("theta"), 0);
2474 AddMacroDef(ltTIMES
, _T("times"), 0);
2475 AddMacroDef(ltCAP_THETA
, _T("Theta"), 0);
2476 AddMacroDef(ltTITLEPAGE
, _T("titlepage"), 1);
2477 AddMacroDef(ltTITLE
, _T("title"), 1);
2478 AddMacroDef(ltTINY
, _T("tiny"), 1);
2479 AddMacroDef(ltTODAY
, _T("today"), 0);
2480 AddMacroDef(ltTOPMARGIN
, _T("topmargin"), 1);
2481 AddMacroDef(ltTOPSKIP
, _T("topskip"), 1);
2482 AddMacroDef(ltTRIANGLE
, _T("triangle"), 0);
2483 AddMacroDef(ltTTFAMILY
, _T("ttfamily"), 1);
2484 AddMacroDef(ltTT
, _T("tt"), 1);
2485 AddMacroDef(ltTYPEIN
, _T("typein"), 1);
2486 AddMacroDef(ltTYPEOUT
, _T("typeout"), 1);
2487 AddMacroDef(ltTWOCOLWIDTHA
, _T("twocolwidtha"), 1);
2488 AddMacroDef(ltTWOCOLWIDTHB
, _T("twocolwidthb"), 1);
2489 AddMacroDef(ltTWOCOLSPACING
, _T("twocolspacing"), 1);
2490 AddMacroDef(ltTWOCOLITEMRULED
, _T("twocolitemruled"), 2);
2491 AddMacroDef(ltTWOCOLITEM
, _T("twocolitem"), 2);
2492 AddMacroDef(ltTWOCOLLIST
, _T("twocollist"), 1);
2493 AddMacroDef(ltTWOCOLUMN
, _T("twocolumn"), 0);
2494 AddMacroDef(ltTHEPAGE
, _T("thepage"), 0);
2495 AddMacroDef(ltTHECHAPTER
, _T("thechapter"), 0);
2496 AddMacroDef(ltTHESECTION
, _T("thesection"), 0);
2497 AddMacroDef(ltTHISPAGESTYLE
, _T("thispagestyle"), 1);
2499 AddMacroDef(ltUNDERLINE
, _T("underline"), 1);
2500 AddMacroDef(ltUPSILON
, _T("upsilon"), 0);
2501 AddMacroDef(ltCAP_UPSILON
, _T("Upsilon"), 0);
2502 AddMacroDef(ltUPARROW
, _T("uparrow"), 0);
2503 AddMacroDef(ltUPARROW2
, _T("Uparrow"), 0);
2504 AddMacroDef(ltUPPERCASE
, _T("uppercase"), 1);
2505 AddMacroDef(ltUPSHAPE
, _T("upshape"), 1);
2506 AddMacroDef(ltURLREF
, _T("urlref"), 2);
2507 AddMacroDef(ltUSEPACKAGE
, _T("usepackage"), 1);
2509 AddMacroDef(ltVAREPSILON
, _T("varepsilon"), 0);
2510 AddMacroDef(ltVARPHI
, _T("varphi"), 0);
2511 AddMacroDef(ltVARPI
, _T("varpi"), 0);
2512 AddMacroDef(ltVARRHO
, _T("varrho"), 0);
2513 AddMacroDef(ltVARSIGMA
, _T("varsigma"), 0);
2514 AddMacroDef(ltVARTHETA
, _T("vartheta"), 0);
2515 AddMacroDef(ltVDOTS
, _T("vdots"), 0);
2516 AddMacroDef(ltVEE
, _T("vee"), 0);
2517 AddMacroDef(ltVERBATIMINPUT
, _T("verbatiminput"), 1);
2518 AddMacroDef(ltVERBATIM
, _T("verbatim"), 1);
2519 AddMacroDef(ltVERBSTAR
, _T("verb*"), 1);
2520 AddMacroDef(ltVERB
, _T("verb"), 1);
2521 AddMacroDef(ltVERSE
, _T("verse"), 1);
2522 AddMacroDef(ltVFILL
, _T("vfill"), 0);
2523 AddMacroDef(ltVLINE
, _T("vline"), 0);
2524 AddMacroDef(ltVOID
, _T("void"), 0);
2525 AddMacroDef(ltVDASH
, _T("vdash"), 0);
2526 AddMacroDef(ltVRULE
, _T("vrule"), 0);
2527 AddMacroDef(ltVSPACESTAR
, _T("vspace*"), 1);
2528 AddMacroDef(ltVSKIPSTAR
, _T("vskip*"), 1);
2529 AddMacroDef(ltVSPACE
, _T("vspace"), 1);
2530 AddMacroDef(ltVSKIP
, _T("vskip"), 1);
2532 AddMacroDef(ltWEDGE
, _T("wedge"), 0);
2533 AddMacroDef(ltWXCLIPS
, _T("wxclips"), 0);
2534 AddMacroDef(ltWINHELPIGNORE
, _T("winhelpignore"), 1);
2535 AddMacroDef(ltWINHELPONLY
, _T("winhelponly"), 1);
2536 AddMacroDef(ltWP
, _T("wp"), 0);
2538 AddMacroDef(ltXI
, _T("xi"), 0);
2539 AddMacroDef(ltCAP_XI
, _T("Xi"), 0);
2540 AddMacroDef(ltXLPIGNORE
, _T("xlpignore"), 1);
2541 AddMacroDef(ltXLPONLY
, _T("xlponly"), 1);
2543 AddMacroDef(ltZETA
, _T("zeta"), 0);
2545 AddMacroDef(ltSPACE
, _T(" "), 0);
2546 AddMacroDef(ltBACKSLASHCHAR
, _T("\\"), 0);
2547 AddMacroDef(ltPIPE
, _T("|"), 0);
2548 AddMacroDef(ltFORWARDSLASH
, _T("/"), 0);
2549 AddMacroDef(ltUNDERSCORE
, _T("_"), 0);
2550 AddMacroDef(ltAMPERSAND
, _T("&"), 0);
2551 AddMacroDef(ltPERCENT
, _T("%"), 0);
2552 AddMacroDef(ltDOLLAR
, _T("$"), 0);
2553 AddMacroDef(ltHASH
, _T("#"), 0);
2554 AddMacroDef(ltLPARENTH
, _T("("), 0);
2555 AddMacroDef(ltRPARENTH
, _T(")"), 0);
2556 AddMacroDef(ltLBRACE
, _T("{"), 0);
2557 AddMacroDef(ltRBRACE
, _T("}"), 0);
2558 // AddMacroDef(ltEQUALS, _T("="), 0);
2559 AddMacroDef(ltRANGLEBRA
, _T(">"), 0);
2560 AddMacroDef(ltLANGLEBRA
, _T("<"), 0);
2561 AddMacroDef(ltPLUS
, _T("+"), 0);
2562 AddMacroDef(ltDASH
, _T("-"), 0);
2563 AddMacroDef(ltAT_SYMBOL
, _T("@"), 0);
2564 // AddMacroDef(ltSINGLEQUOTE, _T("'"), 0);
2565 // AddMacroDef(ltBACKQUOTE, _T("`"), 0);
2569 * Default behaviour, should be called by client if can't match locally.
2573 // Called on start/end of macro examination
2574 void DefaultOnMacro(int macroId
, int no_args
, bool start
)
2578 // Default behaviour for abstract
2583 // Write the heading
2584 FakeCurrentSection(AbstractNameString
);
2585 OnMacro(ltPAR
, 0, true);
2586 OnMacro(ltPAR
, 0, false);
2590 if (DocumentStyle
== LATEX_ARTICLE
)
2598 // Default behaviour for glossary
2599 case ltHELPGLOSSARY
:
2603 // Write the heading
2604 FakeCurrentSection(GlossaryNameString
);
2605 OnMacro(ltPAR
, 0, true);
2606 OnMacro(ltPAR
, 0, false);
2607 if ((convertMode
== TEX_RTF
) && !winHelp
)
2609 OnMacro(ltPAR
, 0, true);
2610 OnMacro(ltPAR
, 0, false);
2615 case ltSPECIALAMPERSAND
:
2623 if (convertMode
== TEX_HTML
)
2624 TexOutput(_T("<<"));
2626 TexOutput(_T("<<"), true);
2632 if (convertMode
== TEX_HTML
)
2633 TexOutput(_T(">>"));
2635 TexOutput(_T(">>"), true);
2640 TexOutput(_T("~"), true);
2644 TexOutput(_T("~"), true);
2646 case ltSPECIALTILDE
:
2648 TexOutput(_T(" "), true);
2652 TexOutput(_T("_"), true);
2656 TexOutput(_T("#"), true);
2660 TexOutput(_T("&"), true);
2664 TexOutput(_T(" "), true);
2668 TexOutput(_T("|"), true);
2672 TexOutput(_T("%"), true);
2676 TexOutput(_T("$"), true);
2680 TexOutput(_T(""), true);
2684 TexOutput(_T(""), true);
2688 TexOutput(_T("{"), true);
2692 TexOutput(_T("}"), true);
2696 TexOutput(_T("(c)"), true);
2700 TexOutput(_T("(r)"), true);
2704 TexOutput(_T("\\"), true);
2709 TexOutput(_T("..."), true);
2713 TexOutput(_T("|"), true);
2717 TexOutput(_T("LaTeX"), true);
2721 TexOutput(_T("TeX"), true);
2725 // FIXME: this is valid only if the output is iso-8859-1
2726 TexOutput(wxString::FromAscii("£"), true);
2728 case ltSPECIALDOUBLEDOLLAR
: // Interpret as center
2729 OnMacro(ltCENTER
, no_args
, start
);
2735 OnMacro(ltIT
, no_args
, start
);
2738 case ltPARAGRAPHSTAR
:
2739 case ltSUBPARAGRAPH
:
2740 case ltSUBPARAGRAPHSTAR
:
2741 OnMacro(ltSUBSUBSECTION
, no_args
, start
);
2749 TexOutput(wxCtime(&when
), true);
2760 if (start
) TexOutput(_T("alpha"));
2763 if (start
) TexOutput(_T("beta"));
2766 if (start
) TexOutput(_T("gamma"));
2769 if (start
) TexOutput(_T("delta"));
2773 if (start
) TexOutput(_T("epsilon"));
2776 if (start
) TexOutput(_T("zeta"));
2779 if (start
) TexOutput(_T("eta"));
2783 if (start
) TexOutput(_T("theta"));
2786 if (start
) TexOutput(_T("iota"));
2789 if (start
) TexOutput(_T("kappa"));
2792 if (start
) TexOutput(_T("lambda"));
2795 if (start
) TexOutput(_T("mu"));
2798 if (start
) TexOutput(_T("nu"));
2801 if (start
) TexOutput(_T("xi"));
2805 if (start
) TexOutput(_T("pi"));
2809 if (start
) TexOutput(_T("rho"));
2813 if (start
) TexOutput(_T("sigma"));
2816 if (start
) TexOutput(_T("tau"));
2819 if (start
) TexOutput(_T("upsilon"));
2823 if (start
) TexOutput(_T("phi"));
2826 if (start
) TexOutput(_T("chi"));
2829 if (start
) TexOutput(_T("psi"));
2832 if (start
) TexOutput(_T("omega"));
2835 if (start
) TexOutput(_T("GAMMA"));
2838 if (start
) TexOutput(_T("DELTA"));
2841 if (start
) TexOutput(_T("THETA"));
2844 if (start
) TexOutput(_T("LAMBDA"));
2847 if (start
) TexOutput(_T("XI"));
2850 if (start
) TexOutput(_T("PI"));
2853 if (start
) TexOutput(_T("SIGMA"));
2856 if (start
) TexOutput(_T("UPSILON"));
2859 if (start
) TexOutput(_T("PHI"));
2862 if (start
) TexOutput(_T("PSI"));
2865 if (start
) TexOutput(_T("OMEGA"));
2868 // Binary operation symbols
2873 if (convertMode
== TEX_HTML
)
2874 TexOutput(_T("<="));
2876 TexOutput(_T("<="));
2882 if (convertMode
== TEX_HTML
)
2883 TexOutput(_T("<<"));
2885 TexOutput(_T("<<"));
2889 if (start
) TexOutput(_T("SUBSET"));
2892 if (start
) TexOutput(_T("SUBSETEQ"));
2895 if (start
) TexOutput(_T("IN"));
2898 if (start
) TexOutput(_T("VDASH"));
2901 if (start
) TexOutput(_T("MODELS"));
2908 if (convertMode
== TEX_HTML
)
2909 TexOutput(_T(">="));
2911 TexOutput(_T(">="));
2918 if (convertMode
== TEX_HTML
)
2919 TexOutput(_T(">>"));
2921 TexOutput(_T(">>"));
2925 if (start
) TexOutput(_T("SUPSET"));
2928 if (start
) TexOutput(_T("SUPSETEQ"));
2931 if (start
) TexOutput(_T("NI"));
2934 if (start
) TexOutput(_T("DASHV"));
2937 if (start
) TexOutput(_T("PERP"));
2940 if (start
) TexOutput(_T("NEQ"));
2943 if (start
) TexOutput(_T("DOTEQ"));
2946 if (start
) TexOutput(_T("APPROX"));
2949 if (start
) TexOutput(_T("CONG"));
2952 if (start
) TexOutput(_T("EQUIV"));
2955 if (start
) TexOutput(_T("PROPTO"));
2958 if (start
) TexOutput(_T("PREC"));
2961 if (start
) TexOutput(_T("PRECEQ"));
2964 if (start
) TexOutput(_T("|"));
2967 if (start
) TexOutput(_T("~"));
2970 if (start
) TexOutput(_T("SIMEQ"));
2973 if (start
) TexOutput(_T("ASYMP"));
2976 if (start
) TexOutput(_T(":-)"));
2979 if (start
) TexOutput(_T(":-("));
2982 if (start
) TexOutput(_T("SUCC"));
2985 if (start
) TexOutput(_T("SUCCEQ"));
2988 if (start
) TexOutput(_T("|"));
2991 // Negated relation symbols
2993 if (start
) TexOutput(_T("!="));
2996 if (start
) TexOutput(_T("NOTIN"));
2999 if (start
) TexOutput(_T("NOTSUBSET"));
3006 if (convertMode
== TEX_HTML
)
3007 TexOutput(_T("<--"));
3009 TexOutput(_T("<--"));
3015 if (convertMode
== TEX_HTML
)
3016 TexOutput(_T("<=="));
3018 TexOutput(_T("<=="));
3024 if (convertMode
== TEX_HTML
)
3025 TexOutput(_T("-->"));
3027 TexOutput(_T("-->"));
3033 if (convertMode
== TEX_HTML
)
3034 TexOutput(_T("==>"));
3036 TexOutput(_T("==>"));
3039 case ltLEFTRIGHTARROW
:
3042 if (convertMode
== TEX_HTML
)
3043 TexOutput(_T("<-->"));
3045 TexOutput(_T("<-->"));
3048 case ltLEFTRIGHTARROW2
:
3051 if (convertMode
== TEX_HTML
)
3052 TexOutput(_T("<==>"));
3054 TexOutput(_T("<==>"));
3058 if (start
) TexOutput(_T("UPARROW"));
3061 if (start
) TexOutput(_T("UPARROW2"));
3064 if (start
) TexOutput(_T("DOWNARROW"));
3067 if (start
) TexOutput(_T("DOWNARROW2"));
3069 // Miscellaneous symbols
3071 if (start
) TexOutput(_T("ALEPH"));
3074 if (start
) TexOutput(_T("WP"));
3077 if (start
) TexOutput(_T("RE"));
3080 if (start
) TexOutput(_T("IM"));
3083 if (start
) TexOutput(_T("EMPTYSET"));
3086 if (start
) TexOutput(_T("NABLA"));
3089 if (start
) TexOutput(_T("SURD"));
3092 if (start
) TexOutput(_T("PARTIAL"));
3095 if (start
) TexOutput(_T("BOT"));
3098 if (start
) TexOutput(_T("FORALL"));
3101 if (start
) TexOutput(_T("EXISTS"));
3104 if (start
) TexOutput(_T("NEG"));
3107 if (start
) TexOutput(_T("SHARP"));
3110 if (start
) TexOutput(_T("ANGLE"));
3113 if (start
) TexOutput(_T("TRIANGLE"));
3116 if (start
) TexOutput(_T("CLUBSUIT"));
3119 if (start
) TexOutput(_T("DIAMONDSUIT"));
3122 if (start
) TexOutput(_T("HEARTSUIT"));
3125 if (start
) TexOutput(_T("SPADESUIT"));
3128 if (start
) TexOutput(_T("INFTY"));
3131 if (start
) TexOutput(_T("PM"));
3134 if (start
) TexOutput(_T("MP"));
3137 if (start
) TexOutput(_T("TIMES"));
3140 if (start
) TexOutput(_T("DIV"));
3143 if (start
) TexOutput(_T("CDOT"));
3146 if (start
) TexOutput(_T("AST"));
3149 if (start
) TexOutput(_T("STAR"));
3152 if (start
) TexOutput(_T("CAP"));
3155 if (start
) TexOutput(_T("CUP"));
3158 if (start
) TexOutput(_T("VEE"));
3161 if (start
) TexOutput(_T("WEDGE"));
3164 if (start
) TexOutput(_T("CIRC"));
3167 if (start
) TexOutput(_T("BULLET"));
3170 if (start
) TexOutput(_T("DIAMOND"));
3173 if (start
) TexOutput(_T("OSLASH"));
3176 if (start
) TexOutput(_T("BOX"));
3179 if (start
) TexOutput(_T("DIAMOND2"));
3181 case ltBIGTRIANGLEDOWN
:
3182 if (start
) TexOutput(_T("BIGTRIANGLEDOWN"));
3185 if (start
) TexOutput(_T("OPLUS"));
3188 if (start
) TexOutput(_T("OTIMES"));
3191 if (start
) TexOutput(_T("s"));
3193 case ltBACKSLASHRAW
:
3194 if (start
) TexOutput(_T("\\"));
3197 if (start
) TexOutput(_T("{"));
3200 if (start
) TexOutput(_T("}"));
3204 if (start
) TexOutput(_T(" "));
3211 // Called on start/end of argument examination
3212 bool DefaultOnArgument(int macroId
, int arg_no
, bool start
)
3218 if (arg_no
== 1 && start
)
3220 wxChar
*refName
= GetArgData();
3223 TexRef
*texRef
= FindReference(refName
);
3226 // Must strip the 'section' or 'chapter' or 'figure' text
3227 // from a normal 'ref' reference
3229 wxStrcpy(buf
, texRef
->sectionNumber
);
3230 int len
= wxStrlen(buf
);
3232 if (wxStrcmp(buf
, _T("??")) != 0)
3244 TexOutput(texRef
->sectionNumber
+ i
, true);
3249 informBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
3250 OnInform(informBuf
);
3253 else TexOutput(_T("??"), true);
3264 if (start
&& (arg_no
== 1))
3265 DocumentAuthor
= GetArgChunk();
3270 if (start
&& (arg_no
== 1))
3271 DocumentDate
= GetArgChunk();
3276 if (start
&& (arg_no
== 1))
3277 DocumentTitle
= GetArgChunk();
3280 case ltDOCUMENTCLASS
:
3281 case ltDOCUMENTSTYLE
:
3283 if (start
&& !IsArgOptional())
3285 DocumentStyleString
= copystring(GetArgData());
3286 if (wxStrncmp(DocumentStyleString
, _T("art"), 3) == 0)
3287 DocumentStyle
= LATEX_ARTICLE
;
3288 else if (wxStrncmp(DocumentStyleString
, _T("rep"), 3) == 0)
3289 DocumentStyle
= LATEX_REPORT
;
3290 else if (wxStrncmp(DocumentStyleString
, _T("book"), 4) == 0 ||
3291 wxStrncmp(DocumentStyleString
, _T("thesis"), 6) == 0)
3292 DocumentStyle
= LATEX_BOOK
;
3293 else if (wxStrncmp(DocumentStyleString
, _T("letter"), 6) == 0)
3294 DocumentStyle
= LATEX_LETTER
;
3295 else if (wxStrncmp(DocumentStyleString
, _T("slides"), 6) == 0)
3296 DocumentStyle
= LATEX_SLIDES
;
3298 if (StringMatch(_T("10"), DocumentStyleString
))
3300 else if (StringMatch(_T("11"), DocumentStyleString
))
3302 else if (StringMatch(_T("12"), DocumentStyleString
))
3305 OnMacro(ltHELPFONTSIZE
, 1, true);
3306 wxSnprintf(currentArgData
, 2000, _T("%d"), normalFont
);
3308 OnArgument(ltHELPFONTSIZE
, 1, true);
3309 OnArgument(ltHELPFONTSIZE
, 1, false);
3310 haveArgData
= false;
3311 OnMacro(ltHELPFONTSIZE
, 1, false);
3313 else if (start
&& IsArgOptional())
3315 MinorDocumentStyleString
= copystring(GetArgData());
3317 if (StringMatch(_T("10"), MinorDocumentStyleString
))
3319 else if (StringMatch(_T("11"), MinorDocumentStyleString
))
3321 else if (StringMatch(_T("12"), MinorDocumentStyleString
))
3326 case ltBIBLIOGRAPHYSTYLE
:
3328 if (start
&& !IsArgOptional())
3329 BibliographyStyleString
= copystring(GetArgData());
3334 if (start
&& !IsArgOptional())
3336 if (PageStyle
) delete[] PageStyle
;
3337 PageStyle
= copystring(GetArgData());
3344 if (start && !IsArgOptional())
3345 LeftHeader = GetArgChunk();
3351 if (start && !IsArgOptional())
3352 LeftFooter = GetArgChunk();
3358 if (start && !IsArgOptional())
3359 CentreHeader = GetArgChunk();
3365 if (start && !IsArgOptional())
3366 CentreFooter = GetArgChunk();
3372 if (start && !IsArgOptional())
3373 RightHeader = GetArgChunk();
3379 if (start && !IsArgOptional())
3380 RightFooter = GetArgChunk();
3388 if (start
&& !IsArgOptional())
3390 wxChar
*citeKeys
= GetArgData();
3392 wxChar
*citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3395 AddCitation(citeKey
);
3396 TexRef
*ref
= FindReference(citeKey
);
3399 TexOutput(ref
->sectionNumber
, true);
3400 if (wxStrcmp(ref
->sectionNumber
, _T("??")) == 0)
3403 informBuf
.Printf(_T("Warning: unresolved citation %s."), citeKey
);
3404 OnInform(informBuf
);
3407 citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3410 TexOutput(_T(", "), true);
3419 if (start
&& !IsArgOptional())
3421 wxChar
*citeKey
= GetArgData();
3422 AddCitation(citeKey
);
3427 case ltHELPFONTSIZE
:
3431 wxChar
*data
= GetArgData();
3432 if (wxStrcmp(data
, _T("10")) == 0)
3434 else if (wxStrcmp(data
, _T("11")) == 0)
3436 else if (wxStrcmp(data
, _T("12")) == 0)
3446 TexOutput(_T(" ??"), true);
3453 if (start
&& arg_no
== 1)
3455 wxChar
*data
= GetArgData();
3456 ParSkip
= ParseUnitArgument(data
);
3463 if (start
&& arg_no
== 1)
3465 wxChar
*data
= GetArgData();
3466 ParIndent
= ParseUnitArgument(data
);
3473 return OnArgument(ltIT
, arg_no
, start
);
3475 case ltSPECIALDOUBLEDOLLAR
:
3477 return OnArgument(ltCENTER
, arg_no
, start
);
3480 case ltPARAGRAPHSTAR
:
3481 case ltSUBPARAGRAPH
:
3482 case ltSUBPARAGRAPHSTAR
:
3484 return OnArgument(ltSUBSUBSECTION
, arg_no
, start
);
3489 OnInform(GetArgData());
3495 TexOutput(_T(" ("), true);
3497 TexOutput(_T(")"), true);
3500 case ltBIBLIOGRAPHY
:
3507 FILE *fd
= wxFopen(TexBibName
, _T("r"));
3511 smallBuf
[0] = (wxChar
)ch
;
3514 TexOutput(smallBuf
);
3516 smallBuf
[0] = (wxChar
)ch
;
3522 OnInform(_T("Run Tex2RTF again to include bibliography."));
3525 // Read in the .bib file, resolve all known references, write out the RTF.
3526 wxChar
*allFiles
= GetArgData();
3528 wxChar
*bibFile
= ParseMultifieldString(allFiles
, &pos
);
3531 wxChar fileBuf
[300];
3532 wxStrcpy(fileBuf
, bibFile
);
3533 wxString actualFile
= TexPathList
.FindValidPath(fileBuf
);
3534 if (actualFile
.empty())
3536 wxStrcat(fileBuf
, _T(".bib"));
3537 actualFile
= TexPathList
.FindValidPath(fileBuf
);
3539 if (!actualFile
.empty())
3541 if (!ReadBib((wxChar
*) (const wxChar
*) actualFile
))
3544 errBuf
.Printf(_T(".bib file %s not found or malformed"), (const wxChar
*) actualFile
);
3551 errBuf
.Printf(_T(".bib file %s not found"), fileBuf
);
3554 bibFile
= ParseMultifieldString(allFiles
, &pos
);
3557 ResolveBibReferences();
3559 // Write it a new bib section in the appropriate format.
3560 FILE *save1
= CurrentOutput1
;
3561 FILE *save2
= CurrentOutput2
;
3562 FILE *Biblio
= wxFopen(TexTmpBibName
, _T("w"));
3563 SetCurrentOutput(Biblio
);
3566 if (wxFileExists(TexTmpBibName
))
3568 if (wxFileExists(TexBibName
)) wxRemoveFile(TexBibName
);
3569 wxRenameFile(TexTmpBibName
, TexBibName
);
3571 SetCurrentOutputs(save1
, save2
);
3577 return (start
&& (arg_no
== 3));
3582 if (start
&& (arg_no
== 1))
3584 wxChar
*s
= GetArgData();
3587 wxChar
*s1
= copystring(s
);
3589 for (i
= 0; i
< (int)wxStrlen(s
); i
++)
3590 s1
[i
] = (wxChar
)wxToupper(s
[i
]);
3602 if (start
&& (arg_no
== 1))
3604 wxChar
*s
= GetArgData();
3607 wxChar
*s1
= copystring(s
);
3609 for (i
= 0; i
< (int)wxStrlen(s
); i
++)
3610 s1
[i
] = (wxChar
)wxTolower(s
[i
]);
3622 if (start
&& (arg_no
== 1))
3624 wxChar
*s
= GetArgData();
3627 wxChar
*s1
= copystring(s
);
3629 for (i
= 0; i
< (int)wxStrlen(s
); i
++)
3630 s1
[i
] = (wxChar
)wxToupper(s
[i
]);
3640 case ltPOPREF
: // Ignore second argument by default
3641 return (start
&& (arg_no
== 1));
3645 return ((convertMode
== TEX_XLP
) ? false : true);
3647 return ((convertMode
!= TEX_XLP
) ? false : true);
3649 return ((convertMode
== TEX_HTML
) ? false : true);
3651 return ((convertMode
!= TEX_HTML
) ? false : true);
3653 return (((convertMode
== TEX_RTF
) && !winHelp
) ? false : true);
3655 return (!((convertMode
== TEX_RTF
) && !winHelp
) ? false : true);
3656 case ltWINHELPIGNORE
:
3657 return (winHelp
? false : true);
3659 return (!winHelp
? false : true);
3671 case ltADDTOCOUNTER
:
3672 case ltADDCONTENTSLINE
:
3676 case ltBASELINESKIP
:
3685 case ltPAGENUMBERING
:
3697 case ltTHISPAGESTYLE
:
3700 case ltEVENSIDEMARGIN
:
3701 case ltODDSIDEMARGIN
:
3703 case ltMARGINPARWIDTH
:
3704 case ltMARGINPARSEP
:
3705 case ltMARGINPAREVEN
:
3706 case ltMARGINPARODD
:
3707 case ltTWOCOLWIDTHA
:
3708 case ltTWOCOLWIDTHB
:
3709 case ltTWOCOLSPACING
:
3716 case ltSETHOTSPOTCOLOUR
:
3717 case ltSETHOTSPOTCOLOR
:
3718 case ltSETHOTSPOTUNDERLINE
:
3719 case ltSETTRANSPARENCY
:
3722 case ltBACKGROUNDCOLOUR
:
3723 case ltBACKGROUNDIMAGE
:
3725 case ltFOLLOWEDLINKCOLOUR
:
3732 case ltINSERTATLEVEL
:
3735 case ltSUPERTABULAR
:
3739 return (arg_no
== 2);
3740 case ltDEFINECOLOUR
:
3743 static int redVal
= 0;
3744 static int greenVal
= 0;
3745 static int blueVal
= 0;
3746 static wxChar
*colourName
= NULL
;
3753 if (colourName
) delete[] colourName
;
3754 colourName
= copystring(GetArgData());
3759 redVal
= wxAtoi(GetArgData());
3764 greenVal
= wxAtoi(GetArgData());
3769 blueVal
= wxAtoi(GetArgData());
3770 AddColour(colourName
, redVal
, greenVal
, blueVal
);
3784 return (!IsArgOptional());