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;
447 while (ch
!= EOF
&& ch
!= 10)
449 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
452 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
453 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(), MAX_LINE_BUFFER_SIZE
);
454 OnError((wxChar
*)errBuf
.c_str());
458 if (((bufIndex
== 14) && (wxStrncmp(buf
, _T("\\end{verbatim}"), 14) == 0)) ||
459 ((bufIndex
== 16) && (wxStrncmp(buf
, _T("\\end{toocomplex}"), 16) == 0)))
460 readInVerbatim
= false;
462 ch
= getc(Inputs
[CurrentInputIndex
]);
464 if (checkCurleyBraces
)
466 if (ch
== '{' && !readInVerbatim
)
468 if (ch
== '}' && !readInVerbatim
)
471 if (rightCurley
> leftCurley
)
474 errBuf
.Printf(_T("An extra right Curley brace ('}') was detected at line %lu inside file %s"), LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
475 OnError((wxChar
*)errBuf
.c_str());
477 // Reduce the count of right Curley braces, so the mismatched count
478 // isn't reported on every line that has a '}' after the first mismatch
486 // Check for 2 consecutive newlines and replace with \par
487 if (ch
== 10 && !readInVerbatim
)
489 int ch1
= getc(Inputs
[CurrentInputIndex
]);
490 if ((ch1
== 10) || (ch1
== 13))
492 // Eliminate newline (10) following DOS linefeed
494 getc(Inputs
[CurrentInputIndex
]);
496 IncrementLineNumber();
497 // wxStrcat(buf, "\\par\n");
499 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
502 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
503 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
504 OnError((wxChar
*)errBuf
.c_str());
507 wxStrcat(buf
, _T("\\par"));
513 ungetc(ch1
, Inputs
[CurrentInputIndex
]);
514 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
517 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
518 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
519 OnError((wxChar
*)errBuf
.c_str());
530 // Convert embedded characters to RTF equivalents
539 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
542 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
543 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
544 OnError((wxChar
*)errBuf
.c_str());
547 buf
[bufIndex
++]='\\';
552 case 0xf6:buf
[bufIndex
++]='o';break; // ö
553 case 0xe4:buf
[bufIndex
++]='a';break; // ä
554 case 0xfc:buf
[bufIndex
++]='u';break; // ü
555 case 0xd6:buf
[bufIndex
++]='O';break; // Ö
556 case 0xc4:buf
[bufIndex
++]='A';break; // Ä
557 case 0xdc:buf
[bufIndex
++]='U';break; // Ü
562 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
565 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
566 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
567 OnError((wxChar
*)errBuf
.c_str());
570 buf
[bufIndex
++]='\\';
573 buf
[bufIndex
++]='\\';
577 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
580 errBuf
.Printf(_T("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated."),
581 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
582 OnError((wxChar
*)errBuf
.c_str());
585 // If the current character read in is a '_', we need to check
586 // whether there should be a '\' before it or not
589 buf
[bufIndex
++] = ch
;
597 // There should NOT be a '\' before the '_'
598 if ((bufIndex
> 0 && (buf
[bufIndex
-1] == '\\')) && (buf
[0] != '%'))
601 errBuf
.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that should NOT have a '\\' before it."),
602 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
603 OnError((wxChar
*)errBuf
.c_str());
608 // There should be a '\' before the '_'
612 errBuf
.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
613 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
614 OnError((wxChar
*)errBuf
.c_str());
616 else if ((buf
[bufIndex
-1] != '\\') && (buf
[0] != '%') && // If it is a comment line, then no warnings
617 (wxStrncmp(buf
, _T("\\input"), 6))) // do not report filenames that have underscores in them
620 errBuf
.Printf(_T("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it."),
621 LineNumbers
[CurrentInputIndex
], (const wxChar
*) currentFileName
.c_str());
622 OnError((wxChar
*)errBuf
.c_str());
626 buf
[bufIndex
++] = ch
;
634 fclose(Inputs
[CurrentInputIndex
]);
635 Inputs
[CurrentInputIndex
] = NULL
;
636 if (CurrentInputIndex
> 0)
637 ch
= ' '; // No real end of file
638 CurrentInputIndex
--;
640 if (checkCurleyBraces
)
642 if (leftCurley
!= rightCurley
)
645 errBuf
.Printf(_T("Curley braces do not match inside file %s\n%lu opens, %lu closes"),
646 (const wxChar
*) currentFileName
.c_str(),leftCurley
,rightCurley
);
647 OnError((wxChar
*)errBuf
.c_str());
655 readingVerbatim
= false;
656 readInVerbatim
= false;
657 wxStrcat(buf
, _T("\\end{verbatim}\n"));
662 IncrementLineNumber();
666 // Strip out comment environment
667 if (wxStrncmp(buf
, _T("\\begin{comment}"), 15) == 0)
669 while (wxStrncmp(buf
, _T("\\end{comment}"), 13) != 0)
671 return read_a_line(buf
);
673 // Read a verbatim input file as if it were a verbatim environment
674 else if (wxStrncmp(buf
, _T("\\verbatiminput"), 14) == 0)
677 wxChar
*fileName
= buf
+ wordLen
+ 1;
679 int j
= bufIndex
- 1;
682 // thing}\par -- eliminate the \par!
683 if (wxStrncmp((buf
+ wxStrlen(buf
)-5), _T("\\par"), 4) == 0)
690 buf
[j
-1] = 0; // Ignore final brace
692 wxString actualFile
= TexPathList
.FindValidPath(fileName
);
693 currentFileName
= actualFile
;
694 if (actualFile
== _T(""))
697 errBuf
.Printf(_T("Could not find file: %s"),fileName
);
698 OnError((wxChar
*)errBuf
.c_str());
703 informStr
.Printf(_T("Processing: %s"),actualFile
.c_str());
704 OnInform((wxChar
*)informStr
.c_str());
705 CurrentInputIndex
++;
707 Inputs
[CurrentInputIndex
] = wxFopen(actualFile
, _T("r"));
708 LineNumbers
[CurrentInputIndex
] = 1;
709 if (FileNames
[CurrentInputIndex
])
710 delete[] FileNames
[CurrentInputIndex
];
711 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
713 if (!Inputs
[CurrentInputIndex
])
715 CurrentInputIndex
--;
716 OnError(_T("Could not open verbatiminput file."));
720 readingVerbatim
= true;
721 readInVerbatim
= true;
722 wxStrcpy(buf
, _T("\\begin{verbatim}\n"));
728 else if (wxStrncmp(buf
, _T("\\input"), 6) == 0 || wxStrncmp(buf
, _T("\\helpinput"), 10) == 0 ||
729 wxStrncmp(buf
, _T("\\include"), 8) == 0)
732 if (wxStrncmp(buf
, _T("\\input"), 6) == 0)
735 if (wxStrncmp(buf
, _T("\\include"), 8) == 0)
740 wxChar
*fileName
= buf
+ wordLen
+ 1;
742 int j
= bufIndex
- 1;
745 // \input{thing}\par -- eliminate the \par!
746 // if (wxStrncmp((buf + wxStrlen(buf)-5), "\\par", 4) == 0)
747 if (wxStrncmp((buf
+ wxStrlen(buf
)-4), _T("\\par"), 4) == 0) // Bug fix 8/2/95 Ulrich Leodolter
754 if (buf
[j
-1] == _T('}'))
755 buf
[j
-1] = 0; // Ignore final brace
757 // Remove backslashes from name
758 wxString
fileNameStr(fileName
);
759 fileNameStr
.Replace(_T("\\"), _T(""));
761 // Ignore some types of input files (e.g. macro definition files)
762 wxChar
*fileOnly
= wxFileNameFromPath((wxChar
*) (const wxChar
*) fileNameStr
);
763 currentFileName
= fileOnly
;
764 if (IgnorableInputFiles
.Member(fileOnly
))
765 return read_a_line(buf
);
767 wxString actualFile
= TexPathList
.FindValidPath(fileNameStr
);
768 if (actualFile
== _T(""))
771 wxSnprintf(buf2
, sizeof(buf2
), _T("%s.tex"), fileNameStr
.c_str());
772 actualFile
= TexPathList
.FindValidPath(buf2
);
774 currentFileName
= actualFile
;
776 if (actualFile
== _T(""))
779 errBuf
.Printf(_T("Could not find file: %s"),fileName
);
780 OnError((wxChar
*)errBuf
.c_str());
784 // Ensure that if this file includes another,
785 // then we look in the same directory as this one.
786 TexPathList
.EnsureFileAccessible(actualFile
);
789 informStr
.Printf(_T("Processing: %s"),actualFile
.c_str());
790 OnInform((wxChar
*)informStr
.c_str());
791 CurrentInputIndex
++;
793 Inputs
[CurrentInputIndex
] = wxFopen(actualFile
, _T("r"));
794 LineNumbers
[CurrentInputIndex
] = 1;
795 if (FileNames
[CurrentInputIndex
])
796 delete[] FileNames
[CurrentInputIndex
];
797 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
799 if (!Inputs
[CurrentInputIndex
])
802 errBuf
.Printf(_T("Could not open include file %s"), (const wxChar
*) actualFile
);
803 CurrentInputIndex
--;
804 OnError((wxChar
*)errBuf
.c_str());
807 bool succ
= read_a_line(buf
);
813 wxString bufStr
= buf
;
814 for (int index
=0; syntaxTokens
[index
] != wxEmptyString
; index
++)
816 size_t pos
= bufStr
.find(syntaxTokens
[index
]);
817 if (pos
!= wxString::npos
&& pos
!= 0)
819 size_t commentStart
= bufStr
.find(_T("%"));
820 if (commentStart
== wxString::npos
|| commentStart
> pos
)
823 if (syntaxTokens
[index
] == _T("\\verb"))
825 errBuf
.Printf(_T("'%s$....$' was detected at line %lu inside file %s. Please replace this form with \\tt{....}"),
826 syntaxTokens
[index
].c_str(),
827 LineNumbers
[CurrentInputIndex
],
828 currentFileName
.c_str());
832 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."),
833 syntaxTokens
[index
].c_str(),
834 LineNumbers
[CurrentInputIndex
],
835 currentFileName
.c_str());
837 OnError((wxChar
*)errBuf
.c_str());
843 if (wxStrncmp(buf
, _T("\\begin{verbatim}"), 16) == 0 ||
844 wxStrncmp(buf
, _T("\\begin{toocomplex}"), 18) == 0)
845 readInVerbatim
= true;
846 else if (wxStrncmp(buf
, _T("\\end{verbatim}"), 14) == 0 ||
847 wxStrncmp(buf
, _T("\\end{toocomplex}"), 16) == 0)
848 readInVerbatim
= false;
850 if (checkCurleyBraces
)
852 if (ch
== EOF
&& leftCurley
!= rightCurley
)
855 errBuf
.Printf(_T("Curley braces do not match inside file %s\n%lu opens, %lu closes"),
856 (const wxChar
*) currentFileName
.c_str(),leftCurley
,rightCurley
);
857 OnError((wxChar
*)errBuf
.c_str());
869 bool ParseNewCommand(wxChar
*buffer
, int *pos
)
871 if ((wxStrncmp((buffer
+(*pos
)), _T("newcommand"), 10) == 0) ||
872 (wxStrncmp((buffer
+(*pos
)), _T("renewcommand"), 12) == 0))
874 if (wxStrncmp((buffer
+(*pos
)), _T("newcommand"), 10) == 0)
879 wxChar commandName
[100];
880 wxChar commandValue
[1000];
883 while (buffer
[*pos
] != _T('}') && (buffer
[*pos
] != 0))
885 commandName
[i
] = buffer
[*pos
];
892 if (buffer
[*pos
] == _T('['))
895 noArgs
= (int)(buffer
[*pos
]) - 48;
896 *pos
+= 2; // read past argument and '['
902 char ch
= buffer
[*pos
];
905 else if (ch
== _T('}'))
913 end
= !read_a_line(buffer
);
918 commandValue
[i
] = ch
;
924 CustomMacro
*macro
= new CustomMacro(commandName
, noArgs
, NULL
);
925 if (wxStrlen(commandValue
) > 0)
926 macro
->macroBody
= copystring(commandValue
);
927 if (!CustomMacroList
.Find(commandName
))
929 CustomMacroList
.Append(commandName
, macro
);
930 AddMacroDef(ltCUSTOM_MACRO
, commandName
, noArgs
);
937 void MacroError(wxChar
*buffer
)
940 wxChar macroBuf
[200];
944 while (((ch
= buffer
[i
-1]) != '\n') && (ch
!= 0))
953 errBuf
.Printf(_T("Could not find macro: %s at line %d, file %s"),
954 macroBuf
, (int)(LineNumbers
[CurrentInputIndex
]-1), FileNames
[CurrentInputIndex
]);
955 OnError((wxChar
*)errBuf
.c_str());
957 if (wxStrcmp(macroBuf
,_T("\\end{document}")) == 0)
959 OnInform( _T("Halted build due to unrecoverable error.") );
966 * 'environment' specifies the name of the macro IFF if we're looking for the end
967 * of an environment, e.g. \end{itemize}. Otherwise it's NULL.
968 * 'parseToBrace' is TRUE if the argument should extend to the next right brace,
969 * e.g. in {\bf an argument} as opposed to \vskip 30pt
972 int ParseArg(TexChunk
*thisArg
, wxList
& children
, wxChar
*buffer
, int pos
, wxChar
*environment
, bool parseToBrace
, TexChunk
*customMacroArgs
)
975 if (stopRunning
) return pos
;
984 // Consume leading brace or square bracket, but ONLY if not following
985 // a space, because this could be e.g. {\large {\bf thing}} where {\bf thing}
986 // is the argument of \large AS WELL as being a block in its
990 if ((pos > 0) && (buffer[pos-1] != ' ') && buffer[pos] == '{')
994 if ((pos > 0) && (buffer[pos-1] != ' ') && (buffer[pos] == '[' || buffer[pos] == '('))
999 else if ((pos > 1) && (buffer[pos-1] != ' ') && (buffer[pos+1] == '[' || buffer[pos+1] == '('))
1007 // If not parsing to brace, just read the next word
1008 // (e.g. \vskip 20pt)
1011 int ch
= buffer
[pos
];
1012 while (!eof
&& ch
!= 13 && ch
!= 32 && ch
!= 10 &&
1013 ch
!= 0 && ch
!= '{')
1015 BigBuffer
[buf_ptr
] = ch
;
1022 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1023 BigBuffer
[buf_ptr
] = 0;
1024 chunk
->value
= copystring(BigBuffer
);
1025 children
.Append((wxObject
*)chunk
);
1032 len
= wxStrlen(buffer
);
1035 if (customMacroArgs
) return 0;
1037 eof
= read_a_line(buffer
);
1039 // Check for verbatim (or toocomplex, which comes to the same thing)
1040 wxString bufStr
= buffer
;
1041 // if (bufStr.find("\\begin{verbatim}") != wxString::npos ||
1042 // bufStr.find("\\begin{toocomplex}") != wxString::npos)
1043 if (wxStrncmp(buffer
, _T("\\begin{verbatim}"), 16) == 0 ||
1044 wxStrncmp(buffer
, _T("\\begin{toocomplex}"), 18) == 0)
1048 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1049 BigBuffer
[buf_ptr
] = 0;
1050 chunk
->value
= copystring(BigBuffer
);
1051 children
.Append((wxObject
*)chunk
);
1056 eof
= read_a_line(buffer
);
1057 while (!eof
&& (wxStrncmp(buffer
, _T("\\end{verbatim}"), 14) != 0) &&
1058 (wxStrncmp(buffer
, _T("\\end{toocomplex}"), 16) != 0)
1061 wxStrcat(BigBuffer
, buffer
);
1062 buf_ptr
+= wxStrlen(buffer
);
1063 eof
= read_a_line(buffer
);
1065 eof
= read_a_line(buffer
);
1068 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, VerbatimMacroDef
);
1070 chunk
->macroId
= ltVERBATIM
;
1071 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, VerbatimMacroDef
);
1073 arg
->macroId
= ltVERBATIM
;
1074 TexChunk
*str
= new TexChunk(CHUNK_TYPE_STRING
);
1075 str
->value
= copystring(BigBuffer
);
1077 children
.Append((wxObject
*)chunk
);
1078 chunk
->children
.Append((wxObject
*)arg
);
1079 arg
->children
.Append((wxObject
*)str
);
1081 // Also want to include the following newline (is always a newline
1082 // after a verbatim): EXCEPT in HTML
1083 if (convertMode
!= TEX_HTML
)
1085 TexMacroDef
*parDef
= (TexMacroDef
*)MacroDefs
.Get(_T("\\"));
1086 TexChunk
*parChunk
= new TexChunk(CHUNK_TYPE_MACRO
, parDef
);
1087 parChunk
->no_args
= 0;
1088 parChunk
->macroId
= ltBACKSLASHCHAR
;
1089 children
.Append((wxObject
*)parChunk
);
1094 char ch
= buffer
[pos
];
1095 // End of optional argument -- pretend it's right brace for simplicity
1096 if (thisArg
->optional
&& (ch
== ']'))
1102 case '}': // End of argument
1106 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1107 BigBuffer
[buf_ptr
] = 0;
1108 chunk
->value
= copystring(BigBuffer
);
1109 children
.Append((wxObject
*)chunk
);
1111 if (ch
== '}') pos
++;
1116 if (buf_ptr
> 0) // Finish off the string we've read so far
1118 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1119 BigBuffer
[buf_ptr
] = 0;
1121 chunk
->value
= copystring(BigBuffer
);
1122 children
.Append((wxObject
*)chunk
);
1126 // Try matching \end{environment}
1127 if (environment
&& FindEndEnvironment(buffer
, &pos
, environment
))
1129 // Eliminate newline after an \end{} if possible
1130 if (buffer
[pos
] == 13)
1133 if (buffer
[pos
] == 10)
1139 if (ParseNewCommand(buffer
, &pos
))
1142 if (wxStrncmp(buffer
+pos
, _T("special"), 7) == 0)
1150 wxTex2RTFBuffer
[0] = 0;
1155 int ch
= buffer
[pos
];
1161 wxTex2RTFBuffer
[i
] = 0;
1166 wxTex2RTFBuffer
[i
] = '}';
1173 wxTex2RTFBuffer
[i
] = '{';
1177 else if (ch
== '\\' && buffer
[pos
+1] == '}')
1179 wxTex2RTFBuffer
[i
] = '}';
1183 else if (ch
== '\\' && buffer
[pos
+1] == '{')
1185 wxTex2RTFBuffer
[i
] = '{';
1191 wxTex2RTFBuffer
[i
] = ch
;
1198 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1200 chunk
->macroId
= ltSPECIAL
;
1201 TexMacroDef
*specialDef
= (TexMacroDef
*)MacroDefs
.Get(_T("special"));
1202 chunk
->def
= specialDef
;
1203 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, specialDef
);
1204 chunk
->children
.Append((wxObject
*)arg
);
1206 arg
->macroId
= chunk
->macroId
;
1208 // The value in the first argument.
1209 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1210 arg
->children
.Append((wxObject
*)argValue
);
1212 argValue
->value
= copystring(wxTex2RTFBuffer
);
1214 children
.Append((wxObject
*)chunk
);
1216 else if (wxStrncmp(buffer
+pos
, _T("verb"), 4) == 0)
1219 if (buffer
[pos
] == '*')
1222 // Find the delimiter character
1223 int ch
= buffer
[pos
];
1225 // Now at start of verbatim text
1227 while ((buffer
[pos
] != ch
) && buffer
[pos
] != 0)
1229 wxChar
*val
= new wxChar
[pos
- j
+ 1];
1231 for (i
= j
; i
< pos
; i
++)
1233 val
[i
-j
] = buffer
[i
];
1239 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1241 chunk
->macroId
= ltVERB
;
1242 TexMacroDef
*verbDef
= (TexMacroDef
*)MacroDefs
.Get(_T("verb"));
1243 chunk
->def
= verbDef
;
1244 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, verbDef
);
1245 chunk
->children
.Append((wxObject
*)arg
);
1247 arg
->macroId
= chunk
->macroId
;
1249 // The value in the first argument.
1250 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1251 arg
->children
.Append((wxObject
*)argValue
);
1253 argValue
->value
= val
;
1255 children
.Append((wxObject
*)chunk
);
1260 bool tmpParseToBrace
= true;
1261 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1264 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1266 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1268 chunk
->no_args
= def
->no_args
;
1269 // chunk->name = copystring(def->name);
1270 chunk
->macroId
= def
->macroId
;
1273 children
.Append((wxObject
*)chunk
);
1275 // Eliminate newline after a \begin{} or a \\ if possible
1276 if (env
|| wxStrcmp(def
->name
, _T("\\")) == 0)
1277 if (buffer
[pos
] == 13)
1280 if (buffer
[pos
] == 10)
1284 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1285 buffer
, pos
, env
, tmpParseToBrace
, customMacroArgs
);
1287 // If custom macro, parse the body substituting the above found args.
1290 if (customMacro
->macroBody
)
1292 wxChar macroBuf
[300];
1293 // wxStrcpy(macroBuf, _T("{"));
1294 wxStrcpy(macroBuf
, customMacro
->macroBody
);
1295 wxStrcat(macroBuf
, _T("}"));
1296 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, true, chunk
);
1299 // delete chunk; // Might delete children
1304 MacroError(buffer
+pos
);
1309 // Parse constructs like {\bf thing} as if they were
1314 if (buffer
[pos
] == '\\')
1318 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1319 BigBuffer
[buf_ptr
] = 0;
1321 chunk
->value
= copystring(BigBuffer
);
1322 children
.Append((wxObject
*)chunk
);
1327 bool tmpParseToBrace
;
1328 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1331 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1333 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1334 chunk
->no_args
= def
->no_args
;
1335 // chunk->name = copystring(def->name);
1336 chunk
->macroId
= def
->macroId
;
1338 children
.Append((wxObject
*)chunk
);
1340 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1341 buffer
, pos
, NULL
, true, customMacroArgs
);
1343 // If custom macro, parse the body substituting the above found args.
1346 if (customMacro
->macroBody
)
1348 wxChar macroBuf
[300];
1349 // wxStrcpy(macroBuf, _T("{"));
1350 wxStrcpy(macroBuf
, customMacro
->macroBody
);
1351 wxStrcat(macroBuf
, _T("}"));
1352 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, true, chunk
);
1355 // delete chunk; // Might delete children
1360 MacroError(buffer
+pos
);
1366 * If all else fails, we assume that we have
1367 * a pair of braces on their own, so return a `dummy' macro
1368 * definition with just one argument to parse.
1372 SoloBlockDef
= new TexMacroDef(ltSOLO_BLOCK
, _T("solo block"), 1, false);
1377 TexChunk
*chunk1
= new TexChunk(CHUNK_TYPE_STRING
);
1378 BigBuffer
[buf_ptr
] = 0;
1380 chunk1
->value
= copystring(BigBuffer
);
1381 children
.Append((wxObject
*)chunk1
);
1383 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, SoloBlockDef
);
1384 chunk
->no_args
= SoloBlockDef
->no_args
;
1385 // chunk->name = copystring(SoloBlockDef->name);
1386 chunk
->macroId
= SoloBlockDef
->macroId
;
1387 children
.Append((wxObject
*)chunk
);
1389 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, SoloBlockDef
);
1391 chunk
->children
.Append((wxObject
*)arg
);
1392 // arg->name = copystring(SoloBlockDef->name);
1394 arg
->macroId
= chunk
->macroId
;
1396 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, NULL
, true, customMacroArgs
);
1404 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1405 BigBuffer
[buf_ptr
] = 0;
1407 chunk
->value
= copystring(BigBuffer
);
1408 children
.Append((wxObject
*)chunk
);
1413 if (buffer
[pos
] == '$')
1415 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1417 // chunk->name = copystring(_T("$$"));
1418 chunk
->macroId
= ltSPECIALDOUBLEDOLLAR
;
1419 children
.Append((wxObject
*)chunk
);
1424 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1426 // chunk->name = copystring(_T("_$"));
1427 chunk
->macroId
= ltSPECIALDOLLAR
;
1428 children
.Append((wxObject
*)chunk
);
1436 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1437 BigBuffer
[buf_ptr
] = 0;
1439 chunk
->value
= copystring(BigBuffer
);
1440 children
.Append((wxObject
*)chunk
);
1444 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1446 // chunk->name = copystring(_T("_~"));
1447 chunk
->macroId
= ltSPECIALTILDE
;
1448 children
.Append((wxObject
*)chunk
);
1451 case '#': // Either treat as a special TeX character or as a macro arg
1455 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1456 BigBuffer
[buf_ptr
] = 0;
1458 chunk
->value
= copystring(BigBuffer
);
1459 children
.Append((wxObject
*)chunk
);
1463 if (!customMacroArgs
)
1465 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1467 // chunk->name = copystring(_T("_#"));
1468 chunk
->macroId
= ltSPECIALHASH
;
1469 children
.Append((wxObject
*)chunk
);
1473 if (isdigit(buffer
[pos
]))
1475 int n
= buffer
[pos
] - 48;
1477 wxNode
*node
= customMacroArgs
->children
.Item(n
-1);
1480 TexChunk
*argChunk
= (TexChunk
*)node
->GetData();
1481 children
.Append((wxObject
*)new TexChunk(*argChunk
));
1489 // Remove white space before and after the ampersand,
1490 // since this is probably a table column separator with
1491 // some convenient -- but useless -- white space in the text.
1492 while ((buf_ptr
> 0) && ((BigBuffer
[buf_ptr
-1] == ' ') || (BigBuffer
[buf_ptr
-1] == 9)))
1497 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1498 BigBuffer
[buf_ptr
] = 0;
1500 chunk
->value
= copystring(BigBuffer
);
1501 children
.Append((wxObject
*)chunk
);
1506 while (buffer
[pos
] == ' ' || buffer
[pos
] == 9)
1509 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1511 // chunk->name = copystring(_T("_&"));
1512 chunk
->macroId
= ltSPECIALAMPERSAND
;
1513 children
.Append((wxObject
*)chunk
);
1516 // Eliminate end-of-line comment
1520 while (ch
!= 10 && ch
!= 13 && ch
!= 0)
1525 if (buffer
[pos
] == 10 || buffer
[pos
] == 13)
1528 if (buffer
[pos
] == 10) pos
++; // Eliminate newline following DOS line feed
1535 BigBuffer
[buf_ptr
] = ' ';
1536 BigBuffer
[buf_ptr
+1] = 0;
1543 BigBuffer
[buf_ptr
] = ch
;
1544 BigBuffer
[buf_ptr
+1] = 0;
1555 * Consume as many arguments as the macro definition specifies
1559 int ParseMacroBody(const wxChar
*WXUNUSED(macro_name
), TexChunk
*parent
,
1560 int no_args
, wxChar
*buffer
, int pos
,
1561 wxChar
*environment
, bool parseToBrace
,
1562 TexChunk
*customMacroArgs
)
1565 if (stopRunning
) return pos
;
1567 // Check for a first optional argument
1568 if (buffer
[pos
] == ' ' && buffer
[pos
+1] == '[')
1570 // Fool following code into thinking that this is definitely
1571 // an optional first argument. (If a space before a non-first argument,
1572 // [ is interpreted as a [, not an optional argument.)
1578 if (buffer
[pos
] == '[')
1584 for (i
= 0; i
< no_args
; i
++)
1587 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, parent
->def
);
1589 parent
->children
.Append((wxObject
*)arg
);
1590 // arg->name = copystring(macro_name);
1591 arg
->argn
= maxArgs
;
1592 arg
->macroId
= parent
->macroId
;
1594 // To parse the first arg of a 2 arg \begin{thing}{arg} ... \end{thing}
1595 // have to fool parser into thinking this is a regular kind of block.
1597 if ((no_args
== 2) && (i
== 0))
1600 actualEnv
= environment
;
1602 bool isOptional
= false;
1604 // Remove the first { of the argument so it doesn't get recognized as { ... }
1605 // EatWhiteSpace(buffer, &pos);
1608 // The reason for these tests is to not consume braces that don't
1609 // belong to this macro.
1610 // E.g. {\bf {\small thing}}
1611 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && buffer
[pos
] == '{')
1614 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && (buffer
[pos
] == '['))
1619 else if ((pos
> 1) && (buffer
[pos
-1] != ' ') && (buffer
[pos
+1] == '['))
1627 wxString
tmpBuffer(buffer
);
1628 if (tmpBuffer
.length() > 4)
1630 if (tmpBuffer
.Right(4) == _T("\\par"))
1631 tmpBuffer
= tmpBuffer
.Mid(0,tmpBuffer
.length()-4);
1633 errBuf
.Printf(_T("Missing macro argument in the line:\n\t%s\n"),tmpBuffer
.c_str());
1634 OnError((wxChar
*)errBuf
.c_str());
1638 arg
->optional
= isOptional
;
1640 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, actualEnv
, parseToBrace
, customMacroArgs
);
1642 // If we've encountered an OPTIONAL argument, go another time around
1643 // the loop, because we've got more than we thought.
1644 // Hopefully optional args don't occur at the end of a macro use
1645 // or we might miss it.
1646 // Don't increment no of times round loop if the first optional arg
1647 // -- we already did it before the loop.
1648 if (arg
->optional
&& (i
> 0))
1651 parent
->no_args
= maxArgs
;
1653 // Tell each argument how many args there are (useful when processing an arg)
1654 wxNode
*node
= parent
->children
.GetFirst();
1657 TexChunk
*chunk
= (TexChunk
*)node
->GetData();
1658 chunk
->no_args
= maxArgs
;
1659 node
= node
->GetNext();
1664 bool TexLoadFile(wxChar
*filename
)
1666 static wxChar
*line_buffer
;
1667 stopRunning
= false;
1668 wxStrcpy(TexFileRoot
, filename
);
1669 StripExtension(TexFileRoot
);
1670 wxSnprintf(TexBibName
, 300, _T("%s.bb"), TexFileRoot
);
1671 wxSnprintf(TexTmpBibName
, 300, _T("%s.bb1"), TexFileRoot
);
1673 TexPathList
.EnsureFileAccessible(filename
);
1678 line_buffer
= new wxChar
[MAX_LINE_BUFFER_SIZE
];
1680 Inputs
[0] = wxFopen(filename
, _T("r"));
1682 FileNames
[0] = copystring(filename
);
1685 read_a_line(line_buffer
);
1686 ParseMacroBody(_T("toplevel"), TopLevel
, 1, line_buffer
, 0, NULL
, true);
1687 if (Inputs
[0]) fclose(Inputs
[0]);
1694 TexMacroDef::TexMacroDef(int the_id
, const wxChar
*the_name
, int n
, bool ig
, bool forbidLevel
)
1696 name
= copystring(the_name
);
1700 forbidden
= forbidLevel
;
1703 TexMacroDef::~TexMacroDef(void)
1705 if (name
) delete[] name
;
1708 TexChunk::TexChunk(int the_type
, TexMacroDef
*the_def
)
1720 TexChunk::TexChunk(TexChunk
& toCopy
)
1723 no_args
= toCopy
.no_args
;
1725 macroId
= toCopy
.macroId
;
1728 // name = copystring(toCopy.name);
1734 value
= copystring(toCopy
.value
);
1738 optional
= toCopy
.optional
;
1739 wxNode
*node
= toCopy
.children
.GetFirst();
1742 TexChunk
*child
= (TexChunk
*)node
->GetData();
1743 children
.Append((wxObject
*)new TexChunk(*child
));
1744 node
= node
->GetNext();
1748 TexChunk::~TexChunk(void)
1750 // if (name) delete[] name;
1751 if (value
) delete[] value
;
1752 wxNode
*node
= children
.GetFirst();
1755 TexChunk
*child
= (TexChunk
*)node
->GetData();
1757 wxNode
*next
= node
->GetNext();
1763 bool IsArgOptional(void) // Is this argument an optional argument?
1765 return isArgOptional
;
1768 int GetNoArgs(void) // Number of args for this macro
1773 /* Gets the text of a chunk on request (must be for small arguments
1778 void GetArgData1(TexChunk
*chunk
)
1780 switch (chunk
->type
)
1782 case CHUNK_TYPE_MACRO
:
1784 TexMacroDef
*def
= chunk
->def
;
1785 if (def
&& def
->ignore
)
1788 if (def
&& (wxStrcmp(def
->name
, _T("solo block")) != 0))
1790 wxStrcat(currentArgData
, _T("\\"));
1791 wxStrcat(currentArgData
, def
->name
);
1794 wxNode
*node
= chunk
->children
.GetFirst();
1797 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1798 wxStrcat(currentArgData
, _T("{"));
1799 GetArgData1(child_chunk
);
1800 wxStrcat(currentArgData
, _T("}"));
1801 node
= node
->GetNext();
1805 case CHUNK_TYPE_ARG
:
1807 wxNode
*node
= chunk
->children
.GetFirst();
1810 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1811 GetArgData1(child_chunk
);
1812 node
= node
->GetNext();
1816 case CHUNK_TYPE_STRING
:
1819 wxStrcat(currentArgData
, chunk
->value
);
1825 wxChar
*GetArgData(TexChunk
*WXUNUSED(chunk
))
1827 currentArgData
[0] = 0;
1828 GetArgData1(currentArgument
);
1829 haveArgData
= false;
1830 return currentArgData
;
1833 wxChar
*GetArgData(void)
1837 currentArgData
[0] = 0;
1838 GetArgData1(currentArgument
);
1840 return currentArgData
;
1843 TexChunk
*GetArgChunk(void)
1845 return currentArgument
;
1848 TexChunk
*GetNextChunk(void) // Look ahead to the next chunk
1853 TexChunk
*GetTopLevelChunk(void)
1858 int GetCurrentColumn(void)
1860 return currentColumn
;
1864 * Traverses document calling functions to allow the client to
1865 * write out the appropriate stuff
1869 void TraverseFromChunk(TexChunk
*chunk
, wxNode
*thisNode
, bool childrenOnly
)
1872 if (stopRunning
) return;
1874 switch (chunk
->type
)
1876 case CHUNK_TYPE_MACRO
:
1878 TexMacroDef
*def
= chunk
->def
;
1879 if (def
&& def
->ignore
)
1883 OnMacro(chunk
->macroId
, chunk
->no_args
, true);
1885 wxNode
*node
= chunk
->children
.GetFirst();
1888 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1889 TraverseFromChunk(child_chunk
, node
);
1890 node
= node
->GetNext();
1893 if (thisNode
&& thisNode
->GetNext())
1894 nextChunk
= (TexChunk
*)thisNode
->GetNext()->GetData();
1897 OnMacro(chunk
->macroId
, chunk
->no_args
, false);
1900 case CHUNK_TYPE_ARG
:
1902 currentArgument
= chunk
;
1904 isArgOptional
= chunk
->optional
;
1905 noArgs
= chunk
->no_args
;
1907 // If OnArgument returns false, don't output.
1909 if (childrenOnly
|| OnArgument(chunk
->macroId
, chunk
->argn
, true))
1911 wxNode
*node
= chunk
->children
.GetFirst();
1914 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1915 TraverseFromChunk(child_chunk
, node
);
1916 node
= node
->GetNext();
1920 currentArgument
= chunk
;
1922 if (thisNode
&& thisNode
->GetNext())
1923 nextChunk
= (TexChunk
*)thisNode
->GetNext()->GetData();
1925 isArgOptional
= chunk
->optional
;
1926 noArgs
= chunk
->no_args
;
1929 (void)OnArgument(chunk
->macroId
, chunk
->argn
, false);
1932 case CHUNK_TYPE_STRING
:
1934 extern int issuedNewParagraph
;
1935 extern int forbidResetPar
;
1936 if (chunk
->value
&& (forbidResetPar
== 0))
1938 // If non-whitespace text, we no longer have a new paragraph.
1939 if (issuedNewParagraph
&& !((chunk
->value
[0] == 10 || chunk
->value
[0] == 13 || chunk
->value
[0] == 32)
1940 && chunk
->value
[1] == 0))
1942 issuedNewParagraph
= false;
1944 TexOutput(chunk
->value
, true);
1951 void TraverseDocument(void)
1953 TraverseFromChunk(TopLevel
, NULL
);
1956 void SetCurrentOutput(FILE *fd
)
1958 CurrentOutput1
= fd
;
1959 CurrentOutput2
= NULL
;
1962 void SetCurrentOutputs(FILE *fd1
, FILE *fd2
)
1964 CurrentOutput1
= fd1
;
1965 CurrentOutput2
= fd2
;
1968 void AddMacroDef(int the_id
, const wxChar
*name
, int n
, bool ignore
, bool forbid
)
1970 MacroDefs
.Put(name
, new TexMacroDef(the_id
, name
, n
, ignore
, forbid
));
1973 void TexInitialize(int bufSize
)
1975 InitialiseColourTable();
1977 TexPathList
.AddEnvList(_T("TEXINPUT"));
1980 TexPathList
.AddEnvList(_T("TEXINPUTS"));
1983 for (i
= 0; i
< 15; i
++)
1987 FileNames
[i
] = NULL
;
1990 IgnorableInputFiles
.Add(_T("psbox.tex"));
1991 BigBuffer
= new wxChar
[(bufSize
*1000)];
1992 currentArgData
= new wxChar
[2000];
1993 TexFileRoot
= new wxChar
[300];
1994 TexBibName
= new wxChar
[300];
1995 TexTmpBibName
= new wxChar
[300];
1996 AddMacroDef(ltTOPLEVEL
, _T("toplevel"), 1);
1997 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
1998 // TopLevel->name = copystring(_T("toplevel"));
1999 TopLevel
->macroId
= ltTOPLEVEL
;
2000 TopLevel
->no_args
= 1;
2001 VerbatimMacroDef
= (TexMacroDef
*)MacroDefs
.Get(_T("verbatim"));
2004 void TexCleanUp(void)
2007 for (i
= 0; i
< 15; i
++)
2013 subsubsectionNo
= 0;
2016 CurrentOutput1
= NULL
;
2017 CurrentOutput2
= NULL
;
2018 CurrentInputIndex
= 0;
2019 haveArgData
= false;
2024 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
2025 // TopLevel->name = copystring(_T("toplevel"));
2026 TopLevel
->macroId
= ltTOPLEVEL
;
2027 TopLevel
->no_args
= 1;
2029 DocumentTitle
= NULL
;
2030 DocumentAuthor
= NULL
;
2031 DocumentDate
= NULL
;
2032 DocumentStyle
= LATEX_REPORT
;
2033 MinorDocumentStyle
= 0;
2034 BibliographyStyleString
= copystring(_T("plain"));
2035 DocumentStyleString
= copystring(_T("report"));
2036 MinorDocumentStyleString
= NULL
;
2038 // gt - Changed this so if this is the final pass
2039 // then we DO want to remove these macros, so that
2040 // memory is not MASSIVELY leaked if the user
2041 // does not exit the program, but instead runs
2042 // the program again
2043 if ((passNumber
== 1 && !runTwice
) ||
2044 (passNumber
== 2 && runTwice
))
2046 /* Don't want to remove custom macros after each pass.*/
2048 wxNode
*node
= CustomMacroList
.GetFirst();
2051 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
2054 node
= CustomMacroList
.GetFirst();
2058 TexReferences
.BeginFind();
2059 wxNode
*node
= TexReferences
.Next();
2062 TexRef
*ref
= (TexRef
*)node
->GetData();
2064 node
= TexReferences
.Next();
2066 TexReferences
.Clear();
2068 node
= BibList
.GetFirst();
2071 BibEntry
*entry
= (BibEntry
*)node
->GetData();
2074 node
= BibList
.GetFirst();
2076 CitationList
.Clear();
2077 ResetTopicCounter();
2080 // There is likely to be one set of macros used by all utilities.
2081 void DefineDefaultMacros(void)
2083 // Put names which subsume other names at the TOP
2084 // so they get recognized first
2086 AddMacroDef(ltACCENT_GRAVE
, _T("`"), 1);
2087 AddMacroDef(ltACCENT_ACUTE
, _T("'"), 1);
2088 AddMacroDef(ltACCENT_CARET
, _T("^"), 1);
2089 AddMacroDef(ltACCENT_UMLAUT
, _T("\""), 1);
2090 AddMacroDef(ltACCENT_TILDE
, _T("~"), 1);
2091 AddMacroDef(ltACCENT_DOT
, _T("."), 1);
2092 AddMacroDef(ltACCENT_CADILLA
, _T("c"), 1);
2093 AddMacroDef(ltSMALLSPACE1
, _T(","), 0);
2094 AddMacroDef(ltSMALLSPACE2
, _T(";"), 0);
2096 AddMacroDef(ltABSTRACT
, _T("abstract"), 1);
2097 AddMacroDef(ltADDCONTENTSLINE
, _T("addcontentsline"), 3);
2098 AddMacroDef(ltADDTOCOUNTER
, _T("addtocounter"), 2);
2099 AddMacroDef(ltALEPH
, _T("aleph"), 0);
2100 AddMacroDef(ltALPHA
, _T("alpha"), 0);
2101 AddMacroDef(ltALPH1
, _T("alph"), 1);
2102 AddMacroDef(ltALPH2
, _T("Alph"), 1);
2103 AddMacroDef(ltANGLE
, _T("angle"), 0);
2104 AddMacroDef(ltAPPENDIX
, _T("appendix"), 0);
2105 AddMacroDef(ltAPPROX
, _T("approx"), 0);
2106 AddMacroDef(ltARABIC
, _T("arabic"), 1);
2107 AddMacroDef(ltARRAY
, _T("array"), 1);
2108 AddMacroDef(ltAST
, _T("ast"), 0);
2109 AddMacroDef(ltASYMP
, _T("asymp"), 0);
2110 AddMacroDef(ltAUTHOR
, _T("author"), 1);
2112 AddMacroDef(ltBACKGROUNDCOLOUR
, _T("backgroundcolour"), 1);
2113 AddMacroDef(ltBACKGROUNDIMAGE
, _T("backgroundimage"), 1);
2114 AddMacroDef(ltBACKGROUND
, _T("background"), 1);
2115 AddMacroDef(ltBACKSLASHRAW
, _T("backslashraw"), 0);
2116 AddMacroDef(ltBACKSLASH
, _T("backslash"), 0);
2117 AddMacroDef(ltBASELINESKIP
, _T("baselineskip"), 1);
2118 AddMacroDef(ltBCOL
, _T("bcol"), 2);
2119 AddMacroDef(ltBETA
, _T("beta"), 0);
2120 AddMacroDef(ltBFSERIES
, _T("bfseries"), 1);
2121 AddMacroDef(ltBF
, _T("bf"), 1);
2122 AddMacroDef(ltBIBITEM
, _T("bibitem"), 2);
2123 // For convenience, bibitem has 2 args: label and item.
2124 // The Latex syntax permits writing as 2 args.
2125 AddMacroDef(ltBIBLIOGRAPHYSTYLE
, _T("bibliographystyle"), 1);
2126 AddMacroDef(ltBIBLIOGRAPHY
, _T("bibliography"), 1);
2127 AddMacroDef(ltBIGTRIANGLEDOWN
, _T("bigtriangledown"), 0);
2128 AddMacroDef(ltBOT
, _T("bot"), 0);
2129 AddMacroDef(ltBOXIT
, _T("boxit"), 1);
2130 AddMacroDef(ltBOX
, _T("box"), 0);
2131 AddMacroDef(ltBRCLEAR
, _T("brclear"), 0);
2132 AddMacroDef(ltBULLET
, _T("bullet"), 0);
2134 AddMacroDef(ltCAPTIONSTAR
, _T("caption*"), 1);
2135 AddMacroDef(ltCAPTION
, _T("caption"), 1);
2136 AddMacroDef(ltCAP
, _T("cap"), 0);
2137 AddMacroDef(ltCDOTS
, _T("cdots"), 0);
2138 AddMacroDef(ltCDOT
, _T("cdot"), 0);
2139 AddMacroDef(ltCENTERLINE
, _T("centerline"), 1);
2140 AddMacroDef(ltCENTERING
, _T("centering"), 0);
2141 AddMacroDef(ltCENTER
, _T("center"), 1);
2142 AddMacroDef(ltCEXTRACT
, _T("cextract"), 0);
2143 AddMacroDef(ltCHAPTERHEADING
, _T("chapterheading"), 1);
2144 AddMacroDef(ltCHAPTERSTAR
, _T("chapter*"), 1);
2145 AddMacroDef(ltCHAPTER
, _T("chapter"), 1);
2146 AddMacroDef(ltCHI
, _T("chi"), 0);
2147 AddMacroDef(ltCINSERT
, _T("cinsert"), 0);
2148 AddMacroDef(ltCIRC
, _T("circ"), 0);
2149 AddMacroDef(ltCITE
, _T("cite"), 1);
2150 AddMacroDef(ltCLASS
, _T("class"), 1);
2151 AddMacroDef(ltCLEARDOUBLEPAGE
, _T("cleardoublepage"), 0);
2152 AddMacroDef(ltCLEARPAGE
, _T("clearpage"), 0);
2153 AddMacroDef(ltCLINE
, _T("cline"), 1);
2154 AddMacroDef(ltCLIPSFUNC
, _T("clipsfunc"), 3);
2155 AddMacroDef(ltCLUBSUIT
, _T("clubsuit"), 0);
2156 AddMacroDef(ltCOLUMNSEP
, _T("columnsep"), 1);
2157 AddMacroDef(ltCOMMENT
, _T("comment"), 1, true);
2158 AddMacroDef(ltCONG
, _T("cong"), 0);
2159 AddMacroDef(ltCOPYRIGHT
, _T("copyright"), 0);
2160 AddMacroDef(ltCPARAM
, _T("cparam"), 2);
2161 AddMacroDef(ltCHEAD
, _T("chead"), 1);
2162 AddMacroDef(ltCFOOT
, _T("cfoot"), 1);
2163 AddMacroDef(ltCUP
, _T("cup"), 0);
2165 AddMacroDef(ltDASHV
, _T("dashv"), 0);
2166 AddMacroDef(ltDATE
, _T("date"), 1);
2167 AddMacroDef(ltDELTA
, _T("delta"), 0);
2168 AddMacroDef(ltCAP_DELTA
, _T("Delta"), 0);
2169 AddMacroDef(ltDEFINECOLOUR
, _T("definecolour"), 4);
2170 AddMacroDef(ltDEFINECOLOR
, _T("definecolor"), 4);
2171 AddMacroDef(ltDESCRIPTION
, _T("description"), 1);
2172 AddMacroDef(ltDESTRUCT
, _T("destruct"), 1);
2173 AddMacroDef(ltDIAMOND2
, _T("diamond2"), 0);
2174 AddMacroDef(ltDIAMOND
, _T("diamond"), 0);
2175 AddMacroDef(ltDIV
, _T("div"), 0);
2176 AddMacroDef(ltDOCUMENTCLASS
, _T("documentclass"), 1);
2177 AddMacroDef(ltDOCUMENTSTYLE
, _T("documentstyle"), 1);
2178 AddMacroDef(ltDOCUMENT
, _T("document"), 1);
2179 AddMacroDef(ltDOUBLESPACE
, _T("doublespace"), 1);
2180 AddMacroDef(ltDOTEQ
, _T("doteq"), 0);
2181 AddMacroDef(ltDOWNARROW
, _T("downarrow"), 0);
2182 AddMacroDef(ltDOWNARROW2
, _T("Downarrow"), 0);
2184 AddMacroDef(ltEMPTYSET
, _T("emptyset"), 0);
2185 AddMacroDef(ltEMPH
, _T("emph"), 1);
2186 AddMacroDef(ltEM
, _T("em"), 1);
2187 AddMacroDef(ltENUMERATE
, _T("enumerate"), 1);
2188 AddMacroDef(ltEPSILON
, _T("epsilon"), 0);
2189 AddMacroDef(ltEQUATION
, _T("equation"), 1);
2190 AddMacroDef(ltEQUIV
, _T("equiv"), 0);
2191 AddMacroDef(ltETA
, _T("eta"), 0);
2192 AddMacroDef(ltEVENSIDEMARGIN
, _T("evensidemargin"), 1);
2193 AddMacroDef(ltEXISTS
, _T("exists"), 0);
2195 AddMacroDef(ltFBOX
, _T("fbox"), 1);
2196 AddMacroDef(ltFCOL
, _T("fcol"), 2);
2197 AddMacroDef(ltFIGURE
, _T("figure"), 1);
2198 AddMacroDef(ltFIGURESTAR
, _T("figure*"), 1);
2199 AddMacroDef(ltFLUSHLEFT
, _T("flushleft"), 1);
2200 AddMacroDef(ltFLUSHRIGHT
, _T("flushright"), 1);
2201 AddMacroDef(ltFOLLOWEDLINKCOLOUR
, _T("followedlinkcolour"), 1);
2202 AddMacroDef(ltFOOTHEIGHT
, _T("footheight"), 1);
2203 AddMacroDef(ltFOOTNOTEPOPUP
, _T("footnotepopup"), 2);
2204 AddMacroDef(ltFOOTNOTE
, _T("footnote"), 1);
2205 AddMacroDef(ltFOOTSKIP
, _T("footskip"), 1);
2206 AddMacroDef(ltFORALL
, _T("forall"), 0);
2207 AddMacroDef(ltFRAMEBOX
, _T("framebox"), 1);
2208 AddMacroDef(ltFROWN
, _T("frown"), 0);
2209 AddMacroDef(ltFUNCTIONSECTION
, _T("functionsection"), 1);
2210 AddMacroDef(ltFUNC
, _T("func"), 3);
2211 AddMacroDef(ltFOOTNOTESIZE
, _T("footnotesize"), 0);
2212 AddMacroDef(ltFANCYPLAIN
, _T("fancyplain"), 2);
2214 AddMacroDef(ltGAMMA
, _T("gamma"), 0);
2215 AddMacroDef(ltCAP_GAMMA
, _T("Gamma"), 0);
2216 AddMacroDef(ltGEQ
, _T("geq"), 0);
2217 AddMacroDef(ltGE
, _T("ge"), 0);
2218 AddMacroDef(ltGG
, _T("gg"), 0);
2219 AddMacroDef(ltGLOSSARY
, _T("glossary"), 1);
2220 AddMacroDef(ltGLOSS
, _T("gloss"), 1);
2222 AddMacroDef(ltHEADHEIGHT
, _T("headheight"), 1);
2223 AddMacroDef(ltHEARTSUIT
, _T("heartsuit"), 0);
2224 AddMacroDef(ltHELPGLOSSARY
, _T("helpglossary"), 1);
2225 AddMacroDef(ltHELPIGNORE
, _T("helpignore"), 1, true);
2226 AddMacroDef(ltHELPONLY
, _T("helponly"), 1);
2227 AddMacroDef(ltHELPINPUT
, _T("helpinput"), 1);
2228 AddMacroDef(ltHELPFONTFAMILY
, _T("helpfontfamily"), 1);
2229 AddMacroDef(ltHELPFONTSIZE
, _T("helpfontsize"), 1);
2230 AddMacroDef(ltHELPREFN
, _T("helprefn"), 2);
2231 AddMacroDef(ltHELPREF
, _T("helpref"), 2);
2232 AddMacroDef(ltHFILL
, _T("hfill"), 0);
2233 AddMacroDef(ltHLINE
, _T("hline"), 0);
2234 AddMacroDef(ltHRULE
, _T("hrule"), 0);
2235 AddMacroDef(ltHSPACESTAR
, _T("hspace*"), 1);
2236 AddMacroDef(ltHSPACE
, _T("hspace"), 1);
2237 AddMacroDef(ltHSKIPSTAR
, _T("hskip*"), 1);
2238 AddMacroDef(ltHSKIP
, _T("hskip"), 1);
2239 AddMacroDef(lthuge
, _T("huge"), 1);
2240 AddMacroDef(ltHuge
, _T("Huge"), 1);
2241 AddMacroDef(ltHUGE
, _T("HUGE"), 1);
2242 AddMacroDef(ltHTMLIGNORE
, _T("htmlignore"), 1);
2243 AddMacroDef(ltHTMLONLY
, _T("htmlonly"), 1);
2245 AddMacroDef(ltIM
, _T("im"), 0);
2246 AddMacroDef(ltINCLUDEONLY
, _T("includeonly"), 1);
2247 AddMacroDef(ltINCLUDE
, _T("include"), 1);
2248 AddMacroDef(ltINDENTED
, _T("indented"), 2);
2249 AddMacroDef(ltINDEX
, _T("index"), 1);
2250 AddMacroDef(ltINPUT
, _T("input"), 1, true);
2251 AddMacroDef(ltIOTA
, _T("iota"), 0);
2252 AddMacroDef(ltITEMIZE
, _T("itemize"), 1);
2253 AddMacroDef(ltITEM
, _T("item"), 0);
2254 AddMacroDef(ltIMAGEMAP
, _T("imagemap"), 3);
2255 AddMacroDef(ltIMAGEL
, _T("imagel"), 2);
2256 AddMacroDef(ltIMAGER
, _T("imager"), 2);
2257 AddMacroDef(ltIMAGE
, _T("image"), 2);
2258 AddMacroDef(ltIN
, _T("in"), 0);
2259 AddMacroDef(ltINFTY
, _T("infty"), 0);
2260 AddMacroDef(ltITSHAPE
, _T("itshape"), 1);
2261 AddMacroDef(ltIT
, _T("it"), 1);
2262 AddMacroDef(ltITEMSEP
, _T("itemsep"), 1);
2263 AddMacroDef(ltINSERTATLEVEL
, _T("insertatlevel"), 2);
2265 AddMacroDef(ltKAPPA
, _T("kappa"), 0);
2266 AddMacroDef(ltKILL
, _T("kill"), 0);
2268 AddMacroDef(ltLABEL
, _T("label"), 1);
2269 AddMacroDef(ltLAMBDA
, _T("lambda"), 0);
2270 AddMacroDef(ltCAP_LAMBDA
, _T("Lambda"), 0);
2271 AddMacroDef(ltlarge
, _T("large"), 1);
2272 AddMacroDef(ltLarge
, _T("Large"), 1);
2273 AddMacroDef(ltLARGE
, _T("LARGE"), 1);
2274 AddMacroDef(ltLATEXIGNORE
, _T("latexignore"), 1);
2275 AddMacroDef(ltLATEXONLY
, _T("latexonly"), 1);
2276 AddMacroDef(ltLATEX
, _T("LaTeX"), 0);
2277 AddMacroDef(ltLBOX
, _T("lbox"), 1);
2278 AddMacroDef(ltLBRACERAW
, _T("lbraceraw"), 0);
2279 AddMacroDef(ltLDOTS
, _T("ldots"), 0);
2280 AddMacroDef(ltLEQ
, _T("leq"), 0);
2281 AddMacroDef(ltLE
, _T("le"), 0);
2282 AddMacroDef(ltLEFTARROW
, _T("leftarrow"), 0);
2283 AddMacroDef(ltLEFTRIGHTARROW
, _T("leftrightarrow"), 0);
2284 AddMacroDef(ltLEFTARROW2
, _T("Leftarrow"), 0);
2285 AddMacroDef(ltLEFTRIGHTARROW2
, _T("Leftrightarrow"), 0);
2286 AddMacroDef(ltLINEBREAK
, _T("linebreak"), 0);
2287 AddMacroDef(ltLINKCOLOUR
, _T("linkcolour"), 1);
2288 AddMacroDef(ltLISTOFFIGURES
, _T("listoffigures"), 0);
2289 AddMacroDef(ltLISTOFTABLES
, _T("listoftables"), 0);
2290 AddMacroDef(ltLHEAD
, _T("lhead"), 1);
2291 AddMacroDef(ltLFOOT
, _T("lfoot"), 1);
2292 AddMacroDef(ltLOWERCASE
, _T("lowercase"), 1);
2293 AddMacroDef(ltLL
, _T("ll"), 0);
2295 AddMacroDef(ltMAKEGLOSSARY
, _T("makeglossary"), 0);
2296 AddMacroDef(ltMAKEINDEX
, _T("makeindex"), 0);
2297 AddMacroDef(ltMAKETITLE
, _T("maketitle"), 0);
2298 AddMacroDef(ltMARKRIGHT
, _T("markright"), 1);
2299 AddMacroDef(ltMARKBOTH
, _T("markboth"), 2);
2300 AddMacroDef(ltMARGINPARWIDTH
, _T("marginparwidth"), 1);
2301 AddMacroDef(ltMARGINPARSEP
, _T("marginparsep"), 1);
2302 AddMacroDef(ltMARGINPARODD
, _T("marginparodd"), 1);
2303 AddMacroDef(ltMARGINPAREVEN
, _T("marginpareven"), 1);
2304 AddMacroDef(ltMARGINPAR
, _T("marginpar"), 1);
2305 AddMacroDef(ltMBOX
, _T("mbox"), 1);
2306 AddMacroDef(ltMDSERIES
, _T("mdseries"), 1);
2307 AddMacroDef(ltMEMBERSECTION
, _T("membersection"), 1);
2308 AddMacroDef(ltMEMBER
, _T("member"), 2);
2309 AddMacroDef(ltMID
, _T("mid"), 0);
2310 AddMacroDef(ltMODELS
, _T("models"), 0);
2311 AddMacroDef(ltMP
, _T("mp"), 0);
2312 AddMacroDef(ltMULTICOLUMN
, _T("multicolumn"), 3);
2313 AddMacroDef(ltMU
, _T("mu"), 0);
2315 AddMacroDef(ltNABLA
, _T("nabla"), 0);
2316 AddMacroDef(ltNEG
, _T("neg"), 0);
2317 AddMacroDef(ltNEQ
, _T("neq"), 0);
2318 AddMacroDef(ltNEWCOUNTER
, _T("newcounter"), 1, false, (bool)FORBID_ABSOLUTELY
);
2319 AddMacroDef(ltNEWLINE
, _T("newline"), 0);
2320 AddMacroDef(ltNEWPAGE
, _T("newpage"), 0);
2321 AddMacroDef(ltNI
, _T("ni"), 0);
2322 AddMacroDef(ltNOCITE
, _T("nocite"), 1);
2323 AddMacroDef(ltNOINDENT
, _T("noindent"), 0);
2324 AddMacroDef(ltNOLINEBREAK
, _T("nolinebreak"), 0);
2325 AddMacroDef(ltNOPAGEBREAK
, _T("nopagebreak"), 0);
2326 AddMacroDef(ltNORMALSIZE
, _T("normalsize"), 1);
2327 AddMacroDef(ltNORMALBOX
, _T("normalbox"), 1);
2328 AddMacroDef(ltNORMALBOXD
, _T("normalboxd"), 1);
2329 AddMacroDef(ltNOTEQ
, _T("noteq"), 0);
2330 AddMacroDef(ltNOTIN
, _T("notin"), 0);
2331 AddMacroDef(ltNOTSUBSET
, _T("notsubset"), 0);
2332 AddMacroDef(ltNU
, _T("nu"), 0);
2334 AddMacroDef(ltODDSIDEMARGIN
, _T("oddsidemargin"), 1);
2335 AddMacroDef(ltOMEGA
, _T("omega"), 0);
2336 AddMacroDef(ltCAP_OMEGA
, _T("Omega"), 0);
2337 AddMacroDef(ltONECOLUMN
, _T("onecolumn"), 0);
2338 AddMacroDef(ltOPLUS
, _T("oplus"), 0);
2339 AddMacroDef(ltOSLASH
, _T("oslash"), 0);
2340 AddMacroDef(ltOTIMES
, _T("otimes"), 0);
2342 AddMacroDef(ltPAGEBREAK
, _T("pagebreak"), 0);
2343 AddMacroDef(ltPAGEREF
, _T("pageref"), 1);
2344 AddMacroDef(ltPAGESTYLE
, _T("pagestyle"), 1);
2345 AddMacroDef(ltPAGENUMBERING
, _T("pagenumbering"), 1);
2346 AddMacroDef(ltPARAGRAPHSTAR
, _T("paragraph*"), 1);
2347 AddMacroDef(ltPARAGRAPH
, _T("paragraph"), 1);
2348 AddMacroDef(ltPARALLEL
, _T("parallel"), 0);
2349 AddMacroDef(ltPARAM
, _T("param"), 2);
2350 AddMacroDef(ltPARINDENT
, _T("parindent"), 1);
2351 AddMacroDef(ltPARSKIP
, _T("parskip"), 1);
2352 AddMacroDef(ltPARTIAL
, _T("partial"), 0);
2353 AddMacroDef(ltPARTSTAR
, _T("part*"), 1);
2354 AddMacroDef(ltPART
, _T("part"), 1);
2355 AddMacroDef(ltPAR
, _T("par"), 0);
2356 AddMacroDef(ltPERP
, _T("perp"), 0);
2357 AddMacroDef(ltPHI
, _T("phi"), 0);
2358 AddMacroDef(ltCAP_PHI
, _T("Phi"), 0);
2359 AddMacroDef(ltPFUNC
, _T("pfunc"), 3);
2360 AddMacroDef(ltPICTURE
, _T("picture"), 1);
2361 AddMacroDef(ltPI
, _T("pi"), 0);
2362 AddMacroDef(ltCAP_PI
, _T("Pi"), 0);
2363 AddMacroDef(ltPM
, _T("pm"), 0);
2364 AddMacroDef(ltPOPREFONLY
, _T("poprefonly"), 1);
2365 AddMacroDef(ltPOPREF
, _T("popref"), 2);
2366 AddMacroDef(ltPOUNDS
, _T("pounds"), 0);
2367 AddMacroDef(ltPREC
, _T("prec"), 0);
2368 AddMacroDef(ltPRECEQ
, _T("preceq"), 0);
2369 AddMacroDef(ltPRINTINDEX
, _T("printindex"), 0);
2370 AddMacroDef(ltPROPTO
, _T("propto"), 0);
2371 AddMacroDef(ltPSBOXTO
, _T("psboxto"), 1, false, (bool)FORBID_ABSOLUTELY
);
2372 AddMacroDef(ltPSBOX
, _T("psbox"), 1, false, (bool)FORBID_ABSOLUTELY
);
2373 AddMacroDef(ltPSI
, _T("psi"), 0);
2374 AddMacroDef(ltCAP_PSI
, _T("Psi"), 0);
2376 AddMacroDef(ltQUOTE
, _T("quote"), 1);
2377 AddMacroDef(ltQUOTATION
, _T("quotation"), 1);
2379 AddMacroDef(ltRAGGEDBOTTOM
, _T("raggedbottom"), 0);
2380 AddMacroDef(ltRAGGEDLEFT
, _T("raggedleft"), 0);
2381 AddMacroDef(ltRAGGEDRIGHT
, _T("raggedright"), 0);
2382 AddMacroDef(ltRBRACERAW
, _T("rbraceraw"), 0);
2383 AddMacroDef(ltREF
, _T("ref"), 1);
2384 AddMacroDef(ltREGISTERED
, _T("registered"), 0);
2385 AddMacroDef(ltRE
, _T("we"), 0);
2386 AddMacroDef(ltRHO
, _T("rho"), 0);
2387 AddMacroDef(ltRIGHTARROW
, _T("rightarrow"), 0);
2388 AddMacroDef(ltRIGHTARROW2
, _T("rightarrow2"), 0);
2389 AddMacroDef(ltRMFAMILY
, _T("rmfamily"), 1);
2390 AddMacroDef(ltRM
, _T("rm"), 1);
2391 AddMacroDef(ltROMAN
, _T("roman"), 1);
2392 AddMacroDef(ltROMAN2
, _T("Roman"), 1);
2393 // AddMacroDef(lt"row", 1);
2394 AddMacroDef(ltRTFSP
, _T("rtfsp"), 0);
2395 AddMacroDef(ltRTFIGNORE
, _T("rtfignore"), 1);
2396 AddMacroDef(ltRTFONLY
, _T("rtfonly"), 1);
2397 AddMacroDef(ltRULEDROW
, _T("ruledrow"), 1);
2398 AddMacroDef(ltDRULED
, _T("druled"), 1);
2399 AddMacroDef(ltRULE
, _T("rule"), 2);
2400 AddMacroDef(ltRHEAD
, _T("rhead"), 1);
2401 AddMacroDef(ltRFOOT
, _T("rfoot"), 1);
2402 AddMacroDef(ltROW
, _T("row"), 1);
2404 AddMacroDef(ltSCSHAPE
, _T("scshape"), 1);
2405 AddMacroDef(ltSC
, _T("sc"), 1);
2406 AddMacroDef(ltSECTIONHEADING
, _T("sectionheading"), 1);
2407 AddMacroDef(ltSECTIONSTAR
, _T("section*"), 1);
2408 AddMacroDef(ltSECTION
, _T("section"), 1);
2409 AddMacroDef(ltSETCOUNTER
, _T("setcounter"), 2);
2410 AddMacroDef(ltSFFAMILY
, _T("sffamily"), 1);
2411 AddMacroDef(ltSF
, _T("sf"), 1);
2412 AddMacroDef(ltSHARP
, _T("sharp"), 0);
2413 AddMacroDef(ltSHORTCITE
, _T("shortcite"), 1);
2414 AddMacroDef(ltSIGMA
, _T("sigma"), 0);
2415 AddMacroDef(ltCAP_SIGMA
, _T("Sigma"), 0);
2416 AddMacroDef(ltSIM
, _T("sim"), 0);
2417 AddMacroDef(ltSIMEQ
, _T("simeq"), 0);
2418 AddMacroDef(ltSINGLESPACE
, _T("singlespace"), 1);
2419 AddMacroDef(ltSIZEDBOX
, _T("sizedbox"), 2);
2420 AddMacroDef(ltSIZEDBOXD
, _T("sizedboxd"), 2);
2421 AddMacroDef(ltSLOPPYPAR
, _T("sloppypar"), 1);
2422 AddMacroDef(ltSLOPPY
, _T("sloppy"), 0);
2423 AddMacroDef(ltSLSHAPE
, _T("slshape"), 1);
2424 AddMacroDef(ltSL
, _T("sl"), 1);
2425 AddMacroDef(ltSMALL
, _T("small"), 1);
2426 AddMacroDef(ltSMILE
, _T("smile"), 0);
2427 AddMacroDef(ltSS
, _T("ss"), 0);
2428 AddMacroDef(ltSTAR
, _T("star"), 0);
2429 AddMacroDef(ltSUBITEM
, _T("subitem"), 0);
2430 AddMacroDef(ltSUBPARAGRAPHSTAR
, _T("subparagraph*"), 1);
2431 AddMacroDef(ltSUBPARAGRAPH
, _T("subparagraph"), 1);
2432 AddMacroDef(ltSPECIAL
, _T("special"), 1);
2433 AddMacroDef(ltSUBSECTIONSTAR
, _T("subsection*"), 1);
2434 AddMacroDef(ltSUBSECTION
, _T("subsection"), 1);
2435 AddMacroDef(ltSUBSETEQ
, _T("subseteq"), 0);
2436 AddMacroDef(ltSUBSET
, _T("subset"), 0);
2437 AddMacroDef(ltSUCC
, _T("succ"), 0);
2438 AddMacroDef(ltSUCCEQ
, _T("succeq"), 0);
2439 AddMacroDef(ltSUPSETEQ
, _T("supseteq"), 0);
2440 AddMacroDef(ltSUPSET
, _T("supset"), 0);
2441 AddMacroDef(ltSUBSUBSECTIONSTAR
, _T("subsubsection*"), 1);
2442 AddMacroDef(ltSUBSUBSECTION
, _T("subsubsection"), 1);
2443 AddMacroDef(ltSUPERTABULAR
, _T("supertabular"), 2, false);
2444 AddMacroDef(ltSURD
, _T("surd"), 0);
2445 AddMacroDef(ltSCRIPTSIZE
, _T("scriptsize"), 1);
2446 AddMacroDef(ltSETHEADER
, _T("setheader"), 6);
2447 AddMacroDef(ltSETFOOTER
, _T("setfooter"), 6);
2448 AddMacroDef(ltSETHOTSPOTCOLOUR
, _T("sethotspotcolour"), 1);
2449 AddMacroDef(ltSETHOTSPOTCOLOR
, _T("sethotspotcolor"), 1);
2450 AddMacroDef(ltSETHOTSPOTUNDERLINE
, _T("sethotspotunderline"), 1);
2451 AddMacroDef(ltSETTRANSPARENCY
, _T("settransparency"), 1);
2452 AddMacroDef(ltSPADESUIT
, _T("spadesuit"), 0);
2454 AddMacroDef(ltTABBING
, _T("tabbing"), 2);
2455 AddMacroDef(ltTABLEOFCONTENTS
, _T("tableofcontents"), 0);
2456 AddMacroDef(ltTABLE
, _T("table"), 1);
2457 AddMacroDef(ltTABULAR
, _T("tabular"), 2, false);
2458 AddMacroDef(ltTAB
, _T("tab"), 0);
2459 AddMacroDef(ltTAU
, _T("tau"), 0);
2460 AddMacroDef(ltTEXTRM
, _T("textrm"), 1);
2461 AddMacroDef(ltTEXTSF
, _T("textsf"), 1);
2462 AddMacroDef(ltTEXTTT
, _T("texttt"), 1);
2463 AddMacroDef(ltTEXTBF
, _T("textbf"), 1);
2464 AddMacroDef(ltTEXTIT
, _T("textit"), 1);
2465 AddMacroDef(ltTEXTSL
, _T("textsl"), 1);
2466 AddMacroDef(ltTEXTSC
, _T("textsc"), 1);
2467 AddMacroDef(ltTEXTWIDTH
, _T("textwidth"), 1);
2468 AddMacroDef(ltTEXTHEIGHT
, _T("textheight"), 1);
2469 AddMacroDef(ltTEXTCOLOUR
, _T("textcolour"), 1);
2470 AddMacroDef(ltTEX
, _T("TeX"), 0);
2471 AddMacroDef(ltTHEBIBLIOGRAPHY
, _T("thebibliography"), 2);
2472 AddMacroDef(ltTHETA
, _T("theta"), 0);
2473 AddMacroDef(ltTIMES
, _T("times"), 0);
2474 AddMacroDef(ltCAP_THETA
, _T("Theta"), 0);
2475 AddMacroDef(ltTITLEPAGE
, _T("titlepage"), 1);
2476 AddMacroDef(ltTITLE
, _T("title"), 1);
2477 AddMacroDef(ltTINY
, _T("tiny"), 1);
2478 AddMacroDef(ltTODAY
, _T("today"), 0);
2479 AddMacroDef(ltTOPMARGIN
, _T("topmargin"), 1);
2480 AddMacroDef(ltTOPSKIP
, _T("topskip"), 1);
2481 AddMacroDef(ltTRIANGLE
, _T("triangle"), 0);
2482 AddMacroDef(ltTTFAMILY
, _T("ttfamily"), 1);
2483 AddMacroDef(ltTT
, _T("tt"), 1);
2484 AddMacroDef(ltTYPEIN
, _T("typein"), 1);
2485 AddMacroDef(ltTYPEOUT
, _T("typeout"), 1);
2486 AddMacroDef(ltTWOCOLWIDTHA
, _T("twocolwidtha"), 1);
2487 AddMacroDef(ltTWOCOLWIDTHB
, _T("twocolwidthb"), 1);
2488 AddMacroDef(ltTWOCOLSPACING
, _T("twocolspacing"), 1);
2489 AddMacroDef(ltTWOCOLITEMRULED
, _T("twocolitemruled"), 2);
2490 AddMacroDef(ltTWOCOLITEM
, _T("twocolitem"), 2);
2491 AddMacroDef(ltTWOCOLLIST
, _T("twocollist"), 1);
2492 AddMacroDef(ltTWOCOLUMN
, _T("twocolumn"), 0);
2493 AddMacroDef(ltTHEPAGE
, _T("thepage"), 0);
2494 AddMacroDef(ltTHECHAPTER
, _T("thechapter"), 0);
2495 AddMacroDef(ltTHESECTION
, _T("thesection"), 0);
2496 AddMacroDef(ltTHISPAGESTYLE
, _T("thispagestyle"), 1);
2498 AddMacroDef(ltUNDERLINE
, _T("underline"), 1);
2499 AddMacroDef(ltUPSILON
, _T("upsilon"), 0);
2500 AddMacroDef(ltCAP_UPSILON
, _T("Upsilon"), 0);
2501 AddMacroDef(ltUPARROW
, _T("uparrow"), 0);
2502 AddMacroDef(ltUPARROW2
, _T("Uparrow"), 0);
2503 AddMacroDef(ltUPPERCASE
, _T("uppercase"), 1);
2504 AddMacroDef(ltUPSHAPE
, _T("upshape"), 1);
2505 AddMacroDef(ltURLREF
, _T("urlref"), 2);
2506 AddMacroDef(ltUSEPACKAGE
, _T("usepackage"), 1);
2508 AddMacroDef(ltVAREPSILON
, _T("varepsilon"), 0);
2509 AddMacroDef(ltVARPHI
, _T("varphi"), 0);
2510 AddMacroDef(ltVARPI
, _T("varpi"), 0);
2511 AddMacroDef(ltVARRHO
, _T("varrho"), 0);
2512 AddMacroDef(ltVARSIGMA
, _T("varsigma"), 0);
2513 AddMacroDef(ltVARTHETA
, _T("vartheta"), 0);
2514 AddMacroDef(ltVDOTS
, _T("vdots"), 0);
2515 AddMacroDef(ltVEE
, _T("vee"), 0);
2516 AddMacroDef(ltVERBATIMINPUT
, _T("verbatiminput"), 1);
2517 AddMacroDef(ltVERBATIM
, _T("verbatim"), 1);
2518 AddMacroDef(ltVERBSTAR
, _T("verb*"), 1);
2519 AddMacroDef(ltVERB
, _T("verb"), 1);
2520 AddMacroDef(ltVERSE
, _T("verse"), 1);
2521 AddMacroDef(ltVFILL
, _T("vfill"), 0);
2522 AddMacroDef(ltVLINE
, _T("vline"), 0);
2523 AddMacroDef(ltVOID
, _T("void"), 0);
2524 AddMacroDef(ltVDASH
, _T("vdash"), 0);
2525 AddMacroDef(ltVRULE
, _T("vrule"), 0);
2526 AddMacroDef(ltVSPACESTAR
, _T("vspace*"), 1);
2527 AddMacroDef(ltVSKIPSTAR
, _T("vskip*"), 1);
2528 AddMacroDef(ltVSPACE
, _T("vspace"), 1);
2529 AddMacroDef(ltVSKIP
, _T("vskip"), 1);
2531 AddMacroDef(ltWEDGE
, _T("wedge"), 0);
2532 AddMacroDef(ltWXCLIPS
, _T("wxclips"), 0);
2533 AddMacroDef(ltWINHELPIGNORE
, _T("winhelpignore"), 1);
2534 AddMacroDef(ltWINHELPONLY
, _T("winhelponly"), 1);
2535 AddMacroDef(ltWP
, _T("wp"), 0);
2537 AddMacroDef(ltXI
, _T("xi"), 0);
2538 AddMacroDef(ltCAP_XI
, _T("Xi"), 0);
2539 AddMacroDef(ltXLPIGNORE
, _T("xlpignore"), 1);
2540 AddMacroDef(ltXLPONLY
, _T("xlponly"), 1);
2542 AddMacroDef(ltZETA
, _T("zeta"), 0);
2544 AddMacroDef(ltSPACE
, _T(" "), 0);
2545 AddMacroDef(ltBACKSLASHCHAR
, _T("\\"), 0);
2546 AddMacroDef(ltPIPE
, _T("|"), 0);
2547 AddMacroDef(ltFORWARDSLASH
, _T("/"), 0);
2548 AddMacroDef(ltUNDERSCORE
, _T("_"), 0);
2549 AddMacroDef(ltAMPERSAND
, _T("&"), 0);
2550 AddMacroDef(ltPERCENT
, _T("%"), 0);
2551 AddMacroDef(ltDOLLAR
, _T("$"), 0);
2552 AddMacroDef(ltHASH
, _T("#"), 0);
2553 AddMacroDef(ltLPARENTH
, _T("("), 0);
2554 AddMacroDef(ltRPARENTH
, _T(")"), 0);
2555 AddMacroDef(ltLBRACE
, _T("{"), 0);
2556 AddMacroDef(ltRBRACE
, _T("}"), 0);
2557 // AddMacroDef(ltEQUALS, _T("="), 0);
2558 AddMacroDef(ltRANGLEBRA
, _T(">"), 0);
2559 AddMacroDef(ltLANGLEBRA
, _T("<"), 0);
2560 AddMacroDef(ltPLUS
, _T("+"), 0);
2561 AddMacroDef(ltDASH
, _T("-"), 0);
2562 AddMacroDef(ltAT_SYMBOL
, _T("@"), 0);
2563 // AddMacroDef(ltSINGLEQUOTE, _T("'"), 0);
2564 // AddMacroDef(ltBACKQUOTE, _T("`"), 0);
2568 * Default behaviour, should be called by client if can't match locally.
2572 // Called on start/end of macro examination
2573 void DefaultOnMacro(int macroId
, int no_args
, bool start
)
2577 // Default behaviour for abstract
2582 // Write the heading
2583 FakeCurrentSection(AbstractNameString
);
2584 OnMacro(ltPAR
, 0, true);
2585 OnMacro(ltPAR
, 0, false);
2589 if (DocumentStyle
== LATEX_ARTICLE
)
2597 // Default behaviour for glossary
2598 case ltHELPGLOSSARY
:
2602 // Write the heading
2603 FakeCurrentSection(GlossaryNameString
);
2604 OnMacro(ltPAR
, 0, true);
2605 OnMacro(ltPAR
, 0, false);
2606 if ((convertMode
== TEX_RTF
) && !winHelp
)
2608 OnMacro(ltPAR
, 0, true);
2609 OnMacro(ltPAR
, 0, false);
2614 case ltSPECIALAMPERSAND
:
2621 TexOutput(_T("<<"), true);
2625 TexOutput(_T(">>"), true);
2629 TexOutput(_T("~"), true);
2633 TexOutput(_T("~"), true);
2635 case ltSPECIALTILDE
:
2637 TexOutput(_T(" "), true);
2641 TexOutput(_T("_"), true);
2645 TexOutput(_T("#"), true);
2649 TexOutput(_T("&"), true);
2653 TexOutput(_T(" "), true);
2657 TexOutput(_T("|"), true);
2661 TexOutput(_T("%"), true);
2665 TexOutput(_T("$"), true);
2669 TexOutput(_T(""), true);
2673 TexOutput(_T(""), true);
2677 TexOutput(_T("{"), true);
2681 TexOutput(_T("}"), true);
2685 TexOutput(_T("(c)"), true);
2689 TexOutput(_T("(r)"), true);
2693 TexOutput(_T("\\"), true);
2698 TexOutput(_T("..."), true);
2702 TexOutput(_T("|"), true);
2706 TexOutput(_T("LaTeX"), true);
2710 TexOutput(_T("TeX"), true);
2714 TexOutput(_T("£"), true);
2716 case ltSPECIALDOUBLEDOLLAR
: // Interpret as center
2717 OnMacro(ltCENTER
, no_args
, start
);
2723 OnMacro(ltIT
, no_args
, start
);
2726 case ltPARAGRAPHSTAR
:
2727 case ltSUBPARAGRAPH
:
2728 case ltSUBPARAGRAPHSTAR
:
2729 OnMacro(ltSUBSUBSECTION
, no_args
, start
);
2737 TexOutput(wxCtime(&when
), true);
2748 if (start
) TexOutput(_T("alpha"));
2751 if (start
) TexOutput(_T("beta"));
2754 if (start
) TexOutput(_T("gamma"));
2757 if (start
) TexOutput(_T("delta"));
2761 if (start
) TexOutput(_T("epsilon"));
2764 if (start
) TexOutput(_T("zeta"));
2767 if (start
) TexOutput(_T("eta"));
2771 if (start
) TexOutput(_T("theta"));
2774 if (start
) TexOutput(_T("iota"));
2777 if (start
) TexOutput(_T("kappa"));
2780 if (start
) TexOutput(_T("lambda"));
2783 if (start
) TexOutput(_T("mu"));
2786 if (start
) TexOutput(_T("nu"));
2789 if (start
) TexOutput(_T("xi"));
2793 if (start
) TexOutput(_T("pi"));
2797 if (start
) TexOutput(_T("rho"));
2801 if (start
) TexOutput(_T("sigma"));
2804 if (start
) TexOutput(_T("tau"));
2807 if (start
) TexOutput(_T("upsilon"));
2811 if (start
) TexOutput(_T("phi"));
2814 if (start
) TexOutput(_T("chi"));
2817 if (start
) TexOutput(_T("psi"));
2820 if (start
) TexOutput(_T("omega"));
2823 if (start
) TexOutput(_T("GAMMA"));
2826 if (start
) TexOutput(_T("DELTA"));
2829 if (start
) TexOutput(_T("THETA"));
2832 if (start
) TexOutput(_T("LAMBDA"));
2835 if (start
) TexOutput(_T("XI"));
2838 if (start
) TexOutput(_T("PI"));
2841 if (start
) TexOutput(_T("SIGMA"));
2844 if (start
) TexOutput(_T("UPSILON"));
2847 if (start
) TexOutput(_T("PHI"));
2850 if (start
) TexOutput(_T("PSI"));
2853 if (start
) TexOutput(_T("OMEGA"));
2856 // Binary operation symbols
2859 if (start
) TexOutput(_T("<="));
2862 if (start
) TexOutput(_T("<<"));
2865 if (start
) TexOutput(_T("SUBSET"));
2868 if (start
) TexOutput(_T("SUBSETEQ"));
2871 if (start
) TexOutput(_T("IN"));
2874 if (start
) TexOutput(_T("VDASH"));
2877 if (start
) TexOutput(_T("MODELS"));
2881 if (start
) TexOutput(_T(">="));
2884 if (start
) TexOutput(_T(">>"));
2887 if (start
) TexOutput(_T("SUPSET"));
2890 if (start
) TexOutput(_T("SUPSETEQ"));
2893 if (start
) TexOutput(_T("NI"));
2896 if (start
) TexOutput(_T("DASHV"));
2899 if (start
) TexOutput(_T("PERP"));
2902 if (start
) TexOutput(_T("NEQ"));
2905 if (start
) TexOutput(_T("DOTEQ"));
2908 if (start
) TexOutput(_T("APPROX"));
2911 if (start
) TexOutput(_T("CONG"));
2914 if (start
) TexOutput(_T("EQUIV"));
2917 if (start
) TexOutput(_T("PROPTO"));
2920 if (start
) TexOutput(_T("PREC"));
2923 if (start
) TexOutput(_T("PRECEQ"));
2926 if (start
) TexOutput(_T("|"));
2929 if (start
) TexOutput(_T("~"));
2932 if (start
) TexOutput(_T("SIMEQ"));
2935 if (start
) TexOutput(_T("ASYMP"));
2938 if (start
) TexOutput(_T(":-)"));
2941 if (start
) TexOutput(_T(":-("));
2944 if (start
) TexOutput(_T("SUCC"));
2947 if (start
) TexOutput(_T("SUCCEQ"));
2950 if (start
) TexOutput(_T("|"));
2953 // Negated relation symbols
2955 if (start
) TexOutput(_T("!="));
2958 if (start
) TexOutput(_T("NOTIN"));
2961 if (start
) TexOutput(_T("NOTSUBSET"));
2966 if (start
) TexOutput(_T("<--"));
2969 if (start
) TexOutput(_T("<=="));
2972 if (start
) TexOutput(_T("-->"));
2975 if (start
) TexOutput(_T("==>"));
2977 case ltLEFTRIGHTARROW
:
2978 if (start
) TexOutput(_T("<-->"));
2980 case ltLEFTRIGHTARROW2
:
2981 if (start
) TexOutput(_T("<==>"));
2984 if (start
) TexOutput(_T("UPARROW"));
2987 if (start
) TexOutput(_T("UPARROW2"));
2990 if (start
) TexOutput(_T("DOWNARROW"));
2993 if (start
) TexOutput(_T("DOWNARROW2"));
2995 // Miscellaneous symbols
2997 if (start
) TexOutput(_T("ALEPH"));
3000 if (start
) TexOutput(_T("WP"));
3003 if (start
) TexOutput(_T("RE"));
3006 if (start
) TexOutput(_T("IM"));
3009 if (start
) TexOutput(_T("EMPTYSET"));
3012 if (start
) TexOutput(_T("NABLA"));
3015 if (start
) TexOutput(_T("SURD"));
3018 if (start
) TexOutput(_T("PARTIAL"));
3021 if (start
) TexOutput(_T("BOT"));
3024 if (start
) TexOutput(_T("FORALL"));
3027 if (start
) TexOutput(_T("EXISTS"));
3030 if (start
) TexOutput(_T("NEG"));
3033 if (start
) TexOutput(_T("SHARP"));
3036 if (start
) TexOutput(_T("ANGLE"));
3039 if (start
) TexOutput(_T("TRIANGLE"));
3042 if (start
) TexOutput(_T("CLUBSUIT"));
3045 if (start
) TexOutput(_T("DIAMONDSUIT"));
3048 if (start
) TexOutput(_T("HEARTSUIT"));
3051 if (start
) TexOutput(_T("SPADESUIT"));
3054 if (start
) TexOutput(_T("INFTY"));
3057 if (start
) TexOutput(_T("PM"));
3060 if (start
) TexOutput(_T("MP"));
3063 if (start
) TexOutput(_T("TIMES"));
3066 if (start
) TexOutput(_T("DIV"));
3069 if (start
) TexOutput(_T("CDOT"));
3072 if (start
) TexOutput(_T("AST"));
3075 if (start
) TexOutput(_T("STAR"));
3078 if (start
) TexOutput(_T("CAP"));
3081 if (start
) TexOutput(_T("CUP"));
3084 if (start
) TexOutput(_T("VEE"));
3087 if (start
) TexOutput(_T("WEDGE"));
3090 if (start
) TexOutput(_T("CIRC"));
3093 if (start
) TexOutput(_T("BULLET"));
3096 if (start
) TexOutput(_T("DIAMOND"));
3099 if (start
) TexOutput(_T("OSLASH"));
3102 if (start
) TexOutput(_T("BOX"));
3105 if (start
) TexOutput(_T("DIAMOND2"));
3107 case ltBIGTRIANGLEDOWN
:
3108 if (start
) TexOutput(_T("BIGTRIANGLEDOWN"));
3111 if (start
) TexOutput(_T("OPLUS"));
3114 if (start
) TexOutput(_T("OTIMES"));
3117 if (start
) TexOutput(_T("s"));
3119 case ltBACKSLASHRAW
:
3120 if (start
) TexOutput(_T("\\"));
3123 if (start
) TexOutput(_T("{"));
3126 if (start
) TexOutput(_T("}"));
3130 if (start
) TexOutput(_T(" "));
3137 // Called on start/end of argument examination
3138 bool DefaultOnArgument(int macroId
, int arg_no
, bool start
)
3144 if (arg_no
== 1 && start
)
3146 wxChar
*refName
= GetArgData();
3149 TexRef
*texRef
= FindReference(refName
);
3152 // Must strip the 'section' or 'chapter' or 'figure' text
3153 // from a normal 'ref' reference
3155 wxStrcpy(buf
, texRef
->sectionNumber
);
3156 int len
= wxStrlen(buf
);
3158 if (wxStrcmp(buf
, _T("??")) != 0)
3170 TexOutput(texRef
->sectionNumber
+ i
, true);
3175 informBuf
.Printf(_T("Warning: unresolved reference '%s'"), refName
);
3176 OnInform((wxChar
*)informBuf
.c_str());
3179 else TexOutput(_T("??"), true);
3190 if (start
&& (arg_no
== 1))
3191 DocumentAuthor
= GetArgChunk();
3196 if (start
&& (arg_no
== 1))
3197 DocumentDate
= GetArgChunk();
3202 if (start
&& (arg_no
== 1))
3203 DocumentTitle
= GetArgChunk();
3206 case ltDOCUMENTCLASS
:
3207 case ltDOCUMENTSTYLE
:
3209 if (start
&& !IsArgOptional())
3211 DocumentStyleString
= copystring(GetArgData());
3212 if (wxStrncmp(DocumentStyleString
, _T("art"), 3) == 0)
3213 DocumentStyle
= LATEX_ARTICLE
;
3214 else if (wxStrncmp(DocumentStyleString
, _T("rep"), 3) == 0)
3215 DocumentStyle
= LATEX_REPORT
;
3216 else if (wxStrncmp(DocumentStyleString
, _T("book"), 4) == 0 ||
3217 wxStrncmp(DocumentStyleString
, _T("thesis"), 6) == 0)
3218 DocumentStyle
= LATEX_BOOK
;
3219 else if (wxStrncmp(DocumentStyleString
, _T("letter"), 6) == 0)
3220 DocumentStyle
= LATEX_LETTER
;
3221 else if (wxStrncmp(DocumentStyleString
, _T("slides"), 6) == 0)
3222 DocumentStyle
= LATEX_SLIDES
;
3224 if (StringMatch(_T("10"), DocumentStyleString
))
3226 else if (StringMatch(_T("11"), DocumentStyleString
))
3228 else if (StringMatch(_T("12"), DocumentStyleString
))
3231 OnMacro(ltHELPFONTSIZE
, 1, true);
3232 wxSnprintf(currentArgData
, 2000, _T("%d"), normalFont
);
3234 OnArgument(ltHELPFONTSIZE
, 1, true);
3235 OnArgument(ltHELPFONTSIZE
, 1, false);
3236 haveArgData
= false;
3237 OnMacro(ltHELPFONTSIZE
, 1, false);
3239 else if (start
&& IsArgOptional())
3241 MinorDocumentStyleString
= copystring(GetArgData());
3243 if (StringMatch(_T("10"), MinorDocumentStyleString
))
3245 else if (StringMatch(_T("11"), MinorDocumentStyleString
))
3247 else if (StringMatch(_T("12"), MinorDocumentStyleString
))
3252 case ltBIBLIOGRAPHYSTYLE
:
3254 if (start
&& !IsArgOptional())
3255 BibliographyStyleString
= copystring(GetArgData());
3260 if (start
&& !IsArgOptional())
3262 if (PageStyle
) delete[] PageStyle
;
3263 PageStyle
= copystring(GetArgData());
3270 if (start && !IsArgOptional())
3271 LeftHeader = GetArgChunk();
3277 if (start && !IsArgOptional())
3278 LeftFooter = GetArgChunk();
3284 if (start && !IsArgOptional())
3285 CentreHeader = GetArgChunk();
3291 if (start && !IsArgOptional())
3292 CentreFooter = GetArgChunk();
3298 if (start && !IsArgOptional())
3299 RightHeader = GetArgChunk();
3305 if (start && !IsArgOptional())
3306 RightFooter = GetArgChunk();
3314 if (start
&& !IsArgOptional())
3316 wxChar
*citeKeys
= GetArgData();
3318 wxChar
*citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3321 AddCitation(citeKey
);
3322 TexRef
*ref
= FindReference(citeKey
);
3325 TexOutput(ref
->sectionNumber
, true);
3326 if (wxStrcmp(ref
->sectionNumber
, _T("??")) == 0)
3329 informBuf
.Printf(_T("Warning: unresolved citation %s."), citeKey
);
3330 OnInform((wxChar
*)informBuf
.c_str());
3333 citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3336 TexOutput(_T(", "), true);
3345 if (start
&& !IsArgOptional())
3347 wxChar
*citeKey
= GetArgData();
3348 AddCitation(citeKey
);
3353 case ltHELPFONTSIZE
:
3357 wxChar
*data
= GetArgData();
3358 if (wxStrcmp(data
, _T("10")) == 0)
3360 else if (wxStrcmp(data
, _T("11")) == 0)
3362 else if (wxStrcmp(data
, _T("12")) == 0)
3372 TexOutput(_T(" ??"), true);
3379 if (start
&& arg_no
== 1)
3381 wxChar
*data
= GetArgData();
3382 ParSkip
= ParseUnitArgument(data
);
3389 if (start
&& arg_no
== 1)
3391 wxChar
*data
= GetArgData();
3392 ParIndent
= ParseUnitArgument(data
);
3399 return OnArgument(ltIT
, arg_no
, start
);
3401 case ltSPECIALDOUBLEDOLLAR
:
3403 return OnArgument(ltCENTER
, arg_no
, start
);
3406 case ltPARAGRAPHSTAR
:
3407 case ltSUBPARAGRAPH
:
3408 case ltSUBPARAGRAPHSTAR
:
3410 return OnArgument(ltSUBSUBSECTION
, arg_no
, start
);
3415 OnInform(GetArgData());
3421 TexOutput(_T(" ("), true);
3423 TexOutput(_T(")"), true);
3426 case ltBIBLIOGRAPHY
:
3433 FILE *fd
= wxFopen(TexBibName
, _T("r"));
3440 TexOutput(smallBuf
);
3448 OnInform(_T("Run Tex2RTF again to include bibliography."));
3451 // Read in the .bib file, resolve all known references, write out the RTF.
3452 wxChar
*allFiles
= GetArgData();
3454 wxChar
*bibFile
= ParseMultifieldString(allFiles
, &pos
);
3457 wxChar fileBuf
[300];
3458 wxStrcpy(fileBuf
, bibFile
);
3459 wxString actualFile
= TexPathList
.FindValidPath(fileBuf
);
3460 if (actualFile
== _T(""))
3462 wxStrcat(fileBuf
, _T(".bib"));
3463 actualFile
= TexPathList
.FindValidPath(fileBuf
);
3465 if (actualFile
!= _T(""))
3467 if (!ReadBib((wxChar
*) (const wxChar
*) actualFile
))
3470 errBuf
.Printf(_T(".bib file %s not found or malformed"), (const wxChar
*) actualFile
);
3471 OnError((wxChar
*)errBuf
.c_str());
3477 errBuf
.Printf(_T(".bib file %s not found"), fileBuf
);
3478 OnError((wxChar
*)errBuf
.c_str());
3480 bibFile
= ParseMultifieldString(allFiles
, &pos
);
3483 ResolveBibReferences();
3485 // Write it a new bib section in the appropriate format.
3486 FILE *save1
= CurrentOutput1
;
3487 FILE *save2
= CurrentOutput2
;
3488 FILE *Biblio
= wxFopen(TexTmpBibName
, _T("w"));
3489 SetCurrentOutput(Biblio
);
3492 if (wxFileExists(TexTmpBibName
))
3494 if (wxFileExists(TexBibName
)) wxRemoveFile(TexBibName
);
3495 wxRenameFile(TexTmpBibName
, TexBibName
);
3497 SetCurrentOutputs(save1
, save2
);
3503 return (start
&& (arg_no
== 3));
3508 if (start
&& (arg_no
== 1))
3510 wxChar
*s
= GetArgData();
3513 wxChar
*s1
= copystring(s
);
3515 for (i
= 0; i
< (int)wxStrlen(s
); i
++)
3516 s1
[i
] = wxToupper(s
[i
]);
3528 if (start
&& (arg_no
== 1))
3530 wxChar
*s
= GetArgData();
3533 wxChar
*s1
= copystring(s
);
3535 for (i
= 0; i
< (int)wxStrlen(s
); i
++)
3536 s1
[i
] = wxTolower(s
[i
]);
3548 if (start
&& (arg_no
== 1))
3550 wxChar
*s
= GetArgData();
3553 wxChar
*s1
= copystring(s
);
3555 for (i
= 0; i
< (int)wxStrlen(s
); i
++)
3556 s1
[i
] = wxToupper(s
[i
]);
3566 case ltPOPREF
: // Ignore second argument by default
3567 return (start
&& (arg_no
== 1));
3571 return ((convertMode
== TEX_XLP
) ? false : true);
3573 return ((convertMode
!= TEX_XLP
) ? false : true);
3575 return ((convertMode
== TEX_HTML
) ? false : true);
3577 return ((convertMode
!= TEX_HTML
) ? false : true);
3579 return (((convertMode
== TEX_RTF
) && !winHelp
) ? false : true);
3581 return (!((convertMode
== TEX_RTF
) && !winHelp
) ? false : true);
3582 case ltWINHELPIGNORE
:
3583 return (winHelp
? false : true);
3585 return (!winHelp
? false : true);
3597 case ltADDTOCOUNTER
:
3598 case ltADDCONTENTSLINE
:
3602 case ltBASELINESKIP
:
3611 case ltPAGENUMBERING
:
3623 case ltTHISPAGESTYLE
:
3626 case ltEVENSIDEMARGIN
:
3627 case ltODDSIDEMARGIN
:
3629 case ltMARGINPARWIDTH
:
3630 case ltMARGINPARSEP
:
3631 case ltMARGINPAREVEN
:
3632 case ltMARGINPARODD
:
3633 case ltTWOCOLWIDTHA
:
3634 case ltTWOCOLWIDTHB
:
3635 case ltTWOCOLSPACING
:
3642 case ltSETHOTSPOTCOLOUR
:
3643 case ltSETHOTSPOTCOLOR
:
3644 case ltSETHOTSPOTUNDERLINE
:
3645 case ltSETTRANSPARENCY
:
3648 case ltBACKGROUNDCOLOUR
:
3649 case ltBACKGROUNDIMAGE
:
3651 case ltFOLLOWEDLINKCOLOUR
:
3658 case ltINSERTATLEVEL
:
3661 case ltSUPERTABULAR
:
3665 return (arg_no
== 2);
3666 case ltDEFINECOLOUR
:
3669 static int redVal
= 0;
3670 static int greenVal
= 0;
3671 static int blueVal
= 0;
3672 static wxChar
*colourName
= NULL
;
3679 if (colourName
) delete[] colourName
;
3680 colourName
= copystring(GetArgData());
3685 redVal
= wxAtoi(GetArgData());
3690 greenVal
= wxAtoi(GetArgData());
3695 blueVal
= wxAtoi(GetArgData());
3696 AddColour(colourName
, redVal
, greenVal
, blueVal
);
3710 return (!IsArgOptional());