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
;
147 bool ignoreBadRefs
= FALSE
;
149 extern int passNumber
;
151 extern wxHashTable TexReferences
;
154 * International support
157 // Names to help with internationalisation
158 char *ContentsNameString
= copystring("Contents");
159 char *AbstractNameString
= copystring("Abstract");
160 char *GlossaryNameString
= copystring("Glossary");
161 char *ReferencesNameString
= copystring("References");
162 char *FiguresNameString
= copystring("List of Figures");
163 char *TablesNameString
= copystring("List of Tables");
164 char *FigureNameString
= copystring("Figure");
165 char *TableNameString
= copystring("Table");
166 char *IndexNameString
= copystring("Index");
167 char *ChapterNameString
= copystring("chapter");
168 char *SectionNameString
= copystring("section");
169 char *SubsectionNameString
= copystring("subsection");
170 char *SubsubsectionNameString
= copystring("subsubsection");
171 char *UpNameString
= copystring("Up");
180 int subsectionNo
= 0;
181 int subsubsectionNo
= 0;
190 FILE *CurrentOutput1
= NULL
;
191 FILE *CurrentOutput2
= NULL
;
195 int CurrentInputIndex
= 0;
197 char *TexFileRoot
= NULL
;
198 char *TexBibName
= NULL
; // Bibliography output file name
199 char *TexTmpBibName
= NULL
; // Temporary bibliography output file name
200 bool isSync
= FALSE
; // If TRUE, should not yield to other processes.
201 bool stopRunning
= FALSE
; // If TRUE, should abort.
203 static int currentColumn
= 0;
204 char *currentArgData
= NULL
;
205 bool haveArgData
= FALSE
; // If TRUE, we're simulating the data.
206 TexChunk
*currentArgument
= NULL
;
207 TexChunk
*nextChunk
= NULL
;
208 bool isArgOptional
= FALSE
;
211 TexChunk
*TopLevel
= NULL
;
212 // wxList MacroDefs(wxKEY_STRING);
213 wxHashTable
MacroDefs(wxKEY_STRING
);
214 wxStringList IgnorableInputFiles
; // Ignorable \input files, e.g. psbox.tex
215 char *BigBuffer
= NULL
; // For reading in large chunks of text
216 TexMacroDef
*SoloBlockDef
= NULL
;
217 TexMacroDef
*VerbatimMacroDef
= NULL
;
219 #define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
222 TexRef::TexRef(const char *label
, const char *file
,
223 const char *section
, const char *sectionN
)
225 refLabel
= copystring(label
);
226 refFile
= file
? copystring(file
) : (char*) NULL
;
227 sectionNumber
= section
? copystring(section
) : copystring("??");
228 sectionName
= sectionN
? copystring(sectionN
) : copystring("??");
231 TexRef::~TexRef(void)
233 delete [] refLabel
; refLabel
= NULL
;
234 delete [] refFile
; refFile
= NULL
;
235 delete [] sectionNumber
; sectionNumber
= NULL
;
236 delete [] sectionName
; sectionName
= NULL
;
240 CustomMacro::~CustomMacro()
248 void TexOutput(const char *s
, bool ordinaryText
)
252 // Update current column, but only if we're guaranteed to
253 // be ordinary text (not mark-up stuff)
256 for (i
= 0; i
< len
; i
++)
258 if (s
[i
] == 13 || s
[i
] == 10)
265 fprintf(CurrentOutput1
, "%s", s
);
267 fprintf(CurrentOutput2
, "%s", s
);
271 * Try to find a Latex macro, in one of the following forms:
272 * (1) \begin{} ... \end{}
273 * (2) \macroname{arg1}...{argn}
277 void ForbidWarning(TexMacroDef
*def
)
280 switch (def
->forbidden
)
284 informBuf
.Printf("Warning: it is recommended that command %s is not used.", def
->name
);
285 OnInform((char *)informBuf
.c_str());
288 case FORBID_ABSOLUTELY
:
290 informBuf
.Printf("Error: command %s cannot be used and will lead to errors.", def
->name
);
291 OnInform((char *)informBuf
.c_str());
299 TexMacroDef
*MatchMacro(char *buffer
, int *pos
, char **env
, bool *parseToBrace
)
301 *parseToBrace
= TRUE
;
303 TexMacroDef
*def
= NULL
;
306 // First, try to find begin{thing}
307 if (strncmp(buffer
+i
, "begin{", 6) == 0)
312 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
314 macroBuf
[j
-i
] = buffer
[j
];
318 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
322 *pos
= j
+ 1; // BUGBUG Should this be + 1???
330 // Failed, so try to find macro from definition list
333 // First try getting a one-character macro, but ONLY
334 // if these TWO characters are not both alphabetical (could
335 // be a longer macro)
336 if (!(isalpha(buffer
[i
]) && isalpha(buffer
[i
+1])))
338 macroBuf
[0] = buffer
[i
];
341 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
347 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
349 macroBuf
[j
-i
] = buffer
[j
];
353 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
360 // We want to check whether this is a space-consuming macro
362 // No brace, e.g. \input thing.tex instead of \input{thing};
363 // or a numeric argument, such as \parindent0pt
364 if ((def
->no_args
> 0) && ((buffer
[i
] == 32) || (buffer
[i
] == '=') || (isdigit(buffer
[i
]))))
366 if ((buffer
[i
] == 32) || (buffer
[i
] == '='))
369 *parseToBrace
= FALSE
;
378 void EatWhiteSpace(char *buffer
, int *pos
)
380 int len
= strlen(buffer
);
382 bool keepGoing
= TRUE
;
383 bool moreLines
= TRUE
;
384 while ((j
< len
) && keepGoing
&&
385 (buffer
[j
] == 10 || buffer
[j
] == 13 || buffer
[j
] == ' ' || buffer
[j
] == 9))
392 moreLines
= read_a_line(buffer
);
393 len
= strlen(buffer
);
403 bool FindEndEnvironment(char *buffer
, int *pos
, char *env
)
407 // Try to find end{thing}
408 if ((strncmp(buffer
+i
, "end{", 4) == 0) &&
409 (strncmp(buffer
+i
+4, env
, strlen(env
)) == 0))
411 *pos
= i
+ 5 + strlen(env
);
417 bool readingVerbatim
= FALSE
;
418 bool readInVerbatim
= FALSE
; // Within a verbatim, but not nec. verbatiminput
420 // Switched this off because e.g. \verb${$ causes it to fail. There is no
421 // detection of \verb yet.
422 // #define CHECK_BRACES 1
424 unsigned long leftCurley
= 0;
425 unsigned long rightCurley
= 0;
426 static wxString currentFileName
= "";
428 bool read_a_line(char *buf
)
430 if (CurrentInputIndex
< 0)
440 while (ch
!= EOF
&& ch
!= 10)
442 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
445 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
446 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
447 OnError((char *)errBuf
.c_str());
451 if (((bufIndex
== 14) && (strncmp(buf
, "\\end{verbatim}", 14) == 0)) ||
452 ((bufIndex
== 16) && (strncmp(buf
, "\\end{toocomplex}", 16) == 0)))
453 readInVerbatim
= FALSE
;
455 ch
= getc(Inputs
[CurrentInputIndex
]);
457 if (checkCurleyBraces
)
459 if (ch
== '{' && !readInVerbatim
)
461 if (ch
== '}' && !readInVerbatim
)
464 if (rightCurley
> leftCurley
)
467 errBuf
.Printf("An extra right Curley brace ('}') was detected at line %lu inside file %s",LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str());
468 OnError((char *)errBuf
.c_str());
470 // Reduce the count of right Curley braces, so the mismatched count
471 // isn't reported on every line that has a '}' after the first mismatch
479 // Check for 2 consecutive newlines and replace with \par
480 if (ch
== 10 && !readInVerbatim
)
482 int ch1
= getc(Inputs
[CurrentInputIndex
]);
483 if ((ch1
== 10) || (ch1
== 13))
485 // Eliminate newline (10) following DOS linefeed
487 ch1
= getc(Inputs
[CurrentInputIndex
]);
489 IncrementLineNumber();
490 // strcat(buf, "\\par\n");
492 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
495 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
496 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
497 OnError((char *)errBuf
.c_str());
500 strcat(buf
, "\\par");
506 ungetc(ch1
, Inputs
[CurrentInputIndex
]);
507 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
510 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
511 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
512 OnError((char *)errBuf
.c_str());
523 // Convert embedded characters to RTF equivalents
532 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
535 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
536 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
537 OnError((char *)errBuf
.c_str());
540 buf
[bufIndex
++]='\\';
545 case 0xf6:buf
[bufIndex
++]='o';break; // ö
546 case 0xe4:buf
[bufIndex
++]='a';break; // ä
547 case 0xfc:buf
[bufIndex
++]='u';break; // ü
548 case 0xd6:buf
[bufIndex
++]='O';break; // Ö
549 case 0xc4:buf
[bufIndex
++]='A';break; // Ä
550 case 0xdc:buf
[bufIndex
++]='U';break; // Ü
555 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
558 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
559 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
560 OnError((char *)errBuf
.c_str());
563 buf
[bufIndex
++]='\\';
566 buf
[bufIndex
++]='\\';
570 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
573 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
574 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
575 OnError((char *)errBuf
.c_str());
578 // If the current character read in is a '_', we need to check
579 // whether there should be a '\' before it or not
582 buf
[bufIndex
++] = ch
;
590 // There should NOT be a '\' before the '_'
591 if ((bufIndex
> 0 && (buf
[bufIndex
-1] == '\\')) && (buf
[0] != '%'))
594 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());
595 OnError((char *)errBuf
.c_str());
600 // There should be a '\' before the '_'
604 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());
605 OnError((char *)errBuf
.c_str());
607 else if ((buf
[bufIndex
-1] != '\\') && (buf
[0] != '%') && // If it is a comment line, then no warnings
608 (strncmp(buf
, "\\input", 6))) // do not report filenames that have underscores in them
611 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());
612 OnError((char *)errBuf
.c_str());
616 buf
[bufIndex
++] = ch
;
624 fclose(Inputs
[CurrentInputIndex
]);
625 Inputs
[CurrentInputIndex
] = NULL
;
626 if (CurrentInputIndex
> 0)
627 ch
= ' '; // No real end of file
628 CurrentInputIndex
--;
630 if (checkCurleyBraces
)
632 if (leftCurley
!= rightCurley
)
635 errBuf
.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName
.c_str(),leftCurley
,rightCurley
);
636 OnError((char *)errBuf
.c_str());
644 readingVerbatim
= FALSE
;
645 readInVerbatim
= FALSE
;
646 strcat(buf
, "\\end{verbatim}\n");
651 IncrementLineNumber();
655 // Strip out comment environment
656 if (strncmp(buf
, "\\begin{comment}", 15) == 0)
658 while (strncmp(buf
, "\\end{comment}", 13) != 0)
660 return read_a_line(buf
);
662 // Read a verbatim input file as if it were a verbatim environment
663 else if (strncmp(buf
, "\\verbatiminput", 14) == 0)
666 char *fileName
= buf
+ wordLen
+ 1;
668 int j
= bufIndex
- 1;
671 // thing}\par -- eliminate the \par!
672 if (strncmp((buf
+ strlen(buf
)-5), "\\par", 4) == 0)
679 buf
[j
-1] = 0; // Ignore final brace
681 wxString actualFile
= TexPathList
.FindValidPath(fileName
);
682 currentFileName
= actualFile
;
683 if (actualFile
== "")
686 errBuf
.Printf("Could not find file: %s",fileName
);
687 OnError((char *)errBuf
.c_str());
692 informStr
.Printf("Processing: %s",actualFile
.c_str());
693 OnInform((char *)informStr
.c_str());
694 CurrentInputIndex
++;
696 Inputs
[CurrentInputIndex
] = fopen(actualFile
, "r");
697 LineNumbers
[CurrentInputIndex
] = 1;
698 if (FileNames
[CurrentInputIndex
])
699 delete[] FileNames
[CurrentInputIndex
];
700 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
702 if (!Inputs
[CurrentInputIndex
])
704 CurrentInputIndex
--;
705 OnError("Could not open verbatiminput file.");
709 readingVerbatim
= TRUE
;
710 readInVerbatim
= TRUE
;
711 strcpy(buf
, "\\begin{verbatim}\n");
717 else if (strncmp(buf
, "\\input", 6) == 0 || strncmp(buf
, "\\helpinput", 10) == 0 ||
718 strncmp(buf
, "\\include", 8) == 0)
721 if (strncmp(buf
, "\\input", 6) == 0)
724 if (strncmp(buf
, "\\include", 8) == 0)
729 char *fileName
= buf
+ wordLen
+ 1;
731 int j
= bufIndex
- 1;
734 // \input{thing}\par -- eliminate the \par!
735 // if (strncmp((buf + strlen(buf)-5), "\\par", 4) == 0)
736 if (strncmp((buf
+ strlen(buf
)-4), "\\par", 4) == 0) // Bug fix 8/2/95 Ulrich Leodolter
744 buf
[j
-1] = 0; // Ignore final brace
746 // Remove backslashes from name
747 wxString
fileNameStr(fileName
);
748 fileNameStr
.Replace("\\", "");
750 // Ignore some types of input files (e.g. macro definition files)
751 char *fileOnly
= FileNameFromPath((char*) (const char*) fileNameStr
);
752 currentFileName
= fileOnly
;
753 if (IgnorableInputFiles
.Member(fileOnly
))
754 return read_a_line(buf
);
756 wxString actualFile
= TexPathList
.FindValidPath(fileNameStr
);
757 if (actualFile
== "")
760 sprintf(buf2
, "%s.tex", (const char*) fileNameStr
);
761 actualFile
= TexPathList
.FindValidPath(buf2
);
763 currentFileName
= actualFile
;
765 if (actualFile
== "")
768 errBuf
.Printf("Could not find file: %s",fileName
);
769 OnError((char *)errBuf
.c_str());
773 // Ensure that if this file includes another,
774 // then we look in the same directory as this one.
775 TexPathList
.EnsureFileAccessible(actualFile
);
778 informStr
.Printf("Processing: %s",actualFile
.c_str());
779 OnInform((char *)informStr
.c_str());
780 CurrentInputIndex
++;
782 Inputs
[CurrentInputIndex
] = fopen(actualFile
, "r");
783 LineNumbers
[CurrentInputIndex
] = 1;
784 if (FileNames
[CurrentInputIndex
])
785 delete[] FileNames
[CurrentInputIndex
];
786 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
788 if (!Inputs
[CurrentInputIndex
])
791 errBuf
.Printf("Could not open include file %s", (const char*) actualFile
);
792 CurrentInputIndex
--;
793 OnError((char *)errBuf
.c_str());
796 bool succ
= read_a_line(buf
);
802 wxString bufStr
= buf
;
805 for (index
=0; syntaxTokens
[index
] != wxEmptyString
; index
++)
807 pos
= bufStr
.find(syntaxTokens
[index
]);
808 if (pos
!= wxString::npos
&& pos
!= 0)
810 size_t commentStart
= bufStr
.find("%");
811 if (commentStart
== wxString::npos
|| commentStart
> pos
)
814 if (syntaxTokens
[index
] == "\\verb")
816 errBuf
.Printf("'%s$....$' was detected at line %lu inside file %s. Please replace this form with \\tt{....}",
817 syntaxTokens
[index
].c_str(),
818 LineNumbers
[CurrentInputIndex
],
819 currentFileName
.c_str());
823 errBuf
.Printf("'%s' was detected at line %lu inside file %s that is not the only text on the line, starting at column one.",
824 syntaxTokens
[index
].c_str(),
825 LineNumbers
[CurrentInputIndex
],
826 currentFileName
.c_str());
828 OnError((char *)errBuf
.c_str());
834 if (strncmp(buf
, "\\begin{verbatim}", 16) == 0 ||
835 strncmp(buf
, "\\begin{toocomplex}", 18) == 0)
836 readInVerbatim
= TRUE
;
837 else if (strncmp(buf
, "\\end{verbatim}", 14) == 0 ||
838 strncmp(buf
, "\\end{toocomplex}", 16) == 0)
839 readInVerbatim
= FALSE
;
841 if (checkCurleyBraces
)
843 if (ch
== EOF
&& leftCurley
!= rightCurley
)
846 errBuf
.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName
.c_str(),leftCurley
,rightCurley
);
847 OnError((char *)errBuf
.c_str());
859 bool ParseNewCommand(char *buffer
, int *pos
)
861 if ((strncmp((buffer
+(*pos
)), "newcommand", 10) == 0) ||
862 (strncmp((buffer
+(*pos
)), "renewcommand", 12) == 0))
864 if (strncmp((buffer
+(*pos
)), "newcommand", 10) == 0)
869 char commandName
[100];
870 char commandValue
[1000];
873 while (buffer
[*pos
] != '}' && (buffer
[*pos
] != 0))
875 commandName
[i
] = buffer
[*pos
];
882 if (buffer
[*pos
] == '[')
885 noArgs
= (int)(buffer
[*pos
]) - 48;
886 *pos
+= 2; // read past argument and '['
892 char ch
= buffer
[*pos
];
903 if (!read_a_line(buffer
))
908 commandValue
[i
] = ch
;
914 CustomMacro
*macro
= new CustomMacro(commandName
, noArgs
, NULL
);
915 if (strlen(commandValue
) > 0)
916 macro
->macroBody
= copystring(commandValue
);
917 if (!CustomMacroList
.Find(commandName
))
919 CustomMacroList
.Append(commandName
, macro
);
920 AddMacroDef(ltCUSTOM_MACRO
, commandName
, noArgs
);
927 void MacroError(char *buffer
)
934 while (((ch
= buffer
[i
-1]) != '\n') && (ch
!= 0))
943 errBuf
.Printf("Could not find macro: %s at line %d, file %s",
944 macroBuf
, (int)(LineNumbers
[CurrentInputIndex
]-1), FileNames
[CurrentInputIndex
]);
945 OnError((char *)errBuf
.c_str());
947 if (wxStrcmp(macroBuf
,"\\end{document}") == 0)
950 buf
= "Halted build due to unrecoverable error.";
951 OnInform((char *)buf
.c_str());
958 * 'environment' specifies the name of the macro IFF if we're looking for the end
959 * of an environment, e.g. \end{itemize}. Otherwise it's NULL.
960 * 'parseToBrace' is TRUE if the argument should extend to the next right brace,
961 * e.g. in {\bf an argument} as opposed to \vskip 30pt
964 int ParseArg(TexChunk
*thisArg
, wxList
& children
, char *buffer
, int pos
, char *environment
, bool parseToBrace
, TexChunk
*customMacroArgs
)
967 if (stopRunning
) return pos
;
976 // Consume leading brace or square bracket, but ONLY if not following
977 // a space, because this could be e.g. {\large {\bf thing}} where {\bf thing}
978 // is the argument of \large AS WELL as being a block in its
982 if ((pos > 0) && (buffer[pos-1] != ' ') && buffer[pos] == '{')
986 if ((pos > 0) && (buffer[pos-1] != ' ') && (buffer[pos] == '[' || buffer[pos] == '('))
991 else if ((pos > 1) && (buffer[pos-1] != ' ') && (buffer[pos+1] == '[' || buffer[pos+1] == '('))
999 // If not parsing to brace, just read the next word
1000 // (e.g. \vskip 20pt)
1003 int ch
= buffer
[pos
];
1004 while (!eof
&& ch
!= 13 && ch
!= 32 && ch
!= 10 &&
1005 ch
!= 0 && ch
!= '{')
1007 BigBuffer
[buf_ptr
] = ch
;
1014 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1015 BigBuffer
[buf_ptr
] = 0;
1017 chunk
->value
= copystring(BigBuffer
);
1018 children
.Append((wxObject
*)chunk
);
1025 len
= strlen(buffer
);
1028 if (customMacroArgs
) return 0;
1030 eof
= read_a_line(buffer
);
1032 len
= strlen(buffer
);
1033 // Check for verbatim (or toocomplex, which comes to the same thing)
1034 wxString bufStr
= buffer
;
1035 // if (bufStr.find("\\begin{verbatim}") != wxString::npos ||
1036 // bufStr.find("\\begin{toocomplex}") != wxString::npos)
1037 if (strncmp(buffer
, "\\begin{verbatim}", 16) == 0 ||
1038 strncmp(buffer
, "\\begin{toocomplex}", 18) == 0)
1042 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1043 BigBuffer
[buf_ptr
] = 0;
1045 chunk
->value
= copystring(BigBuffer
);
1046 children
.Append((wxObject
*)chunk
);
1051 eof
= read_a_line(buffer
);
1052 while (!eof
&& (strncmp(buffer
, "\\end{verbatim}", 14) != 0) &&
1053 (strncmp(buffer
, "\\end{toocomplex}", 16) != 0)
1056 strcat(BigBuffer
, buffer
);
1057 buf_ptr
+= strlen(buffer
);
1058 eof
= read_a_line(buffer
);
1060 eof
= read_a_line(buffer
);
1063 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, VerbatimMacroDef
);
1065 chunk
->macroId
= ltVERBATIM
;
1066 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, VerbatimMacroDef
);
1068 arg
->macroId
= ltVERBATIM
;
1069 TexChunk
*str
= new TexChunk(CHUNK_TYPE_STRING
);
1070 str
->value
= copystring(BigBuffer
);
1072 children
.Append((wxObject
*)chunk
);
1073 chunk
->children
.Append((wxObject
*)arg
);
1074 arg
->children
.Append((wxObject
*)str
);
1076 // Also want to include the following newline (is always a newline
1077 // after a verbatim): EXCEPT in HTML
1078 if (convertMode
!= TEX_HTML
)
1080 TexMacroDef
*parDef
= (TexMacroDef
*)MacroDefs
.Get("\\");
1081 TexChunk
*parChunk
= new TexChunk(CHUNK_TYPE_MACRO
, parDef
);
1082 parChunk
->no_args
= 0;
1083 parChunk
->macroId
= ltBACKSLASHCHAR
;
1084 children
.Append((wxObject
*)parChunk
);
1089 char ch
= buffer
[pos
];
1090 // End of optional argument -- pretend it's right brace for simplicity
1091 if (thisArg
->optional
&& (ch
== ']'))
1097 case '}': // End of argument
1101 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1102 BigBuffer
[buf_ptr
] = 0;
1104 chunk
->value
= copystring(BigBuffer
);
1105 children
.Append((wxObject
*)chunk
);
1107 if (ch
== '}') pos
++;
1113 if (buf_ptr
> 0) // Finish off the string we've read so far
1115 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1116 BigBuffer
[buf_ptr
] = 0;
1118 chunk
->value
= copystring(BigBuffer
);
1119 children
.Append((wxObject
*)chunk
);
1123 // Try matching \end{environment}
1124 if (environment
&& FindEndEnvironment(buffer
, &pos
, environment
))
1126 // Eliminate newline after an \end{} if possible
1127 if (buffer
[pos
] == 13)
1130 if (buffer
[pos
] == 10)
1136 if (ParseNewCommand(buffer
, &pos
))
1139 if (strncmp(buffer
+pos
, "special", 7) == 0)
1152 int ch
= buffer
[pos
];
1174 else if (ch
== '\\' && buffer
[pos
+1] == '}')
1180 else if (ch
== '\\' && buffer
[pos
+1] == '{')
1195 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1197 chunk
->macroId
= ltSPECIAL
;
1198 TexMacroDef
*specialDef
= (TexMacroDef
*)MacroDefs
.Get("special");
1199 chunk
->def
= specialDef
;
1200 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, specialDef
);
1201 chunk
->children
.Append((wxObject
*)arg
);
1203 arg
->macroId
= chunk
->macroId
;
1205 // The value in the first argument.
1206 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1207 arg
->children
.Append((wxObject
*)argValue
);
1209 argValue
->value
= copystring(wxBuffer
);
1211 children
.Append((wxObject
*)chunk
);
1213 else if (strncmp(buffer
+pos
, "verb", 4) == 0)
1216 if (buffer
[pos
] == '*')
1219 // Find the delimiter character
1220 int ch
= buffer
[pos
];
1222 // Now at start of verbatim text
1224 while ((buffer
[pos
] != ch
) && buffer
[pos
] != 0)
1226 char *val
= new char[pos
- j
+ 1];
1228 for (i
= j
; i
< pos
; i
++)
1230 val
[i
-j
] = buffer
[i
];
1236 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1238 chunk
->macroId
= ltVERB
;
1239 TexMacroDef
*verbDef
= (TexMacroDef
*)MacroDefs
.Get("verb");
1240 chunk
->def
= verbDef
;
1241 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, verbDef
);
1242 chunk
->children
.Append((wxObject
*)arg
);
1244 arg
->macroId
= chunk
->macroId
;
1246 // The value in the first argument.
1247 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1248 arg
->children
.Append((wxObject
*)argValue
);
1250 argValue
->value
= val
;
1252 children
.Append((wxObject
*)chunk
);
1257 bool tmpParseToBrace
= TRUE
;
1258 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1261 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1263 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1265 chunk
->no_args
= def
->no_args
;
1266 // chunk->name = copystring(def->name);
1267 chunk
->macroId
= def
->macroId
;
1270 children
.Append((wxObject
*)chunk
);
1272 // Eliminate newline after a \begin{} or a \\ if possible
1273 if (env
|| strcmp(def
->name
, "\\") == 0)
1274 if (buffer
[pos
] == 13)
1277 if (buffer
[pos
] == 10)
1281 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1282 buffer
, pos
, env
, tmpParseToBrace
, customMacroArgs
);
1284 // If custom macro, parse the body substituting the above found args.
1287 if (customMacro
->macroBody
)
1290 // strcpy(macroBuf, "{");
1291 strcpy(macroBuf
, customMacro
->macroBody
);
1292 strcat(macroBuf
, "}");
1293 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, TRUE
, chunk
);
1296 // delete chunk; // Might delete children
1301 MacroError(buffer
+pos
);
1306 // Parse constructs like {\bf thing} as if they were
1311 if (buffer
[pos
] == '\\')
1315 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1316 BigBuffer
[buf_ptr
] = 0;
1318 chunk
->value
= copystring(BigBuffer
);
1319 children
.Append((wxObject
*)chunk
);
1324 bool tmpParseToBrace
;
1325 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1328 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1330 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1331 chunk
->no_args
= def
->no_args
;
1332 // chunk->name = copystring(def->name);
1333 chunk
->macroId
= def
->macroId
;
1335 children
.Append((wxObject
*)chunk
);
1337 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1338 buffer
, pos
, NULL
, TRUE
, customMacroArgs
);
1340 // If custom macro, parse the body substituting the above found args.
1343 if (customMacro
->macroBody
)
1346 // strcpy(macroBuf, "{");
1347 strcpy(macroBuf
, customMacro
->macroBody
);
1348 strcat(macroBuf
, "}");
1349 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, TRUE
, chunk
);
1352 // delete chunk; // Might delete children
1357 MacroError(buffer
+pos
);
1363 * If all else fails, we assume that we have
1364 * a pair of braces on their own, so return a `dummy' macro
1365 * definition with just one argument to parse.
1369 SoloBlockDef
= new TexMacroDef(ltSOLO_BLOCK
, "solo block", 1, FALSE
);
1374 TexChunk
*chunk1
= new TexChunk(CHUNK_TYPE_STRING
);
1375 BigBuffer
[buf_ptr
] = 0;
1377 chunk1
->value
= copystring(BigBuffer
);
1378 children
.Append((wxObject
*)chunk1
);
1380 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, SoloBlockDef
);
1381 chunk
->no_args
= SoloBlockDef
->no_args
;
1382 // chunk->name = copystring(SoloBlockDef->name);
1383 chunk
->macroId
= SoloBlockDef
->macroId
;
1384 children
.Append((wxObject
*)chunk
);
1386 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, SoloBlockDef
);
1388 chunk
->children
.Append((wxObject
*)arg
);
1389 // arg->name = copystring(SoloBlockDef->name);
1391 arg
->macroId
= chunk
->macroId
;
1393 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, NULL
, TRUE
, customMacroArgs
);
1401 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1402 BigBuffer
[buf_ptr
] = 0;
1404 chunk
->value
= copystring(BigBuffer
);
1405 children
.Append((wxObject
*)chunk
);
1410 if (buffer
[pos
] == '$')
1412 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1414 // chunk->name = copystring("$$");
1415 chunk
->macroId
= ltSPECIALDOUBLEDOLLAR
;
1416 children
.Append((wxObject
*)chunk
);
1421 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1423 // chunk->name = copystring("_$");
1424 chunk
->macroId
= ltSPECIALDOLLAR
;
1425 children
.Append((wxObject
*)chunk
);
1433 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1434 BigBuffer
[buf_ptr
] = 0;
1436 chunk
->value
= copystring(BigBuffer
);
1437 children
.Append((wxObject
*)chunk
);
1441 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1443 // chunk->name = copystring("_~");
1444 chunk
->macroId
= ltSPECIALTILDE
;
1445 children
.Append((wxObject
*)chunk
);
1448 case '#': // Either treat as a special TeX character or as a macro arg
1452 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1453 BigBuffer
[buf_ptr
] = 0;
1455 chunk
->value
= copystring(BigBuffer
);
1456 children
.Append((wxObject
*)chunk
);
1460 if (!customMacroArgs
)
1462 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1464 // chunk->name = copystring("_#");
1465 chunk
->macroId
= ltSPECIALHASH
;
1466 children
.Append((wxObject
*)chunk
);
1470 if (isdigit(buffer
[pos
]))
1472 int n
= buffer
[pos
] - 48;
1474 wxNode
*node
= customMacroArgs
->children
.Nth(n
-1);
1477 TexChunk
*argChunk
= (TexChunk
*)node
->Data();
1478 children
.Append((wxObject
*)new TexChunk(*argChunk
));
1486 // Remove white space before and after the ampersand,
1487 // since this is probably a table column separator with
1488 // some convenient -- but useless -- white space in the text.
1489 while ((buf_ptr
> 0) && ((BigBuffer
[buf_ptr
-1] == ' ') || (BigBuffer
[buf_ptr
-1] == 9)))
1494 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1495 BigBuffer
[buf_ptr
] = 0;
1497 chunk
->value
= copystring(BigBuffer
);
1498 children
.Append((wxObject
*)chunk
);
1503 while (buffer
[pos
] == ' ' || buffer
[pos
] == 9)
1506 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1508 // chunk->name = copystring("_&");
1509 chunk
->macroId
= ltSPECIALAMPERSAND
;
1510 children
.Append((wxObject
*)chunk
);
1513 // Eliminate end-of-line comment
1517 while (ch
!= 10 && ch
!= 13 && ch
!= 0)
1522 if (buffer
[pos
] == 10 || buffer
[pos
] == 13)
1525 if (buffer
[pos
] == 10) pos
++; // Eliminate newline following DOS line feed
1532 BigBuffer
[buf_ptr
] = ' ';
1533 BigBuffer
[buf_ptr
+1] = 0;
1540 BigBuffer
[buf_ptr
] = ch
;
1541 BigBuffer
[buf_ptr
+1] = 0;
1552 * Consume as many arguments as the macro definition specifies
1556 int ParseMacroBody(const char *macro_name
, TexChunk
*parent
,
1557 int no_args
, char *buffer
, int pos
,
1558 char *environment
, bool parseToBrace
,
1559 TexChunk
*customMacroArgs
)
1562 if (stopRunning
) return pos
;
1564 // Check for a first optional argument
1565 if (buffer
[pos
] == ' ' && buffer
[pos
+1] == '[')
1567 // Fool following code into thinking that this is definitely
1568 // an optional first argument. (If a space before a non-first argument,
1569 // [ is interpreted as a [, not an optional argument.)
1575 if (buffer
[pos
] == '[')
1581 for (i
= 0; i
< no_args
; i
++)
1584 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, parent
->def
);
1586 parent
->children
.Append((wxObject
*)arg
);
1587 // arg->name = copystring(macro_name);
1588 arg
->argn
= maxArgs
;
1589 arg
->macroId
= parent
->macroId
;
1591 // To parse the first arg of a 2 arg \begin{thing}{arg} ... \end{thing}
1592 // have to fool parser into thinking this is a regular kind of block.
1594 if ((no_args
== 2) && (i
== 0))
1597 actualEnv
= environment
;
1599 bool isOptional
= FALSE
;
1601 // Remove the first { of the argument so it doesn't get recognized as { ... }
1602 // EatWhiteSpace(buffer, &pos);
1605 // The reason for these tests is to not consume braces that don't
1606 // belong to this macro.
1607 // E.g. {\bf {\small thing}}
1608 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && buffer
[pos
] == '{')
1611 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && (buffer
[pos
] == '['))
1616 else if ((pos
> 1) && (buffer
[pos
-1] != ' ') && (buffer
[pos
+1] == '['))
1624 wxString
tmpBuffer(buffer
);
1625 if (tmpBuffer
.length() > 4)
1627 if (tmpBuffer
.Right(4) == "\\par")
1628 tmpBuffer
= tmpBuffer
.Mid(0,tmpBuffer
.length()-4);
1630 errBuf
.Printf("Missing macro argument in the line:\n\t%s\n",tmpBuffer
.c_str());
1631 OnError((char *)errBuf
.c_str());
1635 arg
->optional
= isOptional
;
1637 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, actualEnv
, parseToBrace
, customMacroArgs
);
1639 // If we've encountered an OPTIONAL argument, go another time around
1640 // the loop, because we've got more than we thought.
1641 // Hopefully optional args don't occur at the end of a macro use
1642 // or we might miss it.
1643 // Don't increment no of times round loop if the first optional arg
1644 // -- we already did it before the loop.
1645 if (arg
->optional
&& (i
> 0))
1648 parent
->no_args
= maxArgs
;
1650 // Tell each argument how many args there are (useful when processing an arg)
1651 wxNode
*node
= parent
->children
.First();
1654 TexChunk
*chunk
= (TexChunk
*)node
->Data();
1655 chunk
->no_args
= maxArgs
;
1656 node
= node
->Next();
1661 bool TexLoadFile(char *filename
)
1663 static char *line_buffer
;
1664 stopRunning
= FALSE
;
1665 strcpy(TexFileRoot
, filename
);
1666 StripExtension(TexFileRoot
);
1667 sprintf(TexBibName
, "%s.bb", TexFileRoot
);
1668 sprintf(TexTmpBibName
, "%s.bb1", TexFileRoot
);
1670 TexPathList
.EnsureFileAccessible(filename
);
1675 line_buffer
= new char[MAX_LINE_BUFFER_SIZE
];
1677 Inputs
[0] = fopen(filename
, "r");
1679 FileNames
[0] = copystring(filename
);
1682 read_a_line(line_buffer
);
1683 ParseMacroBody("toplevel", TopLevel
, 1, line_buffer
, 0, NULL
, TRUE
);
1684 if (Inputs
[0]) fclose(Inputs
[0]);
1691 TexMacroDef::TexMacroDef(int the_id
, const char *the_name
, int n
, bool ig
, bool forbidLevel
)
1693 name
= copystring(the_name
);
1697 forbidden
= forbidLevel
;
1700 TexMacroDef::~TexMacroDef(void)
1702 if (name
) delete[] name
;
1705 TexChunk::TexChunk(int the_type
, TexMacroDef
*the_def
)
1717 TexChunk::TexChunk(TexChunk
& toCopy
)
1720 no_args
= toCopy
.no_args
;
1722 macroId
= toCopy
.macroId
;
1725 // name = copystring(toCopy.name);
1731 value
= copystring(toCopy
.value
);
1735 optional
= toCopy
.optional
;
1736 wxNode
*node
= toCopy
.children
.First();
1739 TexChunk
*child
= (TexChunk
*)node
->Data();
1740 children
.Append((wxObject
*)new TexChunk(*child
));
1741 node
= node
->Next();
1745 TexChunk::~TexChunk(void)
1747 // if (name) delete[] name;
1748 if (value
) delete[] value
;
1749 wxNode
*node
= children
.First();
1752 TexChunk
*child
= (TexChunk
*)node
->Data();
1754 wxNode
*next
= node
->Next();
1760 bool IsArgOptional(void) // Is this argument an optional argument?
1762 return isArgOptional
;
1765 int GetNoArgs(void) // Number of args for this macro
1770 /* Gets the text of a chunk on request (must be for small arguments
1775 void GetArgData1(TexChunk
*chunk
)
1777 switch (chunk
->type
)
1779 case CHUNK_TYPE_MACRO
:
1781 TexMacroDef
*def
= chunk
->def
;
1782 if (def
&& def
->ignore
)
1785 if (def
&& (strcmp(def
->name
, "solo block") != 0))
1787 strcat(currentArgData
, "\\");
1788 strcat(currentArgData
, def
->name
);
1791 wxNode
*node
= chunk
->children
.First();
1794 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
1795 strcat(currentArgData
, "{");
1796 GetArgData1(child_chunk
);
1797 strcat(currentArgData
, "}");
1798 node
= node
->Next();
1802 case CHUNK_TYPE_ARG
:
1804 wxNode
*node
= chunk
->children
.First();
1807 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
1808 GetArgData1(child_chunk
);
1809 node
= node
->Next();
1813 case CHUNK_TYPE_STRING
:
1816 strcat(currentArgData
, chunk
->value
);
1822 char *GetArgData(TexChunk
*chunk
)
1824 currentArgData
[0] = 0;
1825 GetArgData1(currentArgument
);
1826 haveArgData
= FALSE
;
1827 return currentArgData
;
1830 char *GetArgData(void)
1834 currentArgData
[0] = 0;
1835 GetArgData1(currentArgument
);
1837 return currentArgData
;
1840 TexChunk
*GetArgChunk(void)
1842 return currentArgument
;
1845 TexChunk
*GetNextChunk(void) // Look ahead to the next chunk
1850 TexChunk
*GetTopLevelChunk(void)
1855 int GetCurrentColumn(void)
1857 return currentColumn
;
1861 * Traverses document calling functions to allow the client to
1862 * write out the appropriate stuff
1866 void TraverseFromChunk(TexChunk
*chunk
, wxNode
*thisNode
, bool childrenOnly
)
1869 if (stopRunning
) return;
1871 switch (chunk
->type
)
1873 case CHUNK_TYPE_MACRO
:
1875 TexMacroDef
*def
= chunk
->def
;
1876 if (def
&& def
->ignore
)
1880 OnMacro(chunk
->macroId
, chunk
->no_args
, TRUE
);
1882 wxNode
*node
= chunk
->children
.First();
1883 TexChunk
*child_chunk
= NULL
;
1886 child_chunk
= (TexChunk
*)node
->Data();
1887 TraverseFromChunk(child_chunk
, node
);
1888 node
= node
->Next();
1891 if (thisNode
&& thisNode
->Next())
1892 nextChunk
= (TexChunk
*)thisNode
->Next()->Data();
1895 OnMacro(chunk
->macroId
, chunk
->no_args
, FALSE
);
1898 case CHUNK_TYPE_ARG
:
1900 currentArgument
= chunk
;
1902 isArgOptional
= chunk
->optional
;
1903 noArgs
= chunk
->no_args
;
1905 // If OnArgument returns FALSE, don't output.
1907 if (childrenOnly
|| OnArgument(chunk
->macroId
, chunk
->argn
, TRUE
))
1909 wxNode
*node
= chunk
->children
.First();
1912 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
1913 TraverseFromChunk(child_chunk
, node
);
1914 node
= node
->Next();
1918 currentArgument
= chunk
;
1920 if (thisNode
&& thisNode
->Next())
1921 nextChunk
= (TexChunk
*)thisNode
->Next()->Data();
1923 isArgOptional
= chunk
->optional
;
1924 noArgs
= chunk
->no_args
;
1927 (void)OnArgument(chunk
->macroId
, chunk
->argn
, FALSE
);
1930 case CHUNK_TYPE_STRING
:
1932 extern int issuedNewParagraph
;
1933 extern int forbidResetPar
;
1934 if (chunk
->value
&& (forbidResetPar
== 0))
1936 // If non-whitespace text, we no longer have a new paragraph.
1937 if (issuedNewParagraph
&& !((chunk
->value
[0] == 10 || chunk
->value
[0] == 13 || chunk
->value
[0] == 32)
1938 && chunk
->value
[1] == 0))
1940 issuedNewParagraph
= FALSE
;
1942 TexOutput(chunk
->value
, TRUE
);
1949 void TraverseDocument(void)
1951 TraverseFromChunk(TopLevel
, NULL
);
1954 void SetCurrentOutput(FILE *fd
)
1956 CurrentOutput1
= fd
;
1957 CurrentOutput2
= NULL
;
1960 void SetCurrentOutputs(FILE *fd1
, FILE *fd2
)
1962 CurrentOutput1
= fd1
;
1963 CurrentOutput2
= fd2
;
1966 void AddMacroDef(int the_id
, const char *name
, int n
, bool ignore
, bool forbid
)
1968 MacroDefs
.Put(name
, new TexMacroDef(the_id
, name
, n
, ignore
, forbid
));
1971 void TexInitialize(int bufSize
)
1973 InitialiseColourTable();
1975 TexPathList
.AddEnvList("TEXINPUT");
1978 TexPathList
.AddEnvList("TEXINPUTS");
1981 for (i
= 0; i
< 15; i
++)
1985 FileNames
[i
] = NULL
;
1988 IgnorableInputFiles
.Add("psbox.tex");
1989 BigBuffer
= new char[(bufSize
*1000)];
1990 currentArgData
= new char[2000];
1991 TexFileRoot
= new char[300];
1992 TexBibName
= new char[300];
1993 TexTmpBibName
= new char[300];
1994 AddMacroDef(ltTOPLEVEL
, "toplevel", 1);
1995 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
1996 // TopLevel->name = copystring("toplevel");
1997 TopLevel
->macroId
= ltTOPLEVEL
;
1998 TopLevel
->no_args
= 1;
1999 VerbatimMacroDef
= (TexMacroDef
*)MacroDefs
.Get("verbatim");
2002 void TexCleanUp(void)
2005 for (i
= 0; i
< 15; i
++)
2011 subsubsectionNo
= 0;
2014 CurrentOutput1
= NULL
;
2015 CurrentOutput2
= NULL
;
2016 CurrentInputIndex
= 0;
2017 haveArgData
= FALSE
;
2022 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
2023 // TopLevel->name = copystring("toplevel");
2024 TopLevel
->macroId
= ltTOPLEVEL
;
2025 TopLevel
->no_args
= 1;
2027 DocumentTitle
= NULL
;
2028 DocumentAuthor
= NULL
;
2029 DocumentDate
= NULL
;
2030 DocumentStyle
= LATEX_REPORT
;
2031 MinorDocumentStyle
= 0;
2032 BibliographyStyleString
= copystring("plain");
2033 DocumentStyleString
= copystring("report");
2034 MinorDocumentStyleString
= NULL
;
2036 // gt - Changed this so if this is the final pass
2037 // then we DO want to remove these macros, so that
2038 // memory is not MASSIVELY leaked if the user
2039 // does not exit the program, but instead runs
2040 // the program again
2041 if ((passNumber
== 1 && !runTwice
) ||
2042 (passNumber
== 2 && runTwice
))
2044 /* Don't want to remove custom macros after each pass.*/
2046 wxNode
*node
= CustomMacroList
.First();
2049 CustomMacro
*macro
= (CustomMacro
*)node
->Data();
2052 node
= CustomMacroList
.First();
2056 TexReferences
.BeginFind();
2057 wxNode
*node
= TexReferences
.Next();
2060 TexRef
*ref
= (TexRef
*)node
->Data();
2062 node
= TexReferences
.Next();
2064 TexReferences
.Clear();
2066 node
= BibList
.First();
2069 BibEntry
*entry
= (BibEntry
*)node
->Data();
2072 node
= BibList
.First();
2074 CitationList
.Clear();
2075 ResetTopicCounter();
2078 // There is likely to be one set of macros used by all utilities.
2079 void DefineDefaultMacros(void)
2081 // Put names which subsume other names at the TOP
2082 // so they get recognized first
2084 AddMacroDef(ltACCENT_GRAVE
, "`", 1);
2085 AddMacroDef(ltACCENT_ACUTE
, "'", 1);
2086 AddMacroDef(ltACCENT_CARET
, "^", 1);
2087 AddMacroDef(ltACCENT_UMLAUT
, "\"", 1);
2088 AddMacroDef(ltACCENT_TILDE
, "~", 1);
2089 AddMacroDef(ltACCENT_DOT
, ".", 1);
2090 AddMacroDef(ltACCENT_CADILLA
, "c", 1);
2091 AddMacroDef(ltSMALLSPACE1
, ",", 0);
2092 AddMacroDef(ltSMALLSPACE2
, ";", 0);
2094 AddMacroDef(ltABSTRACT
, "abstract", 1);
2095 AddMacroDef(ltADDCONTENTSLINE
, "addcontentsline", 3);
2096 AddMacroDef(ltADDTOCOUNTER
, "addtocounter", 2);
2097 AddMacroDef(ltALEPH
, "aleph", 0);
2098 AddMacroDef(ltALPHA
, "alpha", 0);
2099 AddMacroDef(ltALPH1
, "alph", 1);
2100 AddMacroDef(ltALPH2
, "Alph", 1);
2101 AddMacroDef(ltANGLE
, "angle", 0);
2102 AddMacroDef(ltAPPENDIX
, "appendix", 0);
2103 AddMacroDef(ltAPPROX
, "approx", 0);
2104 AddMacroDef(ltARABIC
, "arabic", 1);
2105 AddMacroDef(ltARRAY
, "array", 1);
2106 AddMacroDef(ltAST
, "ast", 0);
2107 AddMacroDef(ltASYMP
, "asymp", 0);
2108 AddMacroDef(ltAUTHOR
, "author", 1);
2110 AddMacroDef(ltBACKGROUNDCOLOUR
, "backgroundcolour", 1);
2111 AddMacroDef(ltBACKGROUNDIMAGE
, "backgroundimage", 1);
2112 AddMacroDef(ltBACKGROUND
, "background", 1);
2113 AddMacroDef(ltBACKSLASHRAW
, "backslashraw", 0);
2114 AddMacroDef(ltBACKSLASH
, "backslash", 0);
2115 AddMacroDef(ltBASELINESKIP
, "baselineskip", 1);
2116 AddMacroDef(ltBCOL
, "bcol", 2);
2117 AddMacroDef(ltBETA
, "beta", 0);
2118 AddMacroDef(ltBFSERIES
, "bfseries", 1);
2119 AddMacroDef(ltBF
, "bf", 1);
2120 AddMacroDef(ltBIBITEM
, "bibitem", 2); // For convenience, bibitem has 2 args: label and item.
2121 // The Latex syntax permits writing as 2 args.
2122 AddMacroDef(ltBIBLIOGRAPHYSTYLE
, "bibliographystyle", 1);
2123 AddMacroDef(ltBIBLIOGRAPHY
, "bibliography", 1);
2124 AddMacroDef(ltBIGTRIANGLEDOWN
, "bigtriangledown", 0);
2125 AddMacroDef(ltBOT
, "bot", 0);
2126 AddMacroDef(ltBOXIT
, "boxit", 1);
2127 AddMacroDef(ltBOX
, "box", 0);
2128 AddMacroDef(ltBRCLEAR
, "brclear", 0);
2129 AddMacroDef(ltBULLET
, "bullet", 0);
2131 AddMacroDef(ltCAPTIONSTAR
, "caption*", 1);
2132 AddMacroDef(ltCAPTION
, "caption", 1);
2133 AddMacroDef(ltCAP
, "cap", 0);
2134 AddMacroDef(ltCDOTS
, "cdots", 0);
2135 AddMacroDef(ltCDOT
, "cdot", 0);
2136 AddMacroDef(ltCENTERLINE
, "centerline", 1);
2137 AddMacroDef(ltCENTERING
, "centering", 0);
2138 AddMacroDef(ltCENTER
, "center", 1);
2139 AddMacroDef(ltCEXTRACT
, "cextract", 0);
2140 AddMacroDef(ltCHAPTERHEADING
, "chapterheading", 1);
2141 AddMacroDef(ltCHAPTERSTAR
, "chapter*", 1);
2142 AddMacroDef(ltCHAPTER
, "chapter", 1);
2143 AddMacroDef(ltCHI
, "chi", 0);
2144 AddMacroDef(ltCINSERT
, "cinsert", 0);
2145 AddMacroDef(ltCIRC
, "circ", 0);
2146 AddMacroDef(ltCITE
, "cite", 1);
2147 AddMacroDef(ltCLASS
, "class", 1);
2148 AddMacroDef(ltCLEARDOUBLEPAGE
, "cleardoublepage", 0);
2149 AddMacroDef(ltCLEARPAGE
, "clearpage", 0);
2150 AddMacroDef(ltCLINE
, "cline", 1);
2151 AddMacroDef(ltCLIPSFUNC
, "clipsfunc", 3);
2152 AddMacroDef(ltCLUBSUIT
, "clubsuit", 0);
2153 AddMacroDef(ltCOLUMNSEP
, "columnsep", 1);
2154 AddMacroDef(ltCOMMENT
, "comment", 1, TRUE
);
2155 AddMacroDef(ltCONG
, "cong", 0);
2156 AddMacroDef(ltCOPYRIGHT
, "copyright", 0);
2157 AddMacroDef(ltCPARAM
, "cparam", 2);
2158 AddMacroDef(ltCHEAD
, "chead", 1);
2159 AddMacroDef(ltCFOOT
, "cfoot", 1);
2160 AddMacroDef(ltCUP
, "cup", 0);
2162 AddMacroDef(ltDASHV
, "dashv", 0);
2163 AddMacroDef(ltDATE
, "date", 1);
2164 AddMacroDef(ltDELTA
, "delta", 0);
2165 AddMacroDef(ltCAP_DELTA
, "Delta", 0);
2166 AddMacroDef(ltDEFINECOLOUR
, "definecolour", 4);
2167 AddMacroDef(ltDEFINECOLOR
, "definecolor", 4);
2168 AddMacroDef(ltDESCRIPTION
, "description", 1);
2169 AddMacroDef(ltDESTRUCT
, "destruct", 1);
2170 AddMacroDef(ltDIAMOND2
, "diamond2", 0);
2171 AddMacroDef(ltDIAMOND
, "diamond", 0);
2172 AddMacroDef(ltDIV
, "div", 0);
2173 AddMacroDef(ltDOCUMENTCLASS
, "documentclass", 1);
2174 AddMacroDef(ltDOCUMENTSTYLE
, "documentstyle", 1);
2175 AddMacroDef(ltDOCUMENT
, "document", 1);
2176 AddMacroDef(ltDOUBLESPACE
, "doublespace", 1);
2177 AddMacroDef(ltDOTEQ
, "doteq", 0);
2178 AddMacroDef(ltDOWNARROW
, "downarrow", 0);
2179 AddMacroDef(ltDOWNARROW2
, "Downarrow", 0);
2181 AddMacroDef(ltEMPTYSET
, "emptyset", 0);
2182 AddMacroDef(ltEMPH
, "emph", 1);
2183 AddMacroDef(ltEM
, "em", 1);
2184 AddMacroDef(ltENUMERATE
, "enumerate", 1);
2185 AddMacroDef(ltEPSILON
, "epsilon", 0);
2186 AddMacroDef(ltEQUATION
, "equation", 1);
2187 AddMacroDef(ltEQUIV
, "equiv", 0);
2188 AddMacroDef(ltETA
, "eta", 0);
2189 AddMacroDef(ltEVENSIDEMARGIN
, "evensidemargin", 1);
2190 AddMacroDef(ltEXISTS
, "exists", 0);
2192 AddMacroDef(ltFBOX
, "fbox", 1);
2193 AddMacroDef(ltFCOL
, "fcol", 2);
2194 AddMacroDef(ltFIGURE
, "figure", 1);
2195 AddMacroDef(ltFIGURESTAR
, "figure*", 1);
2196 AddMacroDef(ltFLUSHLEFT
, "flushleft", 1);
2197 AddMacroDef(ltFLUSHRIGHT
, "flushright", 1);
2198 AddMacroDef(ltFOLLOWEDLINKCOLOUR
, "followedlinkcolour", 1);
2199 AddMacroDef(ltFOOTHEIGHT
, "footheight", 1);
2200 AddMacroDef(ltFOOTNOTEPOPUP
, "footnotepopup", 2);
2201 AddMacroDef(ltFOOTNOTE
, "footnote", 1);
2202 AddMacroDef(ltFOOTSKIP
, "footskip", 1);
2203 AddMacroDef(ltFORALL
, "forall", 0);
2204 AddMacroDef(ltFRAMEBOX
, "framebox", 1);
2205 AddMacroDef(ltFROWN
, "frown", 0);
2206 AddMacroDef(ltFUNCTIONSECTION
, "functionsection", 1);
2207 AddMacroDef(ltFUNC
, "func", 3);
2208 AddMacroDef(ltFOOTNOTESIZE
, "footnotesize", 0);
2209 AddMacroDef(ltFANCYPLAIN
, "fancyplain", 2);
2211 AddMacroDef(ltGAMMA
, "gamma", 0);
2212 AddMacroDef(ltCAP_GAMMA
, "Gamma", 0);
2213 AddMacroDef(ltGEQ
, "geq", 0);
2214 AddMacroDef(ltGE
, "ge", 0);
2215 AddMacroDef(ltGG
, "gg", 0);
2216 AddMacroDef(ltGLOSSARY
, "glossary", 1);
2217 AddMacroDef(ltGLOSS
, "gloss", 1);
2219 AddMacroDef(ltHEADHEIGHT
, "headheight", 1);
2220 AddMacroDef(ltHEARTSUIT
, "heartsuit", 0);
2221 AddMacroDef(ltHELPGLOSSARY
, "helpglossary", 1);
2222 AddMacroDef(ltHELPIGNORE
, "helpignore", 1, TRUE
);
2223 AddMacroDef(ltHELPONLY
, "helponly", 1);
2224 AddMacroDef(ltHELPINPUT
, "helpinput", 1);
2225 AddMacroDef(ltHELPFONTFAMILY
, "helpfontfamily", 1);
2226 AddMacroDef(ltHELPFONTSIZE
, "helpfontsize", 1);
2227 AddMacroDef(ltHELPREFN
, "helprefn", 2);
2228 AddMacroDef(ltHELPREF
, "helpref", 2);
2229 AddMacroDef(ltHFILL
, "hfill", 0);
2230 AddMacroDef(ltHLINE
, "hline", 0);
2231 AddMacroDef(ltHRULE
, "hrule", 0);
2232 AddMacroDef(ltHSPACESTAR
, "hspace*", 1);
2233 AddMacroDef(ltHSPACE
, "hspace", 1);
2234 AddMacroDef(ltHSKIPSTAR
, "hskip*", 1);
2235 AddMacroDef(ltHSKIP
, "hskip", 1);
2236 AddMacroDef(lthuge
, "huge", 1);
2237 AddMacroDef(ltHuge
, "Huge", 1);
2238 AddMacroDef(ltHUGE
, "HUGE", 1);
2239 AddMacroDef(ltHTMLIGNORE
, "htmlignore", 1);
2240 AddMacroDef(ltHTMLONLY
, "htmlonly", 1);
2242 AddMacroDef(ltIM
, "im", 0);
2243 AddMacroDef(ltINCLUDEONLY
, "includeonly", 1);
2244 AddMacroDef(ltINCLUDE
, "include", 1);
2245 AddMacroDef(ltINDENTED
, "indented", 2);
2246 AddMacroDef(ltINDEX
, "index", 1);
2247 AddMacroDef(ltINPUT
, "input", 1, TRUE
);
2248 AddMacroDef(ltIOTA
, "iota", 0);
2249 AddMacroDef(ltITEMIZE
, "itemize", 1);
2250 AddMacroDef(ltITEM
, "item", 0);
2251 AddMacroDef(ltIMAGEMAP
, "imagemap", 3);
2252 AddMacroDef(ltIMAGEL
, "imagel", 2);
2253 AddMacroDef(ltIMAGER
, "imager", 2);
2254 AddMacroDef(ltIMAGE
, "image", 2);
2255 AddMacroDef(ltIN
, "in", 0);
2256 AddMacroDef(ltINFTY
, "infty", 0);
2257 AddMacroDef(ltITSHAPE
, "itshape", 1);
2258 AddMacroDef(ltIT
, "it", 1);
2259 AddMacroDef(ltITEMSEP
, "itemsep", 1);
2260 AddMacroDef(ltINSERTATLEVEL
, "insertatlevel", 2);
2262 AddMacroDef(ltKAPPA
, "kappa", 0);
2263 AddMacroDef(ltKILL
, "kill", 0);
2265 AddMacroDef(ltLABEL
, "label", 1);
2266 AddMacroDef(ltLAMBDA
, "lambda", 0);
2267 AddMacroDef(ltCAP_LAMBDA
, "Lambda", 0);
2268 AddMacroDef(ltlarge
, "large", 1);
2269 AddMacroDef(ltLarge
, "Large", 1);
2270 AddMacroDef(ltLARGE
, "LARGE", 1);
2271 AddMacroDef(ltLATEXIGNORE
, "latexignore", 1);
2272 AddMacroDef(ltLATEXONLY
, "latexonly", 1);
2273 AddMacroDef(ltLATEX
, "LaTeX", 0);
2274 AddMacroDef(ltLBOX
, "lbox", 1);
2275 AddMacroDef(ltLBRACERAW
, "lbraceraw", 0);
2276 AddMacroDef(ltLDOTS
, "ldots", 0);
2277 AddMacroDef(ltLEQ
, "leq", 0);
2278 AddMacroDef(ltLE
, "le", 0);
2279 AddMacroDef(ltLEFTARROW
, "leftarrow", 0);
2280 AddMacroDef(ltLEFTRIGHTARROW
, "leftrightarrow", 0);
2281 AddMacroDef(ltLEFTARROW2
, "Leftarrow", 0);
2282 AddMacroDef(ltLEFTRIGHTARROW2
, "Leftrightarrow", 0);
2283 AddMacroDef(ltLINEBREAK
, "linebreak", 0);
2284 AddMacroDef(ltLINKCOLOUR
, "linkcolour", 1);
2285 AddMacroDef(ltLISTOFFIGURES
, "listoffigures", 0);
2286 AddMacroDef(ltLISTOFTABLES
, "listoftables", 0);
2287 AddMacroDef(ltLHEAD
, "lhead", 1);
2288 AddMacroDef(ltLFOOT
, "lfoot", 1);
2289 AddMacroDef(ltLOWERCASE
, "lowercase", 1);
2290 AddMacroDef(ltLL
, "ll", 0);
2292 AddMacroDef(ltMAKEGLOSSARY
, "makeglossary", 0);
2293 AddMacroDef(ltMAKEINDEX
, "makeindex", 0);
2294 AddMacroDef(ltMAKETITLE
, "maketitle", 0);
2295 AddMacroDef(ltMARKRIGHT
, "markright", 1);
2296 AddMacroDef(ltMARKBOTH
, "markboth", 2);
2297 AddMacroDef(ltMARGINPARWIDTH
, "marginparwidth", 1);
2298 AddMacroDef(ltMARGINPARSEP
, "marginparsep", 1);
2299 AddMacroDef(ltMARGINPARODD
, "marginparodd", 1);
2300 AddMacroDef(ltMARGINPAREVEN
, "marginpareven", 1);
2301 AddMacroDef(ltMARGINPAR
, "marginpar", 1);
2302 AddMacroDef(ltMBOX
, "mbox", 1);
2303 AddMacroDef(ltMDSERIES
, "mdseries", 1);
2304 AddMacroDef(ltMEMBERSECTION
, "membersection", 1);
2305 AddMacroDef(ltMEMBER
, "member", 2);
2306 AddMacroDef(ltMID
, "mid", 0);
2307 AddMacroDef(ltMODELS
, "models", 0);
2308 AddMacroDef(ltMP
, "mp", 0);
2309 AddMacroDef(ltMULTICOLUMN
, "multicolumn", 3);
2310 AddMacroDef(ltMU
, "mu", 0);
2312 AddMacroDef(ltNABLA
, "nabla", 0);
2313 AddMacroDef(ltNEG
, "neg", 0);
2314 AddMacroDef(ltNEQ
, "neq", 0);
2315 AddMacroDef(ltNEWCOUNTER
, "newcounter", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2316 AddMacroDef(ltNEWLINE
, "newline", 0);
2317 AddMacroDef(ltNEWPAGE
, "newpage", 0);
2318 AddMacroDef(ltNI
, "ni", 0);
2319 AddMacroDef(ltNOCITE
, "nocite", 1);
2320 AddMacroDef(ltNOINDENT
, "noindent", 0);
2321 AddMacroDef(ltNOLINEBREAK
, "nolinebreak", 0);
2322 AddMacroDef(ltNOPAGEBREAK
, "nopagebreak", 0);
2323 AddMacroDef(ltNORMALSIZE
, "normalsize", 1);
2324 AddMacroDef(ltNORMALBOX
, "normalbox", 1);
2325 AddMacroDef(ltNORMALBOXD
, "normalboxd", 1);
2326 AddMacroDef(ltNOTEQ
, "noteq", 0);
2327 AddMacroDef(ltNOTIN
, "notin", 0);
2328 AddMacroDef(ltNOTSUBSET
, "notsubset", 0);
2329 AddMacroDef(ltNU
, "nu", 0);
2331 AddMacroDef(ltODDSIDEMARGIN
, "oddsidemargin", 1);
2332 AddMacroDef(ltOMEGA
, "omega", 0);
2333 AddMacroDef(ltCAP_OMEGA
, "Omega", 0);
2334 AddMacroDef(ltONECOLUMN
, "onecolumn", 0);
2335 AddMacroDef(ltOPLUS
, "oplus", 0);
2336 AddMacroDef(ltOSLASH
, "oslash", 0);
2337 AddMacroDef(ltOTIMES
, "otimes", 0);
2339 AddMacroDef(ltPAGEBREAK
, "pagebreak", 0);
2340 AddMacroDef(ltPAGEREF
, "pageref", 1);
2341 AddMacroDef(ltPAGESTYLE
, "pagestyle", 1);
2342 AddMacroDef(ltPAGENUMBERING
, "pagenumbering", 1);
2343 AddMacroDef(ltPARAGRAPHSTAR
, "paragraph*", 1);
2344 AddMacroDef(ltPARAGRAPH
, "paragraph", 1);
2345 AddMacroDef(ltPARALLEL
, "parallel", 0);
2346 AddMacroDef(ltPARAM
, "param", 2);
2347 AddMacroDef(ltPARINDENT
, "parindent", 1);
2348 AddMacroDef(ltPARSKIP
, "parskip", 1);
2349 AddMacroDef(ltPARTIAL
, "partial", 0);
2350 AddMacroDef(ltPARTSTAR
, "part*", 1);
2351 AddMacroDef(ltPART
, "part", 1);
2352 AddMacroDef(ltPAR
, "par", 0);
2353 AddMacroDef(ltPERP
, "perp", 0);
2354 AddMacroDef(ltPHI
, "phi", 0);
2355 AddMacroDef(ltCAP_PHI
, "Phi", 0);
2356 AddMacroDef(ltPFUNC
, "pfunc", 3);
2357 AddMacroDef(ltPICTURE
, "picture", 1);
2358 AddMacroDef(ltPI
, "pi", 0);
2359 AddMacroDef(ltCAP_PI
, "Pi", 0);
2360 AddMacroDef(ltPM
, "pm", 0);
2361 AddMacroDef(ltPOPREFONLY
, "poprefonly", 1);
2362 AddMacroDef(ltPOPREF
, "popref", 2);
2363 AddMacroDef(ltPOUNDS
, "pounds", 0);
2364 AddMacroDef(ltPREC
, "prec", 0);
2365 AddMacroDef(ltPRECEQ
, "preceq", 0);
2366 AddMacroDef(ltPRINTINDEX
, "printindex", 0);
2367 AddMacroDef(ltPROPTO
, "propto", 0);
2368 AddMacroDef(ltPSBOXTO
, "psboxto", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2369 AddMacroDef(ltPSBOX
, "psbox", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2370 AddMacroDef(ltPSI
, "psi", 0);
2371 AddMacroDef(ltCAP_PSI
, "Psi", 0);
2373 AddMacroDef(ltQUOTE
, "quote", 1);
2374 AddMacroDef(ltQUOTATION
, "quotation", 1);
2376 AddMacroDef(ltRAGGEDBOTTOM
, "raggedbottom", 0);
2377 AddMacroDef(ltRAGGEDLEFT
, "raggedleft", 0);
2378 AddMacroDef(ltRAGGEDRIGHT
, "raggedright", 0);
2379 AddMacroDef(ltRBRACERAW
, "rbraceraw", 0);
2380 AddMacroDef(ltREF
, "ref", 1);
2381 AddMacroDef(ltREGISTERED
, "registered", 0);
2382 AddMacroDef(ltRE
, "we", 0);
2383 AddMacroDef(ltRHO
, "rho", 0);
2384 AddMacroDef(ltRIGHTARROW
, "rightarrow", 0);
2385 AddMacroDef(ltRIGHTARROW2
, "rightarrow2", 0);
2386 AddMacroDef(ltRMFAMILY
, "rmfamily", 1);
2387 AddMacroDef(ltRM
, "rm", 1);
2388 AddMacroDef(ltROMAN
, "roman", 1);
2389 AddMacroDef(ltROMAN2
, "Roman", 1);
2390 // AddMacroDef(lt"row", 1);
2391 AddMacroDef(ltRTFSP
, "rtfsp", 0);
2392 AddMacroDef(ltRTFIGNORE
, "rtfignore", 1);
2393 AddMacroDef(ltRTFONLY
, "rtfonly", 1);
2394 AddMacroDef(ltRULEDROW
, "ruledrow", 1);
2395 AddMacroDef(ltDRULED
, "druled", 1);
2396 AddMacroDef(ltRULE
, "rule", 2);
2397 AddMacroDef(ltRHEAD
, "rhead", 1);
2398 AddMacroDef(ltRFOOT
, "rfoot", 1);
2399 AddMacroDef(ltROW
, "row", 1);
2401 AddMacroDef(ltSCSHAPE
, "scshape", 1);
2402 AddMacroDef(ltSC
, "sc", 1);
2403 AddMacroDef(ltSECTIONHEADING
, "sectionheading", 1);
2404 AddMacroDef(ltSECTIONSTAR
, "section*", 1);
2405 AddMacroDef(ltSECTION
, "section", 1);
2406 AddMacroDef(ltSETCOUNTER
, "setcounter", 2);
2407 AddMacroDef(ltSFFAMILY
, "sffamily", 1);
2408 AddMacroDef(ltSF
, "sf", 1);
2409 AddMacroDef(ltSHARP
, "sharp", 0);
2410 AddMacroDef(ltSHORTCITE
, "shortcite", 1);
2411 AddMacroDef(ltSIGMA
, "sigma", 0);
2412 AddMacroDef(ltCAP_SIGMA
, "Sigma", 0);
2413 AddMacroDef(ltSIM
, "sim", 0);
2414 AddMacroDef(ltSIMEQ
, "simeq", 0);
2415 AddMacroDef(ltSINGLESPACE
, "singlespace", 1);
2416 AddMacroDef(ltSIZEDBOX
, "sizedbox", 2);
2417 AddMacroDef(ltSIZEDBOXD
, "sizedboxd", 2);
2418 AddMacroDef(ltSLOPPYPAR
, "sloppypar", 1);
2419 AddMacroDef(ltSLOPPY
, "sloppy", 0);
2420 AddMacroDef(ltSLSHAPE
, "slshape", 1);
2421 AddMacroDef(ltSL
, "sl", 1);
2422 AddMacroDef(ltSMALL
, "small", 1);
2423 AddMacroDef(ltSMILE
, "smile", 0);
2424 AddMacroDef(ltSS
, "ss", 0);
2425 AddMacroDef(ltSTAR
, "star", 0);
2426 AddMacroDef(ltSUBITEM
, "subitem", 0);
2427 AddMacroDef(ltSUBPARAGRAPHSTAR
, "subparagraph*", 1);
2428 AddMacroDef(ltSUBPARAGRAPH
, "subparagraph", 1);
2429 AddMacroDef(ltSPECIAL
, "special", 1);
2430 AddMacroDef(ltSUBSECTIONSTAR
, "subsection*", 1);
2431 AddMacroDef(ltSUBSECTION
, "subsection", 1);
2432 AddMacroDef(ltSUBSETEQ
, "subseteq", 0);
2433 AddMacroDef(ltSUBSET
, "subset", 0);
2434 AddMacroDef(ltSUCC
, "succ", 0);
2435 AddMacroDef(ltSUCCEQ
, "succeq", 0);
2436 AddMacroDef(ltSUPSETEQ
, "supseteq", 0);
2437 AddMacroDef(ltSUPSET
, "supset", 0);
2438 AddMacroDef(ltSUBSUBSECTIONSTAR
,"subsubsection*", 1);
2439 AddMacroDef(ltSUBSUBSECTION
, "subsubsection", 1);
2440 AddMacroDef(ltSUPERTABULAR
, "supertabular", 2, FALSE
);
2441 AddMacroDef(ltSURD
, "surd", 0);
2442 AddMacroDef(ltSCRIPTSIZE
, "scriptsize", 1);
2443 AddMacroDef(ltSETHEADER
, "setheader", 6);
2444 AddMacroDef(ltSETFOOTER
, "setfooter", 6);
2445 AddMacroDef(ltSETHOTSPOTCOLOUR
, "sethotspotcolour", 1);
2446 AddMacroDef(ltSETHOTSPOTCOLOR
, "sethotspotcolor", 1);
2447 AddMacroDef(ltSETHOTSPOTUNDERLINE
, "sethotspotunderline", 1);
2448 AddMacroDef(ltSETTRANSPARENCY
, "settransparency", 1);
2449 AddMacroDef(ltSPADESUIT
, "spadesuit", 0);
2451 AddMacroDef(ltTABBING
, "tabbing", 2);
2452 AddMacroDef(ltTABLEOFCONTENTS
, "tableofcontents", 0);
2453 AddMacroDef(ltTABLE
, "table", 1);
2454 AddMacroDef(ltTABULAR
, "tabular", 2, FALSE
);
2455 AddMacroDef(ltTAB
, "tab", 0);
2456 AddMacroDef(ltTAU
, "tau", 0);
2457 AddMacroDef(ltTEXTRM
, "textrm", 1);
2458 AddMacroDef(ltTEXTSF
, "textsf", 1);
2459 AddMacroDef(ltTEXTTT
, "texttt", 1);
2460 AddMacroDef(ltTEXTBF
, "textbf", 1);
2461 AddMacroDef(ltTEXTIT
, "textit", 1);
2462 AddMacroDef(ltTEXTSL
, "textsl", 1);
2463 AddMacroDef(ltTEXTSC
, "textsc", 1);
2464 AddMacroDef(ltTEXTWIDTH
, "textwidth", 1);
2465 AddMacroDef(ltTEXTHEIGHT
, "textheight", 1);
2466 AddMacroDef(ltTEXTCOLOUR
, "textcolour", 1);
2467 AddMacroDef(ltTEX
, "TeX", 0);
2468 AddMacroDef(ltTHEBIBLIOGRAPHY
, "thebibliography", 2);
2469 AddMacroDef(ltTHETA
, "theta", 0);
2470 AddMacroDef(ltTIMES
, "times", 0);
2471 AddMacroDef(ltCAP_THETA
, "Theta", 0);
2472 AddMacroDef(ltTITLEPAGE
, "titlepage", 1);
2473 AddMacroDef(ltTITLE
, "title", 1);
2474 AddMacroDef(ltTINY
, "tiny", 1);
2475 AddMacroDef(ltTODAY
, "today", 0);
2476 AddMacroDef(ltTOPMARGIN
, "topmargin", 1);
2477 AddMacroDef(ltTOPSKIP
, "topskip", 1);
2478 AddMacroDef(ltTRIANGLE
, "triangle", 0);
2479 AddMacroDef(ltTTFAMILY
, "ttfamily", 1);
2480 AddMacroDef(ltTT
, "tt", 1);
2481 AddMacroDef(ltTYPEIN
, "typein", 1);
2482 AddMacroDef(ltTYPEOUT
, "typeout", 1);
2483 AddMacroDef(ltTWOCOLWIDTHA
, "twocolwidtha", 1);
2484 AddMacroDef(ltTWOCOLWIDTHB
, "twocolwidthb", 1);
2485 AddMacroDef(ltTWOCOLSPACING
, "twocolspacing", 1);
2486 AddMacroDef(ltTWOCOLITEMRULED
, "twocolitemruled", 2);
2487 AddMacroDef(ltTWOCOLITEM
, "twocolitem", 2);
2488 AddMacroDef(ltTWOCOLLIST
, "twocollist", 1);
2489 AddMacroDef(ltTWOCOLUMN
, "twocolumn", 0);
2490 AddMacroDef(ltTHEPAGE
, "thepage", 0);
2491 AddMacroDef(ltTHECHAPTER
, "thechapter", 0);
2492 AddMacroDef(ltTHESECTION
, "thesection", 0);
2493 AddMacroDef(ltTHISPAGESTYLE
, "thispagestyle", 1);
2495 AddMacroDef(ltUNDERLINE
, "underline", 1);
2496 AddMacroDef(ltUPSILON
, "upsilon", 0);
2497 AddMacroDef(ltCAP_UPSILON
, "Upsilon", 0);
2498 AddMacroDef(ltUPARROW
, "uparrow", 0);
2499 AddMacroDef(ltUPARROW2
, "Uparrow", 0);
2500 AddMacroDef(ltUPPERCASE
, "uppercase", 1);
2501 AddMacroDef(ltUPSHAPE
, "upshape", 1);
2502 AddMacroDef(ltURLREF
, "urlref", 2);
2503 AddMacroDef(ltUSEPACKAGE
, "usepackage", 1);
2505 AddMacroDef(ltVAREPSILON
, "varepsilon", 0);
2506 AddMacroDef(ltVARPHI
, "varphi", 0);
2507 AddMacroDef(ltVARPI
, "varpi", 0);
2508 AddMacroDef(ltVARRHO
, "varrho", 0);
2509 AddMacroDef(ltVARSIGMA
, "varsigma", 0);
2510 AddMacroDef(ltVARTHETA
, "vartheta", 0);
2511 AddMacroDef(ltVDOTS
, "vdots", 0);
2512 AddMacroDef(ltVEE
, "vee", 0);
2513 AddMacroDef(ltVERBATIMINPUT
, "verbatiminput", 1);
2514 AddMacroDef(ltVERBATIM
, "verbatim", 1);
2515 AddMacroDef(ltVERBSTAR
, "verb*", 1);
2516 AddMacroDef(ltVERB
, "verb", 1);
2517 AddMacroDef(ltVERSE
, "verse", 1);
2518 AddMacroDef(ltVFILL
, "vfill", 0);
2519 AddMacroDef(ltVLINE
, "vline", 0);
2520 AddMacroDef(ltVOID
, "void", 0);
2521 AddMacroDef(ltVDASH
, "vdash", 0);
2522 AddMacroDef(ltVRULE
, "vrule", 0);
2523 AddMacroDef(ltVSPACESTAR
, "vspace*", 1);
2524 AddMacroDef(ltVSKIPSTAR
, "vskip*", 1);
2525 AddMacroDef(ltVSPACE
, "vspace", 1);
2526 AddMacroDef(ltVSKIP
, "vskip", 1);
2528 AddMacroDef(ltWEDGE
, "wedge", 0);
2529 AddMacroDef(ltWXCLIPS
, "wxclips", 0);
2530 AddMacroDef(ltWINHELPIGNORE
, "winhelpignore", 1);
2531 AddMacroDef(ltWINHELPONLY
, "winhelponly", 1);
2532 AddMacroDef(ltWP
, "wp", 0);
2534 AddMacroDef(ltXI
, "xi", 0);
2535 AddMacroDef(ltCAP_XI
, "Xi", 0);
2536 AddMacroDef(ltXLPIGNORE
, "xlpignore", 1);
2537 AddMacroDef(ltXLPONLY
, "xlponly", 1);
2539 AddMacroDef(ltZETA
, "zeta", 0);
2541 AddMacroDef(ltSPACE
, " ", 0);
2542 AddMacroDef(ltBACKSLASHCHAR
, "\\", 0);
2543 AddMacroDef(ltPIPE
, "|", 0);
2544 AddMacroDef(ltFORWARDSLASH
, "/", 0);
2545 AddMacroDef(ltUNDERSCORE
, "_", 0);
2546 AddMacroDef(ltAMPERSAND
, "&", 0);
2547 AddMacroDef(ltPERCENT
, "%", 0);
2548 AddMacroDef(ltDOLLAR
, "$", 0);
2549 AddMacroDef(ltHASH
, "#", 0);
2550 AddMacroDef(ltLPARENTH
, "(", 0);
2551 AddMacroDef(ltRPARENTH
, ")", 0);
2552 AddMacroDef(ltLBRACE
, "{", 0);
2553 AddMacroDef(ltRBRACE
, "}", 0);
2554 // AddMacroDef(ltEQUALS, "=", 0);
2555 AddMacroDef(ltRANGLEBRA
, ">", 0);
2556 AddMacroDef(ltLANGLEBRA
, "<", 0);
2557 AddMacroDef(ltPLUS
, "+", 0);
2558 AddMacroDef(ltDASH
, "-", 0);
2559 AddMacroDef(ltAT_SYMBOL
, "@", 0);
2560 // AddMacroDef(ltSINGLEQUOTE, "'", 0);
2561 // AddMacroDef(ltBACKQUOTE, "`", 0);
2565 * Default behaviour, should be called by client if can't match locally.
2569 // Called on start/end of macro examination
2570 void DefaultOnMacro(int macroId
, int no_args
, bool start
)
2574 // Default behaviour for abstract
2579 // Write the heading
2580 FakeCurrentSection(AbstractNameString
);
2581 OnMacro(ltPAR
, 0, TRUE
);
2582 OnMacro(ltPAR
, 0, FALSE
);
2586 if (DocumentStyle
== LATEX_ARTICLE
)
2594 // Default behaviour for glossary
2595 case ltHELPGLOSSARY
:
2599 // Write the heading
2600 FakeCurrentSection(GlossaryNameString
);
2601 OnMacro(ltPAR
, 0, TRUE
);
2602 OnMacro(ltPAR
, 0, FALSE
);
2603 if ((convertMode
== TEX_RTF
) && !winHelp
)
2605 OnMacro(ltPAR
, 0, TRUE
);
2606 OnMacro(ltPAR
, 0, FALSE
);
2611 case ltSPECIALAMPERSAND
:
2618 TexOutput("<<", TRUE
);
2622 TexOutput(">>", TRUE
);
2626 TexOutput("~", TRUE
);
2630 TexOutput("~", TRUE
);
2632 case ltSPECIALTILDE
:
2634 TexOutput(" ", TRUE
);
2638 TexOutput("_", TRUE
);
2642 TexOutput("#", TRUE
);
2646 TexOutput("&", TRUE
);
2650 TexOutput(" ", TRUE
);
2654 TexOutput("|", TRUE
);
2658 TexOutput("%", TRUE
);
2662 TexOutput("$", TRUE
);
2666 TexOutput("", TRUE
);
2670 TexOutput("", TRUE
);
2674 TexOutput("{", TRUE
);
2678 TexOutput("}", TRUE
);
2682 TexOutput("(c)", TRUE
);
2686 TexOutput("(r)", TRUE
);
2690 TexOutput("\\", TRUE
);
2695 TexOutput("...", TRUE
);
2699 TexOutput("|", TRUE
);
2703 TexOutput("LaTeX", TRUE
);
2707 TexOutput("TeX", TRUE
);
2711 TexOutput("£", TRUE
);
2713 case ltSPECIALDOUBLEDOLLAR
: // Interpret as center
2714 OnMacro(ltCENTER
, no_args
, start
);
2720 OnMacro(ltIT
, no_args
, start
);
2723 case ltPARAGRAPHSTAR
:
2724 case ltSUBPARAGRAPH
:
2725 case ltSUBPARAGRAPHSTAR
:
2726 OnMacro(ltSUBSUBSECTION
, no_args
, start
);
2734 TexOutput(ctime(&when
), TRUE
);
2745 if (start
) TexOutput("alpha");
2748 if (start
) TexOutput("beta");
2751 if (start
) TexOutput("gamma");
2754 if (start
) TexOutput("delta");
2758 if (start
) TexOutput("epsilon");
2761 if (start
) TexOutput("zeta");
2764 if (start
) TexOutput("eta");
2768 if (start
) TexOutput("theta");
2771 if (start
) TexOutput("iota");
2774 if (start
) TexOutput("kappa");
2777 if (start
) TexOutput("lambda");
2780 if (start
) TexOutput("mu");
2783 if (start
) TexOutput("nu");
2786 if (start
) TexOutput("xi");
2790 if (start
) TexOutput("pi");
2794 if (start
) TexOutput("rho");
2798 if (start
) TexOutput("sigma");
2801 if (start
) TexOutput("tau");
2804 if (start
) TexOutput("upsilon");
2808 if (start
) TexOutput("phi");
2811 if (start
) TexOutput("chi");
2814 if (start
) TexOutput("psi");
2817 if (start
) TexOutput("omega");
2820 if (start
) TexOutput("GAMMA");
2823 if (start
) TexOutput("DELTA");
2826 if (start
) TexOutput("THETA");
2829 if (start
) TexOutput("LAMBDA");
2832 if (start
) TexOutput("XI");
2835 if (start
) TexOutput("PI");
2838 if (start
) TexOutput("SIGMA");
2841 if (start
) TexOutput("UPSILON");
2844 if (start
) TexOutput("PHI");
2847 if (start
) TexOutput("PSI");
2850 if (start
) TexOutput("OMEGA");
2853 // Binary operation symbols
2856 if (start
) TexOutput("<=");
2859 if (start
) TexOutput("<<");
2862 if (start
) TexOutput("SUBSET");
2865 if (start
) TexOutput("SUBSETEQ");
2868 if (start
) TexOutput("IN");
2871 if (start
) TexOutput("VDASH");
2874 if (start
) TexOutput("MODELS");
2878 if (start
) TexOutput(">=");
2881 if (start
) TexOutput(">>");
2884 if (start
) TexOutput("SUPSET");
2887 if (start
) TexOutput("SUPSETEQ");
2890 if (start
) TexOutput("NI");
2893 if (start
) TexOutput("DASHV");
2896 if (start
) TexOutput("PERP");
2899 if (start
) TexOutput("NEQ");
2902 if (start
) TexOutput("DOTEQ");
2905 if (start
) TexOutput("APPROX");
2908 if (start
) TexOutput("CONG");
2911 if (start
) TexOutput("EQUIV");
2914 if (start
) TexOutput("PROPTO");
2917 if (start
) TexOutput("PREC");
2920 if (start
) TexOutput("PRECEQ");
2923 if (start
) TexOutput("|");
2926 if (start
) TexOutput("~");
2929 if (start
) TexOutput("SIMEQ");
2932 if (start
) TexOutput("ASYMP");
2935 if (start
) TexOutput(":-)");
2938 if (start
) TexOutput(":-(");
2941 if (start
) TexOutput("SUCC");
2944 if (start
) TexOutput("SUCCEQ");
2947 if (start
) TexOutput("|");
2950 // Negated relation symbols
2952 if (start
) TexOutput("!=");
2955 if (start
) TexOutput("NOTIN");
2958 if (start
) TexOutput("NOTSUBSET");
2963 if (start
) TexOutput("<--");
2966 if (start
) TexOutput("<==");
2969 if (start
) TexOutput("-->");
2972 if (start
) TexOutput("==>");
2974 case ltLEFTRIGHTARROW
:
2975 if (start
) TexOutput("<-->");
2977 case ltLEFTRIGHTARROW2
:
2978 if (start
) TexOutput("<==>");
2981 if (start
) TexOutput("UPARROW");
2984 if (start
) TexOutput("UPARROW2");
2987 if (start
) TexOutput("DOWNARROW");
2990 if (start
) TexOutput("DOWNARROW2");
2992 // Miscellaneous symbols
2994 if (start
) TexOutput("ALEPH");
2997 if (start
) TexOutput("WP");
3000 if (start
) TexOutput("RE");
3003 if (start
) TexOutput("IM");
3006 if (start
) TexOutput("EMPTYSET");
3009 if (start
) TexOutput("NABLA");
3012 if (start
) TexOutput("SURD");
3015 if (start
) TexOutput("PARTIAL");
3018 if (start
) TexOutput("BOT");
3021 if (start
) TexOutput("FORALL");
3024 if (start
) TexOutput("EXISTS");
3027 if (start
) TexOutput("NEG");
3030 if (start
) TexOutput("SHARP");
3033 if (start
) TexOutput("ANGLE");
3036 if (start
) TexOutput("TRIANGLE");
3039 if (start
) TexOutput("CLUBSUIT");
3042 if (start
) TexOutput("DIAMONDSUIT");
3045 if (start
) TexOutput("HEARTSUIT");
3048 if (start
) TexOutput("SPADESUIT");
3051 if (start
) TexOutput("INFTY");
3054 if (start
) TexOutput("PM");
3057 if (start
) TexOutput("MP");
3060 if (start
) TexOutput("TIMES");
3063 if (start
) TexOutput("DIV");
3066 if (start
) TexOutput("CDOT");
3069 if (start
) TexOutput("AST");
3072 if (start
) TexOutput("STAR");
3075 if (start
) TexOutput("CAP");
3078 if (start
) TexOutput("CUP");
3081 if (start
) TexOutput("VEE");
3084 if (start
) TexOutput("WEDGE");
3087 if (start
) TexOutput("CIRC");
3090 if (start
) TexOutput("BULLET");
3093 if (start
) TexOutput("DIAMOND");
3096 if (start
) TexOutput("OSLASH");
3099 if (start
) TexOutput("BOX");
3102 if (start
) TexOutput("DIAMOND2");
3104 case ltBIGTRIANGLEDOWN
:
3105 if (start
) TexOutput("BIGTRIANGLEDOWN");
3108 if (start
) TexOutput("OPLUS");
3111 if (start
) TexOutput("OTIMES");
3114 if (start
) TexOutput("s");
3116 case ltBACKSLASHRAW
:
3117 if (start
) TexOutput("\\");
3120 if (start
) TexOutput("{");
3123 if (start
) TexOutput("}");
3127 if (start
) TexOutput(" ");
3134 // Called on start/end of argument examination
3135 bool DefaultOnArgument(int macroId
, int arg_no
, bool start
)
3141 if (arg_no
== 1 && start
)
3143 char *refName
= GetArgData();
3146 TexRef
*texRef
= FindReference(refName
);
3149 // Must strip the 'section' or 'chapter' or 'figure' text
3150 // from a normal 'ref' reference
3152 strcpy(buf
, texRef
->sectionNumber
);
3153 int len
= strlen(buf
);
3155 if (strcmp(buf
, "??") != 0)
3167 TexOutput(texRef
->sectionNumber
+ i
, TRUE
);
3172 informBuf
.Printf("Warning: unresolved reference '%s'", refName
);
3173 OnInform((char *)informBuf
.c_str());
3176 else TexOutput("??", TRUE
);
3188 if (start
&& (arg_no
== 1))
3189 DocumentAuthor
= GetArgChunk();
3195 if (start
&& (arg_no
== 1))
3196 DocumentDate
= GetArgChunk();
3202 if (start
&& (arg_no
== 1))
3203 DocumentTitle
= GetArgChunk();
3207 case ltDOCUMENTCLASS
:
3208 case ltDOCUMENTSTYLE
:
3210 if (start
&& !IsArgOptional())
3212 DocumentStyleString
= copystring(GetArgData());
3213 if (strncmp(DocumentStyleString
, "art", 3) == 0)
3214 DocumentStyle
= LATEX_ARTICLE
;
3215 else if (strncmp(DocumentStyleString
, "rep", 3) == 0)
3216 DocumentStyle
= LATEX_REPORT
;
3217 else if (strncmp(DocumentStyleString
, "book", 4) == 0 ||
3218 strncmp(DocumentStyleString
, "thesis", 6) == 0)
3219 DocumentStyle
= LATEX_BOOK
;
3220 else if (strncmp(DocumentStyleString
, "letter", 6) == 0)
3221 DocumentStyle
= LATEX_LETTER
;
3222 else if (strncmp(DocumentStyleString
, "slides", 6) == 0)
3223 DocumentStyle
= LATEX_SLIDES
;
3225 if (StringMatch("10", DocumentStyleString
))
3227 else if (StringMatch("11", DocumentStyleString
))
3229 else if (StringMatch("12", DocumentStyleString
))
3232 OnMacro(ltHELPFONTSIZE
, 1, TRUE
);
3233 sprintf(currentArgData
, "%d", normalFont
);
3235 OnArgument(ltHELPFONTSIZE
, 1, TRUE
);
3236 OnArgument(ltHELPFONTSIZE
, 1, FALSE
);
3237 haveArgData
= FALSE
;
3238 OnMacro(ltHELPFONTSIZE
, 1, FALSE
);
3240 else if (start
&& IsArgOptional())
3242 MinorDocumentStyleString
= copystring(GetArgData());
3244 if (StringMatch("10", MinorDocumentStyleString
))
3246 else if (StringMatch("11", MinorDocumentStyleString
))
3248 else if (StringMatch("12", MinorDocumentStyleString
))
3254 case ltBIBLIOGRAPHYSTYLE
:
3256 if (start
&& !IsArgOptional())
3257 BibliographyStyleString
= copystring(GetArgData());
3263 if (start
&& !IsArgOptional())
3265 if (PageStyle
) delete[] PageStyle
;
3266 PageStyle
= copystring(GetArgData());
3274 if (start && !IsArgOptional())
3275 LeftHeader = GetArgChunk();
3281 if (start && !IsArgOptional())
3282 LeftFooter = GetArgChunk();
3288 if (start && !IsArgOptional())
3289 CentreHeader = GetArgChunk();
3295 if (start && !IsArgOptional())
3296 CentreFooter = GetArgChunk();
3302 if (start && !IsArgOptional())
3303 RightHeader = GetArgChunk();
3309 if (start && !IsArgOptional())
3310 RightFooter = GetArgChunk();
3318 if (start
&& !IsArgOptional())
3320 char *citeKeys
= GetArgData();
3322 char *citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3325 AddCitation(citeKey
);
3326 TexRef
*ref
= FindReference(citeKey
);
3329 TexOutput(ref
->sectionNumber
, TRUE
);
3330 if (strcmp(ref
->sectionNumber
, "??") == 0)
3333 informBuf
.Printf("Warning: unresolved citation %s.", citeKey
);
3334 OnInform((char *)informBuf
.c_str());
3337 citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3340 TexOutput(", ", TRUE
);
3349 if (start
&& !IsArgOptional())
3351 char *citeKey
= GetArgData();
3352 AddCitation(citeKey
);
3357 case ltHELPFONTSIZE
:
3361 char *data
= GetArgData();
3362 if (strcmp(data
, "10") == 0)
3364 else if (strcmp(data
, "11") == 0)
3366 else if (strcmp(data
, "12") == 0)
3376 TexOutput(" ??", TRUE
);
3383 if (start
&& arg_no
== 1)
3385 char *data
= GetArgData();
3386 ParSkip
= ParseUnitArgument(data
);
3393 if (start
&& arg_no
== 1)
3395 char *data
= GetArgData();
3396 ParIndent
= ParseUnitArgument(data
);
3403 return OnArgument(ltIT
, arg_no
, start
);
3406 case ltSPECIALDOUBLEDOLLAR
:
3408 return OnArgument(ltCENTER
, arg_no
, start
);
3412 case ltPARAGRAPHSTAR
:
3413 case ltSUBPARAGRAPH
:
3414 case ltSUBPARAGRAPHSTAR
:
3416 return OnArgument(ltSUBSUBSECTION
, arg_no
, start
);
3422 OnInform(GetArgData());
3428 TexOutput(" (", TRUE
);
3430 TexOutput(")", TRUE
);
3433 case ltBIBLIOGRAPHY
:
3441 if ((fd
= fopen(TexBibName
, "r")))
3447 TexOutput(smallBuf
);
3455 OnInform("Run Tex2RTF again to include bibliography.");
3458 // Read in the .bib file, resolve all known references, write out the RTF.
3459 char *allFiles
= GetArgData();
3461 char *bibFile
= ParseMultifieldString(allFiles
, &pos
);
3465 strcpy(fileBuf
, bibFile
);
3466 wxString actualFile
= TexPathList
.FindValidPath(fileBuf
);
3467 if (actualFile
== "")
3469 strcat(fileBuf
, ".bib");
3470 actualFile
= TexPathList
.FindValidPath(fileBuf
);
3472 if (actualFile
!= "")
3474 if (!ReadBib((char*) (const char*) actualFile
))
3477 errBuf
.Printf(".bib file %s not found or malformed", (const char*) actualFile
);
3478 OnError((char *)errBuf
.c_str());
3484 errBuf
.Printf(".bib file %s not found", fileBuf
);
3485 OnError((char *)errBuf
.c_str());
3487 bibFile
= ParseMultifieldString(allFiles
, &pos
);
3490 ResolveBibReferences();
3492 // Write it a new bib section in the appropriate format.
3493 FILE *save1
= CurrentOutput1
;
3494 FILE *save2
= CurrentOutput2
;
3495 FILE *Biblio
= fopen(TexTmpBibName
, "w");
3496 SetCurrentOutput(Biblio
);
3499 if (wxFileExists(TexTmpBibName
))
3501 if (wxFileExists(TexBibName
)) wxRemoveFile(TexBibName
);
3502 wxRenameFile(TexTmpBibName
, TexBibName
);
3504 SetCurrentOutputs(save1
, save2
);
3511 if (start
&& (arg_no
== 3))
3521 if (start
&& (arg_no
== 1))
3523 char *s
= GetArgData();
3526 char *s1
= copystring(s
);
3528 for (i
= 0; i
< (int)strlen(s
); i
++)
3529 s1
[i
] = toupper(s
[i
]);
3542 if (start
&& (arg_no
== 1))
3544 char *s
= GetArgData();
3547 char *s1
= copystring(s
);
3549 for (i
= 0; i
< (int)strlen(s
); i
++)
3550 s1
[i
] = tolower(s
[i
]);
3563 if (start
&& (arg_no
== 1))
3565 char *s
= GetArgData();
3568 char *s1
= copystring(s
);
3570 for (i
= 0; i
< (int)strlen(s
); i
++)
3571 s1
[i
] = toupper(s
[i
]);
3582 case ltPOPREF
: // Ignore second argument by default
3584 if (start
&& (arg_no
== 1))
3594 return ((convertMode
== TEX_XLP
) ? FALSE
: TRUE
);
3597 return ((convertMode
!= TEX_XLP
) ? FALSE
: TRUE
);
3600 return ((convertMode
== TEX_HTML
) ? FALSE
: TRUE
);
3603 return ((convertMode
!= TEX_HTML
) ? FALSE
: TRUE
);
3606 return (((convertMode
== TEX_RTF
) && !winHelp
) ? FALSE
: TRUE
);
3609 return (!((convertMode
== TEX_RTF
) && !winHelp
) ? FALSE
: TRUE
);
3611 case ltWINHELPIGNORE
:
3612 return (winHelp
? FALSE
: TRUE
);
3615 return (!winHelp
? FALSE
: TRUE
);
3630 case ltADDTOCOUNTER
:
3631 case ltADDCONTENTSLINE
:
3635 case ltBASELINESKIP
:
3644 case ltPAGENUMBERING
:
3656 case ltTHISPAGESTYLE
:
3659 case ltEVENSIDEMARGIN
:
3660 case ltODDSIDEMARGIN
:
3662 case ltMARGINPARWIDTH
:
3663 case ltMARGINPARSEP
:
3664 case ltMARGINPAREVEN
:
3665 case ltMARGINPARODD
:
3666 case ltTWOCOLWIDTHA
:
3667 case ltTWOCOLWIDTHB
:
3668 case ltTWOCOLSPACING
:
3675 case ltSETHOTSPOTCOLOUR
:
3676 case ltSETHOTSPOTCOLOR
:
3677 case ltSETHOTSPOTUNDERLINE
:
3678 case ltSETTRANSPARENCY
:
3681 case ltBACKGROUNDCOLOUR
:
3682 case ltBACKGROUNDIMAGE
:
3684 case ltFOLLOWEDLINKCOLOUR
:
3691 case ltINSERTATLEVEL
:
3695 case ltSUPERTABULAR
:
3704 if (arg_no
== 2) return TRUE
;
3711 if (arg_no
== 2) return TRUE
;
3715 case ltDEFINECOLOUR
:
3718 static int redVal
= 0;
3719 static int greenVal
= 0;
3720 static int blueVal
= 0;
3721 static char *colourName
= NULL
;
3728 if (colourName
) delete[] colourName
;
3729 colourName
= copystring(GetArgData());
3734 redVal
= atoi(GetArgData());
3739 greenVal
= atoi(GetArgData());
3744 blueVal
= atoi(GetArgData());
3745 AddColour(colourName
, redVal
, greenVal
, blueVal
);
3761 if (IsArgOptional())