1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Utilities for Latex conversion.
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
33 * Variables accessible from clients
37 TexChunk
* DocumentTitle
= NULL
;
38 TexChunk
* DocumentAuthor
= NULL
;
39 TexChunk
* DocumentDate
= NULL
;
41 // Header/footers/pagestyle
42 TexChunk
* LeftHeaderEven
= NULL
;
43 TexChunk
* LeftFooterEven
= NULL
;
44 TexChunk
* CentreHeaderEven
= NULL
;
45 TexChunk
* CentreFooterEven
= NULL
;
46 TexChunk
* RightHeaderEven
= NULL
;
47 TexChunk
* RightFooterEven
= NULL
;
48 TexChunk
* LeftHeaderOdd
= NULL
;
49 TexChunk
* LeftFooterOdd
= NULL
;
50 TexChunk
* CentreHeaderOdd
= NULL
;
51 TexChunk
* CentreFooterOdd
= NULL
;
52 TexChunk
* RightHeaderOdd
= NULL
;
53 TexChunk
* RightFooterOdd
= NULL
;
54 char * PageStyle
= copystring("plain");
56 int DocumentStyle
= LATEX_REPORT
;
57 int MinorDocumentStyle
= 0;
58 wxPathList TexPathList
;
59 char * BibliographyStyleString
= copystring("plain");
60 char * DocumentStyleString
= copystring("report");
61 char * MinorDocumentStyleString
= NULL
;
75 // All of these tokens MUST be found on a line by themselves (no other
76 // text) and must start at the first character of the line, or tex2rtf
77 // will fail to process them correctly (a limitation of tex2rtf, not TeX)
78 static const wxString syntaxTokens
[] =
79 { "\\begin{verbatim}",
80 "\\begin{toocomplex}",
96 * USER-ADJUSTABLE SETTINGS
100 // Section font sizes
101 int chapterFont
= 12; // LARGEFont3;
102 int sectionFont
= 12; // LargeFont2;
103 int subsectionFont
= 12; // largeFont1;
104 int titleFont
= LARGEFont3
;
105 int authorFont
= LargeFont2
;
106 int mirrorMargins
= TRUE
;
107 bool winHelp
= FALSE
; // Output in Windows Help format if TRUE, linear otherwise
108 bool isInteractive
= FALSE
;
109 bool runTwice
= FALSE
;
110 int convertMode
= TEX_RTF
;
111 bool checkCurleyBraces
= FALSE
;
112 bool checkSyntax
= FALSE
;
113 bool headerRule
= FALSE
;
114 bool footerRule
= FALSE
;
115 bool compatibilityMode
= FALSE
; // If TRUE, maximum Latex compatibility
116 // (Quality of RTF generation deteriorate)
117 bool generateHPJ
; // Generate WinHelp Help Project file
118 char *winHelpTitle
= NULL
; // Windows Help title
119 int defaultTableColumnWidth
= 2000;
121 int labelIndentTab
= 18; // From left indent to item label (points)
122 int itemIndentTab
= 40; // From left indent to item (points)
124 bool useUpButton
= TRUE
;
125 int htmlBrowseButtons
= HTML_BUTTONS_TEXT
;
127 bool truncateFilenames
= FALSE
; // Truncate for DOS
128 int winHelpVersion
= 3; // WinHelp Version (3 for Windows 3.1, 4 for Win95)
129 bool winHelpContents
= FALSE
; // Generate .cnt file for WinHelp 4
130 bool htmlIndex
= FALSE
; // Generate .htx file for HTML
131 bool htmlFrameContents
= FALSE
; // Use frames for HTML contents page
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 char *bitmapMethod
= copystring("includepicture");
138 bool upperCaseNames
= FALSE
;
139 // HTML background and text colours
140 char *backgroundImageString
= NULL
;
141 char *backgroundColourString
= copystring("255;255;255");
142 char *textColourString
= NULL
;
143 char *linkColourString
= NULL
;
144 char *followedLinkColourString
= NULL
;
145 bool combineSubSections
= FALSE
;
146 bool htmlWorkshopFiles
= FALSE
;
148 extern int passNumber
;
150 extern wxHashTable TexReferences
;
153 * International support
156 // Names to help with internationalisation
157 char *ContentsNameString
= copystring("Contents");
158 char *AbstractNameString
= copystring("Abstract");
159 char *GlossaryNameString
= copystring("Glossary");
160 char *ReferencesNameString
= copystring("References");
161 char *FiguresNameString
= copystring("List of Figures");
162 char *TablesNameString
= copystring("List of Tables");
163 char *FigureNameString
= copystring("Figure");
164 char *TableNameString
= copystring("Table");
165 char *IndexNameString
= copystring("Index");
166 char *ChapterNameString
= copystring("chapter");
167 char *SectionNameString
= copystring("section");
168 char *SubsectionNameString
= copystring("subsection");
169 char *SubsubsectionNameString
= copystring("subsubsection");
170 char *UpNameString
= copystring("Up");
179 int subsectionNo
= 0;
180 int subsubsectionNo
= 0;
189 FILE *CurrentOutput1
= NULL
;
190 FILE *CurrentOutput2
= NULL
;
194 int CurrentInputIndex
= 0;
196 char *TexFileRoot
= NULL
;
197 char *TexBibName
= NULL
; // Bibliography output file name
198 char *TexTmpBibName
= NULL
; // Temporary bibliography output file name
199 bool isSync
= FALSE
; // If TRUE, should not yield to other processes.
200 bool stopRunning
= FALSE
; // If TRUE, should abort.
202 static int currentColumn
= 0;
203 char *currentArgData
= NULL
;
204 bool haveArgData
= FALSE
; // If TRUE, we're simulating the data.
205 TexChunk
*currentArgument
= NULL
;
206 TexChunk
*nextChunk
= NULL
;
207 bool isArgOptional
= FALSE
;
210 TexChunk
*TopLevel
= NULL
;
211 // wxList MacroDefs(wxKEY_STRING);
212 wxHashTable
MacroDefs(wxKEY_STRING
);
213 wxStringList IgnorableInputFiles
; // Ignorable \input files, e.g. psbox.tex
214 char *BigBuffer
= NULL
; // For reading in large chunks of text
215 TexMacroDef
*SoloBlockDef
= NULL
;
216 TexMacroDef
*VerbatimMacroDef
= NULL
;
218 #define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
221 TexRef::TexRef(const char *label
, const char *file
,
222 const char *section
, const char *sectionN
)
224 refLabel
= copystring(label
);
225 refFile
= file
? copystring(file
) : (char*) NULL
;
226 sectionNumber
= section
? copystring(section
) : copystring("??");
227 sectionName
= sectionN
? copystring(sectionN
) : copystring("??");
230 TexRef::~TexRef(void)
232 delete [] refLabel
; refLabel
= NULL
;
233 delete [] refFile
; refFile
= NULL
;
234 delete [] sectionNumber
; sectionNumber
= NULL
;
235 delete [] sectionName
; sectionName
= NULL
;
239 CustomMacro::~CustomMacro()
247 void TexOutput(const char *s
, bool ordinaryText
)
251 // Update current column, but only if we're guaranteed to
252 // be ordinary text (not mark-up stuff)
255 for (i
= 0; i
< len
; i
++)
257 if (s
[i
] == 13 || s
[i
] == 10)
264 fprintf(CurrentOutput1
, "%s", s
);
266 fprintf(CurrentOutput2
, "%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("Warning: it is recommended that command %s is not used.", def
->name
);
284 OnInform((char *)informBuf
.c_str());
287 case FORBID_ABSOLUTELY
:
289 informBuf
.Printf("Error: command %s cannot be used and will lead to errors.", def
->name
);
290 OnInform((char *)informBuf
.c_str());
298 TexMacroDef
*MatchMacro(char *buffer
, int *pos
, char **env
, bool *parseToBrace
)
300 *parseToBrace
= TRUE
;
302 TexMacroDef
*def
= NULL
;
305 // First, try to find begin{thing}
306 if (strncmp(buffer
+i
, "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???
329 // Failed, so try to find macro from definition list
332 // First try getting a one-character macro, but ONLY
333 // if these TWO characters are not both alphabetical (could
334 // be a longer macro)
335 if (!(isalpha(buffer
[i
]) && isalpha(buffer
[i
+1])))
337 macroBuf
[0] = buffer
[i
];
340 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
346 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
348 macroBuf
[j
-i
] = buffer
[j
];
352 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
359 // We want to check whether this is a space-consuming macro
361 // No brace, e.g. \input thing.tex instead of \input{thing};
362 // or a numeric argument, such as \parindent0pt
363 if ((def
->no_args
> 0) && ((buffer
[i
] == 32) || (buffer
[i
] == '=') || (isdigit(buffer
[i
]))))
365 if ((buffer
[i
] == 32) || (buffer
[i
] == '='))
368 *parseToBrace
= FALSE
;
377 void EatWhiteSpace(char *buffer
, int *pos
)
379 int len
= strlen(buffer
);
381 bool keepGoing
= TRUE
;
382 bool moreLines
= TRUE
;
383 while ((j
< len
) && keepGoing
&&
384 (buffer
[j
] == 10 || buffer
[j
] == 13 || buffer
[j
] == ' ' || buffer
[j
] == 9))
391 moreLines
= read_a_line(buffer
);
392 len
= strlen(buffer
);
402 bool FindEndEnvironment(char *buffer
, int *pos
, char *env
)
406 // Try to find end{thing}
407 if ((strncmp(buffer
+i
, "end{", 4) == 0) &&
408 (strncmp(buffer
+i
+4, env
, strlen(env
)) == 0))
410 *pos
= i
+ 5 + strlen(env
);
416 bool readingVerbatim
= FALSE
;
417 bool readInVerbatim
= FALSE
; // Within a verbatim, but not nec. verbatiminput
419 // Switched this off because e.g. \verb${$ causes it to fail. There is no
420 // detection of \verb yet.
421 // #define CHECK_BRACES 1
423 unsigned long leftCurley
= 0;
424 unsigned long rightCurley
= 0;
425 static wxString currentFileName
= "";
427 bool read_a_line(char *buf
)
429 if (CurrentInputIndex
< 0)
439 while (ch
!= EOF
&& ch
!= 10)
441 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
444 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
445 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
446 OnError((char *)errBuf
.c_str());
450 if (((bufIndex
== 14) && (strncmp(buf
, "\\end{verbatim}", 14) == 0)) ||
451 ((bufIndex
== 16) && (strncmp(buf
, "\\end{toocomplex}", 16) == 0)))
452 readInVerbatim
= FALSE
;
454 ch
= getc(Inputs
[CurrentInputIndex
]);
456 if (checkCurleyBraces
)
458 if (ch
== '{' && !readInVerbatim
)
460 if (ch
== '}' && !readInVerbatim
)
463 if (rightCurley
> leftCurley
)
466 errBuf
.Printf("An extra right Curley brace ('}') was detected at line %lu inside file %s",LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str());
467 OnError((char *)errBuf
.c_str());
469 // Reduce the count of right Curley braces, so the mismatched count
470 // isn't reported on every line that has a '}' after the first mismatch
478 // Check for 2 consecutive newlines and replace with \par
479 if (ch
== 10 && !readInVerbatim
)
481 int ch1
= getc(Inputs
[CurrentInputIndex
]);
482 if ((ch1
== 10) || (ch1
== 13))
484 // Eliminate newline (10) following DOS linefeed
486 ch1
= getc(Inputs
[CurrentInputIndex
]);
488 IncrementLineNumber();
489 // strcat(buf, "\\par\n");
491 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
494 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
495 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
496 OnError((char *)errBuf
.c_str());
499 strcat(buf
, "\\par");
505 ungetc(ch1
, Inputs
[CurrentInputIndex
]);
506 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
509 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
510 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
511 OnError((char *)errBuf
.c_str());
522 // Convert embedded characters to RTF equivalents
531 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
534 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
535 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
536 OnError((char *)errBuf
.c_str());
539 buf
[bufIndex
++]='\\';
544 case 0xf6:buf
[bufIndex
++]='o';break; // ö
545 case 0xe4:buf
[bufIndex
++]='a';break; // ä
546 case 0xfc:buf
[bufIndex
++]='u';break; // ü
547 case 0xd6:buf
[bufIndex
++]='O';break; // Ö
548 case 0xc4:buf
[bufIndex
++]='A';break; // Ä
549 case 0xdc:buf
[bufIndex
++]='U';break; // Ü
554 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
557 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
558 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
559 OnError((char *)errBuf
.c_str());
562 buf
[bufIndex
++]='\\';
565 buf
[bufIndex
++]='\\';
569 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
572 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
573 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
574 OnError((char *)errBuf
.c_str());
577 // If the current character read in is a '_', we need to check
578 // whether there should be a '\' before it or not
581 buf
[bufIndex
++] = ch
;
589 // There should NOT be a '\' before the '_'
590 if ((bufIndex
> 0 && (buf
[bufIndex
-1] == '\\')) && (buf
[0] != '%'))
593 errBuf
.Printf("An underscore ('_') was detected at line %lu inside file %s that should NOT have a '\\' before it.",LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str());
594 OnError((char *)errBuf
.c_str());
599 // There should be a '\' before the '_'
603 errBuf
.Printf("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it.",LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str());
604 OnError((char *)errBuf
.c_str());
606 else if ((buf
[bufIndex
-1] != '\\') && (buf
[0] != '%') && // If it is a comment line, then no warnings
607 (strncmp(buf
, "\\input", 6))) // do not report filenames that have underscores in them
610 errBuf
.Printf("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it.",LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str());
611 OnError((char *)errBuf
.c_str());
615 buf
[bufIndex
++] = ch
;
623 fclose(Inputs
[CurrentInputIndex
]);
624 Inputs
[CurrentInputIndex
] = NULL
;
625 if (CurrentInputIndex
> 0)
626 ch
= ' '; // No real end of file
627 CurrentInputIndex
--;
629 if (checkCurleyBraces
)
631 if (leftCurley
!= rightCurley
)
634 errBuf
.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName
.c_str(),leftCurley
,rightCurley
);
635 OnError((char *)errBuf
.c_str());
643 readingVerbatim
= FALSE
;
644 readInVerbatim
= FALSE
;
645 strcat(buf
, "\\end{verbatim}\n");
650 IncrementLineNumber();
654 // Strip out comment environment
655 if (strncmp(buf
, "\\begin{comment}", 15) == 0)
657 while (strncmp(buf
, "\\end{comment}", 13) != 0)
659 return read_a_line(buf
);
661 // Read a verbatim input file as if it were a verbatim environment
662 else if (strncmp(buf
, "\\verbatiminput", 14) == 0)
665 char *fileName
= buf
+ wordLen
+ 1;
667 int j
= bufIndex
- 1;
670 // thing}\par -- eliminate the \par!
671 if (strncmp((buf
+ strlen(buf
)-5), "\\par", 4) == 0)
678 buf
[j
-1] = 0; // Ignore final brace
680 wxString actualFile
= TexPathList
.FindValidPath(fileName
);
681 currentFileName
= actualFile
;
682 if (actualFile
== "")
685 errBuf
.Printf("Could not find file: %s",fileName
);
686 OnError((char *)errBuf
.c_str());
691 informStr
.Printf("Processing: %s",actualFile
.c_str());
692 OnInform((char *)informStr
.c_str());
693 CurrentInputIndex
++;
695 Inputs
[CurrentInputIndex
] = fopen(actualFile
, "r");
696 LineNumbers
[CurrentInputIndex
] = 1;
697 if (FileNames
[CurrentInputIndex
])
698 delete[] FileNames
[CurrentInputIndex
];
699 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
701 if (!Inputs
[CurrentInputIndex
])
703 CurrentInputIndex
--;
704 OnError("Could not open verbatiminput file.");
708 readingVerbatim
= TRUE
;
709 readInVerbatim
= TRUE
;
710 strcpy(buf
, "\\begin{verbatim}\n");
716 else if (strncmp(buf
, "\\input", 6) == 0 || strncmp(buf
, "\\helpinput", 10) == 0 ||
717 strncmp(buf
, "\\include", 8) == 0)
720 if (strncmp(buf
, "\\input", 6) == 0)
723 if (strncmp(buf
, "\\include", 8) == 0)
728 char *fileName
= buf
+ wordLen
+ 1;
730 int j
= bufIndex
- 1;
733 // \input{thing}\par -- eliminate the \par!
734 // if (strncmp((buf + strlen(buf)-5), "\\par", 4) == 0)
735 if (strncmp((buf
+ strlen(buf
)-4), "\\par", 4) == 0) // Bug fix 8/2/95 Ulrich Leodolter
743 buf
[j
-1] = 0; // Ignore final brace
745 // Remove backslashes from name
746 wxString
fileNameStr(fileName
);
747 fileNameStr
.Replace("\\", "");
749 // Ignore some types of input files (e.g. macro definition files)
750 char *fileOnly
= FileNameFromPath((char*) (const char*) fileNameStr
);
751 currentFileName
= fileOnly
;
752 if (IgnorableInputFiles
.Member(fileOnly
))
753 return read_a_line(buf
);
755 wxString actualFile
= TexPathList
.FindValidPath(fileNameStr
);
756 if (actualFile
== "")
759 sprintf(buf2
, "%s.tex", (const char*) fileNameStr
);
760 actualFile
= TexPathList
.FindValidPath(buf2
);
762 currentFileName
= actualFile
;
764 if (actualFile
== "")
767 errBuf
.Printf("Could not find file: %s",fileName
);
768 OnError((char *)errBuf
.c_str());
772 // Ensure that if this file includes another,
773 // then we look in the same directory as this one.
774 TexPathList
.EnsureFileAccessible(actualFile
);
777 informStr
.Printf("Processing: %s",actualFile
.c_str());
778 OnInform((char *)informStr
.c_str());
779 CurrentInputIndex
++;
781 Inputs
[CurrentInputIndex
] = fopen(actualFile
, "r");
782 LineNumbers
[CurrentInputIndex
] = 1;
783 if (FileNames
[CurrentInputIndex
])
784 delete[] FileNames
[CurrentInputIndex
];
785 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
787 if (!Inputs
[CurrentInputIndex
])
790 errBuf
.Printf("Could not open include file %s", (const char*) actualFile
);
791 CurrentInputIndex
--;
792 OnError((char *)errBuf
.c_str());
795 bool succ
= read_a_line(buf
);
801 wxString bufStr
= buf
;
804 for (index
=0; syntaxTokens
[index
] != wxEmptyString
; index
++)
806 pos
= bufStr
.find(syntaxTokens
[index
]);
807 if (pos
!= wxString::npos
&& pos
!= 0)
809 size_t commentStart
= bufStr
.find("%");
810 if (commentStart
== wxString::npos
|| commentStart
> pos
)
813 if (syntaxTokens
[index
] == "\\verb")
815 errBuf
.Printf("'%s$....$' was detected at line %lu inside file %s. Please replace this form with \\tt{....}",
816 syntaxTokens
[index
].c_str(),
817 LineNumbers
[CurrentInputIndex
],
818 currentFileName
.c_str());
822 errBuf
.Printf("'%s' was detected at line %lu inside file %s that is not the only text on the line, starting at column one.",
823 syntaxTokens
[index
].c_str(),
824 LineNumbers
[CurrentInputIndex
],
825 currentFileName
.c_str());
827 OnError((char *)errBuf
.c_str());
833 if (strncmp(buf
, "\\begin{verbatim}", 16) == 0 ||
834 strncmp(buf
, "\\begin{toocomplex}", 18) == 0)
835 readInVerbatim
= TRUE
;
836 else if (strncmp(buf
, "\\end{verbatim}", 14) == 0 ||
837 strncmp(buf
, "\\end{toocomplex}", 16) == 0)
838 readInVerbatim
= FALSE
;
840 if (checkCurleyBraces
)
842 if (ch
== EOF
&& leftCurley
!= rightCurley
)
845 errBuf
.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName
.c_str(),leftCurley
,rightCurley
);
846 OnError((char *)errBuf
.c_str());
858 bool ParseNewCommand(char *buffer
, int *pos
)
860 if ((strncmp((buffer
+(*pos
)), "newcommand", 10) == 0) ||
861 (strncmp((buffer
+(*pos
)), "renewcommand", 12) == 0))
863 if (strncmp((buffer
+(*pos
)), "newcommand", 10) == 0)
868 char commandName
[100];
869 char commandValue
[1000];
872 while (buffer
[*pos
] != '}' && (buffer
[*pos
] != 0))
874 commandName
[i
] = buffer
[*pos
];
881 if (buffer
[*pos
] == '[')
884 noArgs
= (int)(buffer
[*pos
]) - 48;
885 *pos
+= 2; // read past argument and '['
891 char ch
= buffer
[*pos
];
902 if (!read_a_line(buffer
))
907 commandValue
[i
] = ch
;
913 CustomMacro
*macro
= new CustomMacro(commandName
, noArgs
, NULL
);
914 if (strlen(commandValue
) > 0)
915 macro
->macroBody
= copystring(commandValue
);
916 if (!CustomMacroList
.Find(commandName
))
918 CustomMacroList
.Append(commandName
, macro
);
919 AddMacroDef(ltCUSTOM_MACRO
, commandName
, noArgs
);
926 void MacroError(char *buffer
)
933 while (((ch
= buffer
[i
-1]) != '\n') && (ch
!= 0))
942 errBuf
.Printf("Could not find macro: %s at line %d, file %s",
943 macroBuf
, (int)(LineNumbers
[CurrentInputIndex
]-1), FileNames
[CurrentInputIndex
]);
944 OnError((char *)errBuf
.c_str());
946 if (wxStrcmp(macroBuf
,"\\end{document}") == 0)
949 buf
= "Halted build due to unrecoverable error.";
950 OnInform((char *)buf
.c_str());
957 * 'environment' specifies the name of the macro IFF if we're looking for the end
958 * of an environment, e.g. \end{itemize}. Otherwise it's NULL.
959 * 'parseToBrace' is TRUE if the argument should extend to the next right brace,
960 * e.g. in {\bf an argument} as opposed to \vskip 30pt
963 int ParseArg(TexChunk
*thisArg
, wxList
& children
, char *buffer
, int pos
, char *environment
, bool parseToBrace
, TexChunk
*customMacroArgs
)
966 if (stopRunning
) return pos
;
975 // Consume leading brace or square bracket, but ONLY if not following
976 // a space, because this could be e.g. {\large {\bf thing}} where {\bf thing}
977 // is the argument of \large AS WELL as being a block in its
981 if ((pos > 0) && (buffer[pos-1] != ' ') && buffer[pos] == '{')
985 if ((pos > 0) && (buffer[pos-1] != ' ') && (buffer[pos] == '[' || buffer[pos] == '('))
990 else if ((pos > 1) && (buffer[pos-1] != ' ') && (buffer[pos+1] == '[' || buffer[pos+1] == '('))
998 // If not parsing to brace, just read the next word
999 // (e.g. \vskip 20pt)
1002 int ch
= buffer
[pos
];
1003 while (!eof
&& ch
!= 13 && ch
!= 32 && ch
!= 10 &&
1004 ch
!= 0 && ch
!= '{')
1006 BigBuffer
[buf_ptr
] = ch
;
1013 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1014 BigBuffer
[buf_ptr
] = 0;
1016 chunk
->value
= copystring(BigBuffer
);
1017 children
.Append((wxObject
*)chunk
);
1024 len
= strlen(buffer
);
1027 if (customMacroArgs
) return 0;
1029 eof
= read_a_line(buffer
);
1031 len
= strlen(buffer
);
1032 // Check for verbatim (or toocomplex, which comes to the same thing)
1033 wxString bufStr
= buffer
;
1034 // if (bufStr.find("\\begin{verbatim}") != wxString::npos ||
1035 // bufStr.find("\\begin{toocomplex}") != wxString::npos)
1036 if (strncmp(buffer
, "\\begin{verbatim}", 16) == 0 ||
1037 strncmp(buffer
, "\\begin{toocomplex}", 18) == 0)
1041 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1042 BigBuffer
[buf_ptr
] = 0;
1044 chunk
->value
= copystring(BigBuffer
);
1045 children
.Append((wxObject
*)chunk
);
1050 eof
= read_a_line(buffer
);
1051 while (!eof
&& (strncmp(buffer
, "\\end{verbatim}", 14) != 0) &&
1052 (strncmp(buffer
, "\\end{toocomplex}", 16) != 0)
1055 strcat(BigBuffer
, buffer
);
1056 buf_ptr
+= strlen(buffer
);
1057 eof
= read_a_line(buffer
);
1059 eof
= read_a_line(buffer
);
1062 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, VerbatimMacroDef
);
1064 chunk
->macroId
= ltVERBATIM
;
1065 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, VerbatimMacroDef
);
1067 arg
->macroId
= ltVERBATIM
;
1068 TexChunk
*str
= new TexChunk(CHUNK_TYPE_STRING
);
1069 str
->value
= copystring(BigBuffer
);
1071 children
.Append((wxObject
*)chunk
);
1072 chunk
->children
.Append((wxObject
*)arg
);
1073 arg
->children
.Append((wxObject
*)str
);
1075 // Also want to include the following newline (is always a newline
1076 // after a verbatim): EXCEPT in HTML
1077 if (convertMode
!= TEX_HTML
)
1079 TexMacroDef
*parDef
= (TexMacroDef
*)MacroDefs
.Get("\\");
1080 TexChunk
*parChunk
= new TexChunk(CHUNK_TYPE_MACRO
, parDef
);
1081 parChunk
->no_args
= 0;
1082 parChunk
->macroId
= ltBACKSLASHCHAR
;
1083 children
.Append((wxObject
*)parChunk
);
1088 char ch
= buffer
[pos
];
1089 // End of optional argument -- pretend it's right brace for simplicity
1090 if (thisArg
->optional
&& (ch
== ']'))
1096 case '}': // End of argument
1100 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1101 BigBuffer
[buf_ptr
] = 0;
1103 chunk
->value
= copystring(BigBuffer
);
1104 children
.Append((wxObject
*)chunk
);
1106 if (ch
== '}') pos
++;
1112 if (buf_ptr
> 0) // Finish off the string we've read so far
1114 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1115 BigBuffer
[buf_ptr
] = 0;
1117 chunk
->value
= copystring(BigBuffer
);
1118 children
.Append((wxObject
*)chunk
);
1122 // Try matching \end{environment}
1123 if (environment
&& FindEndEnvironment(buffer
, &pos
, environment
))
1125 // Eliminate newline after an \end{} if possible
1126 if (buffer
[pos
] == 13)
1129 if (buffer
[pos
] == 10)
1135 if (ParseNewCommand(buffer
, &pos
))
1138 if (strncmp(buffer
+pos
, "special", 7) == 0)
1151 int ch
= buffer
[pos
];
1173 else if (ch
== '\\' && buffer
[pos
+1] == '}')
1179 else if (ch
== '\\' && buffer
[pos
+1] == '{')
1194 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1196 chunk
->macroId
= ltSPECIAL
;
1197 TexMacroDef
*specialDef
= (TexMacroDef
*)MacroDefs
.Get("special");
1198 chunk
->def
= specialDef
;
1199 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, specialDef
);
1200 chunk
->children
.Append((wxObject
*)arg
);
1202 arg
->macroId
= chunk
->macroId
;
1204 // The value in the first argument.
1205 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1206 arg
->children
.Append((wxObject
*)argValue
);
1208 argValue
->value
= copystring(wxBuffer
);
1210 children
.Append((wxObject
*)chunk
);
1212 else if (strncmp(buffer
+pos
, "verb", 4) == 0)
1215 if (buffer
[pos
] == '*')
1218 // Find the delimiter character
1219 int ch
= buffer
[pos
];
1221 // Now at start of verbatim text
1223 while ((buffer
[pos
] != ch
) && buffer
[pos
] != 0)
1225 char *val
= new char[pos
- j
+ 1];
1227 for (i
= j
; i
< pos
; i
++)
1229 val
[i
-j
] = buffer
[i
];
1235 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1237 chunk
->macroId
= ltVERB
;
1238 TexMacroDef
*verbDef
= (TexMacroDef
*)MacroDefs
.Get("verb");
1239 chunk
->def
= verbDef
;
1240 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, verbDef
);
1241 chunk
->children
.Append((wxObject
*)arg
);
1243 arg
->macroId
= chunk
->macroId
;
1245 // The value in the first argument.
1246 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1247 arg
->children
.Append((wxObject
*)argValue
);
1249 argValue
->value
= val
;
1251 children
.Append((wxObject
*)chunk
);
1256 bool tmpParseToBrace
= TRUE
;
1257 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1260 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1262 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1264 chunk
->no_args
= def
->no_args
;
1265 // chunk->name = copystring(def->name);
1266 chunk
->macroId
= def
->macroId
;
1269 children
.Append((wxObject
*)chunk
);
1271 // Eliminate newline after a \begin{} or a \\ if possible
1272 if (env
|| strcmp(def
->name
, "\\") == 0)
1273 if (buffer
[pos
] == 13)
1276 if (buffer
[pos
] == 10)
1280 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1281 buffer
, pos
, env
, tmpParseToBrace
, customMacroArgs
);
1283 // If custom macro, parse the body substituting the above found args.
1286 if (customMacro
->macroBody
)
1289 // strcpy(macroBuf, "{");
1290 strcpy(macroBuf
, customMacro
->macroBody
);
1291 strcat(macroBuf
, "}");
1292 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, TRUE
, chunk
);
1295 // delete chunk; // Might delete children
1300 MacroError(buffer
+pos
);
1305 // Parse constructs like {\bf thing} as if they were
1310 if (buffer
[pos
] == '\\')
1314 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1315 BigBuffer
[buf_ptr
] = 0;
1317 chunk
->value
= copystring(BigBuffer
);
1318 children
.Append((wxObject
*)chunk
);
1323 bool tmpParseToBrace
;
1324 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1327 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1329 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1330 chunk
->no_args
= def
->no_args
;
1331 // chunk->name = copystring(def->name);
1332 chunk
->macroId
= def
->macroId
;
1334 children
.Append((wxObject
*)chunk
);
1336 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1337 buffer
, pos
, NULL
, TRUE
, customMacroArgs
);
1339 // If custom macro, parse the body substituting the above found args.
1342 if (customMacro
->macroBody
)
1345 // strcpy(macroBuf, "{");
1346 strcpy(macroBuf
, customMacro
->macroBody
);
1347 strcat(macroBuf
, "}");
1348 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, TRUE
, chunk
);
1351 // delete chunk; // Might delete children
1356 MacroError(buffer
+pos
);
1362 * If all else fails, we assume that we have
1363 * a pair of braces on their own, so return a `dummy' macro
1364 * definition with just one argument to parse.
1368 SoloBlockDef
= new TexMacroDef(ltSOLO_BLOCK
, "solo block", 1, FALSE
);
1373 TexChunk
*chunk1
= new TexChunk(CHUNK_TYPE_STRING
);
1374 BigBuffer
[buf_ptr
] = 0;
1376 chunk1
->value
= copystring(BigBuffer
);
1377 children
.Append((wxObject
*)chunk1
);
1379 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, SoloBlockDef
);
1380 chunk
->no_args
= SoloBlockDef
->no_args
;
1381 // chunk->name = copystring(SoloBlockDef->name);
1382 chunk
->macroId
= SoloBlockDef
->macroId
;
1383 children
.Append((wxObject
*)chunk
);
1385 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, SoloBlockDef
);
1387 chunk
->children
.Append((wxObject
*)arg
);
1388 // arg->name = copystring(SoloBlockDef->name);
1390 arg
->macroId
= chunk
->macroId
;
1392 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, NULL
, TRUE
, customMacroArgs
);
1400 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1401 BigBuffer
[buf_ptr
] = 0;
1403 chunk
->value
= copystring(BigBuffer
);
1404 children
.Append((wxObject
*)chunk
);
1409 if (buffer
[pos
] == '$')
1411 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1413 // chunk->name = copystring("$$");
1414 chunk
->macroId
= ltSPECIALDOUBLEDOLLAR
;
1415 children
.Append((wxObject
*)chunk
);
1420 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1422 // chunk->name = copystring("_$");
1423 chunk
->macroId
= ltSPECIALDOLLAR
;
1424 children
.Append((wxObject
*)chunk
);
1432 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1433 BigBuffer
[buf_ptr
] = 0;
1435 chunk
->value
= copystring(BigBuffer
);
1436 children
.Append((wxObject
*)chunk
);
1440 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1442 // chunk->name = copystring("_~");
1443 chunk
->macroId
= ltSPECIALTILDE
;
1444 children
.Append((wxObject
*)chunk
);
1447 case '#': // Either treat as a special TeX character or as a macro arg
1451 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1452 BigBuffer
[buf_ptr
] = 0;
1454 chunk
->value
= copystring(BigBuffer
);
1455 children
.Append((wxObject
*)chunk
);
1459 if (!customMacroArgs
)
1461 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1463 // chunk->name = copystring("_#");
1464 chunk
->macroId
= ltSPECIALHASH
;
1465 children
.Append((wxObject
*)chunk
);
1469 if (isdigit(buffer
[pos
]))
1471 int n
= buffer
[pos
] - 48;
1473 wxNode
*node
= customMacroArgs
->children
.Nth(n
-1);
1476 TexChunk
*argChunk
= (TexChunk
*)node
->Data();
1477 children
.Append((wxObject
*)new TexChunk(*argChunk
));
1485 // Remove white space before and after the ampersand,
1486 // since this is probably a table column separator with
1487 // some convenient -- but useless -- white space in the text.
1488 while ((buf_ptr
> 0) && ((BigBuffer
[buf_ptr
-1] == ' ') || (BigBuffer
[buf_ptr
-1] == 9)))
1493 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1494 BigBuffer
[buf_ptr
] = 0;
1496 chunk
->value
= copystring(BigBuffer
);
1497 children
.Append((wxObject
*)chunk
);
1502 while (buffer
[pos
] == ' ' || buffer
[pos
] == 9)
1505 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1507 // chunk->name = copystring("_&");
1508 chunk
->macroId
= ltSPECIALAMPERSAND
;
1509 children
.Append((wxObject
*)chunk
);
1512 // Eliminate end-of-line comment
1516 while (ch
!= 10 && ch
!= 13 && ch
!= 0)
1521 if (buffer
[pos
] == 10 || buffer
[pos
] == 13)
1524 if (buffer
[pos
] == 10) pos
++; // Eliminate newline following DOS line feed
1531 BigBuffer
[buf_ptr
] = ' ';
1532 BigBuffer
[buf_ptr
+1] = 0;
1539 BigBuffer
[buf_ptr
] = ch
;
1540 BigBuffer
[buf_ptr
+1] = 0;
1551 * Consume as many arguments as the macro definition specifies
1555 int ParseMacroBody(const char *macro_name
, TexChunk
*parent
,
1556 int no_args
, char *buffer
, int pos
,
1557 char *environment
, bool parseToBrace
,
1558 TexChunk
*customMacroArgs
)
1561 if (stopRunning
) return pos
;
1563 // Check for a first optional argument
1564 if (buffer
[pos
] == ' ' && buffer
[pos
+1] == '[')
1566 // Fool following code into thinking that this is definitely
1567 // an optional first argument. (If a space before a non-first argument,
1568 // [ is interpreted as a [, not an optional argument.)
1574 if (buffer
[pos
] == '[')
1580 for (i
= 0; i
< no_args
; i
++)
1583 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, parent
->def
);
1585 parent
->children
.Append((wxObject
*)arg
);
1586 // arg->name = copystring(macro_name);
1587 arg
->argn
= maxArgs
;
1588 arg
->macroId
= parent
->macroId
;
1590 // To parse the first arg of a 2 arg \begin{thing}{arg} ... \end{thing}
1591 // have to fool parser into thinking this is a regular kind of block.
1593 if ((no_args
== 2) && (i
== 0))
1596 actualEnv
= environment
;
1598 bool isOptional
= FALSE
;
1600 // Remove the first { of the argument so it doesn't get recognized as { ... }
1601 // EatWhiteSpace(buffer, &pos);
1604 // The reason for these tests is to not consume braces that don't
1605 // belong to this macro.
1606 // E.g. {\bf {\small thing}}
1607 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && buffer
[pos
] == '{')
1610 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && (buffer
[pos
] == '['))
1615 else if ((pos
> 1) && (buffer
[pos
-1] != ' ') && (buffer
[pos
+1] == '['))
1623 wxString
tmpBuffer(buffer
);
1624 if (tmpBuffer
.length() > 4)
1626 if (tmpBuffer
.Right(4) == "\\par")
1627 tmpBuffer
= tmpBuffer
.Mid(0,tmpBuffer
.length()-4);
1629 errBuf
.Printf("Missing macro argument in the line:\n\t%s\n",tmpBuffer
.c_str());
1630 OnError((char *)errBuf
.c_str());
1634 arg
->optional
= isOptional
;
1636 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, actualEnv
, parseToBrace
, customMacroArgs
);
1638 // If we've encountered an OPTIONAL argument, go another time around
1639 // the loop, because we've got more than we thought.
1640 // Hopefully optional args don't occur at the end of a macro use
1641 // or we might miss it.
1642 // Don't increment no of times round loop if the first optional arg
1643 // -- we already did it before the loop.
1644 if (arg
->optional
&& (i
> 0))
1647 parent
->no_args
= maxArgs
;
1649 // Tell each argument how many args there are (useful when processing an arg)
1650 wxNode
*node
= parent
->children
.First();
1653 TexChunk
*chunk
= (TexChunk
*)node
->Data();
1654 chunk
->no_args
= maxArgs
;
1655 node
= node
->Next();
1660 bool TexLoadFile(char *filename
)
1662 static char *line_buffer
;
1663 stopRunning
= FALSE
;
1664 strcpy(TexFileRoot
, filename
);
1665 StripExtension(TexFileRoot
);
1666 sprintf(TexBibName
, "%s.bb", TexFileRoot
);
1667 sprintf(TexTmpBibName
, "%s.bb1", TexFileRoot
);
1669 TexPathList
.EnsureFileAccessible(filename
);
1674 line_buffer
= new char[MAX_LINE_BUFFER_SIZE
];
1676 Inputs
[0] = fopen(filename
, "r");
1678 FileNames
[0] = copystring(filename
);
1681 read_a_line(line_buffer
);
1682 ParseMacroBody("toplevel", TopLevel
, 1, line_buffer
, 0, NULL
, TRUE
);
1683 if (Inputs
[0]) fclose(Inputs
[0]);
1690 TexMacroDef::TexMacroDef(int the_id
, const char *the_name
, int n
, bool ig
, bool forbidLevel
)
1692 name
= copystring(the_name
);
1696 forbidden
= forbidLevel
;
1699 TexMacroDef::~TexMacroDef(void)
1701 if (name
) delete[] name
;
1704 TexChunk::TexChunk(int the_type
, TexMacroDef
*the_def
)
1716 TexChunk::TexChunk(TexChunk
& toCopy
)
1719 no_args
= toCopy
.no_args
;
1721 macroId
= toCopy
.macroId
;
1724 // name = copystring(toCopy.name);
1730 value
= copystring(toCopy
.value
);
1734 optional
= toCopy
.optional
;
1735 wxNode
*node
= toCopy
.children
.First();
1738 TexChunk
*child
= (TexChunk
*)node
->Data();
1739 children
.Append((wxObject
*)new TexChunk(*child
));
1740 node
= node
->Next();
1744 TexChunk::~TexChunk(void)
1746 // if (name) delete[] name;
1747 if (value
) delete[] value
;
1748 wxNode
*node
= children
.First();
1751 TexChunk
*child
= (TexChunk
*)node
->Data();
1753 wxNode
*next
= node
->Next();
1759 bool IsArgOptional(void) // Is this argument an optional argument?
1761 return isArgOptional
;
1764 int GetNoArgs(void) // Number of args for this macro
1769 /* Gets the text of a chunk on request (must be for small arguments
1774 void GetArgData1(TexChunk
*chunk
)
1776 switch (chunk
->type
)
1778 case CHUNK_TYPE_MACRO
:
1780 TexMacroDef
*def
= chunk
->def
;
1781 if (def
&& def
->ignore
)
1784 if (def
&& (strcmp(def
->name
, "solo block") != 0))
1786 strcat(currentArgData
, "\\");
1787 strcat(currentArgData
, def
->name
);
1790 wxNode
*node
= chunk
->children
.First();
1793 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
1794 strcat(currentArgData
, "{");
1795 GetArgData1(child_chunk
);
1796 strcat(currentArgData
, "}");
1797 node
= node
->Next();
1801 case CHUNK_TYPE_ARG
:
1803 wxNode
*node
= chunk
->children
.First();
1806 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
1807 GetArgData1(child_chunk
);
1808 node
= node
->Next();
1812 case CHUNK_TYPE_STRING
:
1815 strcat(currentArgData
, chunk
->value
);
1821 char *GetArgData(TexChunk
*chunk
)
1823 currentArgData
[0] = 0;
1824 GetArgData1(currentArgument
);
1825 haveArgData
= FALSE
;
1826 return currentArgData
;
1829 char *GetArgData(void)
1833 currentArgData
[0] = 0;
1834 GetArgData1(currentArgument
);
1836 return currentArgData
;
1839 TexChunk
*GetArgChunk(void)
1841 return currentArgument
;
1844 TexChunk
*GetNextChunk(void) // Look ahead to the next chunk
1849 TexChunk
*GetTopLevelChunk(void)
1854 int GetCurrentColumn(void)
1856 return currentColumn
;
1860 * Traverses document calling functions to allow the client to
1861 * write out the appropriate stuff
1865 void TraverseFromChunk(TexChunk
*chunk
, wxNode
*thisNode
, bool childrenOnly
)
1868 if (stopRunning
) return;
1870 switch (chunk
->type
)
1872 case CHUNK_TYPE_MACRO
:
1874 TexMacroDef
*def
= chunk
->def
;
1875 if (def
&& def
->ignore
)
1879 OnMacro(chunk
->macroId
, chunk
->no_args
, TRUE
);
1881 wxNode
*node
= chunk
->children
.First();
1882 TexChunk
*child_chunk
= NULL
;
1885 child_chunk
= (TexChunk
*)node
->Data();
1886 TraverseFromChunk(child_chunk
, node
);
1887 node
= node
->Next();
1890 if (thisNode
&& thisNode
->Next())
1891 nextChunk
= (TexChunk
*)thisNode
->Next()->Data();
1894 OnMacro(chunk
->macroId
, chunk
->no_args
, FALSE
);
1897 case CHUNK_TYPE_ARG
:
1899 currentArgument
= chunk
;
1901 isArgOptional
= chunk
->optional
;
1902 noArgs
= chunk
->no_args
;
1904 // If OnArgument returns FALSE, don't output.
1906 if (childrenOnly
|| OnArgument(chunk
->macroId
, chunk
->argn
, TRUE
))
1908 wxNode
*node
= chunk
->children
.First();
1911 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
1912 TraverseFromChunk(child_chunk
, node
);
1913 node
= node
->Next();
1917 currentArgument
= chunk
;
1919 if (thisNode
&& thisNode
->Next())
1920 nextChunk
= (TexChunk
*)thisNode
->Next()->Data();
1922 isArgOptional
= chunk
->optional
;
1923 noArgs
= chunk
->no_args
;
1926 (void)OnArgument(chunk
->macroId
, chunk
->argn
, FALSE
);
1929 case CHUNK_TYPE_STRING
:
1931 extern int issuedNewParagraph
;
1932 extern int forbidResetPar
;
1933 if (chunk
->value
&& (forbidResetPar
== 0))
1935 // If non-whitespace text, we no longer have a new paragraph.
1936 if (issuedNewParagraph
&& !((chunk
->value
[0] == 10 || chunk
->value
[0] == 13 || chunk
->value
[0] == 32)
1937 && chunk
->value
[1] == 0))
1939 issuedNewParagraph
= FALSE
;
1941 TexOutput(chunk
->value
, TRUE
);
1948 void TraverseDocument(void)
1950 TraverseFromChunk(TopLevel
, NULL
);
1953 void SetCurrentOutput(FILE *fd
)
1955 CurrentOutput1
= fd
;
1956 CurrentOutput2
= NULL
;
1959 void SetCurrentOutputs(FILE *fd1
, FILE *fd2
)
1961 CurrentOutput1
= fd1
;
1962 CurrentOutput2
= fd2
;
1965 void AddMacroDef(int the_id
, const char *name
, int n
, bool ignore
, bool forbid
)
1967 MacroDefs
.Put(name
, new TexMacroDef(the_id
, name
, n
, ignore
, forbid
));
1970 void TexInitialize(int bufSize
)
1972 InitialiseColourTable();
1974 TexPathList
.AddEnvList("TEXINPUT");
1977 TexPathList
.AddEnvList("TEXINPUTS");
1980 for (i
= 0; i
< 15; i
++)
1984 FileNames
[i
] = NULL
;
1987 IgnorableInputFiles
.Add("psbox.tex");
1988 BigBuffer
= new char[(bufSize
*1000)];
1989 currentArgData
= new char[2000];
1990 TexFileRoot
= new char[300];
1991 TexBibName
= new char[300];
1992 TexTmpBibName
= new char[300];
1993 AddMacroDef(ltTOPLEVEL
, "toplevel", 1);
1994 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
1995 // TopLevel->name = copystring("toplevel");
1996 TopLevel
->macroId
= ltTOPLEVEL
;
1997 TopLevel
->no_args
= 1;
1998 VerbatimMacroDef
= (TexMacroDef
*)MacroDefs
.Get("verbatim");
2001 void TexCleanUp(void)
2004 for (i
= 0; i
< 15; i
++)
2010 subsubsectionNo
= 0;
2013 CurrentOutput1
= NULL
;
2014 CurrentOutput2
= NULL
;
2015 CurrentInputIndex
= 0;
2016 haveArgData
= FALSE
;
2021 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
2022 // TopLevel->name = copystring("toplevel");
2023 TopLevel
->macroId
= ltTOPLEVEL
;
2024 TopLevel
->no_args
= 1;
2026 DocumentTitle
= NULL
;
2027 DocumentAuthor
= NULL
;
2028 DocumentDate
= NULL
;
2029 DocumentStyle
= LATEX_REPORT
;
2030 MinorDocumentStyle
= 0;
2031 BibliographyStyleString
= copystring("plain");
2032 DocumentStyleString
= copystring("report");
2033 MinorDocumentStyleString
= NULL
;
2035 // gt - Changed this so if this is the final pass
2036 // then we DO want to remove these macros, so that
2037 // memory is not MASSIVELY leaked if the user
2038 // does not exit the program, but instead runs
2039 // the program again
2040 if ((passNumber
== 1 && !runTwice
) ||
2041 (passNumber
== 2 && runTwice
))
2043 /* Don't want to remove custom macros after each pass.*/
2045 wxNode
*node
= CustomMacroList
.First();
2048 CustomMacro
*macro
= (CustomMacro
*)node
->Data();
2051 node
= CustomMacroList
.First();
2055 TexReferences
.BeginFind();
2056 wxNode
*node
= TexReferences
.Next();
2059 TexRef
*ref
= (TexRef
*)node
->Data();
2061 node
= TexReferences
.Next();
2063 TexReferences
.Clear();
2065 node
= BibList
.First();
2068 BibEntry
*entry
= (BibEntry
*)node
->Data();
2071 node
= BibList
.First();
2073 CitationList
.Clear();
2074 ResetTopicCounter();
2077 // There is likely to be one set of macros used by all utilities.
2078 void DefineDefaultMacros(void)
2080 // Put names which subsume other names at the TOP
2081 // so they get recognized first
2083 AddMacroDef(ltACCENT_GRAVE
, "`", 1);
2084 AddMacroDef(ltACCENT_ACUTE
, "'", 1);
2085 AddMacroDef(ltACCENT_CARET
, "^", 1);
2086 AddMacroDef(ltACCENT_UMLAUT
, "\"", 1);
2087 AddMacroDef(ltACCENT_TILDE
, "~", 1);
2088 AddMacroDef(ltACCENT_DOT
, ".", 1);
2089 AddMacroDef(ltACCENT_CADILLA
, "c", 1);
2090 AddMacroDef(ltSMALLSPACE1
, ",", 0);
2091 AddMacroDef(ltSMALLSPACE2
, ";", 0);
2093 AddMacroDef(ltABSTRACT
, "abstract", 1);
2094 AddMacroDef(ltADDCONTENTSLINE
, "addcontentsline", 3);
2095 AddMacroDef(ltADDTOCOUNTER
, "addtocounter", 2);
2096 AddMacroDef(ltALEPH
, "aleph", 0);
2097 AddMacroDef(ltALPHA
, "alpha", 0);
2098 AddMacroDef(ltALPH1
, "alph", 1);
2099 AddMacroDef(ltALPH2
, "Alph", 1);
2100 AddMacroDef(ltANGLE
, "angle", 0);
2101 AddMacroDef(ltAPPENDIX
, "appendix", 0);
2102 AddMacroDef(ltAPPROX
, "approx", 0);
2103 AddMacroDef(ltARABIC
, "arabic", 1);
2104 AddMacroDef(ltARRAY
, "array", 1);
2105 AddMacroDef(ltAST
, "ast", 0);
2106 AddMacroDef(ltASYMP
, "asymp", 0);
2107 AddMacroDef(ltAUTHOR
, "author", 1);
2109 AddMacroDef(ltBACKGROUNDCOLOUR
, "backgroundcolour", 1);
2110 AddMacroDef(ltBACKGROUNDIMAGE
, "backgroundimage", 1);
2111 AddMacroDef(ltBACKGROUND
, "background", 1);
2112 AddMacroDef(ltBACKSLASHRAW
, "backslashraw", 0);
2113 AddMacroDef(ltBACKSLASH
, "backslash", 0);
2114 AddMacroDef(ltBASELINESKIP
, "baselineskip", 1);
2115 AddMacroDef(ltBCOL
, "bcol", 2);
2116 AddMacroDef(ltBETA
, "beta", 0);
2117 AddMacroDef(ltBFSERIES
, "bfseries", 1);
2118 AddMacroDef(ltBF
, "bf", 1);
2119 AddMacroDef(ltBIBITEM
, "bibitem", 2); // For convenience, bibitem has 2 args: label and item.
2120 // The Latex syntax permits writing as 2 args.
2121 AddMacroDef(ltBIBLIOGRAPHYSTYLE
, "bibliographystyle", 1);
2122 AddMacroDef(ltBIBLIOGRAPHY
, "bibliography", 1);
2123 AddMacroDef(ltBIGTRIANGLEDOWN
, "bigtriangledown", 0);
2124 AddMacroDef(ltBOT
, "bot", 0);
2125 AddMacroDef(ltBOXIT
, "boxit", 1);
2126 AddMacroDef(ltBOX
, "box", 0);
2127 AddMacroDef(ltBRCLEAR
, "brclear", 0);
2128 AddMacroDef(ltBULLET
, "bullet", 0);
2130 AddMacroDef(ltCAPTIONSTAR
, "caption*", 1);
2131 AddMacroDef(ltCAPTION
, "caption", 1);
2132 AddMacroDef(ltCAP
, "cap", 0);
2133 AddMacroDef(ltCDOTS
, "cdots", 0);
2134 AddMacroDef(ltCDOT
, "cdot", 0);
2135 AddMacroDef(ltCENTERLINE
, "centerline", 1);
2136 AddMacroDef(ltCENTERING
, "centering", 0);
2137 AddMacroDef(ltCENTER
, "center", 1);
2138 AddMacroDef(ltCEXTRACT
, "cextract", 0);
2139 AddMacroDef(ltCHAPTERHEADING
, "chapterheading", 1);
2140 AddMacroDef(ltCHAPTERSTAR
, "chapter*", 1);
2141 AddMacroDef(ltCHAPTER
, "chapter", 1);
2142 AddMacroDef(ltCHI
, "chi", 0);
2143 AddMacroDef(ltCINSERT
, "cinsert", 0);
2144 AddMacroDef(ltCIRC
, "circ", 0);
2145 AddMacroDef(ltCITE
, "cite", 1);
2146 AddMacroDef(ltCLASS
, "class", 1);
2147 AddMacroDef(ltCLEARDOUBLEPAGE
, "cleardoublepage", 0);
2148 AddMacroDef(ltCLEARPAGE
, "clearpage", 0);
2149 AddMacroDef(ltCLINE
, "cline", 1);
2150 AddMacroDef(ltCLIPSFUNC
, "clipsfunc", 3);
2151 AddMacroDef(ltCLUBSUIT
, "clubsuit", 0);
2152 AddMacroDef(ltCOLUMNSEP
, "columnsep", 1);
2153 AddMacroDef(ltCOMMENT
, "comment", 1, TRUE
);
2154 AddMacroDef(ltCONG
, "cong", 0);
2155 AddMacroDef(ltCOPYRIGHT
, "copyright", 0);
2156 AddMacroDef(ltCPARAM
, "cparam", 2);
2157 AddMacroDef(ltCHEAD
, "chead", 1);
2158 AddMacroDef(ltCFOOT
, "cfoot", 1);
2159 AddMacroDef(ltCUP
, "cup", 0);
2161 AddMacroDef(ltDASHV
, "dashv", 0);
2162 AddMacroDef(ltDATE
, "date", 1);
2163 AddMacroDef(ltDELTA
, "delta", 0);
2164 AddMacroDef(ltCAP_DELTA
, "Delta", 0);
2165 AddMacroDef(ltDEFINECOLOUR
, "definecolour", 4);
2166 AddMacroDef(ltDEFINECOLOR
, "definecolor", 4);
2167 AddMacroDef(ltDESCRIPTION
, "description", 1);
2168 AddMacroDef(ltDESTRUCT
, "destruct", 1);
2169 AddMacroDef(ltDIAMOND2
, "diamond2", 0);
2170 AddMacroDef(ltDIAMOND
, "diamond", 0);
2171 AddMacroDef(ltDIV
, "div", 0);
2172 AddMacroDef(ltDOCUMENTCLASS
, "documentclass", 1);
2173 AddMacroDef(ltDOCUMENTSTYLE
, "documentstyle", 1);
2174 AddMacroDef(ltDOCUMENT
, "document", 1);
2175 AddMacroDef(ltDOUBLESPACE
, "doublespace", 1);
2176 AddMacroDef(ltDOTEQ
, "doteq", 0);
2177 AddMacroDef(ltDOWNARROW
, "downarrow", 0);
2178 AddMacroDef(ltDOWNARROW2
, "Downarrow", 0);
2180 AddMacroDef(ltEMPTYSET
, "emptyset", 0);
2181 AddMacroDef(ltEMPH
, "emph", 1);
2182 AddMacroDef(ltEM
, "em", 1);
2183 AddMacroDef(ltENUMERATE
, "enumerate", 1);
2184 AddMacroDef(ltEPSILON
, "epsilon", 0);
2185 AddMacroDef(ltEQUATION
, "equation", 1);
2186 AddMacroDef(ltEQUIV
, "equiv", 0);
2187 AddMacroDef(ltETA
, "eta", 0);
2188 AddMacroDef(ltEVENSIDEMARGIN
, "evensidemargin", 1);
2189 AddMacroDef(ltEXISTS
, "exists", 0);
2191 AddMacroDef(ltFBOX
, "fbox", 1);
2192 AddMacroDef(ltFCOL
, "fcol", 2);
2193 AddMacroDef(ltFIGURE
, "figure", 1);
2194 AddMacroDef(ltFIGURESTAR
, "figure*", 1);
2195 AddMacroDef(ltFLUSHLEFT
, "flushleft", 1);
2196 AddMacroDef(ltFLUSHRIGHT
, "flushright", 1);
2197 AddMacroDef(ltFOLLOWEDLINKCOLOUR
, "followedlinkcolour", 1);
2198 AddMacroDef(ltFOOTHEIGHT
, "footheight", 1);
2199 AddMacroDef(ltFOOTNOTEPOPUP
, "footnotepopup", 2);
2200 AddMacroDef(ltFOOTNOTE
, "footnote", 1);
2201 AddMacroDef(ltFOOTSKIP
, "footskip", 1);
2202 AddMacroDef(ltFORALL
, "forall", 0);
2203 AddMacroDef(ltFRAMEBOX
, "framebox", 1);
2204 AddMacroDef(ltFROWN
, "frown", 0);
2205 AddMacroDef(ltFUNCTIONSECTION
, "functionsection", 1);
2206 AddMacroDef(ltFUNC
, "func", 3);
2207 AddMacroDef(ltFOOTNOTESIZE
, "footnotesize", 0);
2208 AddMacroDef(ltFANCYPLAIN
, "fancyplain", 2);
2210 AddMacroDef(ltGAMMA
, "gamma", 0);
2211 AddMacroDef(ltCAP_GAMMA
, "Gamma", 0);
2212 AddMacroDef(ltGEQ
, "geq", 0);
2213 AddMacroDef(ltGE
, "ge", 0);
2214 AddMacroDef(ltGG
, "gg", 0);
2215 AddMacroDef(ltGLOSSARY
, "glossary", 1);
2216 AddMacroDef(ltGLOSS
, "gloss", 1);
2218 AddMacroDef(ltHEADHEIGHT
, "headheight", 1);
2219 AddMacroDef(ltHEARTSUIT
, "heartsuit", 0);
2220 AddMacroDef(ltHELPGLOSSARY
, "helpglossary", 1);
2221 AddMacroDef(ltHELPIGNORE
, "helpignore", 1, TRUE
);
2222 AddMacroDef(ltHELPONLY
, "helponly", 1);
2223 AddMacroDef(ltHELPINPUT
, "helpinput", 1);
2224 AddMacroDef(ltHELPFONTFAMILY
, "helpfontfamily", 1);
2225 AddMacroDef(ltHELPFONTSIZE
, "helpfontsize", 1);
2226 AddMacroDef(ltHELPREFN
, "helprefn", 2);
2227 AddMacroDef(ltHELPREF
, "helpref", 2);
2228 AddMacroDef(ltHFILL
, "hfill", 0);
2229 AddMacroDef(ltHLINE
, "hline", 0);
2230 AddMacroDef(ltHRULE
, "hrule", 0);
2231 AddMacroDef(ltHSPACESTAR
, "hspace*", 1);
2232 AddMacroDef(ltHSPACE
, "hspace", 1);
2233 AddMacroDef(ltHSKIPSTAR
, "hskip*", 1);
2234 AddMacroDef(ltHSKIP
, "hskip", 1);
2235 AddMacroDef(lthuge
, "huge", 1);
2236 AddMacroDef(ltHuge
, "Huge", 1);
2237 AddMacroDef(ltHUGE
, "HUGE", 1);
2238 AddMacroDef(ltHTMLIGNORE
, "htmlignore", 1);
2239 AddMacroDef(ltHTMLONLY
, "htmlonly", 1);
2241 AddMacroDef(ltIM
, "im", 0);
2242 AddMacroDef(ltINCLUDEONLY
, "includeonly", 1);
2243 AddMacroDef(ltINCLUDE
, "include", 1);
2244 AddMacroDef(ltINDENTED
, "indented", 2);
2245 AddMacroDef(ltINDEX
, "index", 1);
2246 AddMacroDef(ltINPUT
, "input", 1, TRUE
);
2247 AddMacroDef(ltIOTA
, "iota", 0);
2248 AddMacroDef(ltITEMIZE
, "itemize", 1);
2249 AddMacroDef(ltITEM
, "item", 0);
2250 AddMacroDef(ltIMAGEMAP
, "imagemap", 3);
2251 AddMacroDef(ltIMAGEL
, "imagel", 2);
2252 AddMacroDef(ltIMAGER
, "imager", 2);
2253 AddMacroDef(ltIMAGE
, "image", 2);
2254 AddMacroDef(ltIN
, "in", 0);
2255 AddMacroDef(ltINFTY
, "infty", 0);
2256 AddMacroDef(ltITSHAPE
, "itshape", 1);
2257 AddMacroDef(ltIT
, "it", 1);
2258 AddMacroDef(ltITEMSEP
, "itemsep", 1);
2259 AddMacroDef(ltINSERTATLEVEL
, "insertatlevel", 2);
2261 AddMacroDef(ltKAPPA
, "kappa", 0);
2262 AddMacroDef(ltKILL
, "kill", 0);
2264 AddMacroDef(ltLABEL
, "label", 1);
2265 AddMacroDef(ltLAMBDA
, "lambda", 0);
2266 AddMacroDef(ltCAP_LAMBDA
, "Lambda", 0);
2267 AddMacroDef(ltlarge
, "large", 1);
2268 AddMacroDef(ltLarge
, "Large", 1);
2269 AddMacroDef(ltLARGE
, "LARGE", 1);
2270 AddMacroDef(ltLATEXIGNORE
, "latexignore", 1);
2271 AddMacroDef(ltLATEXONLY
, "latexonly", 1);
2272 AddMacroDef(ltLATEX
, "LaTeX", 0);
2273 AddMacroDef(ltLBOX
, "lbox", 1);
2274 AddMacroDef(ltLBRACERAW
, "lbraceraw", 0);
2275 AddMacroDef(ltLDOTS
, "ldots", 0);
2276 AddMacroDef(ltLEQ
, "leq", 0);
2277 AddMacroDef(ltLE
, "le", 0);
2278 AddMacroDef(ltLEFTARROW
, "leftarrow", 0);
2279 AddMacroDef(ltLEFTRIGHTARROW
, "leftrightarrow", 0);
2280 AddMacroDef(ltLEFTARROW2
, "Leftarrow", 0);
2281 AddMacroDef(ltLEFTRIGHTARROW2
, "Leftrightarrow", 0);
2282 AddMacroDef(ltLINEBREAK
, "linebreak", 0);
2283 AddMacroDef(ltLINKCOLOUR
, "linkcolour", 1);
2284 AddMacroDef(ltLISTOFFIGURES
, "listoffigures", 0);
2285 AddMacroDef(ltLISTOFTABLES
, "listoftables", 0);
2286 AddMacroDef(ltLHEAD
, "lhead", 1);
2287 AddMacroDef(ltLFOOT
, "lfoot", 1);
2288 AddMacroDef(ltLOWERCASE
, "lowercase", 1);
2289 AddMacroDef(ltLL
, "ll", 0);
2291 AddMacroDef(ltMAKEGLOSSARY
, "makeglossary", 0);
2292 AddMacroDef(ltMAKEINDEX
, "makeindex", 0);
2293 AddMacroDef(ltMAKETITLE
, "maketitle", 0);
2294 AddMacroDef(ltMARKRIGHT
, "markright", 1);
2295 AddMacroDef(ltMARKBOTH
, "markboth", 2);
2296 AddMacroDef(ltMARGINPARWIDTH
, "marginparwidth", 1);
2297 AddMacroDef(ltMARGINPARSEP
, "marginparsep", 1);
2298 AddMacroDef(ltMARGINPARODD
, "marginparodd", 1);
2299 AddMacroDef(ltMARGINPAREVEN
, "marginpareven", 1);
2300 AddMacroDef(ltMARGINPAR
, "marginpar", 1);
2301 AddMacroDef(ltMBOX
, "mbox", 1);
2302 AddMacroDef(ltMDSERIES
, "mdseries", 1);
2303 AddMacroDef(ltMEMBERSECTION
, "membersection", 1);
2304 AddMacroDef(ltMEMBER
, "member", 2);
2305 AddMacroDef(ltMID
, "mid", 0);
2306 AddMacroDef(ltMODELS
, "models", 0);
2307 AddMacroDef(ltMP
, "mp", 0);
2308 AddMacroDef(ltMULTICOLUMN
, "multicolumn", 3);
2309 AddMacroDef(ltMU
, "mu", 0);
2311 AddMacroDef(ltNABLA
, "nabla", 0);
2312 AddMacroDef(ltNEG
, "neg", 0);
2313 AddMacroDef(ltNEQ
, "neq", 0);
2314 AddMacroDef(ltNEWCOUNTER
, "newcounter", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2315 AddMacroDef(ltNEWLINE
, "newline", 0);
2316 AddMacroDef(ltNEWPAGE
, "newpage", 0);
2317 AddMacroDef(ltNI
, "ni", 0);
2318 AddMacroDef(ltNOCITE
, "nocite", 1);
2319 AddMacroDef(ltNOINDENT
, "noindent", 0);
2320 AddMacroDef(ltNOLINEBREAK
, "nolinebreak", 0);
2321 AddMacroDef(ltNOPAGEBREAK
, "nopagebreak", 0);
2322 AddMacroDef(ltNORMALSIZE
, "normalsize", 1);
2323 AddMacroDef(ltNORMALBOX
, "normalbox", 1);
2324 AddMacroDef(ltNORMALBOXD
, "normalboxd", 1);
2325 AddMacroDef(ltNOTEQ
, "noteq", 0);
2326 AddMacroDef(ltNOTIN
, "notin", 0);
2327 AddMacroDef(ltNOTSUBSET
, "notsubset", 0);
2328 AddMacroDef(ltNU
, "nu", 0);
2330 AddMacroDef(ltODDSIDEMARGIN
, "oddsidemargin", 1);
2331 AddMacroDef(ltOMEGA
, "omega", 0);
2332 AddMacroDef(ltCAP_OMEGA
, "Omega", 0);
2333 AddMacroDef(ltONECOLUMN
, "onecolumn", 0);
2334 AddMacroDef(ltOPLUS
, "oplus", 0);
2335 AddMacroDef(ltOSLASH
, "oslash", 0);
2336 AddMacroDef(ltOTIMES
, "otimes", 0);
2338 AddMacroDef(ltPAGEBREAK
, "pagebreak", 0);
2339 AddMacroDef(ltPAGEREF
, "pageref", 1);
2340 AddMacroDef(ltPAGESTYLE
, "pagestyle", 1);
2341 AddMacroDef(ltPAGENUMBERING
, "pagenumbering", 1);
2342 AddMacroDef(ltPARAGRAPHSTAR
, "paragraph*", 1);
2343 AddMacroDef(ltPARAGRAPH
, "paragraph", 1);
2344 AddMacroDef(ltPARALLEL
, "parallel", 0);
2345 AddMacroDef(ltPARAM
, "param", 2);
2346 AddMacroDef(ltPARINDENT
, "parindent", 1);
2347 AddMacroDef(ltPARSKIP
, "parskip", 1);
2348 AddMacroDef(ltPARTIAL
, "partial", 0);
2349 AddMacroDef(ltPARTSTAR
, "part*", 1);
2350 AddMacroDef(ltPART
, "part", 1);
2351 AddMacroDef(ltPAR
, "par", 0);
2352 AddMacroDef(ltPERP
, "perp", 0);
2353 AddMacroDef(ltPHI
, "phi", 0);
2354 AddMacroDef(ltCAP_PHI
, "Phi", 0);
2355 AddMacroDef(ltPFUNC
, "pfunc", 3);
2356 AddMacroDef(ltPICTURE
, "picture", 1);
2357 AddMacroDef(ltPI
, "pi", 0);
2358 AddMacroDef(ltCAP_PI
, "Pi", 0);
2359 AddMacroDef(ltPM
, "pm", 0);
2360 AddMacroDef(ltPOPREFONLY
, "poprefonly", 1);
2361 AddMacroDef(ltPOPREF
, "popref", 2);
2362 AddMacroDef(ltPOUNDS
, "pounds", 0);
2363 AddMacroDef(ltPREC
, "prec", 0);
2364 AddMacroDef(ltPRECEQ
, "preceq", 0);
2365 AddMacroDef(ltPRINTINDEX
, "printindex", 0);
2366 AddMacroDef(ltPROPTO
, "propto", 0);
2367 AddMacroDef(ltPSBOXTO
, "psboxto", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2368 AddMacroDef(ltPSBOX
, "psbox", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2369 AddMacroDef(ltPSI
, "psi", 0);
2370 AddMacroDef(ltCAP_PSI
, "Psi", 0);
2372 AddMacroDef(ltQUOTE
, "quote", 1);
2373 AddMacroDef(ltQUOTATION
, "quotation", 1);
2375 AddMacroDef(ltRAGGEDBOTTOM
, "raggedbottom", 0);
2376 AddMacroDef(ltRAGGEDLEFT
, "raggedleft", 0);
2377 AddMacroDef(ltRAGGEDRIGHT
, "raggedright", 0);
2378 AddMacroDef(ltRBRACERAW
, "rbraceraw", 0);
2379 AddMacroDef(ltREF
, "ref", 1);
2380 AddMacroDef(ltREGISTERED
, "registered", 0);
2381 AddMacroDef(ltRE
, "we", 0);
2382 AddMacroDef(ltRHO
, "rho", 0);
2383 AddMacroDef(ltRIGHTARROW
, "rightarrow", 0);
2384 AddMacroDef(ltRIGHTARROW2
, "rightarrow2", 0);
2385 AddMacroDef(ltRMFAMILY
, "rmfamily", 1);
2386 AddMacroDef(ltRM
, "rm", 1);
2387 AddMacroDef(ltROMAN
, "roman", 1);
2388 AddMacroDef(ltROMAN2
, "Roman", 1);
2389 // AddMacroDef(lt"row", 1);
2390 AddMacroDef(ltRTFSP
, "rtfsp", 0);
2391 AddMacroDef(ltRTFIGNORE
, "rtfignore", 1);
2392 AddMacroDef(ltRTFONLY
, "rtfonly", 1);
2393 AddMacroDef(ltRULEDROW
, "ruledrow", 1);
2394 AddMacroDef(ltDRULED
, "druled", 1);
2395 AddMacroDef(ltRULE
, "rule", 2);
2396 AddMacroDef(ltRHEAD
, "rhead", 1);
2397 AddMacroDef(ltRFOOT
, "rfoot", 1);
2398 AddMacroDef(ltROW
, "row", 1);
2400 AddMacroDef(ltSCSHAPE
, "scshape", 1);
2401 AddMacroDef(ltSC
, "sc", 1);
2402 AddMacroDef(ltSECTIONHEADING
, "sectionheading", 1);
2403 AddMacroDef(ltSECTIONSTAR
, "section*", 1);
2404 AddMacroDef(ltSECTION
, "section", 1);
2405 AddMacroDef(ltSETCOUNTER
, "setcounter", 2);
2406 AddMacroDef(ltSFFAMILY
, "sffamily", 1);
2407 AddMacroDef(ltSF
, "sf", 1);
2408 AddMacroDef(ltSHARP
, "sharp", 0);
2409 AddMacroDef(ltSHORTCITE
, "shortcite", 1);
2410 AddMacroDef(ltSIGMA
, "sigma", 0);
2411 AddMacroDef(ltCAP_SIGMA
, "Sigma", 0);
2412 AddMacroDef(ltSIM
, "sim", 0);
2413 AddMacroDef(ltSIMEQ
, "simeq", 0);
2414 AddMacroDef(ltSINGLESPACE
, "singlespace", 1);
2415 AddMacroDef(ltSIZEDBOX
, "sizedbox", 2);
2416 AddMacroDef(ltSIZEDBOXD
, "sizedboxd", 2);
2417 AddMacroDef(ltSLOPPYPAR
, "sloppypar", 1);
2418 AddMacroDef(ltSLOPPY
, "sloppy", 0);
2419 AddMacroDef(ltSLSHAPE
, "slshape", 1);
2420 AddMacroDef(ltSL
, "sl", 1);
2421 AddMacroDef(ltSMALL
, "small", 1);
2422 AddMacroDef(ltSMILE
, "smile", 0);
2423 AddMacroDef(ltSS
, "ss", 0);
2424 AddMacroDef(ltSTAR
, "star", 0);
2425 AddMacroDef(ltSUBITEM
, "subitem", 0);
2426 AddMacroDef(ltSUBPARAGRAPHSTAR
, "subparagraph*", 1);
2427 AddMacroDef(ltSUBPARAGRAPH
, "subparagraph", 1);
2428 AddMacroDef(ltSPECIAL
, "special", 1);
2429 AddMacroDef(ltSUBSECTIONSTAR
, "subsection*", 1);
2430 AddMacroDef(ltSUBSECTION
, "subsection", 1);
2431 AddMacroDef(ltSUBSETEQ
, "subseteq", 0);
2432 AddMacroDef(ltSUBSET
, "subset", 0);
2433 AddMacroDef(ltSUCC
, "succ", 0);
2434 AddMacroDef(ltSUCCEQ
, "succeq", 0);
2435 AddMacroDef(ltSUPSETEQ
, "supseteq", 0);
2436 AddMacroDef(ltSUPSET
, "supset", 0);
2437 AddMacroDef(ltSUBSUBSECTIONSTAR
,"subsubsection*", 1);
2438 AddMacroDef(ltSUBSUBSECTION
, "subsubsection", 1);
2439 AddMacroDef(ltSUPERTABULAR
, "supertabular", 2, FALSE
);
2440 AddMacroDef(ltSURD
, "surd", 0);
2441 AddMacroDef(ltSCRIPTSIZE
, "scriptsize", 1);
2442 AddMacroDef(ltSETHEADER
, "setheader", 6);
2443 AddMacroDef(ltSETFOOTER
, "setfooter", 6);
2444 AddMacroDef(ltSETHOTSPOTCOLOUR
, "sethotspotcolour", 1);
2445 AddMacroDef(ltSETHOTSPOTCOLOR
, "sethotspotcolor", 1);
2446 AddMacroDef(ltSETHOTSPOTUNDERLINE
, "sethotspotunderline", 1);
2447 AddMacroDef(ltSETTRANSPARENCY
, "settransparency", 1);
2448 AddMacroDef(ltSPADESUIT
, "spadesuit", 0);
2450 AddMacroDef(ltTABBING
, "tabbing", 2);
2451 AddMacroDef(ltTABLEOFCONTENTS
, "tableofcontents", 0);
2452 AddMacroDef(ltTABLE
, "table", 1);
2453 AddMacroDef(ltTABULAR
, "tabular", 2, FALSE
);
2454 AddMacroDef(ltTAB
, "tab", 0);
2455 AddMacroDef(ltTAU
, "tau", 0);
2456 AddMacroDef(ltTEXTRM
, "textrm", 1);
2457 AddMacroDef(ltTEXTSF
, "textsf", 1);
2458 AddMacroDef(ltTEXTTT
, "texttt", 1);
2459 AddMacroDef(ltTEXTBF
, "textbf", 1);
2460 AddMacroDef(ltTEXTIT
, "textit", 1);
2461 AddMacroDef(ltTEXTSL
, "textsl", 1);
2462 AddMacroDef(ltTEXTSC
, "textsc", 1);
2463 AddMacroDef(ltTEXTWIDTH
, "textwidth", 1);
2464 AddMacroDef(ltTEXTHEIGHT
, "textheight", 1);
2465 AddMacroDef(ltTEXTCOLOUR
, "textcolour", 1);
2466 AddMacroDef(ltTEX
, "TeX", 0);
2467 AddMacroDef(ltTHEBIBLIOGRAPHY
, "thebibliography", 2);
2468 AddMacroDef(ltTHETA
, "theta", 0);
2469 AddMacroDef(ltTIMES
, "times", 0);
2470 AddMacroDef(ltCAP_THETA
, "Theta", 0);
2471 AddMacroDef(ltTITLEPAGE
, "titlepage", 1);
2472 AddMacroDef(ltTITLE
, "title", 1);
2473 AddMacroDef(ltTINY
, "tiny", 1);
2474 AddMacroDef(ltTODAY
, "today", 0);
2475 AddMacroDef(ltTOPMARGIN
, "topmargin", 1);
2476 AddMacroDef(ltTOPSKIP
, "topskip", 1);
2477 AddMacroDef(ltTRIANGLE
, "triangle", 0);
2478 AddMacroDef(ltTTFAMILY
, "ttfamily", 1);
2479 AddMacroDef(ltTT
, "tt", 1);
2480 AddMacroDef(ltTYPEIN
, "typein", 1);
2481 AddMacroDef(ltTYPEOUT
, "typeout", 1);
2482 AddMacroDef(ltTWOCOLWIDTHA
, "twocolwidtha", 1);
2483 AddMacroDef(ltTWOCOLWIDTHB
, "twocolwidthb", 1);
2484 AddMacroDef(ltTWOCOLSPACING
, "twocolspacing", 1);
2485 AddMacroDef(ltTWOCOLITEMRULED
, "twocolitemruled", 2);
2486 AddMacroDef(ltTWOCOLITEM
, "twocolitem", 2);
2487 AddMacroDef(ltTWOCOLLIST
, "twocollist", 1);
2488 AddMacroDef(ltTWOCOLUMN
, "twocolumn", 0);
2489 AddMacroDef(ltTHEPAGE
, "thepage", 0);
2490 AddMacroDef(ltTHECHAPTER
, "thechapter", 0);
2491 AddMacroDef(ltTHESECTION
, "thesection", 0);
2492 AddMacroDef(ltTHISPAGESTYLE
, "thispagestyle", 1);
2494 AddMacroDef(ltUNDERLINE
, "underline", 1);
2495 AddMacroDef(ltUPSILON
, "upsilon", 0);
2496 AddMacroDef(ltCAP_UPSILON
, "Upsilon", 0);
2497 AddMacroDef(ltUPARROW
, "uparrow", 0);
2498 AddMacroDef(ltUPARROW2
, "Uparrow", 0);
2499 AddMacroDef(ltUPPERCASE
, "uppercase", 1);
2500 AddMacroDef(ltUPSHAPE
, "upshape", 1);
2501 AddMacroDef(ltURLREF
, "urlref", 2);
2502 AddMacroDef(ltUSEPACKAGE
, "usepackage", 1);
2504 AddMacroDef(ltVAREPSILON
, "varepsilon", 0);
2505 AddMacroDef(ltVARPHI
, "varphi", 0);
2506 AddMacroDef(ltVARPI
, "varpi", 0);
2507 AddMacroDef(ltVARRHO
, "varrho", 0);
2508 AddMacroDef(ltVARSIGMA
, "varsigma", 0);
2509 AddMacroDef(ltVARTHETA
, "vartheta", 0);
2510 AddMacroDef(ltVDOTS
, "vdots", 0);
2511 AddMacroDef(ltVEE
, "vee", 0);
2512 AddMacroDef(ltVERBATIMINPUT
, "verbatiminput", 1);
2513 AddMacroDef(ltVERBATIM
, "verbatim", 1);
2514 AddMacroDef(ltVERBSTAR
, "verb*", 1);
2515 AddMacroDef(ltVERB
, "verb", 1);
2516 AddMacroDef(ltVERSE
, "verse", 1);
2517 AddMacroDef(ltVFILL
, "vfill", 0);
2518 AddMacroDef(ltVLINE
, "vline", 0);
2519 AddMacroDef(ltVOID
, "void", 0);
2520 AddMacroDef(ltVDASH
, "vdash", 0);
2521 AddMacroDef(ltVRULE
, "vrule", 0);
2522 AddMacroDef(ltVSPACESTAR
, "vspace*", 1);
2523 AddMacroDef(ltVSKIPSTAR
, "vskip*", 1);
2524 AddMacroDef(ltVSPACE
, "vspace", 1);
2525 AddMacroDef(ltVSKIP
, "vskip", 1);
2527 AddMacroDef(ltWEDGE
, "wedge", 0);
2528 AddMacroDef(ltWXCLIPS
, "wxclips", 0);
2529 AddMacroDef(ltWINHELPIGNORE
, "winhelpignore", 1);
2530 AddMacroDef(ltWINHELPONLY
, "winhelponly", 1);
2531 AddMacroDef(ltWP
, "wp", 0);
2533 AddMacroDef(ltXI
, "xi", 0);
2534 AddMacroDef(ltCAP_XI
, "Xi", 0);
2535 AddMacroDef(ltXLPIGNORE
, "xlpignore", 1);
2536 AddMacroDef(ltXLPONLY
, "xlponly", 1);
2538 AddMacroDef(ltZETA
, "zeta", 0);
2540 AddMacroDef(ltSPACE
, " ", 0);
2541 AddMacroDef(ltBACKSLASHCHAR
, "\\", 0);
2542 AddMacroDef(ltPIPE
, "|", 0);
2543 AddMacroDef(ltFORWARDSLASH
, "/", 0);
2544 AddMacroDef(ltUNDERSCORE
, "_", 0);
2545 AddMacroDef(ltAMPERSAND
, "&", 0);
2546 AddMacroDef(ltPERCENT
, "%", 0);
2547 AddMacroDef(ltDOLLAR
, "$", 0);
2548 AddMacroDef(ltHASH
, "#", 0);
2549 AddMacroDef(ltLPARENTH
, "(", 0);
2550 AddMacroDef(ltRPARENTH
, ")", 0);
2551 AddMacroDef(ltLBRACE
, "{", 0);
2552 AddMacroDef(ltRBRACE
, "}", 0);
2553 // AddMacroDef(ltEQUALS, "=", 0);
2554 AddMacroDef(ltRANGLEBRA
, ">", 0);
2555 AddMacroDef(ltLANGLEBRA
, "<", 0);
2556 AddMacroDef(ltPLUS
, "+", 0);
2557 AddMacroDef(ltDASH
, "-", 0);
2558 AddMacroDef(ltAT_SYMBOL
, "@", 0);
2559 // AddMacroDef(ltSINGLEQUOTE, "'", 0);
2560 // AddMacroDef(ltBACKQUOTE, "`", 0);
2564 * Default behaviour, should be called by client if can't match locally.
2568 // Called on start/end of macro examination
2569 void DefaultOnMacro(int macroId
, int no_args
, bool start
)
2573 // Default behaviour for abstract
2578 // Write the heading
2579 FakeCurrentSection(AbstractNameString
);
2580 OnMacro(ltPAR
, 0, TRUE
);
2581 OnMacro(ltPAR
, 0, FALSE
);
2585 if (DocumentStyle
== LATEX_ARTICLE
)
2593 // Default behaviour for glossary
2594 case ltHELPGLOSSARY
:
2598 // Write the heading
2599 FakeCurrentSection(GlossaryNameString
);
2600 OnMacro(ltPAR
, 0, TRUE
);
2601 OnMacro(ltPAR
, 0, FALSE
);
2602 if ((convertMode
== TEX_RTF
) && !winHelp
)
2604 OnMacro(ltPAR
, 0, TRUE
);
2605 OnMacro(ltPAR
, 0, FALSE
);
2610 case ltSPECIALAMPERSAND
:
2617 TexOutput("<<", TRUE
);
2621 TexOutput(">>", TRUE
);
2625 TexOutput("~", TRUE
);
2629 TexOutput("~", TRUE
);
2631 case ltSPECIALTILDE
:
2633 TexOutput(" ", TRUE
);
2637 TexOutput("_", TRUE
);
2641 TexOutput("#", TRUE
);
2645 TexOutput("&", TRUE
);
2649 TexOutput(" ", TRUE
);
2653 TexOutput("|", TRUE
);
2657 TexOutput("%", TRUE
);
2661 TexOutput("$", TRUE
);
2665 TexOutput("", TRUE
);
2669 TexOutput("", TRUE
);
2673 TexOutput("{", TRUE
);
2677 TexOutput("}", TRUE
);
2681 TexOutput("(c)", TRUE
);
2685 TexOutput("(r)", TRUE
);
2689 TexOutput("\\", TRUE
);
2694 TexOutput("...", TRUE
);
2698 TexOutput("|", TRUE
);
2702 TexOutput("LaTeX", TRUE
);
2706 TexOutput("TeX", TRUE
);
2710 TexOutput("£", TRUE
);
2712 case ltSPECIALDOUBLEDOLLAR
: // Interpret as center
2713 OnMacro(ltCENTER
, no_args
, start
);
2719 OnMacro(ltIT
, no_args
, start
);
2722 case ltPARAGRAPHSTAR
:
2723 case ltSUBPARAGRAPH
:
2724 case ltSUBPARAGRAPHSTAR
:
2725 OnMacro(ltSUBSUBSECTION
, no_args
, start
);
2733 TexOutput(ctime(&when
), TRUE
);
2744 if (start
) TexOutput("alpha");
2747 if (start
) TexOutput("beta");
2750 if (start
) TexOutput("gamma");
2753 if (start
) TexOutput("delta");
2757 if (start
) TexOutput("epsilon");
2760 if (start
) TexOutput("zeta");
2763 if (start
) TexOutput("eta");
2767 if (start
) TexOutput("theta");
2770 if (start
) TexOutput("iota");
2773 if (start
) TexOutput("kappa");
2776 if (start
) TexOutput("lambda");
2779 if (start
) TexOutput("mu");
2782 if (start
) TexOutput("nu");
2785 if (start
) TexOutput("xi");
2789 if (start
) TexOutput("pi");
2793 if (start
) TexOutput("rho");
2797 if (start
) TexOutput("sigma");
2800 if (start
) TexOutput("tau");
2803 if (start
) TexOutput("upsilon");
2807 if (start
) TexOutput("phi");
2810 if (start
) TexOutput("chi");
2813 if (start
) TexOutput("psi");
2816 if (start
) TexOutput("omega");
2819 if (start
) TexOutput("GAMMA");
2822 if (start
) TexOutput("DELTA");
2825 if (start
) TexOutput("THETA");
2828 if (start
) TexOutput("LAMBDA");
2831 if (start
) TexOutput("XI");
2834 if (start
) TexOutput("PI");
2837 if (start
) TexOutput("SIGMA");
2840 if (start
) TexOutput("UPSILON");
2843 if (start
) TexOutput("PHI");
2846 if (start
) TexOutput("PSI");
2849 if (start
) TexOutput("OMEGA");
2852 // Binary operation symbols
2855 if (start
) TexOutput("<=");
2858 if (start
) TexOutput("<<");
2861 if (start
) TexOutput("SUBSET");
2864 if (start
) TexOutput("SUBSETEQ");
2867 if (start
) TexOutput("IN");
2870 if (start
) TexOutput("VDASH");
2873 if (start
) TexOutput("MODELS");
2877 if (start
) TexOutput(">=");
2880 if (start
) TexOutput(">>");
2883 if (start
) TexOutput("SUPSET");
2886 if (start
) TexOutput("SUPSETEQ");
2889 if (start
) TexOutput("NI");
2892 if (start
) TexOutput("DASHV");
2895 if (start
) TexOutput("PERP");
2898 if (start
) TexOutput("NEQ");
2901 if (start
) TexOutput("DOTEQ");
2904 if (start
) TexOutput("APPROX");
2907 if (start
) TexOutput("CONG");
2910 if (start
) TexOutput("EQUIV");
2913 if (start
) TexOutput("PROPTO");
2916 if (start
) TexOutput("PREC");
2919 if (start
) TexOutput("PRECEQ");
2922 if (start
) TexOutput("|");
2925 if (start
) TexOutput("~");
2928 if (start
) TexOutput("SIMEQ");
2931 if (start
) TexOutput("ASYMP");
2934 if (start
) TexOutput(":-)");
2937 if (start
) TexOutput(":-(");
2940 if (start
) TexOutput("SUCC");
2943 if (start
) TexOutput("SUCCEQ");
2946 if (start
) TexOutput("|");
2949 // Negated relation symbols
2951 if (start
) TexOutput("!=");
2954 if (start
) TexOutput("NOTIN");
2957 if (start
) TexOutput("NOTSUBSET");
2962 if (start
) TexOutput("<--");
2965 if (start
) TexOutput("<==");
2968 if (start
) TexOutput("-->");
2971 if (start
) TexOutput("==>");
2973 case ltLEFTRIGHTARROW
:
2974 if (start
) TexOutput("<-->");
2976 case ltLEFTRIGHTARROW2
:
2977 if (start
) TexOutput("<==>");
2980 if (start
) TexOutput("UPARROW");
2983 if (start
) TexOutput("UPARROW2");
2986 if (start
) TexOutput("DOWNARROW");
2989 if (start
) TexOutput("DOWNARROW2");
2991 // Miscellaneous symbols
2993 if (start
) TexOutput("ALEPH");
2996 if (start
) TexOutput("WP");
2999 if (start
) TexOutput("RE");
3002 if (start
) TexOutput("IM");
3005 if (start
) TexOutput("EMPTYSET");
3008 if (start
) TexOutput("NABLA");
3011 if (start
) TexOutput("SURD");
3014 if (start
) TexOutput("PARTIAL");
3017 if (start
) TexOutput("BOT");
3020 if (start
) TexOutput("FORALL");
3023 if (start
) TexOutput("EXISTS");
3026 if (start
) TexOutput("NEG");
3029 if (start
) TexOutput("SHARP");
3032 if (start
) TexOutput("ANGLE");
3035 if (start
) TexOutput("TRIANGLE");
3038 if (start
) TexOutput("CLUBSUIT");
3041 if (start
) TexOutput("DIAMONDSUIT");
3044 if (start
) TexOutput("HEARTSUIT");
3047 if (start
) TexOutput("SPADESUIT");
3050 if (start
) TexOutput("INFTY");
3053 if (start
) TexOutput("PM");
3056 if (start
) TexOutput("MP");
3059 if (start
) TexOutput("TIMES");
3062 if (start
) TexOutput("DIV");
3065 if (start
) TexOutput("CDOT");
3068 if (start
) TexOutput("AST");
3071 if (start
) TexOutput("STAR");
3074 if (start
) TexOutput("CAP");
3077 if (start
) TexOutput("CUP");
3080 if (start
) TexOutput("VEE");
3083 if (start
) TexOutput("WEDGE");
3086 if (start
) TexOutput("CIRC");
3089 if (start
) TexOutput("BULLET");
3092 if (start
) TexOutput("DIAMOND");
3095 if (start
) TexOutput("OSLASH");
3098 if (start
) TexOutput("BOX");
3101 if (start
) TexOutput("DIAMOND2");
3103 case ltBIGTRIANGLEDOWN
:
3104 if (start
) TexOutput("BIGTRIANGLEDOWN");
3107 if (start
) TexOutput("OPLUS");
3110 if (start
) TexOutput("OTIMES");
3113 if (start
) TexOutput("s");
3115 case ltBACKSLASHRAW
:
3116 if (start
) TexOutput("\\");
3119 if (start
) TexOutput("{");
3122 if (start
) TexOutput("}");
3126 if (start
) TexOutput(" ");
3133 // Called on start/end of argument examination
3134 bool DefaultOnArgument(int macroId
, int arg_no
, bool start
)
3140 if (arg_no
== 1 && start
)
3142 char *refName
= GetArgData();
3145 TexRef
*texRef
= FindReference(refName
);
3148 // Must strip the 'section' or 'chapter' or 'figure' text
3149 // from a normal 'ref' reference
3151 strcpy(buf
, texRef
->sectionNumber
);
3152 int len
= strlen(buf
);
3154 if (strcmp(buf
, "??") != 0)
3166 TexOutput(texRef
->sectionNumber
+ i
, TRUE
);
3171 informBuf
.Printf("Warning: unresolved reference '%s'", refName
);
3172 OnInform((char *)informBuf
.c_str());
3175 else TexOutput("??", TRUE
);
3187 if (start
&& (arg_no
== 1))
3188 DocumentAuthor
= GetArgChunk();
3194 if (start
&& (arg_no
== 1))
3195 DocumentDate
= GetArgChunk();
3201 if (start
&& (arg_no
== 1))
3202 DocumentTitle
= GetArgChunk();
3206 case ltDOCUMENTCLASS
:
3207 case ltDOCUMENTSTYLE
:
3209 if (start
&& !IsArgOptional())
3211 DocumentStyleString
= copystring(GetArgData());
3212 if (strncmp(DocumentStyleString
, "art", 3) == 0)
3213 DocumentStyle
= LATEX_ARTICLE
;
3214 else if (strncmp(DocumentStyleString
, "rep", 3) == 0)
3215 DocumentStyle
= LATEX_REPORT
;
3216 else if (strncmp(DocumentStyleString
, "book", 4) == 0 ||
3217 strncmp(DocumentStyleString
, "thesis", 6) == 0)
3218 DocumentStyle
= LATEX_BOOK
;
3219 else if (strncmp(DocumentStyleString
, "letter", 6) == 0)
3220 DocumentStyle
= LATEX_LETTER
;
3221 else if (strncmp(DocumentStyleString
, "slides", 6) == 0)
3222 DocumentStyle
= LATEX_SLIDES
;
3224 if (StringMatch("10", DocumentStyleString
))
3226 else if (StringMatch("11", DocumentStyleString
))
3228 else if (StringMatch("12", DocumentStyleString
))
3231 OnMacro(ltHELPFONTSIZE
, 1, TRUE
);
3232 sprintf(currentArgData
, "%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("10", MinorDocumentStyleString
))
3245 else if (StringMatch("11", MinorDocumentStyleString
))
3247 else if (StringMatch("12", MinorDocumentStyleString
))
3253 case ltBIBLIOGRAPHYSTYLE
:
3255 if (start
&& !IsArgOptional())
3256 BibliographyStyleString
= copystring(GetArgData());
3262 if (start
&& !IsArgOptional())
3264 if (PageStyle
) delete[] PageStyle
;
3265 PageStyle
= copystring(GetArgData());
3273 if (start && !IsArgOptional())
3274 LeftHeader = GetArgChunk();
3280 if (start && !IsArgOptional())
3281 LeftFooter = GetArgChunk();
3287 if (start && !IsArgOptional())
3288 CentreHeader = GetArgChunk();
3294 if (start && !IsArgOptional())
3295 CentreFooter = GetArgChunk();
3301 if (start && !IsArgOptional())
3302 RightHeader = GetArgChunk();
3308 if (start && !IsArgOptional())
3309 RightFooter = GetArgChunk();
3317 if (start
&& !IsArgOptional())
3319 char *citeKeys
= GetArgData();
3321 char *citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3324 AddCitation(citeKey
);
3325 TexRef
*ref
= FindReference(citeKey
);
3328 TexOutput(ref
->sectionNumber
, TRUE
);
3329 if (strcmp(ref
->sectionNumber
, "??") == 0)
3332 informBuf
.Printf("Warning: unresolved citation %s.", citeKey
);
3333 OnInform((char *)informBuf
.c_str());
3336 citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3339 TexOutput(", ", TRUE
);
3348 if (start
&& !IsArgOptional())
3350 char *citeKey
= GetArgData();
3351 AddCitation(citeKey
);
3356 case ltHELPFONTSIZE
:
3360 char *data
= GetArgData();
3361 if (strcmp(data
, "10") == 0)
3363 else if (strcmp(data
, "11") == 0)
3365 else if (strcmp(data
, "12") == 0)
3375 TexOutput(" ??", TRUE
);
3382 if (start
&& arg_no
== 1)
3384 char *data
= GetArgData();
3385 ParSkip
= ParseUnitArgument(data
);
3392 if (start
&& arg_no
== 1)
3394 char *data
= GetArgData();
3395 ParIndent
= ParseUnitArgument(data
);
3402 return OnArgument(ltIT
, arg_no
, start
);
3405 case ltSPECIALDOUBLEDOLLAR
:
3407 return OnArgument(ltCENTER
, arg_no
, start
);
3411 case ltPARAGRAPHSTAR
:
3412 case ltSUBPARAGRAPH
:
3413 case ltSUBPARAGRAPHSTAR
:
3415 return OnArgument(ltSUBSUBSECTION
, arg_no
, start
);
3421 OnInform(GetArgData());
3427 TexOutput(" (", TRUE
);
3429 TexOutput(")", TRUE
);
3432 case ltBIBLIOGRAPHY
:
3440 if ((fd
= fopen(TexBibName
, "r")))
3446 TexOutput(smallBuf
);
3454 OnInform("Run Tex2RTF again to include bibliography.");
3457 // Read in the .bib file, resolve all known references, write out the RTF.
3458 char *allFiles
= GetArgData();
3460 char *bibFile
= ParseMultifieldString(allFiles
, &pos
);
3464 strcpy(fileBuf
, bibFile
);
3465 wxString actualFile
= TexPathList
.FindValidPath(fileBuf
);
3466 if (actualFile
== "")
3468 strcat(fileBuf
, ".bib");
3469 actualFile
= TexPathList
.FindValidPath(fileBuf
);
3471 if (actualFile
!= "")
3473 if (!ReadBib((char*) (const char*) actualFile
))
3476 errBuf
.Printf(".bib file %s not found or malformed", (const char*) actualFile
);
3477 OnError((char *)errBuf
.c_str());
3483 errBuf
.Printf(".bib file %s not found", fileBuf
);
3484 OnError((char *)errBuf
.c_str());
3486 bibFile
= ParseMultifieldString(allFiles
, &pos
);
3489 ResolveBibReferences();
3491 // Write it a new bib section in the appropriate format.
3492 FILE *save1
= CurrentOutput1
;
3493 FILE *save2
= CurrentOutput2
;
3494 FILE *Biblio
= fopen(TexTmpBibName
, "w");
3495 SetCurrentOutput(Biblio
);
3498 if (wxFileExists(TexTmpBibName
))
3500 if (wxFileExists(TexBibName
)) wxRemoveFile(TexBibName
);
3501 wxRenameFile(TexTmpBibName
, TexBibName
);
3503 SetCurrentOutputs(save1
, save2
);
3510 if (start
&& (arg_no
== 3))
3520 if (start
&& (arg_no
== 1))
3522 char *s
= GetArgData();
3525 char *s1
= copystring(s
);
3527 for (i
= 0; i
< (int)strlen(s
); i
++)
3528 s1
[i
] = toupper(s
[i
]);
3541 if (start
&& (arg_no
== 1))
3543 char *s
= GetArgData();
3546 char *s1
= copystring(s
);
3548 for (i
= 0; i
< (int)strlen(s
); i
++)
3549 s1
[i
] = tolower(s
[i
]);
3562 if (start
&& (arg_no
== 1))
3564 char *s
= GetArgData();
3567 char *s1
= copystring(s
);
3569 for (i
= 0; i
< (int)strlen(s
); i
++)
3570 s1
[i
] = toupper(s
[i
]);
3581 case ltPOPREF
: // Ignore second argument by default
3583 if (start
&& (arg_no
== 1))
3593 return ((convertMode
== TEX_XLP
) ? FALSE
: TRUE
);
3596 return ((convertMode
!= TEX_XLP
) ? FALSE
: TRUE
);
3599 return ((convertMode
== TEX_HTML
) ? FALSE
: TRUE
);
3602 return ((convertMode
!= TEX_HTML
) ? FALSE
: TRUE
);
3605 return (((convertMode
== TEX_RTF
) && !winHelp
) ? FALSE
: TRUE
);
3608 return (!((convertMode
== TEX_RTF
) && !winHelp
) ? FALSE
: TRUE
);
3610 case ltWINHELPIGNORE
:
3611 return (winHelp
? FALSE
: TRUE
);
3614 return (!winHelp
? FALSE
: TRUE
);
3629 case ltADDTOCOUNTER
:
3630 case ltADDCONTENTSLINE
:
3634 case ltBASELINESKIP
:
3643 case ltPAGENUMBERING
:
3655 case ltTHISPAGESTYLE
:
3658 case ltEVENSIDEMARGIN
:
3659 case ltODDSIDEMARGIN
:
3661 case ltMARGINPARWIDTH
:
3662 case ltMARGINPARSEP
:
3663 case ltMARGINPAREVEN
:
3664 case ltMARGINPARODD
:
3665 case ltTWOCOLWIDTHA
:
3666 case ltTWOCOLWIDTHB
:
3667 case ltTWOCOLSPACING
:
3674 case ltSETHOTSPOTCOLOUR
:
3675 case ltSETHOTSPOTCOLOR
:
3676 case ltSETHOTSPOTUNDERLINE
:
3677 case ltSETTRANSPARENCY
:
3680 case ltBACKGROUNDCOLOUR
:
3681 case ltBACKGROUNDIMAGE
:
3683 case ltFOLLOWEDLINKCOLOUR
:
3690 case ltINSERTATLEVEL
:
3694 case ltSUPERTABULAR
:
3703 if (arg_no
== 2) return TRUE
;
3710 if (arg_no
== 2) return TRUE
;
3714 case ltDEFINECOLOUR
:
3717 static int redVal
= 0;
3718 static int greenVal
= 0;
3719 static int blueVal
= 0;
3720 static char *colourName
= NULL
;
3727 if (colourName
) delete[] colourName
;
3728 colourName
= copystring(GetArgData());
3733 redVal
= atoi(GetArgData());
3738 greenVal
= atoi(GetArgData());
3743 blueVal
= atoi(GetArgData());
3744 AddColour(colourName
, redVal
, greenVal
, blueVal
);
3760 if (IsArgOptional())