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
;
148 char *htmlFaceName
= copystring("Times New Roman");
150 extern int passNumber
;
152 extern wxHashTable TexReferences
;
155 * International support
158 // Names to help with internationalisation
159 char *ContentsNameString
= copystring("Contents");
160 char *AbstractNameString
= copystring("Abstract");
161 char *GlossaryNameString
= copystring("Glossary");
162 char *ReferencesNameString
= copystring("References");
163 char *FiguresNameString
= copystring("List of Figures");
164 char *TablesNameString
= copystring("List of Tables");
165 char *FigureNameString
= copystring("Figure");
166 char *TableNameString
= copystring("Table");
167 char *IndexNameString
= copystring("Index");
168 char *ChapterNameString
= copystring("chapter");
169 char *SectionNameString
= copystring("section");
170 char *SubsectionNameString
= copystring("subsection");
171 char *SubsubsectionNameString
= copystring("subsubsection");
172 char *UpNameString
= copystring("Up");
181 int subsectionNo
= 0;
182 int subsubsectionNo
= 0;
191 FILE *CurrentOutput1
= NULL
;
192 FILE *CurrentOutput2
= NULL
;
196 int CurrentInputIndex
= 0;
198 char *TexFileRoot
= NULL
;
199 char *TexBibName
= NULL
; // Bibliography output file name
200 char *TexTmpBibName
= NULL
; // Temporary bibliography output file name
201 bool isSync
= FALSE
; // If TRUE, should not yield to other processes.
202 bool stopRunning
= FALSE
; // If TRUE, should abort.
204 static int currentColumn
= 0;
205 char *currentArgData
= NULL
;
206 bool haveArgData
= FALSE
; // If TRUE, we're simulating the data.
207 TexChunk
*currentArgument
= NULL
;
208 TexChunk
*nextChunk
= NULL
;
209 bool isArgOptional
= FALSE
;
212 TexChunk
*TopLevel
= NULL
;
213 // wxList MacroDefs(wxKEY_STRING);
214 wxHashTable
MacroDefs(wxKEY_STRING
);
215 wxStringList IgnorableInputFiles
; // Ignorable \input files, e.g. psbox.tex
216 char *BigBuffer
= NULL
; // For reading in large chunks of text
217 TexMacroDef
*SoloBlockDef
= NULL
;
218 TexMacroDef
*VerbatimMacroDef
= NULL
;
220 #define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
223 TexRef::TexRef(const char *label
, const char *file
,
224 const char *section
, const char *sectionN
)
226 refLabel
= copystring(label
);
227 refFile
= file
? copystring(file
) : (char*) NULL
;
228 sectionNumber
= section
? copystring(section
) : copystring("??");
229 sectionName
= sectionN
? copystring(sectionN
) : copystring("??");
232 TexRef::~TexRef(void)
234 delete [] refLabel
; refLabel
= NULL
;
235 delete [] refFile
; refFile
= NULL
;
236 delete [] sectionNumber
; sectionNumber
= NULL
;
237 delete [] sectionName
; sectionName
= NULL
;
241 CustomMacro::~CustomMacro()
249 void TexOutput(const char *s
, bool ordinaryText
)
253 // Update current column, but only if we're guaranteed to
254 // be ordinary text (not mark-up stuff)
257 for (i
= 0; i
< len
; i
++)
259 if (s
[i
] == 13 || s
[i
] == 10)
266 fprintf(CurrentOutput1
, "%s", s
);
268 fprintf(CurrentOutput2
, "%s", s
);
272 * Try to find a Latex macro, in one of the following forms:
273 * (1) \begin{} ... \end{}
274 * (2) \macroname{arg1}...{argn}
278 void ForbidWarning(TexMacroDef
*def
)
281 switch (def
->forbidden
)
285 informBuf
.Printf("Warning: it is recommended that command %s is not used.", def
->name
);
286 OnInform((char *)informBuf
.c_str());
289 case FORBID_ABSOLUTELY
:
291 informBuf
.Printf("Error: command %s cannot be used and will lead to errors.", def
->name
);
292 OnInform((char *)informBuf
.c_str());
300 TexMacroDef
*MatchMacro(char *buffer
, int *pos
, char **env
, bool *parseToBrace
)
302 *parseToBrace
= TRUE
;
304 TexMacroDef
*def
= NULL
;
307 // First, try to find begin{thing}
308 if (strncmp(buffer
+i
, "begin{", 6) == 0)
313 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
315 macroBuf
[j
-i
] = buffer
[j
];
319 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
323 *pos
= j
+ 1; // BUGBUG Should this be + 1???
331 // Failed, so try to find macro from definition list
334 // First try getting a one-character macro, but ONLY
335 // if these TWO characters are not both alphabetical (could
336 // be a longer macro)
337 if (!(isalpha(buffer
[i
]) && isalpha(buffer
[i
+1])))
339 macroBuf
[0] = buffer
[i
];
342 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
348 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
350 macroBuf
[j
-i
] = buffer
[j
];
354 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
361 // We want to check whether this is a space-consuming macro
363 // No brace, e.g. \input thing.tex instead of \input{thing};
364 // or a numeric argument, such as \parindent0pt
365 if ((def
->no_args
> 0) && ((buffer
[i
] == 32) || (buffer
[i
] == '=') || (isdigit(buffer
[i
]))))
367 if ((buffer
[i
] == 32) || (buffer
[i
] == '='))
370 *parseToBrace
= FALSE
;
379 void EatWhiteSpace(char *buffer
, int *pos
)
381 int len
= strlen(buffer
);
383 bool keepGoing
= TRUE
;
384 bool moreLines
= TRUE
;
385 while ((j
< len
) && keepGoing
&&
386 (buffer
[j
] == 10 || buffer
[j
] == 13 || buffer
[j
] == ' ' || buffer
[j
] == 9))
393 moreLines
= read_a_line(buffer
);
394 len
= strlen(buffer
);
404 bool FindEndEnvironment(char *buffer
, int *pos
, char *env
)
408 // Try to find end{thing}
409 if ((strncmp(buffer
+i
, "end{", 4) == 0) &&
410 (strncmp(buffer
+i
+4, env
, strlen(env
)) == 0))
412 *pos
= i
+ 5 + strlen(env
);
418 bool readingVerbatim
= FALSE
;
419 bool readInVerbatim
= FALSE
; // Within a verbatim, but not nec. verbatiminput
421 // Switched this off because e.g. \verb${$ causes it to fail. There is no
422 // detection of \verb yet.
423 // #define CHECK_BRACES 1
425 unsigned long leftCurley
= 0;
426 unsigned long rightCurley
= 0;
427 static wxString currentFileName
= "";
429 bool read_a_line(char *buf
)
431 if (CurrentInputIndex
< 0)
441 while (ch
!= EOF
&& ch
!= 10)
443 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
446 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
447 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
448 OnError((char *)errBuf
.c_str());
452 if (((bufIndex
== 14) && (strncmp(buf
, "\\end{verbatim}", 14) == 0)) ||
453 ((bufIndex
== 16) && (strncmp(buf
, "\\end{toocomplex}", 16) == 0)))
454 readInVerbatim
= FALSE
;
456 ch
= getc(Inputs
[CurrentInputIndex
]);
458 if (checkCurleyBraces
)
460 if (ch
== '{' && !readInVerbatim
)
462 if (ch
== '}' && !readInVerbatim
)
465 if (rightCurley
> leftCurley
)
468 errBuf
.Printf("An extra right Curley brace ('}') was detected at line %lu inside file %s",LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str());
469 OnError((char *)errBuf
.c_str());
471 // Reduce the count of right Curley braces, so the mismatched count
472 // isn't reported on every line that has a '}' after the first mismatch
480 // Check for 2 consecutive newlines and replace with \par
481 if (ch
== 10 && !readInVerbatim
)
483 int ch1
= getc(Inputs
[CurrentInputIndex
]);
484 if ((ch1
== 10) || (ch1
== 13))
486 // Eliminate newline (10) following DOS linefeed
488 ch1
= getc(Inputs
[CurrentInputIndex
]);
490 IncrementLineNumber();
491 // strcat(buf, "\\par\n");
493 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
496 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
497 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
498 OnError((char *)errBuf
.c_str());
501 strcat(buf
, "\\par");
507 ungetc(ch1
, Inputs
[CurrentInputIndex
]);
508 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
511 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
512 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
513 OnError((char *)errBuf
.c_str());
524 // Convert embedded characters to RTF equivalents
533 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
536 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
537 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
538 OnError((char *)errBuf
.c_str());
541 buf
[bufIndex
++]='\\';
546 case 0xf6:buf
[bufIndex
++]='o';break; // ö
547 case 0xe4:buf
[bufIndex
++]='a';break; // ä
548 case 0xfc:buf
[bufIndex
++]='u';break; // ü
549 case 0xd6:buf
[bufIndex
++]='O';break; // Ö
550 case 0xc4:buf
[bufIndex
++]='A';break; // Ä
551 case 0xdc:buf
[bufIndex
++]='U';break; // Ü
556 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
559 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
560 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
561 OnError((char *)errBuf
.c_str());
564 buf
[bufIndex
++]='\\';
567 buf
[bufIndex
++]='\\';
571 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
574 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
575 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
576 OnError((char *)errBuf
.c_str());
579 // If the current character read in is a '_', we need to check
580 // whether there should be a '\' before it or not
583 buf
[bufIndex
++] = ch
;
591 // There should NOT be a '\' before the '_'
592 if ((bufIndex
> 0 && (buf
[bufIndex
-1] == '\\')) && (buf
[0] != '%'))
595 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());
596 OnError((char *)errBuf
.c_str());
601 // There should be a '\' before the '_'
605 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());
606 OnError((char *)errBuf
.c_str());
608 else if ((buf
[bufIndex
-1] != '\\') && (buf
[0] != '%') && // If it is a comment line, then no warnings
609 (strncmp(buf
, "\\input", 6))) // do not report filenames that have underscores in them
612 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());
613 OnError((char *)errBuf
.c_str());
617 buf
[bufIndex
++] = ch
;
625 fclose(Inputs
[CurrentInputIndex
]);
626 Inputs
[CurrentInputIndex
] = NULL
;
627 if (CurrentInputIndex
> 0)
628 ch
= ' '; // No real end of file
629 CurrentInputIndex
--;
631 if (checkCurleyBraces
)
633 if (leftCurley
!= rightCurley
)
636 errBuf
.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName
.c_str(),leftCurley
,rightCurley
);
637 OnError((char *)errBuf
.c_str());
645 readingVerbatim
= FALSE
;
646 readInVerbatim
= FALSE
;
647 strcat(buf
, "\\end{verbatim}\n");
652 IncrementLineNumber();
656 // Strip out comment environment
657 if (strncmp(buf
, "\\begin{comment}", 15) == 0)
659 while (strncmp(buf
, "\\end{comment}", 13) != 0)
661 return read_a_line(buf
);
663 // Read a verbatim input file as if it were a verbatim environment
664 else if (strncmp(buf
, "\\verbatiminput", 14) == 0)
667 char *fileName
= buf
+ wordLen
+ 1;
669 int j
= bufIndex
- 1;
672 // thing}\par -- eliminate the \par!
673 if (strncmp((buf
+ strlen(buf
)-5), "\\par", 4) == 0)
680 buf
[j
-1] = 0; // Ignore final brace
682 wxString actualFile
= TexPathList
.FindValidPath(fileName
);
683 currentFileName
= actualFile
;
684 if (actualFile
== "")
687 errBuf
.Printf("Could not find file: %s",fileName
);
688 OnError((char *)errBuf
.c_str());
693 informStr
.Printf("Processing: %s",actualFile
.c_str());
694 OnInform((char *)informStr
.c_str());
695 CurrentInputIndex
++;
697 Inputs
[CurrentInputIndex
] = fopen(actualFile
, "r");
698 LineNumbers
[CurrentInputIndex
] = 1;
699 if (FileNames
[CurrentInputIndex
])
700 delete[] FileNames
[CurrentInputIndex
];
701 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
703 if (!Inputs
[CurrentInputIndex
])
705 CurrentInputIndex
--;
706 OnError("Could not open verbatiminput file.");
710 readingVerbatim
= TRUE
;
711 readInVerbatim
= TRUE
;
712 strcpy(buf
, "\\begin{verbatim}\n");
718 else if (strncmp(buf
, "\\input", 6) == 0 || strncmp(buf
, "\\helpinput", 10) == 0 ||
719 strncmp(buf
, "\\include", 8) == 0)
722 if (strncmp(buf
, "\\input", 6) == 0)
725 if (strncmp(buf
, "\\include", 8) == 0)
730 char *fileName
= buf
+ wordLen
+ 1;
732 int j
= bufIndex
- 1;
735 // \input{thing}\par -- eliminate the \par!
736 // if (strncmp((buf + strlen(buf)-5), "\\par", 4) == 0)
737 if (strncmp((buf
+ strlen(buf
)-4), "\\par", 4) == 0) // Bug fix 8/2/95 Ulrich Leodolter
745 buf
[j
-1] = 0; // Ignore final brace
747 // Remove backslashes from name
748 wxString
fileNameStr(fileName
);
749 fileNameStr
.Replace("\\", "");
751 // Ignore some types of input files (e.g. macro definition files)
752 char *fileOnly
= FileNameFromPath((char*) (const char*) fileNameStr
);
753 currentFileName
= fileOnly
;
754 if (IgnorableInputFiles
.Member(fileOnly
))
755 return read_a_line(buf
);
757 wxString actualFile
= TexPathList
.FindValidPath(fileNameStr
);
758 if (actualFile
== "")
761 sprintf(buf2
, "%s.tex", (const char*) fileNameStr
);
762 actualFile
= TexPathList
.FindValidPath(buf2
);
764 currentFileName
= actualFile
;
766 if (actualFile
== "")
769 errBuf
.Printf("Could not find file: %s",fileName
);
770 OnError((char *)errBuf
.c_str());
774 // Ensure that if this file includes another,
775 // then we look in the same directory as this one.
776 TexPathList
.EnsureFileAccessible(actualFile
);
779 informStr
.Printf("Processing: %s",actualFile
.c_str());
780 OnInform((char *)informStr
.c_str());
781 CurrentInputIndex
++;
783 Inputs
[CurrentInputIndex
] = fopen(actualFile
, "r");
784 LineNumbers
[CurrentInputIndex
] = 1;
785 if (FileNames
[CurrentInputIndex
])
786 delete[] FileNames
[CurrentInputIndex
];
787 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
789 if (!Inputs
[CurrentInputIndex
])
792 errBuf
.Printf("Could not open include file %s", (const char*) actualFile
);
793 CurrentInputIndex
--;
794 OnError((char *)errBuf
.c_str());
797 bool succ
= read_a_line(buf
);
803 wxString bufStr
= buf
;
806 for (index
=0; syntaxTokens
[index
] != wxEmptyString
; index
++)
808 pos
= bufStr
.find(syntaxTokens
[index
]);
809 if (pos
!= wxString::npos
&& pos
!= 0)
811 size_t commentStart
= bufStr
.find("%");
812 if (commentStart
== wxString::npos
|| commentStart
> pos
)
815 if (syntaxTokens
[index
] == "\\verb")
817 errBuf
.Printf("'%s$....$' was detected at line %lu inside file %s. Please replace this form with \\tt{....}",
818 syntaxTokens
[index
].c_str(),
819 LineNumbers
[CurrentInputIndex
],
820 currentFileName
.c_str());
824 errBuf
.Printf("'%s' was detected at line %lu inside file %s that is not the only text on the line, starting at column one.",
825 syntaxTokens
[index
].c_str(),
826 LineNumbers
[CurrentInputIndex
],
827 currentFileName
.c_str());
829 OnError((char *)errBuf
.c_str());
835 if (strncmp(buf
, "\\begin{verbatim}", 16) == 0 ||
836 strncmp(buf
, "\\begin{toocomplex}", 18) == 0)
837 readInVerbatim
= TRUE
;
838 else if (strncmp(buf
, "\\end{verbatim}", 14) == 0 ||
839 strncmp(buf
, "\\end{toocomplex}", 16) == 0)
840 readInVerbatim
= FALSE
;
842 if (checkCurleyBraces
)
844 if (ch
== EOF
&& leftCurley
!= rightCurley
)
847 errBuf
.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName
.c_str(),leftCurley
,rightCurley
);
848 OnError((char *)errBuf
.c_str());
860 bool ParseNewCommand(char *buffer
, int *pos
)
862 if ((strncmp((buffer
+(*pos
)), "newcommand", 10) == 0) ||
863 (strncmp((buffer
+(*pos
)), "renewcommand", 12) == 0))
865 if (strncmp((buffer
+(*pos
)), "newcommand", 10) == 0)
870 char commandName
[100];
871 char commandValue
[1000];
874 while (buffer
[*pos
] != '}' && (buffer
[*pos
] != 0))
876 commandName
[i
] = buffer
[*pos
];
883 if (buffer
[*pos
] == '[')
886 noArgs
= (int)(buffer
[*pos
]) - 48;
887 *pos
+= 2; // read past argument and '['
893 char ch
= buffer
[*pos
];
904 if (!read_a_line(buffer
))
909 commandValue
[i
] = ch
;
915 CustomMacro
*macro
= new CustomMacro(commandName
, noArgs
, NULL
);
916 if (strlen(commandValue
) > 0)
917 macro
->macroBody
= copystring(commandValue
);
918 if (!CustomMacroList
.Find(commandName
))
920 CustomMacroList
.Append(commandName
, macro
);
921 AddMacroDef(ltCUSTOM_MACRO
, commandName
, noArgs
);
928 void MacroError(char *buffer
)
935 while (((ch
= buffer
[i
-1]) != '\n') && (ch
!= 0))
944 errBuf
.Printf("Could not find macro: %s at line %d, file %s",
945 macroBuf
, (int)(LineNumbers
[CurrentInputIndex
]-1), FileNames
[CurrentInputIndex
]);
946 OnError((char *)errBuf
.c_str());
948 if (wxStrcmp(macroBuf
,"\\end{document}") == 0)
951 buf
= "Halted build due to unrecoverable error.";
952 OnInform((char *)buf
.c_str());
959 * 'environment' specifies the name of the macro IFF if we're looking for the end
960 * of an environment, e.g. \end{itemize}. Otherwise it's NULL.
961 * 'parseToBrace' is TRUE if the argument should extend to the next right brace,
962 * e.g. in {\bf an argument} as opposed to \vskip 30pt
965 int ParseArg(TexChunk
*thisArg
, wxList
& children
, char *buffer
, int pos
, char *environment
, bool parseToBrace
, TexChunk
*customMacroArgs
)
968 if (stopRunning
) return pos
;
977 // Consume leading brace or square bracket, but ONLY if not following
978 // a space, because this could be e.g. {\large {\bf thing}} where {\bf thing}
979 // is the argument of \large AS WELL as being a block in its
983 if ((pos > 0) && (buffer[pos-1] != ' ') && buffer[pos] == '{')
987 if ((pos > 0) && (buffer[pos-1] != ' ') && (buffer[pos] == '[' || buffer[pos] == '('))
992 else if ((pos > 1) && (buffer[pos-1] != ' ') && (buffer[pos+1] == '[' || buffer[pos+1] == '('))
1000 // If not parsing to brace, just read the next word
1001 // (e.g. \vskip 20pt)
1004 int ch
= buffer
[pos
];
1005 while (!eof
&& ch
!= 13 && ch
!= 32 && ch
!= 10 &&
1006 ch
!= 0 && ch
!= '{')
1008 BigBuffer
[buf_ptr
] = ch
;
1015 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1016 BigBuffer
[buf_ptr
] = 0;
1018 chunk
->value
= copystring(BigBuffer
);
1019 children
.Append((wxObject
*)chunk
);
1026 len
= strlen(buffer
);
1029 if (customMacroArgs
) return 0;
1031 eof
= read_a_line(buffer
);
1033 len
= strlen(buffer
);
1034 // Check for verbatim (or toocomplex, which comes to the same thing)
1035 wxString bufStr
= buffer
;
1036 // if (bufStr.find("\\begin{verbatim}") != wxString::npos ||
1037 // bufStr.find("\\begin{toocomplex}") != wxString::npos)
1038 if (strncmp(buffer
, "\\begin{verbatim}", 16) == 0 ||
1039 strncmp(buffer
, "\\begin{toocomplex}", 18) == 0)
1043 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1044 BigBuffer
[buf_ptr
] = 0;
1046 chunk
->value
= copystring(BigBuffer
);
1047 children
.Append((wxObject
*)chunk
);
1052 eof
= read_a_line(buffer
);
1053 while (!eof
&& (strncmp(buffer
, "\\end{verbatim}", 14) != 0) &&
1054 (strncmp(buffer
, "\\end{toocomplex}", 16) != 0)
1057 strcat(BigBuffer
, buffer
);
1058 buf_ptr
+= strlen(buffer
);
1059 eof
= read_a_line(buffer
);
1061 eof
= read_a_line(buffer
);
1064 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, VerbatimMacroDef
);
1066 chunk
->macroId
= ltVERBATIM
;
1067 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, VerbatimMacroDef
);
1069 arg
->macroId
= ltVERBATIM
;
1070 TexChunk
*str
= new TexChunk(CHUNK_TYPE_STRING
);
1071 str
->value
= copystring(BigBuffer
);
1073 children
.Append((wxObject
*)chunk
);
1074 chunk
->children
.Append((wxObject
*)arg
);
1075 arg
->children
.Append((wxObject
*)str
);
1077 // Also want to include the following newline (is always a newline
1078 // after a verbatim): EXCEPT in HTML
1079 if (convertMode
!= TEX_HTML
)
1081 TexMacroDef
*parDef
= (TexMacroDef
*)MacroDefs
.Get("\\");
1082 TexChunk
*parChunk
= new TexChunk(CHUNK_TYPE_MACRO
, parDef
);
1083 parChunk
->no_args
= 0;
1084 parChunk
->macroId
= ltBACKSLASHCHAR
;
1085 children
.Append((wxObject
*)parChunk
);
1090 char ch
= buffer
[pos
];
1091 // End of optional argument -- pretend it's right brace for simplicity
1092 if (thisArg
->optional
&& (ch
== ']'))
1098 case '}': // End of argument
1102 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1103 BigBuffer
[buf_ptr
] = 0;
1105 chunk
->value
= copystring(BigBuffer
);
1106 children
.Append((wxObject
*)chunk
);
1108 if (ch
== '}') pos
++;
1114 if (buf_ptr
> 0) // Finish off the string we've read so far
1116 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1117 BigBuffer
[buf_ptr
] = 0;
1119 chunk
->value
= copystring(BigBuffer
);
1120 children
.Append((wxObject
*)chunk
);
1124 // Try matching \end{environment}
1125 if (environment
&& FindEndEnvironment(buffer
, &pos
, environment
))
1127 // Eliminate newline after an \end{} if possible
1128 if (buffer
[pos
] == 13)
1131 if (buffer
[pos
] == 10)
1137 if (ParseNewCommand(buffer
, &pos
))
1140 if (strncmp(buffer
+pos
, "special", 7) == 0)
1148 wxTex2RTFBuffer
[0] = 0;
1153 int ch
= buffer
[pos
];
1159 wxTex2RTFBuffer
[i
] = 0;
1164 wxTex2RTFBuffer
[i
] = '}';
1171 wxTex2RTFBuffer
[i
] = '{';
1175 else if (ch
== '\\' && buffer
[pos
+1] == '}')
1177 wxTex2RTFBuffer
[i
] = '}';
1181 else if (ch
== '\\' && buffer
[pos
+1] == '{')
1183 wxTex2RTFBuffer
[i
] = '{';
1189 wxTex2RTFBuffer
[i
] = ch
;
1196 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1198 chunk
->macroId
= ltSPECIAL
;
1199 TexMacroDef
*specialDef
= (TexMacroDef
*)MacroDefs
.Get("special");
1200 chunk
->def
= specialDef
;
1201 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, specialDef
);
1202 chunk
->children
.Append((wxObject
*)arg
);
1204 arg
->macroId
= chunk
->macroId
;
1206 // The value in the first argument.
1207 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1208 arg
->children
.Append((wxObject
*)argValue
);
1210 argValue
->value
= copystring(wxTex2RTFBuffer
);
1212 children
.Append((wxObject
*)chunk
);
1214 else if (strncmp(buffer
+pos
, "verb", 4) == 0)
1217 if (buffer
[pos
] == '*')
1220 // Find the delimiter character
1221 int ch
= buffer
[pos
];
1223 // Now at start of verbatim text
1225 while ((buffer
[pos
] != ch
) && buffer
[pos
] != 0)
1227 char *val
= new char[pos
- j
+ 1];
1229 for (i
= j
; i
< pos
; i
++)
1231 val
[i
-j
] = buffer
[i
];
1237 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1239 chunk
->macroId
= ltVERB
;
1240 TexMacroDef
*verbDef
= (TexMacroDef
*)MacroDefs
.Get("verb");
1241 chunk
->def
= verbDef
;
1242 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, verbDef
);
1243 chunk
->children
.Append((wxObject
*)arg
);
1245 arg
->macroId
= chunk
->macroId
;
1247 // The value in the first argument.
1248 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1249 arg
->children
.Append((wxObject
*)argValue
);
1251 argValue
->value
= val
;
1253 children
.Append((wxObject
*)chunk
);
1258 bool tmpParseToBrace
= TRUE
;
1259 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1262 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1264 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1266 chunk
->no_args
= def
->no_args
;
1267 // chunk->name = copystring(def->name);
1268 chunk
->macroId
= def
->macroId
;
1271 children
.Append((wxObject
*)chunk
);
1273 // Eliminate newline after a \begin{} or a \\ if possible
1274 if (env
|| strcmp(def
->name
, "\\") == 0)
1275 if (buffer
[pos
] == 13)
1278 if (buffer
[pos
] == 10)
1282 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1283 buffer
, pos
, env
, tmpParseToBrace
, customMacroArgs
);
1285 // If custom macro, parse the body substituting the above found args.
1288 if (customMacro
->macroBody
)
1291 // strcpy(macroBuf, "{");
1292 strcpy(macroBuf
, customMacro
->macroBody
);
1293 strcat(macroBuf
, "}");
1294 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, TRUE
, chunk
);
1297 // delete chunk; // Might delete children
1302 MacroError(buffer
+pos
);
1307 // Parse constructs like {\bf thing} as if they were
1312 if (buffer
[pos
] == '\\')
1316 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1317 BigBuffer
[buf_ptr
] = 0;
1319 chunk
->value
= copystring(BigBuffer
);
1320 children
.Append((wxObject
*)chunk
);
1325 bool tmpParseToBrace
;
1326 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1329 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1331 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1332 chunk
->no_args
= def
->no_args
;
1333 // chunk->name = copystring(def->name);
1334 chunk
->macroId
= def
->macroId
;
1336 children
.Append((wxObject
*)chunk
);
1338 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1339 buffer
, pos
, NULL
, TRUE
, customMacroArgs
);
1341 // If custom macro, parse the body substituting the above found args.
1344 if (customMacro
->macroBody
)
1347 // strcpy(macroBuf, "{");
1348 strcpy(macroBuf
, customMacro
->macroBody
);
1349 strcat(macroBuf
, "}");
1350 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, TRUE
, chunk
);
1353 // delete chunk; // Might delete children
1358 MacroError(buffer
+pos
);
1364 * If all else fails, we assume that we have
1365 * a pair of braces on their own, so return a `dummy' macro
1366 * definition with just one argument to parse.
1370 SoloBlockDef
= new TexMacroDef(ltSOLO_BLOCK
, "solo block", 1, FALSE
);
1375 TexChunk
*chunk1
= new TexChunk(CHUNK_TYPE_STRING
);
1376 BigBuffer
[buf_ptr
] = 0;
1378 chunk1
->value
= copystring(BigBuffer
);
1379 children
.Append((wxObject
*)chunk1
);
1381 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, SoloBlockDef
);
1382 chunk
->no_args
= SoloBlockDef
->no_args
;
1383 // chunk->name = copystring(SoloBlockDef->name);
1384 chunk
->macroId
= SoloBlockDef
->macroId
;
1385 children
.Append((wxObject
*)chunk
);
1387 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, SoloBlockDef
);
1389 chunk
->children
.Append((wxObject
*)arg
);
1390 // arg->name = copystring(SoloBlockDef->name);
1392 arg
->macroId
= chunk
->macroId
;
1394 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, NULL
, TRUE
, customMacroArgs
);
1402 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1403 BigBuffer
[buf_ptr
] = 0;
1405 chunk
->value
= copystring(BigBuffer
);
1406 children
.Append((wxObject
*)chunk
);
1411 if (buffer
[pos
] == '$')
1413 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1415 // chunk->name = copystring("$$");
1416 chunk
->macroId
= ltSPECIALDOUBLEDOLLAR
;
1417 children
.Append((wxObject
*)chunk
);
1422 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1424 // chunk->name = copystring("_$");
1425 chunk
->macroId
= ltSPECIALDOLLAR
;
1426 children
.Append((wxObject
*)chunk
);
1434 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1435 BigBuffer
[buf_ptr
] = 0;
1437 chunk
->value
= copystring(BigBuffer
);
1438 children
.Append((wxObject
*)chunk
);
1442 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1444 // chunk->name = copystring("_~");
1445 chunk
->macroId
= ltSPECIALTILDE
;
1446 children
.Append((wxObject
*)chunk
);
1449 case '#': // Either treat as a special TeX character or as a macro arg
1453 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1454 BigBuffer
[buf_ptr
] = 0;
1456 chunk
->value
= copystring(BigBuffer
);
1457 children
.Append((wxObject
*)chunk
);
1461 if (!customMacroArgs
)
1463 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1465 // chunk->name = copystring("_#");
1466 chunk
->macroId
= ltSPECIALHASH
;
1467 children
.Append((wxObject
*)chunk
);
1471 if (isdigit(buffer
[pos
]))
1473 int n
= buffer
[pos
] - 48;
1475 wxNode
*node
= customMacroArgs
->children
.Nth(n
-1);
1478 TexChunk
*argChunk
= (TexChunk
*)node
->Data();
1479 children
.Append((wxObject
*)new TexChunk(*argChunk
));
1487 // Remove white space before and after the ampersand,
1488 // since this is probably a table column separator with
1489 // some convenient -- but useless -- white space in the text.
1490 while ((buf_ptr
> 0) && ((BigBuffer
[buf_ptr
-1] == ' ') || (BigBuffer
[buf_ptr
-1] == 9)))
1495 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1496 BigBuffer
[buf_ptr
] = 0;
1498 chunk
->value
= copystring(BigBuffer
);
1499 children
.Append((wxObject
*)chunk
);
1504 while (buffer
[pos
] == ' ' || buffer
[pos
] == 9)
1507 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1509 // chunk->name = copystring("_&");
1510 chunk
->macroId
= ltSPECIALAMPERSAND
;
1511 children
.Append((wxObject
*)chunk
);
1514 // Eliminate end-of-line comment
1518 while (ch
!= 10 && ch
!= 13 && ch
!= 0)
1523 if (buffer
[pos
] == 10 || buffer
[pos
] == 13)
1526 if (buffer
[pos
] == 10) pos
++; // Eliminate newline following DOS line feed
1533 BigBuffer
[buf_ptr
] = ' ';
1534 BigBuffer
[buf_ptr
+1] = 0;
1541 BigBuffer
[buf_ptr
] = ch
;
1542 BigBuffer
[buf_ptr
+1] = 0;
1553 * Consume as many arguments as the macro definition specifies
1557 int ParseMacroBody(const char *macro_name
, TexChunk
*parent
,
1558 int no_args
, char *buffer
, int pos
,
1559 char *environment
, bool parseToBrace
,
1560 TexChunk
*customMacroArgs
)
1563 if (stopRunning
) return pos
;
1565 // Check for a first optional argument
1566 if (buffer
[pos
] == ' ' && buffer
[pos
+1] == '[')
1568 // Fool following code into thinking that this is definitely
1569 // an optional first argument. (If a space before a non-first argument,
1570 // [ is interpreted as a [, not an optional argument.)
1576 if (buffer
[pos
] == '[')
1582 for (i
= 0; i
< no_args
; i
++)
1585 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, parent
->def
);
1587 parent
->children
.Append((wxObject
*)arg
);
1588 // arg->name = copystring(macro_name);
1589 arg
->argn
= maxArgs
;
1590 arg
->macroId
= parent
->macroId
;
1592 // To parse the first arg of a 2 arg \begin{thing}{arg} ... \end{thing}
1593 // have to fool parser into thinking this is a regular kind of block.
1595 if ((no_args
== 2) && (i
== 0))
1598 actualEnv
= environment
;
1600 bool isOptional
= FALSE
;
1602 // Remove the first { of the argument so it doesn't get recognized as { ... }
1603 // EatWhiteSpace(buffer, &pos);
1606 // The reason for these tests is to not consume braces that don't
1607 // belong to this macro.
1608 // E.g. {\bf {\small thing}}
1609 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && buffer
[pos
] == '{')
1612 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && (buffer
[pos
] == '['))
1617 else if ((pos
> 1) && (buffer
[pos
-1] != ' ') && (buffer
[pos
+1] == '['))
1625 wxString
tmpBuffer(buffer
);
1626 if (tmpBuffer
.length() > 4)
1628 if (tmpBuffer
.Right(4) == "\\par")
1629 tmpBuffer
= tmpBuffer
.Mid(0,tmpBuffer
.length()-4);
1631 errBuf
.Printf("Missing macro argument in the line:\n\t%s\n",tmpBuffer
.c_str());
1632 OnError((char *)errBuf
.c_str());
1636 arg
->optional
= isOptional
;
1638 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, actualEnv
, parseToBrace
, customMacroArgs
);
1640 // If we've encountered an OPTIONAL argument, go another time around
1641 // the loop, because we've got more than we thought.
1642 // Hopefully optional args don't occur at the end of a macro use
1643 // or we might miss it.
1644 // Don't increment no of times round loop if the first optional arg
1645 // -- we already did it before the loop.
1646 if (arg
->optional
&& (i
> 0))
1649 parent
->no_args
= maxArgs
;
1651 // Tell each argument how many args there are (useful when processing an arg)
1652 wxNode
*node
= parent
->children
.First();
1655 TexChunk
*chunk
= (TexChunk
*)node
->Data();
1656 chunk
->no_args
= maxArgs
;
1657 node
= node
->Next();
1662 bool TexLoadFile(char *filename
)
1664 static char *line_buffer
;
1665 stopRunning
= FALSE
;
1666 strcpy(TexFileRoot
, filename
);
1667 StripExtension(TexFileRoot
);
1668 sprintf(TexBibName
, "%s.bb", TexFileRoot
);
1669 sprintf(TexTmpBibName
, "%s.bb1", TexFileRoot
);
1671 TexPathList
.EnsureFileAccessible(filename
);
1676 line_buffer
= new char[MAX_LINE_BUFFER_SIZE
];
1678 Inputs
[0] = fopen(filename
, "r");
1680 FileNames
[0] = copystring(filename
);
1683 read_a_line(line_buffer
);
1684 ParseMacroBody("toplevel", TopLevel
, 1, line_buffer
, 0, NULL
, TRUE
);
1685 if (Inputs
[0]) fclose(Inputs
[0]);
1692 TexMacroDef::TexMacroDef(int the_id
, const char *the_name
, int n
, bool ig
, bool forbidLevel
)
1694 name
= copystring(the_name
);
1698 forbidden
= forbidLevel
;
1701 TexMacroDef::~TexMacroDef(void)
1703 if (name
) delete[] name
;
1706 TexChunk::TexChunk(int the_type
, TexMacroDef
*the_def
)
1718 TexChunk::TexChunk(TexChunk
& toCopy
)
1721 no_args
= toCopy
.no_args
;
1723 macroId
= toCopy
.macroId
;
1726 // name = copystring(toCopy.name);
1732 value
= copystring(toCopy
.value
);
1736 optional
= toCopy
.optional
;
1737 wxNode
*node
= toCopy
.children
.First();
1740 TexChunk
*child
= (TexChunk
*)node
->Data();
1741 children
.Append((wxObject
*)new TexChunk(*child
));
1742 node
= node
->Next();
1746 TexChunk::~TexChunk(void)
1748 // if (name) delete[] name;
1749 if (value
) delete[] value
;
1750 wxNode
*node
= children
.First();
1753 TexChunk
*child
= (TexChunk
*)node
->Data();
1755 wxNode
*next
= node
->Next();
1761 bool IsArgOptional(void) // Is this argument an optional argument?
1763 return isArgOptional
;
1766 int GetNoArgs(void) // Number of args for this macro
1771 /* Gets the text of a chunk on request (must be for small arguments
1776 void GetArgData1(TexChunk
*chunk
)
1778 switch (chunk
->type
)
1780 case CHUNK_TYPE_MACRO
:
1782 TexMacroDef
*def
= chunk
->def
;
1783 if (def
&& def
->ignore
)
1786 if (def
&& (strcmp(def
->name
, "solo block") != 0))
1788 strcat(currentArgData
, "\\");
1789 strcat(currentArgData
, def
->name
);
1792 wxNode
*node
= chunk
->children
.First();
1795 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
1796 strcat(currentArgData
, "{");
1797 GetArgData1(child_chunk
);
1798 strcat(currentArgData
, "}");
1799 node
= node
->Next();
1803 case CHUNK_TYPE_ARG
:
1805 wxNode
*node
= chunk
->children
.First();
1808 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
1809 GetArgData1(child_chunk
);
1810 node
= node
->Next();
1814 case CHUNK_TYPE_STRING
:
1817 strcat(currentArgData
, chunk
->value
);
1823 char *GetArgData(TexChunk
*chunk
)
1825 currentArgData
[0] = 0;
1826 GetArgData1(currentArgument
);
1827 haveArgData
= FALSE
;
1828 return currentArgData
;
1831 char *GetArgData(void)
1835 currentArgData
[0] = 0;
1836 GetArgData1(currentArgument
);
1838 return currentArgData
;
1841 TexChunk
*GetArgChunk(void)
1843 return currentArgument
;
1846 TexChunk
*GetNextChunk(void) // Look ahead to the next chunk
1851 TexChunk
*GetTopLevelChunk(void)
1856 int GetCurrentColumn(void)
1858 return currentColumn
;
1862 * Traverses document calling functions to allow the client to
1863 * write out the appropriate stuff
1867 void TraverseFromChunk(TexChunk
*chunk
, wxNode
*thisNode
, bool childrenOnly
)
1870 if (stopRunning
) return;
1872 switch (chunk
->type
)
1874 case CHUNK_TYPE_MACRO
:
1876 TexMacroDef
*def
= chunk
->def
;
1877 if (def
&& def
->ignore
)
1881 OnMacro(chunk
->macroId
, chunk
->no_args
, TRUE
);
1883 wxNode
*node
= chunk
->children
.First();
1884 TexChunk
*child_chunk
= NULL
;
1887 child_chunk
= (TexChunk
*)node
->Data();
1888 TraverseFromChunk(child_chunk
, node
);
1889 node
= node
->Next();
1892 if (thisNode
&& thisNode
->Next())
1893 nextChunk
= (TexChunk
*)thisNode
->Next()->Data();
1896 OnMacro(chunk
->macroId
, chunk
->no_args
, FALSE
);
1899 case CHUNK_TYPE_ARG
:
1901 currentArgument
= chunk
;
1903 isArgOptional
= chunk
->optional
;
1904 noArgs
= chunk
->no_args
;
1906 // If OnArgument returns FALSE, don't output.
1908 if (childrenOnly
|| OnArgument(chunk
->macroId
, chunk
->argn
, TRUE
))
1910 wxNode
*node
= chunk
->children
.First();
1913 TexChunk
*child_chunk
= (TexChunk
*)node
->Data();
1914 TraverseFromChunk(child_chunk
, node
);
1915 node
= node
->Next();
1919 currentArgument
= chunk
;
1921 if (thisNode
&& thisNode
->Next())
1922 nextChunk
= (TexChunk
*)thisNode
->Next()->Data();
1924 isArgOptional
= chunk
->optional
;
1925 noArgs
= chunk
->no_args
;
1928 (void)OnArgument(chunk
->macroId
, chunk
->argn
, FALSE
);
1931 case CHUNK_TYPE_STRING
:
1933 extern int issuedNewParagraph
;
1934 extern int forbidResetPar
;
1935 if (chunk
->value
&& (forbidResetPar
== 0))
1937 // If non-whitespace text, we no longer have a new paragraph.
1938 if (issuedNewParagraph
&& !((chunk
->value
[0] == 10 || chunk
->value
[0] == 13 || chunk
->value
[0] == 32)
1939 && chunk
->value
[1] == 0))
1941 issuedNewParagraph
= FALSE
;
1943 TexOutput(chunk
->value
, TRUE
);
1950 void TraverseDocument(void)
1952 TraverseFromChunk(TopLevel
, NULL
);
1955 void SetCurrentOutput(FILE *fd
)
1957 CurrentOutput1
= fd
;
1958 CurrentOutput2
= NULL
;
1961 void SetCurrentOutputs(FILE *fd1
, FILE *fd2
)
1963 CurrentOutput1
= fd1
;
1964 CurrentOutput2
= fd2
;
1967 void AddMacroDef(int the_id
, const char *name
, int n
, bool ignore
, bool forbid
)
1969 MacroDefs
.Put(name
, new TexMacroDef(the_id
, name
, n
, ignore
, forbid
));
1972 void TexInitialize(int bufSize
)
1974 InitialiseColourTable();
1976 TexPathList
.AddEnvList("TEXINPUT");
1979 TexPathList
.AddEnvList("TEXINPUTS");
1982 for (i
= 0; i
< 15; i
++)
1986 FileNames
[i
] = NULL
;
1989 IgnorableInputFiles
.Add("psbox.tex");
1990 BigBuffer
= new char[(bufSize
*1000)];
1991 currentArgData
= new char[2000];
1992 TexFileRoot
= new char[300];
1993 TexBibName
= new char[300];
1994 TexTmpBibName
= new char[300];
1995 AddMacroDef(ltTOPLEVEL
, "toplevel", 1);
1996 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
1997 // TopLevel->name = copystring("toplevel");
1998 TopLevel
->macroId
= ltTOPLEVEL
;
1999 TopLevel
->no_args
= 1;
2000 VerbatimMacroDef
= (TexMacroDef
*)MacroDefs
.Get("verbatim");
2003 void TexCleanUp(void)
2006 for (i
= 0; i
< 15; i
++)
2012 subsubsectionNo
= 0;
2015 CurrentOutput1
= NULL
;
2016 CurrentOutput2
= NULL
;
2017 CurrentInputIndex
= 0;
2018 haveArgData
= FALSE
;
2023 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
2024 // TopLevel->name = copystring("toplevel");
2025 TopLevel
->macroId
= ltTOPLEVEL
;
2026 TopLevel
->no_args
= 1;
2028 DocumentTitle
= NULL
;
2029 DocumentAuthor
= NULL
;
2030 DocumentDate
= NULL
;
2031 DocumentStyle
= LATEX_REPORT
;
2032 MinorDocumentStyle
= 0;
2033 BibliographyStyleString
= copystring("plain");
2034 DocumentStyleString
= copystring("report");
2035 MinorDocumentStyleString
= NULL
;
2037 // gt - Changed this so if this is the final pass
2038 // then we DO want to remove these macros, so that
2039 // memory is not MASSIVELY leaked if the user
2040 // does not exit the program, but instead runs
2041 // the program again
2042 if ((passNumber
== 1 && !runTwice
) ||
2043 (passNumber
== 2 && runTwice
))
2045 /* Don't want to remove custom macros after each pass.*/
2047 wxNode
*node
= CustomMacroList
.First();
2050 CustomMacro
*macro
= (CustomMacro
*)node
->Data();
2053 node
= CustomMacroList
.First();
2057 TexReferences
.BeginFind();
2058 wxNode
*node
= TexReferences
.Next();
2061 TexRef
*ref
= (TexRef
*)node
->Data();
2063 node
= TexReferences
.Next();
2065 TexReferences
.Clear();
2067 node
= BibList
.First();
2070 BibEntry
*entry
= (BibEntry
*)node
->Data();
2073 node
= BibList
.First();
2075 CitationList
.Clear();
2076 ResetTopicCounter();
2079 // There is likely to be one set of macros used by all utilities.
2080 void DefineDefaultMacros(void)
2082 // Put names which subsume other names at the TOP
2083 // so they get recognized first
2085 AddMacroDef(ltACCENT_GRAVE
, "`", 1);
2086 AddMacroDef(ltACCENT_ACUTE
, "'", 1);
2087 AddMacroDef(ltACCENT_CARET
, "^", 1);
2088 AddMacroDef(ltACCENT_UMLAUT
, "\"", 1);
2089 AddMacroDef(ltACCENT_TILDE
, "~", 1);
2090 AddMacroDef(ltACCENT_DOT
, ".", 1);
2091 AddMacroDef(ltACCENT_CADILLA
, "c", 1);
2092 AddMacroDef(ltSMALLSPACE1
, ",", 0);
2093 AddMacroDef(ltSMALLSPACE2
, ";", 0);
2095 AddMacroDef(ltABSTRACT
, "abstract", 1);
2096 AddMacroDef(ltADDCONTENTSLINE
, "addcontentsline", 3);
2097 AddMacroDef(ltADDTOCOUNTER
, "addtocounter", 2);
2098 AddMacroDef(ltALEPH
, "aleph", 0);
2099 AddMacroDef(ltALPHA
, "alpha", 0);
2100 AddMacroDef(ltALPH1
, "alph", 1);
2101 AddMacroDef(ltALPH2
, "Alph", 1);
2102 AddMacroDef(ltANGLE
, "angle", 0);
2103 AddMacroDef(ltAPPENDIX
, "appendix", 0);
2104 AddMacroDef(ltAPPROX
, "approx", 0);
2105 AddMacroDef(ltARABIC
, "arabic", 1);
2106 AddMacroDef(ltARRAY
, "array", 1);
2107 AddMacroDef(ltAST
, "ast", 0);
2108 AddMacroDef(ltASYMP
, "asymp", 0);
2109 AddMacroDef(ltAUTHOR
, "author", 1);
2111 AddMacroDef(ltBACKGROUNDCOLOUR
, "backgroundcolour", 1);
2112 AddMacroDef(ltBACKGROUNDIMAGE
, "backgroundimage", 1);
2113 AddMacroDef(ltBACKGROUND
, "background", 1);
2114 AddMacroDef(ltBACKSLASHRAW
, "backslashraw", 0);
2115 AddMacroDef(ltBACKSLASH
, "backslash", 0);
2116 AddMacroDef(ltBASELINESKIP
, "baselineskip", 1);
2117 AddMacroDef(ltBCOL
, "bcol", 2);
2118 AddMacroDef(ltBETA
, "beta", 0);
2119 AddMacroDef(ltBFSERIES
, "bfseries", 1);
2120 AddMacroDef(ltBF
, "bf", 1);
2121 AddMacroDef(ltBIBITEM
, "bibitem", 2); // For convenience, bibitem has 2 args: label and item.
2122 // The Latex syntax permits writing as 2 args.
2123 AddMacroDef(ltBIBLIOGRAPHYSTYLE
, "bibliographystyle", 1);
2124 AddMacroDef(ltBIBLIOGRAPHY
, "bibliography", 1);
2125 AddMacroDef(ltBIGTRIANGLEDOWN
, "bigtriangledown", 0);
2126 AddMacroDef(ltBOT
, "bot", 0);
2127 AddMacroDef(ltBOXIT
, "boxit", 1);
2128 AddMacroDef(ltBOX
, "box", 0);
2129 AddMacroDef(ltBRCLEAR
, "brclear", 0);
2130 AddMacroDef(ltBULLET
, "bullet", 0);
2132 AddMacroDef(ltCAPTIONSTAR
, "caption*", 1);
2133 AddMacroDef(ltCAPTION
, "caption", 1);
2134 AddMacroDef(ltCAP
, "cap", 0);
2135 AddMacroDef(ltCDOTS
, "cdots", 0);
2136 AddMacroDef(ltCDOT
, "cdot", 0);
2137 AddMacroDef(ltCENTERLINE
, "centerline", 1);
2138 AddMacroDef(ltCENTERING
, "centering", 0);
2139 AddMacroDef(ltCENTER
, "center", 1);
2140 AddMacroDef(ltCEXTRACT
, "cextract", 0);
2141 AddMacroDef(ltCHAPTERHEADING
, "chapterheading", 1);
2142 AddMacroDef(ltCHAPTERSTAR
, "chapter*", 1);
2143 AddMacroDef(ltCHAPTER
, "chapter", 1);
2144 AddMacroDef(ltCHI
, "chi", 0);
2145 AddMacroDef(ltCINSERT
, "cinsert", 0);
2146 AddMacroDef(ltCIRC
, "circ", 0);
2147 AddMacroDef(ltCITE
, "cite", 1);
2148 AddMacroDef(ltCLASS
, "class", 1);
2149 AddMacroDef(ltCLEARDOUBLEPAGE
, "cleardoublepage", 0);
2150 AddMacroDef(ltCLEARPAGE
, "clearpage", 0);
2151 AddMacroDef(ltCLINE
, "cline", 1);
2152 AddMacroDef(ltCLIPSFUNC
, "clipsfunc", 3);
2153 AddMacroDef(ltCLUBSUIT
, "clubsuit", 0);
2154 AddMacroDef(ltCOLUMNSEP
, "columnsep", 1);
2155 AddMacroDef(ltCOMMENT
, "comment", 1, TRUE
);
2156 AddMacroDef(ltCONG
, "cong", 0);
2157 AddMacroDef(ltCOPYRIGHT
, "copyright", 0);
2158 AddMacroDef(ltCPARAM
, "cparam", 2);
2159 AddMacroDef(ltCHEAD
, "chead", 1);
2160 AddMacroDef(ltCFOOT
, "cfoot", 1);
2161 AddMacroDef(ltCUP
, "cup", 0);
2163 AddMacroDef(ltDASHV
, "dashv", 0);
2164 AddMacroDef(ltDATE
, "date", 1);
2165 AddMacroDef(ltDELTA
, "delta", 0);
2166 AddMacroDef(ltCAP_DELTA
, "Delta", 0);
2167 AddMacroDef(ltDEFINECOLOUR
, "definecolour", 4);
2168 AddMacroDef(ltDEFINECOLOR
, "definecolor", 4);
2169 AddMacroDef(ltDESCRIPTION
, "description", 1);
2170 AddMacroDef(ltDESTRUCT
, "destruct", 1);
2171 AddMacroDef(ltDIAMOND2
, "diamond2", 0);
2172 AddMacroDef(ltDIAMOND
, "diamond", 0);
2173 AddMacroDef(ltDIV
, "div", 0);
2174 AddMacroDef(ltDOCUMENTCLASS
, "documentclass", 1);
2175 AddMacroDef(ltDOCUMENTSTYLE
, "documentstyle", 1);
2176 AddMacroDef(ltDOCUMENT
, "document", 1);
2177 AddMacroDef(ltDOUBLESPACE
, "doublespace", 1);
2178 AddMacroDef(ltDOTEQ
, "doteq", 0);
2179 AddMacroDef(ltDOWNARROW
, "downarrow", 0);
2180 AddMacroDef(ltDOWNARROW2
, "Downarrow", 0);
2182 AddMacroDef(ltEMPTYSET
, "emptyset", 0);
2183 AddMacroDef(ltEMPH
, "emph", 1);
2184 AddMacroDef(ltEM
, "em", 1);
2185 AddMacroDef(ltENUMERATE
, "enumerate", 1);
2186 AddMacroDef(ltEPSILON
, "epsilon", 0);
2187 AddMacroDef(ltEQUATION
, "equation", 1);
2188 AddMacroDef(ltEQUIV
, "equiv", 0);
2189 AddMacroDef(ltETA
, "eta", 0);
2190 AddMacroDef(ltEVENSIDEMARGIN
, "evensidemargin", 1);
2191 AddMacroDef(ltEXISTS
, "exists", 0);
2193 AddMacroDef(ltFBOX
, "fbox", 1);
2194 AddMacroDef(ltFCOL
, "fcol", 2);
2195 AddMacroDef(ltFIGURE
, "figure", 1);
2196 AddMacroDef(ltFIGURESTAR
, "figure*", 1);
2197 AddMacroDef(ltFLUSHLEFT
, "flushleft", 1);
2198 AddMacroDef(ltFLUSHRIGHT
, "flushright", 1);
2199 AddMacroDef(ltFOLLOWEDLINKCOLOUR
, "followedlinkcolour", 1);
2200 AddMacroDef(ltFOOTHEIGHT
, "footheight", 1);
2201 AddMacroDef(ltFOOTNOTEPOPUP
, "footnotepopup", 2);
2202 AddMacroDef(ltFOOTNOTE
, "footnote", 1);
2203 AddMacroDef(ltFOOTSKIP
, "footskip", 1);
2204 AddMacroDef(ltFORALL
, "forall", 0);
2205 AddMacroDef(ltFRAMEBOX
, "framebox", 1);
2206 AddMacroDef(ltFROWN
, "frown", 0);
2207 AddMacroDef(ltFUNCTIONSECTION
, "functionsection", 1);
2208 AddMacroDef(ltFUNC
, "func", 3);
2209 AddMacroDef(ltFOOTNOTESIZE
, "footnotesize", 0);
2210 AddMacroDef(ltFANCYPLAIN
, "fancyplain", 2);
2212 AddMacroDef(ltGAMMA
, "gamma", 0);
2213 AddMacroDef(ltCAP_GAMMA
, "Gamma", 0);
2214 AddMacroDef(ltGEQ
, "geq", 0);
2215 AddMacroDef(ltGE
, "ge", 0);
2216 AddMacroDef(ltGG
, "gg", 0);
2217 AddMacroDef(ltGLOSSARY
, "glossary", 1);
2218 AddMacroDef(ltGLOSS
, "gloss", 1);
2220 AddMacroDef(ltHEADHEIGHT
, "headheight", 1);
2221 AddMacroDef(ltHEARTSUIT
, "heartsuit", 0);
2222 AddMacroDef(ltHELPGLOSSARY
, "helpglossary", 1);
2223 AddMacroDef(ltHELPIGNORE
, "helpignore", 1, TRUE
);
2224 AddMacroDef(ltHELPONLY
, "helponly", 1);
2225 AddMacroDef(ltHELPINPUT
, "helpinput", 1);
2226 AddMacroDef(ltHELPFONTFAMILY
, "helpfontfamily", 1);
2227 AddMacroDef(ltHELPFONTSIZE
, "helpfontsize", 1);
2228 AddMacroDef(ltHELPREFN
, "helprefn", 2);
2229 AddMacroDef(ltHELPREF
, "helpref", 2);
2230 AddMacroDef(ltHFILL
, "hfill", 0);
2231 AddMacroDef(ltHLINE
, "hline", 0);
2232 AddMacroDef(ltHRULE
, "hrule", 0);
2233 AddMacroDef(ltHSPACESTAR
, "hspace*", 1);
2234 AddMacroDef(ltHSPACE
, "hspace", 1);
2235 AddMacroDef(ltHSKIPSTAR
, "hskip*", 1);
2236 AddMacroDef(ltHSKIP
, "hskip", 1);
2237 AddMacroDef(lthuge
, "huge", 1);
2238 AddMacroDef(ltHuge
, "Huge", 1);
2239 AddMacroDef(ltHUGE
, "HUGE", 1);
2240 AddMacroDef(ltHTMLIGNORE
, "htmlignore", 1);
2241 AddMacroDef(ltHTMLONLY
, "htmlonly", 1);
2243 AddMacroDef(ltIM
, "im", 0);
2244 AddMacroDef(ltINCLUDEONLY
, "includeonly", 1);
2245 AddMacroDef(ltINCLUDE
, "include", 1);
2246 AddMacroDef(ltINDENTED
, "indented", 2);
2247 AddMacroDef(ltINDEX
, "index", 1);
2248 AddMacroDef(ltINPUT
, "input", 1, TRUE
);
2249 AddMacroDef(ltIOTA
, "iota", 0);
2250 AddMacroDef(ltITEMIZE
, "itemize", 1);
2251 AddMacroDef(ltITEM
, "item", 0);
2252 AddMacroDef(ltIMAGEMAP
, "imagemap", 3);
2253 AddMacroDef(ltIMAGEL
, "imagel", 2);
2254 AddMacroDef(ltIMAGER
, "imager", 2);
2255 AddMacroDef(ltIMAGE
, "image", 2);
2256 AddMacroDef(ltIN
, "in", 0);
2257 AddMacroDef(ltINFTY
, "infty", 0);
2258 AddMacroDef(ltITSHAPE
, "itshape", 1);
2259 AddMacroDef(ltIT
, "it", 1);
2260 AddMacroDef(ltITEMSEP
, "itemsep", 1);
2261 AddMacroDef(ltINSERTATLEVEL
, "insertatlevel", 2);
2263 AddMacroDef(ltKAPPA
, "kappa", 0);
2264 AddMacroDef(ltKILL
, "kill", 0);
2266 AddMacroDef(ltLABEL
, "label", 1);
2267 AddMacroDef(ltLAMBDA
, "lambda", 0);
2268 AddMacroDef(ltCAP_LAMBDA
, "Lambda", 0);
2269 AddMacroDef(ltlarge
, "large", 1);
2270 AddMacroDef(ltLarge
, "Large", 1);
2271 AddMacroDef(ltLARGE
, "LARGE", 1);
2272 AddMacroDef(ltLATEXIGNORE
, "latexignore", 1);
2273 AddMacroDef(ltLATEXONLY
, "latexonly", 1);
2274 AddMacroDef(ltLATEX
, "LaTeX", 0);
2275 AddMacroDef(ltLBOX
, "lbox", 1);
2276 AddMacroDef(ltLBRACERAW
, "lbraceraw", 0);
2277 AddMacroDef(ltLDOTS
, "ldots", 0);
2278 AddMacroDef(ltLEQ
, "leq", 0);
2279 AddMacroDef(ltLE
, "le", 0);
2280 AddMacroDef(ltLEFTARROW
, "leftarrow", 0);
2281 AddMacroDef(ltLEFTRIGHTARROW
, "leftrightarrow", 0);
2282 AddMacroDef(ltLEFTARROW2
, "Leftarrow", 0);
2283 AddMacroDef(ltLEFTRIGHTARROW2
, "Leftrightarrow", 0);
2284 AddMacroDef(ltLINEBREAK
, "linebreak", 0);
2285 AddMacroDef(ltLINKCOLOUR
, "linkcolour", 1);
2286 AddMacroDef(ltLISTOFFIGURES
, "listoffigures", 0);
2287 AddMacroDef(ltLISTOFTABLES
, "listoftables", 0);
2288 AddMacroDef(ltLHEAD
, "lhead", 1);
2289 AddMacroDef(ltLFOOT
, "lfoot", 1);
2290 AddMacroDef(ltLOWERCASE
, "lowercase", 1);
2291 AddMacroDef(ltLL
, "ll", 0);
2293 AddMacroDef(ltMAKEGLOSSARY
, "makeglossary", 0);
2294 AddMacroDef(ltMAKEINDEX
, "makeindex", 0);
2295 AddMacroDef(ltMAKETITLE
, "maketitle", 0);
2296 AddMacroDef(ltMARKRIGHT
, "markright", 1);
2297 AddMacroDef(ltMARKBOTH
, "markboth", 2);
2298 AddMacroDef(ltMARGINPARWIDTH
, "marginparwidth", 1);
2299 AddMacroDef(ltMARGINPARSEP
, "marginparsep", 1);
2300 AddMacroDef(ltMARGINPARODD
, "marginparodd", 1);
2301 AddMacroDef(ltMARGINPAREVEN
, "marginpareven", 1);
2302 AddMacroDef(ltMARGINPAR
, "marginpar", 1);
2303 AddMacroDef(ltMBOX
, "mbox", 1);
2304 AddMacroDef(ltMDSERIES
, "mdseries", 1);
2305 AddMacroDef(ltMEMBERSECTION
, "membersection", 1);
2306 AddMacroDef(ltMEMBER
, "member", 2);
2307 AddMacroDef(ltMID
, "mid", 0);
2308 AddMacroDef(ltMODELS
, "models", 0);
2309 AddMacroDef(ltMP
, "mp", 0);
2310 AddMacroDef(ltMULTICOLUMN
, "multicolumn", 3);
2311 AddMacroDef(ltMU
, "mu", 0);
2313 AddMacroDef(ltNABLA
, "nabla", 0);
2314 AddMacroDef(ltNEG
, "neg", 0);
2315 AddMacroDef(ltNEQ
, "neq", 0);
2316 AddMacroDef(ltNEWCOUNTER
, "newcounter", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2317 AddMacroDef(ltNEWLINE
, "newline", 0);
2318 AddMacroDef(ltNEWPAGE
, "newpage", 0);
2319 AddMacroDef(ltNI
, "ni", 0);
2320 AddMacroDef(ltNOCITE
, "nocite", 1);
2321 AddMacroDef(ltNOINDENT
, "noindent", 0);
2322 AddMacroDef(ltNOLINEBREAK
, "nolinebreak", 0);
2323 AddMacroDef(ltNOPAGEBREAK
, "nopagebreak", 0);
2324 AddMacroDef(ltNORMALSIZE
, "normalsize", 1);
2325 AddMacroDef(ltNORMALBOX
, "normalbox", 1);
2326 AddMacroDef(ltNORMALBOXD
, "normalboxd", 1);
2327 AddMacroDef(ltNOTEQ
, "noteq", 0);
2328 AddMacroDef(ltNOTIN
, "notin", 0);
2329 AddMacroDef(ltNOTSUBSET
, "notsubset", 0);
2330 AddMacroDef(ltNU
, "nu", 0);
2332 AddMacroDef(ltODDSIDEMARGIN
, "oddsidemargin", 1);
2333 AddMacroDef(ltOMEGA
, "omega", 0);
2334 AddMacroDef(ltCAP_OMEGA
, "Omega", 0);
2335 AddMacroDef(ltONECOLUMN
, "onecolumn", 0);
2336 AddMacroDef(ltOPLUS
, "oplus", 0);
2337 AddMacroDef(ltOSLASH
, "oslash", 0);
2338 AddMacroDef(ltOTIMES
, "otimes", 0);
2340 AddMacroDef(ltPAGEBREAK
, "pagebreak", 0);
2341 AddMacroDef(ltPAGEREF
, "pageref", 1);
2342 AddMacroDef(ltPAGESTYLE
, "pagestyle", 1);
2343 AddMacroDef(ltPAGENUMBERING
, "pagenumbering", 1);
2344 AddMacroDef(ltPARAGRAPHSTAR
, "paragraph*", 1);
2345 AddMacroDef(ltPARAGRAPH
, "paragraph", 1);
2346 AddMacroDef(ltPARALLEL
, "parallel", 0);
2347 AddMacroDef(ltPARAM
, "param", 2);
2348 AddMacroDef(ltPARINDENT
, "parindent", 1);
2349 AddMacroDef(ltPARSKIP
, "parskip", 1);
2350 AddMacroDef(ltPARTIAL
, "partial", 0);
2351 AddMacroDef(ltPARTSTAR
, "part*", 1);
2352 AddMacroDef(ltPART
, "part", 1);
2353 AddMacroDef(ltPAR
, "par", 0);
2354 AddMacroDef(ltPERP
, "perp", 0);
2355 AddMacroDef(ltPHI
, "phi", 0);
2356 AddMacroDef(ltCAP_PHI
, "Phi", 0);
2357 AddMacroDef(ltPFUNC
, "pfunc", 3);
2358 AddMacroDef(ltPICTURE
, "picture", 1);
2359 AddMacroDef(ltPI
, "pi", 0);
2360 AddMacroDef(ltCAP_PI
, "Pi", 0);
2361 AddMacroDef(ltPM
, "pm", 0);
2362 AddMacroDef(ltPOPREFONLY
, "poprefonly", 1);
2363 AddMacroDef(ltPOPREF
, "popref", 2);
2364 AddMacroDef(ltPOUNDS
, "pounds", 0);
2365 AddMacroDef(ltPREC
, "prec", 0);
2366 AddMacroDef(ltPRECEQ
, "preceq", 0);
2367 AddMacroDef(ltPRINTINDEX
, "printindex", 0);
2368 AddMacroDef(ltPROPTO
, "propto", 0);
2369 AddMacroDef(ltPSBOXTO
, "psboxto", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2370 AddMacroDef(ltPSBOX
, "psbox", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2371 AddMacroDef(ltPSI
, "psi", 0);
2372 AddMacroDef(ltCAP_PSI
, "Psi", 0);
2374 AddMacroDef(ltQUOTE
, "quote", 1);
2375 AddMacroDef(ltQUOTATION
, "quotation", 1);
2377 AddMacroDef(ltRAGGEDBOTTOM
, "raggedbottom", 0);
2378 AddMacroDef(ltRAGGEDLEFT
, "raggedleft", 0);
2379 AddMacroDef(ltRAGGEDRIGHT
, "raggedright", 0);
2380 AddMacroDef(ltRBRACERAW
, "rbraceraw", 0);
2381 AddMacroDef(ltREF
, "ref", 1);
2382 AddMacroDef(ltREGISTERED
, "registered", 0);
2383 AddMacroDef(ltRE
, "we", 0);
2384 AddMacroDef(ltRHO
, "rho", 0);
2385 AddMacroDef(ltRIGHTARROW
, "rightarrow", 0);
2386 AddMacroDef(ltRIGHTARROW2
, "rightarrow2", 0);
2387 AddMacroDef(ltRMFAMILY
, "rmfamily", 1);
2388 AddMacroDef(ltRM
, "rm", 1);
2389 AddMacroDef(ltROMAN
, "roman", 1);
2390 AddMacroDef(ltROMAN2
, "Roman", 1);
2391 // AddMacroDef(lt"row", 1);
2392 AddMacroDef(ltRTFSP
, "rtfsp", 0);
2393 AddMacroDef(ltRTFIGNORE
, "rtfignore", 1);
2394 AddMacroDef(ltRTFONLY
, "rtfonly", 1);
2395 AddMacroDef(ltRULEDROW
, "ruledrow", 1);
2396 AddMacroDef(ltDRULED
, "druled", 1);
2397 AddMacroDef(ltRULE
, "rule", 2);
2398 AddMacroDef(ltRHEAD
, "rhead", 1);
2399 AddMacroDef(ltRFOOT
, "rfoot", 1);
2400 AddMacroDef(ltROW
, "row", 1);
2402 AddMacroDef(ltSCSHAPE
, "scshape", 1);
2403 AddMacroDef(ltSC
, "sc", 1);
2404 AddMacroDef(ltSECTIONHEADING
, "sectionheading", 1);
2405 AddMacroDef(ltSECTIONSTAR
, "section*", 1);
2406 AddMacroDef(ltSECTION
, "section", 1);
2407 AddMacroDef(ltSETCOUNTER
, "setcounter", 2);
2408 AddMacroDef(ltSFFAMILY
, "sffamily", 1);
2409 AddMacroDef(ltSF
, "sf", 1);
2410 AddMacroDef(ltSHARP
, "sharp", 0);
2411 AddMacroDef(ltSHORTCITE
, "shortcite", 1);
2412 AddMacroDef(ltSIGMA
, "sigma", 0);
2413 AddMacroDef(ltCAP_SIGMA
, "Sigma", 0);
2414 AddMacroDef(ltSIM
, "sim", 0);
2415 AddMacroDef(ltSIMEQ
, "simeq", 0);
2416 AddMacroDef(ltSINGLESPACE
, "singlespace", 1);
2417 AddMacroDef(ltSIZEDBOX
, "sizedbox", 2);
2418 AddMacroDef(ltSIZEDBOXD
, "sizedboxd", 2);
2419 AddMacroDef(ltSLOPPYPAR
, "sloppypar", 1);
2420 AddMacroDef(ltSLOPPY
, "sloppy", 0);
2421 AddMacroDef(ltSLSHAPE
, "slshape", 1);
2422 AddMacroDef(ltSL
, "sl", 1);
2423 AddMacroDef(ltSMALL
, "small", 1);
2424 AddMacroDef(ltSMILE
, "smile", 0);
2425 AddMacroDef(ltSS
, "ss", 0);
2426 AddMacroDef(ltSTAR
, "star", 0);
2427 AddMacroDef(ltSUBITEM
, "subitem", 0);
2428 AddMacroDef(ltSUBPARAGRAPHSTAR
, "subparagraph*", 1);
2429 AddMacroDef(ltSUBPARAGRAPH
, "subparagraph", 1);
2430 AddMacroDef(ltSPECIAL
, "special", 1);
2431 AddMacroDef(ltSUBSECTIONSTAR
, "subsection*", 1);
2432 AddMacroDef(ltSUBSECTION
, "subsection", 1);
2433 AddMacroDef(ltSUBSETEQ
, "subseteq", 0);
2434 AddMacroDef(ltSUBSET
, "subset", 0);
2435 AddMacroDef(ltSUCC
, "succ", 0);
2436 AddMacroDef(ltSUCCEQ
, "succeq", 0);
2437 AddMacroDef(ltSUPSETEQ
, "supseteq", 0);
2438 AddMacroDef(ltSUPSET
, "supset", 0);
2439 AddMacroDef(ltSUBSUBSECTIONSTAR
,"subsubsection*", 1);
2440 AddMacroDef(ltSUBSUBSECTION
, "subsubsection", 1);
2441 AddMacroDef(ltSUPERTABULAR
, "supertabular", 2, FALSE
);
2442 AddMacroDef(ltSURD
, "surd", 0);
2443 AddMacroDef(ltSCRIPTSIZE
, "scriptsize", 1);
2444 AddMacroDef(ltSETHEADER
, "setheader", 6);
2445 AddMacroDef(ltSETFOOTER
, "setfooter", 6);
2446 AddMacroDef(ltSETHOTSPOTCOLOUR
, "sethotspotcolour", 1);
2447 AddMacroDef(ltSETHOTSPOTCOLOR
, "sethotspotcolor", 1);
2448 AddMacroDef(ltSETHOTSPOTUNDERLINE
, "sethotspotunderline", 1);
2449 AddMacroDef(ltSETTRANSPARENCY
, "settransparency", 1);
2450 AddMacroDef(ltSPADESUIT
, "spadesuit", 0);
2452 AddMacroDef(ltTABBING
, "tabbing", 2);
2453 AddMacroDef(ltTABLEOFCONTENTS
, "tableofcontents", 0);
2454 AddMacroDef(ltTABLE
, "table", 1);
2455 AddMacroDef(ltTABULAR
, "tabular", 2, FALSE
);
2456 AddMacroDef(ltTAB
, "tab", 0);
2457 AddMacroDef(ltTAU
, "tau", 0);
2458 AddMacroDef(ltTEXTRM
, "textrm", 1);
2459 AddMacroDef(ltTEXTSF
, "textsf", 1);
2460 AddMacroDef(ltTEXTTT
, "texttt", 1);
2461 AddMacroDef(ltTEXTBF
, "textbf", 1);
2462 AddMacroDef(ltTEXTIT
, "textit", 1);
2463 AddMacroDef(ltTEXTSL
, "textsl", 1);
2464 AddMacroDef(ltTEXTSC
, "textsc", 1);
2465 AddMacroDef(ltTEXTWIDTH
, "textwidth", 1);
2466 AddMacroDef(ltTEXTHEIGHT
, "textheight", 1);
2467 AddMacroDef(ltTEXTCOLOUR
, "textcolour", 1);
2468 AddMacroDef(ltTEX
, "TeX", 0);
2469 AddMacroDef(ltTHEBIBLIOGRAPHY
, "thebibliography", 2);
2470 AddMacroDef(ltTHETA
, "theta", 0);
2471 AddMacroDef(ltTIMES
, "times", 0);
2472 AddMacroDef(ltCAP_THETA
, "Theta", 0);
2473 AddMacroDef(ltTITLEPAGE
, "titlepage", 1);
2474 AddMacroDef(ltTITLE
, "title", 1);
2475 AddMacroDef(ltTINY
, "tiny", 1);
2476 AddMacroDef(ltTODAY
, "today", 0);
2477 AddMacroDef(ltTOPMARGIN
, "topmargin", 1);
2478 AddMacroDef(ltTOPSKIP
, "topskip", 1);
2479 AddMacroDef(ltTRIANGLE
, "triangle", 0);
2480 AddMacroDef(ltTTFAMILY
, "ttfamily", 1);
2481 AddMacroDef(ltTT
, "tt", 1);
2482 AddMacroDef(ltTYPEIN
, "typein", 1);
2483 AddMacroDef(ltTYPEOUT
, "typeout", 1);
2484 AddMacroDef(ltTWOCOLWIDTHA
, "twocolwidtha", 1);
2485 AddMacroDef(ltTWOCOLWIDTHB
, "twocolwidthb", 1);
2486 AddMacroDef(ltTWOCOLSPACING
, "twocolspacing", 1);
2487 AddMacroDef(ltTWOCOLITEMRULED
, "twocolitemruled", 2);
2488 AddMacroDef(ltTWOCOLITEM
, "twocolitem", 2);
2489 AddMacroDef(ltTWOCOLLIST
, "twocollist", 1);
2490 AddMacroDef(ltTWOCOLUMN
, "twocolumn", 0);
2491 AddMacroDef(ltTHEPAGE
, "thepage", 0);
2492 AddMacroDef(ltTHECHAPTER
, "thechapter", 0);
2493 AddMacroDef(ltTHESECTION
, "thesection", 0);
2494 AddMacroDef(ltTHISPAGESTYLE
, "thispagestyle", 1);
2496 AddMacroDef(ltUNDERLINE
, "underline", 1);
2497 AddMacroDef(ltUPSILON
, "upsilon", 0);
2498 AddMacroDef(ltCAP_UPSILON
, "Upsilon", 0);
2499 AddMacroDef(ltUPARROW
, "uparrow", 0);
2500 AddMacroDef(ltUPARROW2
, "Uparrow", 0);
2501 AddMacroDef(ltUPPERCASE
, "uppercase", 1);
2502 AddMacroDef(ltUPSHAPE
, "upshape", 1);
2503 AddMacroDef(ltURLREF
, "urlref", 2);
2504 AddMacroDef(ltUSEPACKAGE
, "usepackage", 1);
2506 AddMacroDef(ltVAREPSILON
, "varepsilon", 0);
2507 AddMacroDef(ltVARPHI
, "varphi", 0);
2508 AddMacroDef(ltVARPI
, "varpi", 0);
2509 AddMacroDef(ltVARRHO
, "varrho", 0);
2510 AddMacroDef(ltVARSIGMA
, "varsigma", 0);
2511 AddMacroDef(ltVARTHETA
, "vartheta", 0);
2512 AddMacroDef(ltVDOTS
, "vdots", 0);
2513 AddMacroDef(ltVEE
, "vee", 0);
2514 AddMacroDef(ltVERBATIMINPUT
, "verbatiminput", 1);
2515 AddMacroDef(ltVERBATIM
, "verbatim", 1);
2516 AddMacroDef(ltVERBSTAR
, "verb*", 1);
2517 AddMacroDef(ltVERB
, "verb", 1);
2518 AddMacroDef(ltVERSE
, "verse", 1);
2519 AddMacroDef(ltVFILL
, "vfill", 0);
2520 AddMacroDef(ltVLINE
, "vline", 0);
2521 AddMacroDef(ltVOID
, "void", 0);
2522 AddMacroDef(ltVDASH
, "vdash", 0);
2523 AddMacroDef(ltVRULE
, "vrule", 0);
2524 AddMacroDef(ltVSPACESTAR
, "vspace*", 1);
2525 AddMacroDef(ltVSKIPSTAR
, "vskip*", 1);
2526 AddMacroDef(ltVSPACE
, "vspace", 1);
2527 AddMacroDef(ltVSKIP
, "vskip", 1);
2529 AddMacroDef(ltWEDGE
, "wedge", 0);
2530 AddMacroDef(ltWXCLIPS
, "wxclips", 0);
2531 AddMacroDef(ltWINHELPIGNORE
, "winhelpignore", 1);
2532 AddMacroDef(ltWINHELPONLY
, "winhelponly", 1);
2533 AddMacroDef(ltWP
, "wp", 0);
2535 AddMacroDef(ltXI
, "xi", 0);
2536 AddMacroDef(ltCAP_XI
, "Xi", 0);
2537 AddMacroDef(ltXLPIGNORE
, "xlpignore", 1);
2538 AddMacroDef(ltXLPONLY
, "xlponly", 1);
2540 AddMacroDef(ltZETA
, "zeta", 0);
2542 AddMacroDef(ltSPACE
, " ", 0);
2543 AddMacroDef(ltBACKSLASHCHAR
, "\\", 0);
2544 AddMacroDef(ltPIPE
, "|", 0);
2545 AddMacroDef(ltFORWARDSLASH
, "/", 0);
2546 AddMacroDef(ltUNDERSCORE
, "_", 0);
2547 AddMacroDef(ltAMPERSAND
, "&", 0);
2548 AddMacroDef(ltPERCENT
, "%", 0);
2549 AddMacroDef(ltDOLLAR
, "$", 0);
2550 AddMacroDef(ltHASH
, "#", 0);
2551 AddMacroDef(ltLPARENTH
, "(", 0);
2552 AddMacroDef(ltRPARENTH
, ")", 0);
2553 AddMacroDef(ltLBRACE
, "{", 0);
2554 AddMacroDef(ltRBRACE
, "}", 0);
2555 // AddMacroDef(ltEQUALS, "=", 0);
2556 AddMacroDef(ltRANGLEBRA
, ">", 0);
2557 AddMacroDef(ltLANGLEBRA
, "<", 0);
2558 AddMacroDef(ltPLUS
, "+", 0);
2559 AddMacroDef(ltDASH
, "-", 0);
2560 AddMacroDef(ltAT_SYMBOL
, "@", 0);
2561 // AddMacroDef(ltSINGLEQUOTE, "'", 0);
2562 // AddMacroDef(ltBACKQUOTE, "`", 0);
2566 * Default behaviour, should be called by client if can't match locally.
2570 // Called on start/end of macro examination
2571 void DefaultOnMacro(int macroId
, int no_args
, bool start
)
2575 // Default behaviour for abstract
2580 // Write the heading
2581 FakeCurrentSection(AbstractNameString
);
2582 OnMacro(ltPAR
, 0, TRUE
);
2583 OnMacro(ltPAR
, 0, FALSE
);
2587 if (DocumentStyle
== LATEX_ARTICLE
)
2595 // Default behaviour for glossary
2596 case ltHELPGLOSSARY
:
2600 // Write the heading
2601 FakeCurrentSection(GlossaryNameString
);
2602 OnMacro(ltPAR
, 0, TRUE
);
2603 OnMacro(ltPAR
, 0, FALSE
);
2604 if ((convertMode
== TEX_RTF
) && !winHelp
)
2606 OnMacro(ltPAR
, 0, TRUE
);
2607 OnMacro(ltPAR
, 0, FALSE
);
2612 case ltSPECIALAMPERSAND
:
2619 TexOutput("<<", TRUE
);
2623 TexOutput(">>", TRUE
);
2627 TexOutput("~", TRUE
);
2631 TexOutput("~", TRUE
);
2633 case ltSPECIALTILDE
:
2635 TexOutput(" ", TRUE
);
2639 TexOutput("_", TRUE
);
2643 TexOutput("#", TRUE
);
2647 TexOutput("&", TRUE
);
2651 TexOutput(" ", TRUE
);
2655 TexOutput("|", TRUE
);
2659 TexOutput("%", TRUE
);
2663 TexOutput("$", TRUE
);
2667 TexOutput("", TRUE
);
2671 TexOutput("", TRUE
);
2675 TexOutput("{", TRUE
);
2679 TexOutput("}", TRUE
);
2683 TexOutput("(c)", TRUE
);
2687 TexOutput("(r)", TRUE
);
2691 TexOutput("\\", TRUE
);
2696 TexOutput("...", TRUE
);
2700 TexOutput("|", TRUE
);
2704 TexOutput("LaTeX", TRUE
);
2708 TexOutput("TeX", TRUE
);
2712 TexOutput("£", TRUE
);
2714 case ltSPECIALDOUBLEDOLLAR
: // Interpret as center
2715 OnMacro(ltCENTER
, no_args
, start
);
2721 OnMacro(ltIT
, no_args
, start
);
2724 case ltPARAGRAPHSTAR
:
2725 case ltSUBPARAGRAPH
:
2726 case ltSUBPARAGRAPHSTAR
:
2727 OnMacro(ltSUBSUBSECTION
, no_args
, start
);
2735 TexOutput(ctime(&when
), TRUE
);
2746 if (start
) TexOutput("alpha");
2749 if (start
) TexOutput("beta");
2752 if (start
) TexOutput("gamma");
2755 if (start
) TexOutput("delta");
2759 if (start
) TexOutput("epsilon");
2762 if (start
) TexOutput("zeta");
2765 if (start
) TexOutput("eta");
2769 if (start
) TexOutput("theta");
2772 if (start
) TexOutput("iota");
2775 if (start
) TexOutput("kappa");
2778 if (start
) TexOutput("lambda");
2781 if (start
) TexOutput("mu");
2784 if (start
) TexOutput("nu");
2787 if (start
) TexOutput("xi");
2791 if (start
) TexOutput("pi");
2795 if (start
) TexOutput("rho");
2799 if (start
) TexOutput("sigma");
2802 if (start
) TexOutput("tau");
2805 if (start
) TexOutput("upsilon");
2809 if (start
) TexOutput("phi");
2812 if (start
) TexOutput("chi");
2815 if (start
) TexOutput("psi");
2818 if (start
) TexOutput("omega");
2821 if (start
) TexOutput("GAMMA");
2824 if (start
) TexOutput("DELTA");
2827 if (start
) TexOutput("THETA");
2830 if (start
) TexOutput("LAMBDA");
2833 if (start
) TexOutput("XI");
2836 if (start
) TexOutput("PI");
2839 if (start
) TexOutput("SIGMA");
2842 if (start
) TexOutput("UPSILON");
2845 if (start
) TexOutput("PHI");
2848 if (start
) TexOutput("PSI");
2851 if (start
) TexOutput("OMEGA");
2854 // Binary operation symbols
2857 if (start
) TexOutput("<=");
2860 if (start
) TexOutput("<<");
2863 if (start
) TexOutput("SUBSET");
2866 if (start
) TexOutput("SUBSETEQ");
2869 if (start
) TexOutput("IN");
2872 if (start
) TexOutput("VDASH");
2875 if (start
) TexOutput("MODELS");
2879 if (start
) TexOutput(">=");
2882 if (start
) TexOutput(">>");
2885 if (start
) TexOutput("SUPSET");
2888 if (start
) TexOutput("SUPSETEQ");
2891 if (start
) TexOutput("NI");
2894 if (start
) TexOutput("DASHV");
2897 if (start
) TexOutput("PERP");
2900 if (start
) TexOutput("NEQ");
2903 if (start
) TexOutput("DOTEQ");
2906 if (start
) TexOutput("APPROX");
2909 if (start
) TexOutput("CONG");
2912 if (start
) TexOutput("EQUIV");
2915 if (start
) TexOutput("PROPTO");
2918 if (start
) TexOutput("PREC");
2921 if (start
) TexOutput("PRECEQ");
2924 if (start
) TexOutput("|");
2927 if (start
) TexOutput("~");
2930 if (start
) TexOutput("SIMEQ");
2933 if (start
) TexOutput("ASYMP");
2936 if (start
) TexOutput(":-)");
2939 if (start
) TexOutput(":-(");
2942 if (start
) TexOutput("SUCC");
2945 if (start
) TexOutput("SUCCEQ");
2948 if (start
) TexOutput("|");
2951 // Negated relation symbols
2953 if (start
) TexOutput("!=");
2956 if (start
) TexOutput("NOTIN");
2959 if (start
) TexOutput("NOTSUBSET");
2964 if (start
) TexOutput("<--");
2967 if (start
) TexOutput("<==");
2970 if (start
) TexOutput("-->");
2973 if (start
) TexOutput("==>");
2975 case ltLEFTRIGHTARROW
:
2976 if (start
) TexOutput("<-->");
2978 case ltLEFTRIGHTARROW2
:
2979 if (start
) TexOutput("<==>");
2982 if (start
) TexOutput("UPARROW");
2985 if (start
) TexOutput("UPARROW2");
2988 if (start
) TexOutput("DOWNARROW");
2991 if (start
) TexOutput("DOWNARROW2");
2993 // Miscellaneous symbols
2995 if (start
) TexOutput("ALEPH");
2998 if (start
) TexOutput("WP");
3001 if (start
) TexOutput("RE");
3004 if (start
) TexOutput("IM");
3007 if (start
) TexOutput("EMPTYSET");
3010 if (start
) TexOutput("NABLA");
3013 if (start
) TexOutput("SURD");
3016 if (start
) TexOutput("PARTIAL");
3019 if (start
) TexOutput("BOT");
3022 if (start
) TexOutput("FORALL");
3025 if (start
) TexOutput("EXISTS");
3028 if (start
) TexOutput("NEG");
3031 if (start
) TexOutput("SHARP");
3034 if (start
) TexOutput("ANGLE");
3037 if (start
) TexOutput("TRIANGLE");
3040 if (start
) TexOutput("CLUBSUIT");
3043 if (start
) TexOutput("DIAMONDSUIT");
3046 if (start
) TexOutput("HEARTSUIT");
3049 if (start
) TexOutput("SPADESUIT");
3052 if (start
) TexOutput("INFTY");
3055 if (start
) TexOutput("PM");
3058 if (start
) TexOutput("MP");
3061 if (start
) TexOutput("TIMES");
3064 if (start
) TexOutput("DIV");
3067 if (start
) TexOutput("CDOT");
3070 if (start
) TexOutput("AST");
3073 if (start
) TexOutput("STAR");
3076 if (start
) TexOutput("CAP");
3079 if (start
) TexOutput("CUP");
3082 if (start
) TexOutput("VEE");
3085 if (start
) TexOutput("WEDGE");
3088 if (start
) TexOutput("CIRC");
3091 if (start
) TexOutput("BULLET");
3094 if (start
) TexOutput("DIAMOND");
3097 if (start
) TexOutput("OSLASH");
3100 if (start
) TexOutput("BOX");
3103 if (start
) TexOutput("DIAMOND2");
3105 case ltBIGTRIANGLEDOWN
:
3106 if (start
) TexOutput("BIGTRIANGLEDOWN");
3109 if (start
) TexOutput("OPLUS");
3112 if (start
) TexOutput("OTIMES");
3115 if (start
) TexOutput("s");
3117 case ltBACKSLASHRAW
:
3118 if (start
) TexOutput("\\");
3121 if (start
) TexOutput("{");
3124 if (start
) TexOutput("}");
3128 if (start
) TexOutput(" ");
3135 // Called on start/end of argument examination
3136 bool DefaultOnArgument(int macroId
, int arg_no
, bool start
)
3142 if (arg_no
== 1 && start
)
3144 char *refName
= GetArgData();
3147 TexRef
*texRef
= FindReference(refName
);
3150 // Must strip the 'section' or 'chapter' or 'figure' text
3151 // from a normal 'ref' reference
3153 strcpy(buf
, texRef
->sectionNumber
);
3154 int len
= strlen(buf
);
3156 if (strcmp(buf
, "??") != 0)
3168 TexOutput(texRef
->sectionNumber
+ i
, TRUE
);
3173 informBuf
.Printf("Warning: unresolved reference '%s'", refName
);
3174 OnInform((char *)informBuf
.c_str());
3177 else TexOutput("??", TRUE
);
3189 if (start
&& (arg_no
== 1))
3190 DocumentAuthor
= GetArgChunk();
3196 if (start
&& (arg_no
== 1))
3197 DocumentDate
= GetArgChunk();
3203 if (start
&& (arg_no
== 1))
3204 DocumentTitle
= GetArgChunk();
3208 case ltDOCUMENTCLASS
:
3209 case ltDOCUMENTSTYLE
:
3211 if (start
&& !IsArgOptional())
3213 DocumentStyleString
= copystring(GetArgData());
3214 if (strncmp(DocumentStyleString
, "art", 3) == 0)
3215 DocumentStyle
= LATEX_ARTICLE
;
3216 else if (strncmp(DocumentStyleString
, "rep", 3) == 0)
3217 DocumentStyle
= LATEX_REPORT
;
3218 else if (strncmp(DocumentStyleString
, "book", 4) == 0 ||
3219 strncmp(DocumentStyleString
, "thesis", 6) == 0)
3220 DocumentStyle
= LATEX_BOOK
;
3221 else if (strncmp(DocumentStyleString
, "letter", 6) == 0)
3222 DocumentStyle
= LATEX_LETTER
;
3223 else if (strncmp(DocumentStyleString
, "slides", 6) == 0)
3224 DocumentStyle
= LATEX_SLIDES
;
3226 if (StringMatch("10", DocumentStyleString
))
3228 else if (StringMatch("11", DocumentStyleString
))
3230 else if (StringMatch("12", DocumentStyleString
))
3233 OnMacro(ltHELPFONTSIZE
, 1, TRUE
);
3234 sprintf(currentArgData
, "%d", normalFont
);
3236 OnArgument(ltHELPFONTSIZE
, 1, TRUE
);
3237 OnArgument(ltHELPFONTSIZE
, 1, FALSE
);
3238 haveArgData
= FALSE
;
3239 OnMacro(ltHELPFONTSIZE
, 1, FALSE
);
3241 else if (start
&& IsArgOptional())
3243 MinorDocumentStyleString
= copystring(GetArgData());
3245 if (StringMatch("10", MinorDocumentStyleString
))
3247 else if (StringMatch("11", MinorDocumentStyleString
))
3249 else if (StringMatch("12", MinorDocumentStyleString
))
3255 case ltBIBLIOGRAPHYSTYLE
:
3257 if (start
&& !IsArgOptional())
3258 BibliographyStyleString
= copystring(GetArgData());
3264 if (start
&& !IsArgOptional())
3266 if (PageStyle
) delete[] PageStyle
;
3267 PageStyle
= copystring(GetArgData());
3275 if (start && !IsArgOptional())
3276 LeftHeader = GetArgChunk();
3282 if (start && !IsArgOptional())
3283 LeftFooter = GetArgChunk();
3289 if (start && !IsArgOptional())
3290 CentreHeader = GetArgChunk();
3296 if (start && !IsArgOptional())
3297 CentreFooter = GetArgChunk();
3303 if (start && !IsArgOptional())
3304 RightHeader = GetArgChunk();
3310 if (start && !IsArgOptional())
3311 RightFooter = GetArgChunk();
3319 if (start
&& !IsArgOptional())
3321 char *citeKeys
= GetArgData();
3323 char *citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3326 AddCitation(citeKey
);
3327 TexRef
*ref
= FindReference(citeKey
);
3330 TexOutput(ref
->sectionNumber
, TRUE
);
3331 if (strcmp(ref
->sectionNumber
, "??") == 0)
3334 informBuf
.Printf("Warning: unresolved citation %s.", citeKey
);
3335 OnInform((char *)informBuf
.c_str());
3338 citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3341 TexOutput(", ", TRUE
);
3350 if (start
&& !IsArgOptional())
3352 char *citeKey
= GetArgData();
3353 AddCitation(citeKey
);
3358 case ltHELPFONTSIZE
:
3362 char *data
= GetArgData();
3363 if (strcmp(data
, "10") == 0)
3365 else if (strcmp(data
, "11") == 0)
3367 else if (strcmp(data
, "12") == 0)
3377 TexOutput(" ??", TRUE
);
3384 if (start
&& arg_no
== 1)
3386 char *data
= GetArgData();
3387 ParSkip
= ParseUnitArgument(data
);
3394 if (start
&& arg_no
== 1)
3396 char *data
= GetArgData();
3397 ParIndent
= ParseUnitArgument(data
);
3404 return OnArgument(ltIT
, arg_no
, start
);
3407 case ltSPECIALDOUBLEDOLLAR
:
3409 return OnArgument(ltCENTER
, arg_no
, start
);
3413 case ltPARAGRAPHSTAR
:
3414 case ltSUBPARAGRAPH
:
3415 case ltSUBPARAGRAPHSTAR
:
3417 return OnArgument(ltSUBSUBSECTION
, arg_no
, start
);
3423 OnInform(GetArgData());
3429 TexOutput(" (", TRUE
);
3431 TexOutput(")", TRUE
);
3434 case ltBIBLIOGRAPHY
:
3442 if ((fd
= fopen(TexBibName
, "r")))
3448 TexOutput(smallBuf
);
3456 OnInform("Run Tex2RTF again to include bibliography.");
3459 // Read in the .bib file, resolve all known references, write out the RTF.
3460 char *allFiles
= GetArgData();
3462 char *bibFile
= ParseMultifieldString(allFiles
, &pos
);
3466 strcpy(fileBuf
, bibFile
);
3467 wxString actualFile
= TexPathList
.FindValidPath(fileBuf
);
3468 if (actualFile
== "")
3470 strcat(fileBuf
, ".bib");
3471 actualFile
= TexPathList
.FindValidPath(fileBuf
);
3473 if (actualFile
!= "")
3475 if (!ReadBib((char*) (const char*) actualFile
))
3478 errBuf
.Printf(".bib file %s not found or malformed", (const char*) actualFile
);
3479 OnError((char *)errBuf
.c_str());
3485 errBuf
.Printf(".bib file %s not found", fileBuf
);
3486 OnError((char *)errBuf
.c_str());
3488 bibFile
= ParseMultifieldString(allFiles
, &pos
);
3491 ResolveBibReferences();
3493 // Write it a new bib section in the appropriate format.
3494 FILE *save1
= CurrentOutput1
;
3495 FILE *save2
= CurrentOutput2
;
3496 FILE *Biblio
= fopen(TexTmpBibName
, "w");
3497 SetCurrentOutput(Biblio
);
3500 if (wxFileExists(TexTmpBibName
))
3502 if (wxFileExists(TexBibName
)) wxRemoveFile(TexBibName
);
3503 wxRenameFile(TexTmpBibName
, TexBibName
);
3505 SetCurrentOutputs(save1
, save2
);
3512 if (start
&& (arg_no
== 3))
3522 if (start
&& (arg_no
== 1))
3524 char *s
= GetArgData();
3527 char *s1
= copystring(s
);
3529 for (i
= 0; i
< (int)strlen(s
); i
++)
3530 s1
[i
] = toupper(s
[i
]);
3543 if (start
&& (arg_no
== 1))
3545 char *s
= GetArgData();
3548 char *s1
= copystring(s
);
3550 for (i
= 0; i
< (int)strlen(s
); i
++)
3551 s1
[i
] = tolower(s
[i
]);
3564 if (start
&& (arg_no
== 1))
3566 char *s
= GetArgData();
3569 char *s1
= copystring(s
);
3571 for (i
= 0; i
< (int)strlen(s
); i
++)
3572 s1
[i
] = toupper(s
[i
]);
3583 case ltPOPREF
: // Ignore second argument by default
3585 if (start
&& (arg_no
== 1))
3595 return ((convertMode
== TEX_XLP
) ? FALSE
: TRUE
);
3598 return ((convertMode
!= TEX_XLP
) ? FALSE
: TRUE
);
3601 return ((convertMode
== TEX_HTML
) ? FALSE
: TRUE
);
3604 return ((convertMode
!= TEX_HTML
) ? FALSE
: TRUE
);
3607 return (((convertMode
== TEX_RTF
) && !winHelp
) ? FALSE
: TRUE
);
3610 return (!((convertMode
== TEX_RTF
) && !winHelp
) ? FALSE
: TRUE
);
3612 case ltWINHELPIGNORE
:
3613 return (winHelp
? FALSE
: TRUE
);
3616 return (!winHelp
? FALSE
: TRUE
);
3631 case ltADDTOCOUNTER
:
3632 case ltADDCONTENTSLINE
:
3636 case ltBASELINESKIP
:
3645 case ltPAGENUMBERING
:
3657 case ltTHISPAGESTYLE
:
3660 case ltEVENSIDEMARGIN
:
3661 case ltODDSIDEMARGIN
:
3663 case ltMARGINPARWIDTH
:
3664 case ltMARGINPARSEP
:
3665 case ltMARGINPAREVEN
:
3666 case ltMARGINPARODD
:
3667 case ltTWOCOLWIDTHA
:
3668 case ltTWOCOLWIDTHB
:
3669 case ltTWOCOLSPACING
:
3676 case ltSETHOTSPOTCOLOUR
:
3677 case ltSETHOTSPOTCOLOR
:
3678 case ltSETHOTSPOTUNDERLINE
:
3679 case ltSETTRANSPARENCY
:
3682 case ltBACKGROUNDCOLOUR
:
3683 case ltBACKGROUNDIMAGE
:
3685 case ltFOLLOWEDLINKCOLOUR
:
3692 case ltINSERTATLEVEL
:
3696 case ltSUPERTABULAR
:
3705 if (arg_no
== 2) return TRUE
;
3712 if (arg_no
== 2) return TRUE
;
3716 case ltDEFINECOLOUR
:
3719 static int redVal
= 0;
3720 static int greenVal
= 0;
3721 static int blueVal
= 0;
3722 static char *colourName
= NULL
;
3729 if (colourName
) delete[] colourName
;
3730 colourName
= copystring(GetArgData());
3735 redVal
= atoi(GetArgData());
3740 greenVal
= atoi(GetArgData());
3745 blueVal
= atoi(GetArgData());
3746 AddColour(colourName
, redVal
, greenVal
, blueVal
);
3762 if (IsArgOptional())