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"
31 #if !WXWIN_COMPATIBILITY_2_4
32 static inline wxChar
* copystring(const wxChar
* s
)
33 { return wxStrcpy(new wxChar
[wxStrlen(s
) + 1], s
); }
37 * Variables accessible from clients
41 TexChunk
* DocumentTitle
= NULL
;
42 TexChunk
* DocumentAuthor
= NULL
;
43 TexChunk
* DocumentDate
= NULL
;
45 // Header/footers/pagestyle
46 TexChunk
* LeftHeaderEven
= NULL
;
47 TexChunk
* LeftFooterEven
= NULL
;
48 TexChunk
* CentreHeaderEven
= NULL
;
49 TexChunk
* CentreFooterEven
= NULL
;
50 TexChunk
* RightHeaderEven
= NULL
;
51 TexChunk
* RightFooterEven
= NULL
;
52 TexChunk
* LeftHeaderOdd
= NULL
;
53 TexChunk
* LeftFooterOdd
= NULL
;
54 TexChunk
* CentreHeaderOdd
= NULL
;
55 TexChunk
* CentreFooterOdd
= NULL
;
56 TexChunk
* RightHeaderOdd
= NULL
;
57 TexChunk
* RightFooterOdd
= NULL
;
58 char * PageStyle
= copystring("plain");
60 int DocumentStyle
= LATEX_REPORT
;
61 int MinorDocumentStyle
= 0;
62 wxPathList TexPathList
;
63 char * BibliographyStyleString
= copystring("plain");
64 char * DocumentStyleString
= copystring("report");
65 char * MinorDocumentStyleString
= NULL
;
79 // All of these tokens MUST be found on a line by themselves (no other
80 // text) and must start at the first character of the line, or tex2rtf
81 // will fail to process them correctly (a limitation of tex2rtf, not TeX)
82 static const wxString syntaxTokens
[] =
83 { "\\begin{verbatim}",
84 "\\begin{toocomplex}",
100 * USER-ADJUSTABLE SETTINGS
104 // Section font sizes
105 int chapterFont
= 12; // LARGEFont3;
106 int sectionFont
= 12; // LargeFont2;
107 int subsectionFont
= 12; // largeFont1;
108 int titleFont
= LARGEFont3
;
109 int authorFont
= LargeFont2
;
110 int mirrorMargins
= TRUE
;
111 bool winHelp
= FALSE
; // Output in Windows Help format if TRUE, linear otherwise
112 bool isInteractive
= FALSE
;
113 bool runTwice
= FALSE
;
114 int convertMode
= TEX_RTF
;
115 bool checkCurleyBraces
= FALSE
;
116 bool checkSyntax
= FALSE
;
117 bool headerRule
= FALSE
;
118 bool footerRule
= FALSE
;
119 bool compatibilityMode
= FALSE
; // If TRUE, maximum Latex compatibility
120 // (Quality of RTF generation deteriorate)
121 bool generateHPJ
; // Generate WinHelp Help Project file
122 char *winHelpTitle
= NULL
; // Windows Help title
123 int defaultTableColumnWidth
= 2000;
125 int labelIndentTab
= 18; // From left indent to item label (points)
126 int itemIndentTab
= 40; // From left indent to item (points)
128 bool useUpButton
= TRUE
;
129 int htmlBrowseButtons
= HTML_BUTTONS_TEXT
;
131 bool truncateFilenames
= FALSE
; // Truncate for DOS
132 int winHelpVersion
= 3; // WinHelp Version (3 for Windows 3.1, 4 for Win95)
133 bool winHelpContents
= FALSE
; // Generate .cnt file for WinHelp 4
134 bool htmlIndex
= FALSE
; // Generate .htx file for HTML
135 bool htmlFrameContents
= FALSE
; // Use frames for HTML contents page
136 char *htmlStylesheet
= NULL
; // Use this CSS stylesheet for HTML pages
137 bool useHeadingStyles
= TRUE
; // Insert \s1, s2 etc.
138 bool useWord
= TRUE
; // Insert proper Word table of contents, etc etc
139 int contentsDepth
= 4; // Depth of Word table of contents
140 bool indexSubsections
= TRUE
; // Index subsections in linear RTF
141 // Linear RTF method of including bitmaps. Can be "includepicture", "hex"
142 char *bitmapMethod
= copystring("includepicture");
143 bool upperCaseNames
= FALSE
;
144 // HTML background and text colours
145 char *backgroundImageString
= NULL
;
146 char *backgroundColourString
= copystring("255;255;255");
147 char *textColourString
= NULL
;
148 char *linkColourString
= NULL
;
149 char *followedLinkColourString
= NULL
;
150 bool combineSubSections
= FALSE
;
151 bool htmlWorkshopFiles
= FALSE
;
152 bool ignoreBadRefs
= FALSE
;
153 char *htmlFaceName
= NULL
;
155 extern int passNumber
;
157 extern wxHashTable TexReferences
;
160 * International support
163 // Names to help with internationalisation
164 char *ContentsNameString
= copystring("Contents");
165 char *AbstractNameString
= copystring("Abstract");
166 char *GlossaryNameString
= copystring("Glossary");
167 char *ReferencesNameString
= copystring("References");
168 char *FiguresNameString
= copystring("List of Figures");
169 char *TablesNameString
= copystring("List of Tables");
170 char *FigureNameString
= copystring("Figure");
171 char *TableNameString
= copystring("Table");
172 char *IndexNameString
= copystring("Index");
173 char *ChapterNameString
= copystring("chapter");
174 char *SectionNameString
= copystring("section");
175 char *SubsectionNameString
= copystring("subsection");
176 char *SubsubsectionNameString
= copystring("subsubsection");
177 char *UpNameString
= copystring("Up");
186 int subsectionNo
= 0;
187 int subsubsectionNo
= 0;
196 FILE *CurrentOutput1
= NULL
;
197 FILE *CurrentOutput2
= NULL
;
199 unsigned long LineNumbers
[15];
201 int CurrentInputIndex
= 0;
203 char *TexFileRoot
= NULL
;
204 char *TexBibName
= NULL
; // Bibliography output file name
205 char *TexTmpBibName
= NULL
; // Temporary bibliography output file name
206 bool isSync
= FALSE
; // If TRUE, should not yield to other processes.
207 bool stopRunning
= FALSE
; // If TRUE, should abort.
209 static int currentColumn
= 0;
210 char *currentArgData
= NULL
;
211 bool haveArgData
= FALSE
; // If TRUE, we're simulating the data.
212 TexChunk
*currentArgument
= NULL
;
213 TexChunk
*nextChunk
= NULL
;
214 bool isArgOptional
= FALSE
;
217 TexChunk
*TopLevel
= NULL
;
218 // wxList MacroDefs(wxKEY_STRING);
219 wxHashTable
MacroDefs(wxKEY_STRING
);
220 wxStringList IgnorableInputFiles
; // Ignorable \input files, e.g. psbox.tex
221 char *BigBuffer
= NULL
; // For reading in large chunks of text
222 TexMacroDef
*SoloBlockDef
= NULL
;
223 TexMacroDef
*VerbatimMacroDef
= NULL
;
225 #define IncrementLineNumber() LineNumbers[CurrentInputIndex] ++
228 TexRef::TexRef(const char *label
, const char *file
,
229 const char *section
, const char *sectionN
)
231 refLabel
= copystring(label
);
232 refFile
= file
? copystring(file
) : (char*) NULL
;
233 sectionNumber
= section
? copystring(section
) : copystring("??");
234 sectionName
= sectionN
? copystring(sectionN
) : copystring("??");
237 TexRef::~TexRef(void)
239 delete [] refLabel
; refLabel
= NULL
;
240 delete [] refFile
; refFile
= NULL
;
241 delete [] sectionNumber
; sectionNumber
= NULL
;
242 delete [] sectionName
; sectionName
= NULL
;
246 CustomMacro::~CustomMacro()
254 void TexOutput(const char *s
, bool ordinaryText
)
258 // Update current column, but only if we're guaranteed to
259 // be ordinary text (not mark-up stuff)
262 for (i
= 0; i
< len
; i
++)
264 if (s
[i
] == 13 || s
[i
] == 10)
271 fprintf(CurrentOutput1
, "%s", s
);
273 fprintf(CurrentOutput2
, "%s", s
);
277 * Try to find a Latex macro, in one of the following forms:
278 * (1) \begin{} ... \end{}
279 * (2) \macroname{arg1}...{argn}
283 void ForbidWarning(TexMacroDef
*def
)
286 switch (def
->forbidden
)
290 informBuf
.Printf("Warning: it is recommended that command %s is not used.", def
->name
);
291 OnInform((char *)informBuf
.c_str());
294 case FORBID_ABSOLUTELY
:
296 informBuf
.Printf("Error: command %s cannot be used and will lead to errors.", def
->name
);
297 OnInform((char *)informBuf
.c_str());
305 TexMacroDef
*MatchMacro(char *buffer
, int *pos
, char **env
, bool *parseToBrace
)
307 *parseToBrace
= TRUE
;
309 TexMacroDef
*def
= NULL
;
312 // First, try to find begin{thing}
313 if (strncmp(buffer
+i
, "begin{", 6) == 0)
318 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
320 macroBuf
[j
-i
] = buffer
[j
];
324 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
328 *pos
= j
+ 1; // BUGBUG Should this be + 1???
336 // Failed, so try to find macro from definition list
339 // First try getting a one-character macro, but ONLY
340 // if these TWO characters are not both alphabetical (could
341 // be a longer macro)
342 if (!(isalpha(buffer
[i
]) && isalpha(buffer
[i
+1])))
344 macroBuf
[0] = buffer
[i
];
347 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
353 while ((isalpha(buffer
[j
]) || buffer
[j
] == '*') && ((j
- i
) < 39))
355 macroBuf
[j
-i
] = buffer
[j
];
359 def
= (TexMacroDef
*)MacroDefs
.Get(macroBuf
);
366 // We want to check whether this is a space-consuming macro
368 // No brace, e.g. \input thing.tex instead of \input{thing};
369 // or a numeric argument, such as \parindent0pt
370 if ((def
->no_args
> 0) && ((buffer
[i
] == 32) || (buffer
[i
] == '=') || (isdigit(buffer
[i
]))))
372 if ((buffer
[i
] == 32) || (buffer
[i
] == '='))
375 *parseToBrace
= FALSE
;
384 void EatWhiteSpace(char *buffer
, int *pos
)
386 int len
= strlen(buffer
);
388 bool keepGoing
= TRUE
;
389 bool moreLines
= TRUE
;
390 while ((j
< len
) && keepGoing
&&
391 (buffer
[j
] == 10 || buffer
[j
] == 13 || buffer
[j
] == ' ' || buffer
[j
] == 9))
398 moreLines
= read_a_line(buffer
);
399 len
= strlen(buffer
);
409 bool FindEndEnvironment(char *buffer
, int *pos
, char *env
)
413 // Try to find end{thing}
414 if ((strncmp(buffer
+i
, "end{", 4) == 0) &&
415 (strncmp(buffer
+i
+4, env
, strlen(env
)) == 0))
417 *pos
= i
+ 5 + strlen(env
);
423 bool readingVerbatim
= FALSE
;
424 bool readInVerbatim
= FALSE
; // Within a verbatim, but not nec. verbatiminput
426 // Switched this off because e.g. \verb${$ causes it to fail. There is no
427 // detection of \verb yet.
428 // #define CHECK_BRACES 1
430 unsigned long leftCurley
= 0;
431 unsigned long rightCurley
= 0;
432 static wxString currentFileName
= "";
434 bool read_a_line(char *buf
)
436 if (CurrentInputIndex
< 0)
443 unsigned long bufIndex
= 0;
446 while (ch
!= EOF
&& ch
!= 10)
448 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
451 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
452 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(), MAX_LINE_BUFFER_SIZE
);
453 OnError((char *)errBuf
.c_str());
457 if (((bufIndex
== 14) && (strncmp(buf
, "\\end{verbatim}", 14) == 0)) ||
458 ((bufIndex
== 16) && (strncmp(buf
, "\\end{toocomplex}", 16) == 0)))
459 readInVerbatim
= FALSE
;
461 ch
= getc(Inputs
[CurrentInputIndex
]);
463 if (checkCurleyBraces
)
465 if (ch
== '{' && !readInVerbatim
)
467 if (ch
== '}' && !readInVerbatim
)
470 if (rightCurley
> leftCurley
)
473 errBuf
.Printf("An extra right Curley brace ('}') was detected at line %lu inside file %s", LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str());
474 OnError((char *)errBuf
.c_str());
476 // Reduce the count of right Curley braces, so the mismatched count
477 // isn't reported on every line that has a '}' after the first mismatch
485 // Check for 2 consecutive newlines and replace with \par
486 if (ch
== 10 && !readInVerbatim
)
488 int ch1
= getc(Inputs
[CurrentInputIndex
]);
489 if ((ch1
== 10) || (ch1
== 13))
491 // Eliminate newline (10) following DOS linefeed
493 ch1
= getc(Inputs
[CurrentInputIndex
]);
495 IncrementLineNumber();
496 // strcat(buf, "\\par\n");
498 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
501 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
502 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
503 OnError((char *)errBuf
.c_str());
506 strcat(buf
, "\\par");
512 ungetc(ch1
, Inputs
[CurrentInputIndex
]);
513 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
516 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
517 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
518 OnError((char *)errBuf
.c_str());
529 // Convert embedded characters to RTF equivalents
538 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
541 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
542 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
543 OnError((char *)errBuf
.c_str());
546 buf
[bufIndex
++]='\\';
551 case 0xf6:buf
[bufIndex
++]='o';break; // ö
552 case 0xe4:buf
[bufIndex
++]='a';break; // ä
553 case 0xfc:buf
[bufIndex
++]='u';break; // ü
554 case 0xd6:buf
[bufIndex
++]='O';break; // Ö
555 case 0xc4:buf
[bufIndex
++]='A';break; // Ä
556 case 0xdc:buf
[bufIndex
++]='U';break; // Ü
561 if (bufIndex
+5 >= MAX_LINE_BUFFER_SIZE
)
564 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
565 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
566 OnError((char *)errBuf
.c_str());
569 buf
[bufIndex
++]='\\';
572 buf
[bufIndex
++]='\\';
576 if (bufIndex
>= MAX_LINE_BUFFER_SIZE
)
579 errBuf
.Printf("Line %lu of file %s is too long. Lines can be no longer than %lu characters. Truncated.",
580 LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str(),MAX_LINE_BUFFER_SIZE
);
581 OnError((char *)errBuf
.c_str());
584 // If the current character read in is a '_', we need to check
585 // whether there should be a '\' before it or not
588 buf
[bufIndex
++] = ch
;
596 // There should NOT be a '\' before the '_'
597 if ((bufIndex
> 0 && (buf
[bufIndex
-1] == '\\')) && (buf
[0] != '%'))
600 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());
601 OnError((char *)errBuf
.c_str());
606 // There should be a '\' before the '_'
610 errBuf
.Printf("An underscore ('_') was detected at line %lu inside file %s that may need a '\\' before it.",LineNumbers
[CurrentInputIndex
], (const char*) currentFileName
.c_str());
611 OnError((char *)errBuf
.c_str());
613 else if ((buf
[bufIndex
-1] != '\\') && (buf
[0] != '%') && // If it is a comment line, then no warnings
614 (strncmp(buf
, "\\input", 6))) // do not report filenames that have underscores in them
617 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());
618 OnError((char *)errBuf
.c_str());
622 buf
[bufIndex
++] = ch
;
630 fclose(Inputs
[CurrentInputIndex
]);
631 Inputs
[CurrentInputIndex
] = NULL
;
632 if (CurrentInputIndex
> 0)
633 ch
= ' '; // No real end of file
634 CurrentInputIndex
--;
636 if (checkCurleyBraces
)
638 if (leftCurley
!= rightCurley
)
641 errBuf
.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName
.c_str(),leftCurley
,rightCurley
);
642 OnError((char *)errBuf
.c_str());
650 readingVerbatim
= FALSE
;
651 readInVerbatim
= FALSE
;
652 strcat(buf
, "\\end{verbatim}\n");
657 IncrementLineNumber();
661 // Strip out comment environment
662 if (strncmp(buf
, "\\begin{comment}", 15) == 0)
664 while (strncmp(buf
, "\\end{comment}", 13) != 0)
666 return read_a_line(buf
);
668 // Read a verbatim input file as if it were a verbatim environment
669 else if (strncmp(buf
, "\\verbatiminput", 14) == 0)
672 char *fileName
= buf
+ wordLen
+ 1;
674 int j
= bufIndex
- 1;
677 // thing}\par -- eliminate the \par!
678 if (strncmp((buf
+ strlen(buf
)-5), "\\par", 4) == 0)
685 buf
[j
-1] = 0; // Ignore final brace
687 wxString actualFile
= TexPathList
.FindValidPath(fileName
);
688 currentFileName
= actualFile
;
689 if (actualFile
== "")
692 errBuf
.Printf("Could not find file: %s",fileName
);
693 OnError((char *)errBuf
.c_str());
698 informStr
.Printf("Processing: %s",actualFile
.c_str());
699 OnInform((char *)informStr
.c_str());
700 CurrentInputIndex
++;
702 Inputs
[CurrentInputIndex
] = fopen(actualFile
, "r");
703 LineNumbers
[CurrentInputIndex
] = 1;
704 if (FileNames
[CurrentInputIndex
])
705 delete[] FileNames
[CurrentInputIndex
];
706 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
708 if (!Inputs
[CurrentInputIndex
])
710 CurrentInputIndex
--;
711 OnError("Could not open verbatiminput file.");
715 readingVerbatim
= TRUE
;
716 readInVerbatim
= TRUE
;
717 strcpy(buf
, "\\begin{verbatim}\n");
723 else if (strncmp(buf
, "\\input", 6) == 0 || strncmp(buf
, "\\helpinput", 10) == 0 ||
724 strncmp(buf
, "\\include", 8) == 0)
727 if (strncmp(buf
, "\\input", 6) == 0)
730 if (strncmp(buf
, "\\include", 8) == 0)
735 char *fileName
= buf
+ wordLen
+ 1;
737 int j
= bufIndex
- 1;
740 // \input{thing}\par -- eliminate the \par!
741 // if (strncmp((buf + strlen(buf)-5), "\\par", 4) == 0)
742 if (strncmp((buf
+ strlen(buf
)-4), "\\par", 4) == 0) // Bug fix 8/2/95 Ulrich Leodolter
750 buf
[j
-1] = 0; // Ignore final brace
752 // Remove backslashes from name
753 wxString
fileNameStr(fileName
);
754 fileNameStr
.Replace("\\", "");
756 // Ignore some types of input files (e.g. macro definition files)
757 char *fileOnly
= wxFileNameFromPath((char*) (const char*) fileNameStr
);
758 currentFileName
= fileOnly
;
759 if (IgnorableInputFiles
.Member(fileOnly
))
760 return read_a_line(buf
);
762 wxString actualFile
= TexPathList
.FindValidPath(fileNameStr
);
763 if (actualFile
== "")
766 sprintf(buf2
, "%s.tex", (const char*) fileNameStr
);
767 actualFile
= TexPathList
.FindValidPath(buf2
);
769 currentFileName
= actualFile
;
771 if (actualFile
== "")
774 errBuf
.Printf("Could not find file: %s",fileName
);
775 OnError((char *)errBuf
.c_str());
779 // Ensure that if this file includes another,
780 // then we look in the same directory as this one.
781 TexPathList
.EnsureFileAccessible(actualFile
);
784 informStr
.Printf("Processing: %s",actualFile
.c_str());
785 OnInform((char *)informStr
.c_str());
786 CurrentInputIndex
++;
788 Inputs
[CurrentInputIndex
] = fopen(actualFile
, "r");
789 LineNumbers
[CurrentInputIndex
] = 1;
790 if (FileNames
[CurrentInputIndex
])
791 delete[] FileNames
[CurrentInputIndex
];
792 FileNames
[CurrentInputIndex
] = copystring(actualFile
);
794 if (!Inputs
[CurrentInputIndex
])
797 errBuf
.Printf("Could not open include file %s", (const char*) actualFile
);
798 CurrentInputIndex
--;
799 OnError((char *)errBuf
.c_str());
802 bool succ
= read_a_line(buf
);
808 wxString bufStr
= buf
;
811 for (index
=0; syntaxTokens
[index
] != wxEmptyString
; index
++)
813 pos
= bufStr
.find(syntaxTokens
[index
]);
814 if (pos
!= wxString::npos
&& pos
!= 0)
816 size_t commentStart
= bufStr
.find("%");
817 if (commentStart
== wxString::npos
|| commentStart
> pos
)
820 if (syntaxTokens
[index
] == "\\verb")
822 errBuf
.Printf("'%s$....$' was detected at line %lu inside file %s. Please replace this form with \\tt{....}",
823 syntaxTokens
[index
].c_str(),
824 LineNumbers
[CurrentInputIndex
],
825 currentFileName
.c_str());
829 errBuf
.Printf("'%s' was detected at line %lu inside file %s that is not the only text on the line, starting at column one.",
830 syntaxTokens
[index
].c_str(),
831 LineNumbers
[CurrentInputIndex
],
832 currentFileName
.c_str());
834 OnError((char *)errBuf
.c_str());
840 if (strncmp(buf
, "\\begin{verbatim}", 16) == 0 ||
841 strncmp(buf
, "\\begin{toocomplex}", 18) == 0)
842 readInVerbatim
= TRUE
;
843 else if (strncmp(buf
, "\\end{verbatim}", 14) == 0 ||
844 strncmp(buf
, "\\end{toocomplex}", 16) == 0)
845 readInVerbatim
= FALSE
;
847 if (checkCurleyBraces
)
849 if (ch
== EOF
&& leftCurley
!= rightCurley
)
852 errBuf
.Printf("Curley braces do not match inside file %s\n%lu opens, %lu closes", (const char*) currentFileName
.c_str(),leftCurley
,rightCurley
);
853 OnError((char *)errBuf
.c_str());
865 bool ParseNewCommand(char *buffer
, int *pos
)
867 if ((strncmp((buffer
+(*pos
)), "newcommand", 10) == 0) ||
868 (strncmp((buffer
+(*pos
)), "renewcommand", 12) == 0))
870 if (strncmp((buffer
+(*pos
)), "newcommand", 10) == 0)
875 char commandName
[100];
876 char commandValue
[1000];
879 while (buffer
[*pos
] != '}' && (buffer
[*pos
] != 0))
881 commandName
[i
] = buffer
[*pos
];
888 if (buffer
[*pos
] == '[')
891 noArgs
= (int)(buffer
[*pos
]) - 48;
892 *pos
+= 2; // read past argument and '['
898 char ch
= buffer
[*pos
];
909 if (!read_a_line(buffer
))
914 commandValue
[i
] = ch
;
920 CustomMacro
*macro
= new CustomMacro(commandName
, noArgs
, NULL
);
921 if (strlen(commandValue
) > 0)
922 macro
->macroBody
= copystring(commandValue
);
923 if (!CustomMacroList
.Find(commandName
))
925 CustomMacroList
.Append(commandName
, macro
);
926 AddMacroDef(ltCUSTOM_MACRO
, commandName
, noArgs
);
933 void MacroError(char *buffer
)
940 while (((ch
= buffer
[i
-1]) != '\n') && (ch
!= 0))
949 errBuf
.Printf("Could not find macro: %s at line %d, file %s",
950 macroBuf
, (int)(LineNumbers
[CurrentInputIndex
]-1), FileNames
[CurrentInputIndex
]);
951 OnError((char *)errBuf
.c_str());
953 if (wxStrcmp(macroBuf
,"\\end{document}") == 0)
956 buf
= "Halted build due to unrecoverable error.";
957 OnInform((char *)buf
.c_str());
964 * 'environment' specifies the name of the macro IFF if we're looking for the end
965 * of an environment, e.g. \end{itemize}. Otherwise it's NULL.
966 * 'parseToBrace' is TRUE if the argument should extend to the next right brace,
967 * e.g. in {\bf an argument} as opposed to \vskip 30pt
970 int ParseArg(TexChunk
*thisArg
, wxList
& children
, char *buffer
, int pos
, char *environment
, bool parseToBrace
, TexChunk
*customMacroArgs
)
973 if (stopRunning
) return pos
;
982 // Consume leading brace or square bracket, but ONLY if not following
983 // a space, because this could be e.g. {\large {\bf thing}} where {\bf thing}
984 // is the argument of \large AS WELL as being a block in its
988 if ((pos > 0) && (buffer[pos-1] != ' ') && buffer[pos] == '{')
992 if ((pos > 0) && (buffer[pos-1] != ' ') && (buffer[pos] == '[' || buffer[pos] == '('))
997 else if ((pos > 1) && (buffer[pos-1] != ' ') && (buffer[pos+1] == '[' || buffer[pos+1] == '('))
1005 // If not parsing to brace, just read the next word
1006 // (e.g. \vskip 20pt)
1009 int ch
= buffer
[pos
];
1010 while (!eof
&& ch
!= 13 && ch
!= 32 && ch
!= 10 &&
1011 ch
!= 0 && ch
!= '{')
1013 BigBuffer
[buf_ptr
] = ch
;
1020 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1021 BigBuffer
[buf_ptr
] = 0;
1023 chunk
->value
= copystring(BigBuffer
);
1024 children
.Append((wxObject
*)chunk
);
1031 len
= strlen(buffer
);
1034 if (customMacroArgs
) return 0;
1036 eof
= read_a_line(buffer
);
1038 len
= strlen(buffer
);
1039 // Check for verbatim (or toocomplex, which comes to the same thing)
1040 wxString bufStr
= buffer
;
1041 // if (bufStr.find("\\begin{verbatim}") != wxString::npos ||
1042 // bufStr.find("\\begin{toocomplex}") != wxString::npos)
1043 if (strncmp(buffer
, "\\begin{verbatim}", 16) == 0 ||
1044 strncmp(buffer
, "\\begin{toocomplex}", 18) == 0)
1048 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1049 BigBuffer
[buf_ptr
] = 0;
1051 chunk
->value
= copystring(BigBuffer
);
1052 children
.Append((wxObject
*)chunk
);
1057 eof
= read_a_line(buffer
);
1058 while (!eof
&& (strncmp(buffer
, "\\end{verbatim}", 14) != 0) &&
1059 (strncmp(buffer
, "\\end{toocomplex}", 16) != 0)
1062 strcat(BigBuffer
, buffer
);
1063 buf_ptr
+= strlen(buffer
);
1064 eof
= read_a_line(buffer
);
1066 eof
= read_a_line(buffer
);
1069 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, VerbatimMacroDef
);
1071 chunk
->macroId
= ltVERBATIM
;
1072 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, VerbatimMacroDef
);
1074 arg
->macroId
= ltVERBATIM
;
1075 TexChunk
*str
= new TexChunk(CHUNK_TYPE_STRING
);
1076 str
->value
= copystring(BigBuffer
);
1078 children
.Append((wxObject
*)chunk
);
1079 chunk
->children
.Append((wxObject
*)arg
);
1080 arg
->children
.Append((wxObject
*)str
);
1082 // Also want to include the following newline (is always a newline
1083 // after a verbatim): EXCEPT in HTML
1084 if (convertMode
!= TEX_HTML
)
1086 TexMacroDef
*parDef
= (TexMacroDef
*)MacroDefs
.Get("\\");
1087 TexChunk
*parChunk
= new TexChunk(CHUNK_TYPE_MACRO
, parDef
);
1088 parChunk
->no_args
= 0;
1089 parChunk
->macroId
= ltBACKSLASHCHAR
;
1090 children
.Append((wxObject
*)parChunk
);
1095 char ch
= buffer
[pos
];
1096 // End of optional argument -- pretend it's right brace for simplicity
1097 if (thisArg
->optional
&& (ch
== ']'))
1103 case '}': // End of argument
1107 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1108 BigBuffer
[buf_ptr
] = 0;
1110 chunk
->value
= copystring(BigBuffer
);
1111 children
.Append((wxObject
*)chunk
);
1113 if (ch
== '}') pos
++;
1119 if (buf_ptr
> 0) // Finish off the string we've read so far
1121 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1122 BigBuffer
[buf_ptr
] = 0;
1124 chunk
->value
= copystring(BigBuffer
);
1125 children
.Append((wxObject
*)chunk
);
1129 // Try matching \end{environment}
1130 if (environment
&& FindEndEnvironment(buffer
, &pos
, environment
))
1132 // Eliminate newline after an \end{} if possible
1133 if (buffer
[pos
] == 13)
1136 if (buffer
[pos
] == 10)
1142 if (ParseNewCommand(buffer
, &pos
))
1145 if (strncmp(buffer
+pos
, "special", 7) == 0)
1153 wxTex2RTFBuffer
[0] = 0;
1158 int ch
= buffer
[pos
];
1164 wxTex2RTFBuffer
[i
] = 0;
1169 wxTex2RTFBuffer
[i
] = '}';
1176 wxTex2RTFBuffer
[i
] = '{';
1180 else if (ch
== '\\' && buffer
[pos
+1] == '}')
1182 wxTex2RTFBuffer
[i
] = '}';
1186 else if (ch
== '\\' && buffer
[pos
+1] == '{')
1188 wxTex2RTFBuffer
[i
] = '{';
1194 wxTex2RTFBuffer
[i
] = ch
;
1201 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1203 chunk
->macroId
= ltSPECIAL
;
1204 TexMacroDef
*specialDef
= (TexMacroDef
*)MacroDefs
.Get("special");
1205 chunk
->def
= specialDef
;
1206 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, specialDef
);
1207 chunk
->children
.Append((wxObject
*)arg
);
1209 arg
->macroId
= chunk
->macroId
;
1211 // The value in the first argument.
1212 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1213 arg
->children
.Append((wxObject
*)argValue
);
1215 argValue
->value
= copystring(wxTex2RTFBuffer
);
1217 children
.Append((wxObject
*)chunk
);
1219 else if (strncmp(buffer
+pos
, "verb", 4) == 0)
1222 if (buffer
[pos
] == '*')
1225 // Find the delimiter character
1226 int ch
= buffer
[pos
];
1228 // Now at start of verbatim text
1230 while ((buffer
[pos
] != ch
) && buffer
[pos
] != 0)
1232 char *val
= new char[pos
- j
+ 1];
1234 for (i
= j
; i
< pos
; i
++)
1236 val
[i
-j
] = buffer
[i
];
1242 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1244 chunk
->macroId
= ltVERB
;
1245 TexMacroDef
*verbDef
= (TexMacroDef
*)MacroDefs
.Get("verb");
1246 chunk
->def
= verbDef
;
1247 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, verbDef
);
1248 chunk
->children
.Append((wxObject
*)arg
);
1250 arg
->macroId
= chunk
->macroId
;
1252 // The value in the first argument.
1253 TexChunk
*argValue
= new TexChunk(CHUNK_TYPE_STRING
);
1254 arg
->children
.Append((wxObject
*)argValue
);
1256 argValue
->value
= val
;
1258 children
.Append((wxObject
*)chunk
);
1263 bool tmpParseToBrace
= TRUE
;
1264 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1267 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1269 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1271 chunk
->no_args
= def
->no_args
;
1272 // chunk->name = copystring(def->name);
1273 chunk
->macroId
= def
->macroId
;
1276 children
.Append((wxObject
*)chunk
);
1278 // Eliminate newline after a \begin{} or a \\ if possible
1279 if (env
|| strcmp(def
->name
, "\\") == 0)
1280 if (buffer
[pos
] == 13)
1283 if (buffer
[pos
] == 10)
1287 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1288 buffer
, pos
, env
, tmpParseToBrace
, customMacroArgs
);
1290 // If custom macro, parse the body substituting the above found args.
1293 if (customMacro
->macroBody
)
1296 // strcpy(macroBuf, "{");
1297 strcpy(macroBuf
, customMacro
->macroBody
);
1298 strcat(macroBuf
, "}");
1299 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, TRUE
, chunk
);
1302 // delete chunk; // Might delete children
1307 MacroError(buffer
+pos
);
1312 // Parse constructs like {\bf thing} as if they were
1317 if (buffer
[pos
] == '\\')
1321 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1322 BigBuffer
[buf_ptr
] = 0;
1324 chunk
->value
= copystring(BigBuffer
);
1325 children
.Append((wxObject
*)chunk
);
1330 bool tmpParseToBrace
;
1331 TexMacroDef
*def
= MatchMacro(buffer
, &pos
, &env
, &tmpParseToBrace
);
1334 CustomMacro
*customMacro
= FindCustomMacro(def
->name
);
1336 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, def
);
1337 chunk
->no_args
= def
->no_args
;
1338 // chunk->name = copystring(def->name);
1339 chunk
->macroId
= def
->macroId
;
1341 children
.Append((wxObject
*)chunk
);
1343 pos
= ParseMacroBody(def
->name
, chunk
, chunk
->no_args
,
1344 buffer
, pos
, NULL
, TRUE
, customMacroArgs
);
1346 // If custom macro, parse the body substituting the above found args.
1349 if (customMacro
->macroBody
)
1352 // strcpy(macroBuf, "{");
1353 strcpy(macroBuf
, customMacro
->macroBody
);
1354 strcat(macroBuf
, "}");
1355 ParseArg(thisArg
, children
, macroBuf
, 0, NULL
, TRUE
, chunk
);
1358 // delete chunk; // Might delete children
1363 MacroError(buffer
+pos
);
1369 * If all else fails, we assume that we have
1370 * a pair of braces on their own, so return a `dummy' macro
1371 * definition with just one argument to parse.
1375 SoloBlockDef
= new TexMacroDef(ltSOLO_BLOCK
, "solo block", 1, FALSE
);
1380 TexChunk
*chunk1
= new TexChunk(CHUNK_TYPE_STRING
);
1381 BigBuffer
[buf_ptr
] = 0;
1383 chunk1
->value
= copystring(BigBuffer
);
1384 children
.Append((wxObject
*)chunk1
);
1386 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
, SoloBlockDef
);
1387 chunk
->no_args
= SoloBlockDef
->no_args
;
1388 // chunk->name = copystring(SoloBlockDef->name);
1389 chunk
->macroId
= SoloBlockDef
->macroId
;
1390 children
.Append((wxObject
*)chunk
);
1392 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, SoloBlockDef
);
1394 chunk
->children
.Append((wxObject
*)arg
);
1395 // arg->name = copystring(SoloBlockDef->name);
1397 arg
->macroId
= chunk
->macroId
;
1399 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, NULL
, TRUE
, customMacroArgs
);
1407 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1408 BigBuffer
[buf_ptr
] = 0;
1410 chunk
->value
= copystring(BigBuffer
);
1411 children
.Append((wxObject
*)chunk
);
1416 if (buffer
[pos
] == '$')
1418 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1420 // chunk->name = copystring("$$");
1421 chunk
->macroId
= ltSPECIALDOUBLEDOLLAR
;
1422 children
.Append((wxObject
*)chunk
);
1427 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1429 // chunk->name = copystring("_$");
1430 chunk
->macroId
= ltSPECIALDOLLAR
;
1431 children
.Append((wxObject
*)chunk
);
1439 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1440 BigBuffer
[buf_ptr
] = 0;
1442 chunk
->value
= copystring(BigBuffer
);
1443 children
.Append((wxObject
*)chunk
);
1447 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1449 // chunk->name = copystring("_~");
1450 chunk
->macroId
= ltSPECIALTILDE
;
1451 children
.Append((wxObject
*)chunk
);
1454 case '#': // Either treat as a special TeX character or as a macro arg
1458 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1459 BigBuffer
[buf_ptr
] = 0;
1461 chunk
->value
= copystring(BigBuffer
);
1462 children
.Append((wxObject
*)chunk
);
1466 if (!customMacroArgs
)
1468 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1470 // chunk->name = copystring("_#");
1471 chunk
->macroId
= ltSPECIALHASH
;
1472 children
.Append((wxObject
*)chunk
);
1476 if (isdigit(buffer
[pos
]))
1478 int n
= buffer
[pos
] - 48;
1480 wxNode
*node
= customMacroArgs
->children
.Item(n
-1);
1483 TexChunk
*argChunk
= (TexChunk
*)node
->GetData();
1484 children
.Append((wxObject
*)new TexChunk(*argChunk
));
1492 // Remove white space before and after the ampersand,
1493 // since this is probably a table column separator with
1494 // some convenient -- but useless -- white space in the text.
1495 while ((buf_ptr
> 0) && ((BigBuffer
[buf_ptr
-1] == ' ') || (BigBuffer
[buf_ptr
-1] == 9)))
1500 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_STRING
);
1501 BigBuffer
[buf_ptr
] = 0;
1503 chunk
->value
= copystring(BigBuffer
);
1504 children
.Append((wxObject
*)chunk
);
1509 while (buffer
[pos
] == ' ' || buffer
[pos
] == 9)
1512 TexChunk
*chunk
= new TexChunk(CHUNK_TYPE_MACRO
);
1514 // chunk->name = copystring("_&");
1515 chunk
->macroId
= ltSPECIALAMPERSAND
;
1516 children
.Append((wxObject
*)chunk
);
1519 // Eliminate end-of-line comment
1523 while (ch
!= 10 && ch
!= 13 && ch
!= 0)
1528 if (buffer
[pos
] == 10 || buffer
[pos
] == 13)
1531 if (buffer
[pos
] == 10) pos
++; // Eliminate newline following DOS line feed
1538 BigBuffer
[buf_ptr
] = ' ';
1539 BigBuffer
[buf_ptr
+1] = 0;
1546 BigBuffer
[buf_ptr
] = ch
;
1547 BigBuffer
[buf_ptr
+1] = 0;
1558 * Consume as many arguments as the macro definition specifies
1562 int ParseMacroBody(const char *macro_name
, TexChunk
*parent
,
1563 int no_args
, char *buffer
, int pos
,
1564 char *environment
, bool parseToBrace
,
1565 TexChunk
*customMacroArgs
)
1568 if (stopRunning
) return pos
;
1570 // Check for a first optional argument
1571 if (buffer
[pos
] == ' ' && buffer
[pos
+1] == '[')
1573 // Fool following code into thinking that this is definitely
1574 // an optional first argument. (If a space before a non-first argument,
1575 // [ is interpreted as a [, not an optional argument.)
1581 if (buffer
[pos
] == '[')
1587 for (i
= 0; i
< no_args
; i
++)
1590 TexChunk
*arg
= new TexChunk(CHUNK_TYPE_ARG
, parent
->def
);
1592 parent
->children
.Append((wxObject
*)arg
);
1593 // arg->name = copystring(macro_name);
1594 arg
->argn
= maxArgs
;
1595 arg
->macroId
= parent
->macroId
;
1597 // To parse the first arg of a 2 arg \begin{thing}{arg} ... \end{thing}
1598 // have to fool parser into thinking this is a regular kind of block.
1600 if ((no_args
== 2) && (i
== 0))
1603 actualEnv
= environment
;
1605 bool isOptional
= FALSE
;
1607 // Remove the first { of the argument so it doesn't get recognized as { ... }
1608 // EatWhiteSpace(buffer, &pos);
1611 // The reason for these tests is to not consume braces that don't
1612 // belong to this macro.
1613 // E.g. {\bf {\small thing}}
1614 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && buffer
[pos
] == '{')
1617 if ((pos
> 0) && (buffer
[pos
-1] != ' ') && (buffer
[pos
] == '['))
1622 else if ((pos
> 1) && (buffer
[pos
-1] != ' ') && (buffer
[pos
+1] == '['))
1630 wxString
tmpBuffer(buffer
);
1631 if (tmpBuffer
.length() > 4)
1633 if (tmpBuffer
.Right(4) == "\\par")
1634 tmpBuffer
= tmpBuffer
.Mid(0,tmpBuffer
.length()-4);
1636 errBuf
.Printf("Missing macro argument in the line:\n\t%s\n",tmpBuffer
.c_str());
1637 OnError((char *)errBuf
.c_str());
1641 arg
->optional
= isOptional
;
1643 pos
= ParseArg(arg
, arg
->children
, buffer
, pos
, actualEnv
, parseToBrace
, customMacroArgs
);
1645 // If we've encountered an OPTIONAL argument, go another time around
1646 // the loop, because we've got more than we thought.
1647 // Hopefully optional args don't occur at the end of a macro use
1648 // or we might miss it.
1649 // Don't increment no of times round loop if the first optional arg
1650 // -- we already did it before the loop.
1651 if (arg
->optional
&& (i
> 0))
1654 parent
->no_args
= maxArgs
;
1656 // Tell each argument how many args there are (useful when processing an arg)
1657 wxNode
*node
= parent
->children
.GetFirst();
1660 TexChunk
*chunk
= (TexChunk
*)node
->GetData();
1661 chunk
->no_args
= maxArgs
;
1662 node
= node
->GetNext();
1667 bool TexLoadFile(char *filename
)
1669 static char *line_buffer
;
1670 stopRunning
= FALSE
;
1671 strcpy(TexFileRoot
, filename
);
1672 StripExtension(TexFileRoot
);
1673 sprintf(TexBibName
, "%s.bb", TexFileRoot
);
1674 sprintf(TexTmpBibName
, "%s.bb1", TexFileRoot
);
1676 TexPathList
.EnsureFileAccessible(filename
);
1681 line_buffer
= new char[MAX_LINE_BUFFER_SIZE
];
1683 Inputs
[0] = fopen(filename
, "r");
1685 FileNames
[0] = copystring(filename
);
1688 read_a_line(line_buffer
);
1689 ParseMacroBody("toplevel", TopLevel
, 1, line_buffer
, 0, NULL
, TRUE
);
1690 if (Inputs
[0]) fclose(Inputs
[0]);
1697 TexMacroDef::TexMacroDef(int the_id
, const char *the_name
, int n
, bool ig
, bool forbidLevel
)
1699 name
= copystring(the_name
);
1703 forbidden
= forbidLevel
;
1706 TexMacroDef::~TexMacroDef(void)
1708 if (name
) delete[] name
;
1711 TexChunk::TexChunk(int the_type
, TexMacroDef
*the_def
)
1723 TexChunk::TexChunk(TexChunk
& toCopy
)
1726 no_args
= toCopy
.no_args
;
1728 macroId
= toCopy
.macroId
;
1731 // name = copystring(toCopy.name);
1737 value
= copystring(toCopy
.value
);
1741 optional
= toCopy
.optional
;
1742 wxNode
*node
= toCopy
.children
.GetFirst();
1745 TexChunk
*child
= (TexChunk
*)node
->GetData();
1746 children
.Append((wxObject
*)new TexChunk(*child
));
1747 node
= node
->GetNext();
1751 TexChunk::~TexChunk(void)
1753 // if (name) delete[] name;
1754 if (value
) delete[] value
;
1755 wxNode
*node
= children
.GetFirst();
1758 TexChunk
*child
= (TexChunk
*)node
->GetData();
1760 wxNode
*next
= node
->GetNext();
1766 bool IsArgOptional(void) // Is this argument an optional argument?
1768 return isArgOptional
;
1771 int GetNoArgs(void) // Number of args for this macro
1776 /* Gets the text of a chunk on request (must be for small arguments
1781 void GetArgData1(TexChunk
*chunk
)
1783 switch (chunk
->type
)
1785 case CHUNK_TYPE_MACRO
:
1787 TexMacroDef
*def
= chunk
->def
;
1788 if (def
&& def
->ignore
)
1791 if (def
&& (strcmp(def
->name
, "solo block") != 0))
1793 strcat(currentArgData
, "\\");
1794 strcat(currentArgData
, def
->name
);
1797 wxNode
*node
= chunk
->children
.GetFirst();
1800 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1801 strcat(currentArgData
, "{");
1802 GetArgData1(child_chunk
);
1803 strcat(currentArgData
, "}");
1804 node
= node
->GetNext();
1808 case CHUNK_TYPE_ARG
:
1810 wxNode
*node
= chunk
->children
.GetFirst();
1813 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1814 GetArgData1(child_chunk
);
1815 node
= node
->GetNext();
1819 case CHUNK_TYPE_STRING
:
1822 strcat(currentArgData
, chunk
->value
);
1828 char *GetArgData(TexChunk
*chunk
)
1830 currentArgData
[0] = 0;
1831 GetArgData1(currentArgument
);
1832 haveArgData
= FALSE
;
1833 return currentArgData
;
1836 char *GetArgData(void)
1840 currentArgData
[0] = 0;
1841 GetArgData1(currentArgument
);
1843 return currentArgData
;
1846 TexChunk
*GetArgChunk(void)
1848 return currentArgument
;
1851 TexChunk
*GetNextChunk(void) // Look ahead to the next chunk
1856 TexChunk
*GetTopLevelChunk(void)
1861 int GetCurrentColumn(void)
1863 return currentColumn
;
1867 * Traverses document calling functions to allow the client to
1868 * write out the appropriate stuff
1872 void TraverseFromChunk(TexChunk
*chunk
, wxNode
*thisNode
, bool childrenOnly
)
1875 if (stopRunning
) return;
1877 switch (chunk
->type
)
1879 case CHUNK_TYPE_MACRO
:
1881 TexMacroDef
*def
= chunk
->def
;
1882 if (def
&& def
->ignore
)
1886 OnMacro(chunk
->macroId
, chunk
->no_args
, TRUE
);
1888 wxNode
*node
= chunk
->children
.GetFirst();
1889 TexChunk
*child_chunk
= NULL
;
1892 child_chunk
= (TexChunk
*)node
->GetData();
1893 TraverseFromChunk(child_chunk
, node
);
1894 node
= node
->GetNext();
1897 if (thisNode
&& thisNode
->GetNext())
1898 nextChunk
= (TexChunk
*)thisNode
->GetNext()->GetData();
1901 OnMacro(chunk
->macroId
, chunk
->no_args
, FALSE
);
1904 case CHUNK_TYPE_ARG
:
1906 currentArgument
= chunk
;
1908 isArgOptional
= chunk
->optional
;
1909 noArgs
= chunk
->no_args
;
1911 // If OnArgument returns FALSE, don't output.
1913 if (childrenOnly
|| OnArgument(chunk
->macroId
, chunk
->argn
, TRUE
))
1915 wxNode
*node
= chunk
->children
.GetFirst();
1918 TexChunk
*child_chunk
= (TexChunk
*)node
->GetData();
1919 TraverseFromChunk(child_chunk
, node
);
1920 node
= node
->GetNext();
1924 currentArgument
= chunk
;
1926 if (thisNode
&& thisNode
->GetNext())
1927 nextChunk
= (TexChunk
*)thisNode
->GetNext()->GetData();
1929 isArgOptional
= chunk
->optional
;
1930 noArgs
= chunk
->no_args
;
1933 (void)OnArgument(chunk
->macroId
, chunk
->argn
, FALSE
);
1936 case CHUNK_TYPE_STRING
:
1938 extern int issuedNewParagraph
;
1939 extern int forbidResetPar
;
1940 if (chunk
->value
&& (forbidResetPar
== 0))
1942 // If non-whitespace text, we no longer have a new paragraph.
1943 if (issuedNewParagraph
&& !((chunk
->value
[0] == 10 || chunk
->value
[0] == 13 || chunk
->value
[0] == 32)
1944 && chunk
->value
[1] == 0))
1946 issuedNewParagraph
= FALSE
;
1948 TexOutput(chunk
->value
, TRUE
);
1955 void TraverseDocument(void)
1957 TraverseFromChunk(TopLevel
, NULL
);
1960 void SetCurrentOutput(FILE *fd
)
1962 CurrentOutput1
= fd
;
1963 CurrentOutput2
= NULL
;
1966 void SetCurrentOutputs(FILE *fd1
, FILE *fd2
)
1968 CurrentOutput1
= fd1
;
1969 CurrentOutput2
= fd2
;
1972 void AddMacroDef(int the_id
, const char *name
, int n
, bool ignore
, bool forbid
)
1974 MacroDefs
.Put(name
, new TexMacroDef(the_id
, name
, n
, ignore
, forbid
));
1977 void TexInitialize(int bufSize
)
1979 InitialiseColourTable();
1981 TexPathList
.AddEnvList("TEXINPUT");
1984 TexPathList
.AddEnvList("TEXINPUTS");
1987 for (i
= 0; i
< 15; i
++)
1991 FileNames
[i
] = NULL
;
1994 IgnorableInputFiles
.Add("psbox.tex");
1995 BigBuffer
= new char[(bufSize
*1000)];
1996 currentArgData
= new char[2000];
1997 TexFileRoot
= new char[300];
1998 TexBibName
= new char[300];
1999 TexTmpBibName
= new char[300];
2000 AddMacroDef(ltTOPLEVEL
, "toplevel", 1);
2001 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
2002 // TopLevel->name = copystring("toplevel");
2003 TopLevel
->macroId
= ltTOPLEVEL
;
2004 TopLevel
->no_args
= 1;
2005 VerbatimMacroDef
= (TexMacroDef
*)MacroDefs
.Get("verbatim");
2008 void TexCleanUp(void)
2011 for (i
= 0; i
< 15; i
++)
2017 subsubsectionNo
= 0;
2020 CurrentOutput1
= NULL
;
2021 CurrentOutput2
= NULL
;
2022 CurrentInputIndex
= 0;
2023 haveArgData
= FALSE
;
2028 TopLevel
= new TexChunk(CHUNK_TYPE_MACRO
);
2029 // TopLevel->name = copystring("toplevel");
2030 TopLevel
->macroId
= ltTOPLEVEL
;
2031 TopLevel
->no_args
= 1;
2033 DocumentTitle
= NULL
;
2034 DocumentAuthor
= NULL
;
2035 DocumentDate
= NULL
;
2036 DocumentStyle
= LATEX_REPORT
;
2037 MinorDocumentStyle
= 0;
2038 BibliographyStyleString
= copystring("plain");
2039 DocumentStyleString
= copystring("report");
2040 MinorDocumentStyleString
= NULL
;
2042 // gt - Changed this so if this is the final pass
2043 // then we DO want to remove these macros, so that
2044 // memory is not MASSIVELY leaked if the user
2045 // does not exit the program, but instead runs
2046 // the program again
2047 if ((passNumber
== 1 && !runTwice
) ||
2048 (passNumber
== 2 && runTwice
))
2050 /* Don't want to remove custom macros after each pass.*/
2052 wxNode
*node
= CustomMacroList
.GetFirst();
2055 CustomMacro
*macro
= (CustomMacro
*)node
->GetData();
2058 node
= CustomMacroList
.GetFirst();
2062 TexReferences
.BeginFind();
2063 wxNode
*node
= TexReferences
.Next();
2066 TexRef
*ref
= (TexRef
*)node
->GetData();
2068 node
= TexReferences
.Next();
2070 TexReferences
.Clear();
2072 node
= BibList
.GetFirst();
2075 BibEntry
*entry
= (BibEntry
*)node
->GetData();
2078 node
= BibList
.GetFirst();
2080 CitationList
.Clear();
2081 ResetTopicCounter();
2084 // There is likely to be one set of macros used by all utilities.
2085 void DefineDefaultMacros(void)
2087 // Put names which subsume other names at the TOP
2088 // so they get recognized first
2090 AddMacroDef(ltACCENT_GRAVE
, "`", 1);
2091 AddMacroDef(ltACCENT_ACUTE
, "'", 1);
2092 AddMacroDef(ltACCENT_CARET
, "^", 1);
2093 AddMacroDef(ltACCENT_UMLAUT
, "\"", 1);
2094 AddMacroDef(ltACCENT_TILDE
, "~", 1);
2095 AddMacroDef(ltACCENT_DOT
, ".", 1);
2096 AddMacroDef(ltACCENT_CADILLA
, "c", 1);
2097 AddMacroDef(ltSMALLSPACE1
, ",", 0);
2098 AddMacroDef(ltSMALLSPACE2
, ";", 0);
2100 AddMacroDef(ltABSTRACT
, "abstract", 1);
2101 AddMacroDef(ltADDCONTENTSLINE
, "addcontentsline", 3);
2102 AddMacroDef(ltADDTOCOUNTER
, "addtocounter", 2);
2103 AddMacroDef(ltALEPH
, "aleph", 0);
2104 AddMacroDef(ltALPHA
, "alpha", 0);
2105 AddMacroDef(ltALPH1
, "alph", 1);
2106 AddMacroDef(ltALPH2
, "Alph", 1);
2107 AddMacroDef(ltANGLE
, "angle", 0);
2108 AddMacroDef(ltAPPENDIX
, "appendix", 0);
2109 AddMacroDef(ltAPPROX
, "approx", 0);
2110 AddMacroDef(ltARABIC
, "arabic", 1);
2111 AddMacroDef(ltARRAY
, "array", 1);
2112 AddMacroDef(ltAST
, "ast", 0);
2113 AddMacroDef(ltASYMP
, "asymp", 0);
2114 AddMacroDef(ltAUTHOR
, "author", 1);
2116 AddMacroDef(ltBACKGROUNDCOLOUR
, "backgroundcolour", 1);
2117 AddMacroDef(ltBACKGROUNDIMAGE
, "backgroundimage", 1);
2118 AddMacroDef(ltBACKGROUND
, "background", 1);
2119 AddMacroDef(ltBACKSLASHRAW
, "backslashraw", 0);
2120 AddMacroDef(ltBACKSLASH
, "backslash", 0);
2121 AddMacroDef(ltBASELINESKIP
, "baselineskip", 1);
2122 AddMacroDef(ltBCOL
, "bcol", 2);
2123 AddMacroDef(ltBETA
, "beta", 0);
2124 AddMacroDef(ltBFSERIES
, "bfseries", 1);
2125 AddMacroDef(ltBF
, "bf", 1);
2126 AddMacroDef(ltBIBITEM
, "bibitem", 2); // For convenience, bibitem has 2 args: label and item.
2127 // The Latex syntax permits writing as 2 args.
2128 AddMacroDef(ltBIBLIOGRAPHYSTYLE
, "bibliographystyle", 1);
2129 AddMacroDef(ltBIBLIOGRAPHY
, "bibliography", 1);
2130 AddMacroDef(ltBIGTRIANGLEDOWN
, "bigtriangledown", 0);
2131 AddMacroDef(ltBOT
, "bot", 0);
2132 AddMacroDef(ltBOXIT
, "boxit", 1);
2133 AddMacroDef(ltBOX
, "box", 0);
2134 AddMacroDef(ltBRCLEAR
, "brclear", 0);
2135 AddMacroDef(ltBULLET
, "bullet", 0);
2137 AddMacroDef(ltCAPTIONSTAR
, "caption*", 1);
2138 AddMacroDef(ltCAPTION
, "caption", 1);
2139 AddMacroDef(ltCAP
, "cap", 0);
2140 AddMacroDef(ltCDOTS
, "cdots", 0);
2141 AddMacroDef(ltCDOT
, "cdot", 0);
2142 AddMacroDef(ltCENTERLINE
, "centerline", 1);
2143 AddMacroDef(ltCENTERING
, "centering", 0);
2144 AddMacroDef(ltCENTER
, "center", 1);
2145 AddMacroDef(ltCEXTRACT
, "cextract", 0);
2146 AddMacroDef(ltCHAPTERHEADING
, "chapterheading", 1);
2147 AddMacroDef(ltCHAPTERSTAR
, "chapter*", 1);
2148 AddMacroDef(ltCHAPTER
, "chapter", 1);
2149 AddMacroDef(ltCHI
, "chi", 0);
2150 AddMacroDef(ltCINSERT
, "cinsert", 0);
2151 AddMacroDef(ltCIRC
, "circ", 0);
2152 AddMacroDef(ltCITE
, "cite", 1);
2153 AddMacroDef(ltCLASS
, "class", 1);
2154 AddMacroDef(ltCLEARDOUBLEPAGE
, "cleardoublepage", 0);
2155 AddMacroDef(ltCLEARPAGE
, "clearpage", 0);
2156 AddMacroDef(ltCLINE
, "cline", 1);
2157 AddMacroDef(ltCLIPSFUNC
, "clipsfunc", 3);
2158 AddMacroDef(ltCLUBSUIT
, "clubsuit", 0);
2159 AddMacroDef(ltCOLUMNSEP
, "columnsep", 1);
2160 AddMacroDef(ltCOMMENT
, "comment", 1, TRUE
);
2161 AddMacroDef(ltCONG
, "cong", 0);
2162 AddMacroDef(ltCOPYRIGHT
, "copyright", 0);
2163 AddMacroDef(ltCPARAM
, "cparam", 2);
2164 AddMacroDef(ltCHEAD
, "chead", 1);
2165 AddMacroDef(ltCFOOT
, "cfoot", 1);
2166 AddMacroDef(ltCUP
, "cup", 0);
2168 AddMacroDef(ltDASHV
, "dashv", 0);
2169 AddMacroDef(ltDATE
, "date", 1);
2170 AddMacroDef(ltDELTA
, "delta", 0);
2171 AddMacroDef(ltCAP_DELTA
, "Delta", 0);
2172 AddMacroDef(ltDEFINECOLOUR
, "definecolour", 4);
2173 AddMacroDef(ltDEFINECOLOR
, "definecolor", 4);
2174 AddMacroDef(ltDESCRIPTION
, "description", 1);
2175 AddMacroDef(ltDESTRUCT
, "destruct", 1);
2176 AddMacroDef(ltDIAMOND2
, "diamond2", 0);
2177 AddMacroDef(ltDIAMOND
, "diamond", 0);
2178 AddMacroDef(ltDIV
, "div", 0);
2179 AddMacroDef(ltDOCUMENTCLASS
, "documentclass", 1);
2180 AddMacroDef(ltDOCUMENTSTYLE
, "documentstyle", 1);
2181 AddMacroDef(ltDOCUMENT
, "document", 1);
2182 AddMacroDef(ltDOUBLESPACE
, "doublespace", 1);
2183 AddMacroDef(ltDOTEQ
, "doteq", 0);
2184 AddMacroDef(ltDOWNARROW
, "downarrow", 0);
2185 AddMacroDef(ltDOWNARROW2
, "Downarrow", 0);
2187 AddMacroDef(ltEMPTYSET
, "emptyset", 0);
2188 AddMacroDef(ltEMPH
, "emph", 1);
2189 AddMacroDef(ltEM
, "em", 1);
2190 AddMacroDef(ltENUMERATE
, "enumerate", 1);
2191 AddMacroDef(ltEPSILON
, "epsilon", 0);
2192 AddMacroDef(ltEQUATION
, "equation", 1);
2193 AddMacroDef(ltEQUIV
, "equiv", 0);
2194 AddMacroDef(ltETA
, "eta", 0);
2195 AddMacroDef(ltEVENSIDEMARGIN
, "evensidemargin", 1);
2196 AddMacroDef(ltEXISTS
, "exists", 0);
2198 AddMacroDef(ltFBOX
, "fbox", 1);
2199 AddMacroDef(ltFCOL
, "fcol", 2);
2200 AddMacroDef(ltFIGURE
, "figure", 1);
2201 AddMacroDef(ltFIGURESTAR
, "figure*", 1);
2202 AddMacroDef(ltFLUSHLEFT
, "flushleft", 1);
2203 AddMacroDef(ltFLUSHRIGHT
, "flushright", 1);
2204 AddMacroDef(ltFOLLOWEDLINKCOLOUR
, "followedlinkcolour", 1);
2205 AddMacroDef(ltFOOTHEIGHT
, "footheight", 1);
2206 AddMacroDef(ltFOOTNOTEPOPUP
, "footnotepopup", 2);
2207 AddMacroDef(ltFOOTNOTE
, "footnote", 1);
2208 AddMacroDef(ltFOOTSKIP
, "footskip", 1);
2209 AddMacroDef(ltFORALL
, "forall", 0);
2210 AddMacroDef(ltFRAMEBOX
, "framebox", 1);
2211 AddMacroDef(ltFROWN
, "frown", 0);
2212 AddMacroDef(ltFUNCTIONSECTION
, "functionsection", 1);
2213 AddMacroDef(ltFUNC
, "func", 3);
2214 AddMacroDef(ltFOOTNOTESIZE
, "footnotesize", 0);
2215 AddMacroDef(ltFANCYPLAIN
, "fancyplain", 2);
2217 AddMacroDef(ltGAMMA
, "gamma", 0);
2218 AddMacroDef(ltCAP_GAMMA
, "Gamma", 0);
2219 AddMacroDef(ltGEQ
, "geq", 0);
2220 AddMacroDef(ltGE
, "ge", 0);
2221 AddMacroDef(ltGG
, "gg", 0);
2222 AddMacroDef(ltGLOSSARY
, "glossary", 1);
2223 AddMacroDef(ltGLOSS
, "gloss", 1);
2225 AddMacroDef(ltHEADHEIGHT
, "headheight", 1);
2226 AddMacroDef(ltHEARTSUIT
, "heartsuit", 0);
2227 AddMacroDef(ltHELPGLOSSARY
, "helpglossary", 1);
2228 AddMacroDef(ltHELPIGNORE
, "helpignore", 1, TRUE
);
2229 AddMacroDef(ltHELPONLY
, "helponly", 1);
2230 AddMacroDef(ltHELPINPUT
, "helpinput", 1);
2231 AddMacroDef(ltHELPFONTFAMILY
, "helpfontfamily", 1);
2232 AddMacroDef(ltHELPFONTSIZE
, "helpfontsize", 1);
2233 AddMacroDef(ltHELPREFN
, "helprefn", 2);
2234 AddMacroDef(ltHELPREF
, "helpref", 2);
2235 AddMacroDef(ltHFILL
, "hfill", 0);
2236 AddMacroDef(ltHLINE
, "hline", 0);
2237 AddMacroDef(ltHRULE
, "hrule", 0);
2238 AddMacroDef(ltHSPACESTAR
, "hspace*", 1);
2239 AddMacroDef(ltHSPACE
, "hspace", 1);
2240 AddMacroDef(ltHSKIPSTAR
, "hskip*", 1);
2241 AddMacroDef(ltHSKIP
, "hskip", 1);
2242 AddMacroDef(lthuge
, "huge", 1);
2243 AddMacroDef(ltHuge
, "Huge", 1);
2244 AddMacroDef(ltHUGE
, "HUGE", 1);
2245 AddMacroDef(ltHTMLIGNORE
, "htmlignore", 1);
2246 AddMacroDef(ltHTMLONLY
, "htmlonly", 1);
2248 AddMacroDef(ltIM
, "im", 0);
2249 AddMacroDef(ltINCLUDEONLY
, "includeonly", 1);
2250 AddMacroDef(ltINCLUDE
, "include", 1);
2251 AddMacroDef(ltINDENTED
, "indented", 2);
2252 AddMacroDef(ltINDEX
, "index", 1);
2253 AddMacroDef(ltINPUT
, "input", 1, TRUE
);
2254 AddMacroDef(ltIOTA
, "iota", 0);
2255 AddMacroDef(ltITEMIZE
, "itemize", 1);
2256 AddMacroDef(ltITEM
, "item", 0);
2257 AddMacroDef(ltIMAGEMAP
, "imagemap", 3);
2258 AddMacroDef(ltIMAGEL
, "imagel", 2);
2259 AddMacroDef(ltIMAGER
, "imager", 2);
2260 AddMacroDef(ltIMAGE
, "image", 2);
2261 AddMacroDef(ltIN
, "in", 0);
2262 AddMacroDef(ltINFTY
, "infty", 0);
2263 AddMacroDef(ltITSHAPE
, "itshape", 1);
2264 AddMacroDef(ltIT
, "it", 1);
2265 AddMacroDef(ltITEMSEP
, "itemsep", 1);
2266 AddMacroDef(ltINSERTATLEVEL
, "insertatlevel", 2);
2268 AddMacroDef(ltKAPPA
, "kappa", 0);
2269 AddMacroDef(ltKILL
, "kill", 0);
2271 AddMacroDef(ltLABEL
, "label", 1);
2272 AddMacroDef(ltLAMBDA
, "lambda", 0);
2273 AddMacroDef(ltCAP_LAMBDA
, "Lambda", 0);
2274 AddMacroDef(ltlarge
, "large", 1);
2275 AddMacroDef(ltLarge
, "Large", 1);
2276 AddMacroDef(ltLARGE
, "LARGE", 1);
2277 AddMacroDef(ltLATEXIGNORE
, "latexignore", 1);
2278 AddMacroDef(ltLATEXONLY
, "latexonly", 1);
2279 AddMacroDef(ltLATEX
, "LaTeX", 0);
2280 AddMacroDef(ltLBOX
, "lbox", 1);
2281 AddMacroDef(ltLBRACERAW
, "lbraceraw", 0);
2282 AddMacroDef(ltLDOTS
, "ldots", 0);
2283 AddMacroDef(ltLEQ
, "leq", 0);
2284 AddMacroDef(ltLE
, "le", 0);
2285 AddMacroDef(ltLEFTARROW
, "leftarrow", 0);
2286 AddMacroDef(ltLEFTRIGHTARROW
, "leftrightarrow", 0);
2287 AddMacroDef(ltLEFTARROW2
, "Leftarrow", 0);
2288 AddMacroDef(ltLEFTRIGHTARROW2
, "Leftrightarrow", 0);
2289 AddMacroDef(ltLINEBREAK
, "linebreak", 0);
2290 AddMacroDef(ltLINKCOLOUR
, "linkcolour", 1);
2291 AddMacroDef(ltLISTOFFIGURES
, "listoffigures", 0);
2292 AddMacroDef(ltLISTOFTABLES
, "listoftables", 0);
2293 AddMacroDef(ltLHEAD
, "lhead", 1);
2294 AddMacroDef(ltLFOOT
, "lfoot", 1);
2295 AddMacroDef(ltLOWERCASE
, "lowercase", 1);
2296 AddMacroDef(ltLL
, "ll", 0);
2298 AddMacroDef(ltMAKEGLOSSARY
, "makeglossary", 0);
2299 AddMacroDef(ltMAKEINDEX
, "makeindex", 0);
2300 AddMacroDef(ltMAKETITLE
, "maketitle", 0);
2301 AddMacroDef(ltMARKRIGHT
, "markright", 1);
2302 AddMacroDef(ltMARKBOTH
, "markboth", 2);
2303 AddMacroDef(ltMARGINPARWIDTH
, "marginparwidth", 1);
2304 AddMacroDef(ltMARGINPARSEP
, "marginparsep", 1);
2305 AddMacroDef(ltMARGINPARODD
, "marginparodd", 1);
2306 AddMacroDef(ltMARGINPAREVEN
, "marginpareven", 1);
2307 AddMacroDef(ltMARGINPAR
, "marginpar", 1);
2308 AddMacroDef(ltMBOX
, "mbox", 1);
2309 AddMacroDef(ltMDSERIES
, "mdseries", 1);
2310 AddMacroDef(ltMEMBERSECTION
, "membersection", 1);
2311 AddMacroDef(ltMEMBER
, "member", 2);
2312 AddMacroDef(ltMID
, "mid", 0);
2313 AddMacroDef(ltMODELS
, "models", 0);
2314 AddMacroDef(ltMP
, "mp", 0);
2315 AddMacroDef(ltMULTICOLUMN
, "multicolumn", 3);
2316 AddMacroDef(ltMU
, "mu", 0);
2318 AddMacroDef(ltNABLA
, "nabla", 0);
2319 AddMacroDef(ltNEG
, "neg", 0);
2320 AddMacroDef(ltNEQ
, "neq", 0);
2321 AddMacroDef(ltNEWCOUNTER
, "newcounter", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2322 AddMacroDef(ltNEWLINE
, "newline", 0);
2323 AddMacroDef(ltNEWPAGE
, "newpage", 0);
2324 AddMacroDef(ltNI
, "ni", 0);
2325 AddMacroDef(ltNOCITE
, "nocite", 1);
2326 AddMacroDef(ltNOINDENT
, "noindent", 0);
2327 AddMacroDef(ltNOLINEBREAK
, "nolinebreak", 0);
2328 AddMacroDef(ltNOPAGEBREAK
, "nopagebreak", 0);
2329 AddMacroDef(ltNORMALSIZE
, "normalsize", 1);
2330 AddMacroDef(ltNORMALBOX
, "normalbox", 1);
2331 AddMacroDef(ltNORMALBOXD
, "normalboxd", 1);
2332 AddMacroDef(ltNOTEQ
, "noteq", 0);
2333 AddMacroDef(ltNOTIN
, "notin", 0);
2334 AddMacroDef(ltNOTSUBSET
, "notsubset", 0);
2335 AddMacroDef(ltNU
, "nu", 0);
2337 AddMacroDef(ltODDSIDEMARGIN
, "oddsidemargin", 1);
2338 AddMacroDef(ltOMEGA
, "omega", 0);
2339 AddMacroDef(ltCAP_OMEGA
, "Omega", 0);
2340 AddMacroDef(ltONECOLUMN
, "onecolumn", 0);
2341 AddMacroDef(ltOPLUS
, "oplus", 0);
2342 AddMacroDef(ltOSLASH
, "oslash", 0);
2343 AddMacroDef(ltOTIMES
, "otimes", 0);
2345 AddMacroDef(ltPAGEBREAK
, "pagebreak", 0);
2346 AddMacroDef(ltPAGEREF
, "pageref", 1);
2347 AddMacroDef(ltPAGESTYLE
, "pagestyle", 1);
2348 AddMacroDef(ltPAGENUMBERING
, "pagenumbering", 1);
2349 AddMacroDef(ltPARAGRAPHSTAR
, "paragraph*", 1);
2350 AddMacroDef(ltPARAGRAPH
, "paragraph", 1);
2351 AddMacroDef(ltPARALLEL
, "parallel", 0);
2352 AddMacroDef(ltPARAM
, "param", 2);
2353 AddMacroDef(ltPARINDENT
, "parindent", 1);
2354 AddMacroDef(ltPARSKIP
, "parskip", 1);
2355 AddMacroDef(ltPARTIAL
, "partial", 0);
2356 AddMacroDef(ltPARTSTAR
, "part*", 1);
2357 AddMacroDef(ltPART
, "part", 1);
2358 AddMacroDef(ltPAR
, "par", 0);
2359 AddMacroDef(ltPERP
, "perp", 0);
2360 AddMacroDef(ltPHI
, "phi", 0);
2361 AddMacroDef(ltCAP_PHI
, "Phi", 0);
2362 AddMacroDef(ltPFUNC
, "pfunc", 3);
2363 AddMacroDef(ltPICTURE
, "picture", 1);
2364 AddMacroDef(ltPI
, "pi", 0);
2365 AddMacroDef(ltCAP_PI
, "Pi", 0);
2366 AddMacroDef(ltPM
, "pm", 0);
2367 AddMacroDef(ltPOPREFONLY
, "poprefonly", 1);
2368 AddMacroDef(ltPOPREF
, "popref", 2);
2369 AddMacroDef(ltPOUNDS
, "pounds", 0);
2370 AddMacroDef(ltPREC
, "prec", 0);
2371 AddMacroDef(ltPRECEQ
, "preceq", 0);
2372 AddMacroDef(ltPRINTINDEX
, "printindex", 0);
2373 AddMacroDef(ltPROPTO
, "propto", 0);
2374 AddMacroDef(ltPSBOXTO
, "psboxto", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2375 AddMacroDef(ltPSBOX
, "psbox", 1, FALSE
, (bool)FORBID_ABSOLUTELY
);
2376 AddMacroDef(ltPSI
, "psi", 0);
2377 AddMacroDef(ltCAP_PSI
, "Psi", 0);
2379 AddMacroDef(ltQUOTE
, "quote", 1);
2380 AddMacroDef(ltQUOTATION
, "quotation", 1);
2382 AddMacroDef(ltRAGGEDBOTTOM
, "raggedbottom", 0);
2383 AddMacroDef(ltRAGGEDLEFT
, "raggedleft", 0);
2384 AddMacroDef(ltRAGGEDRIGHT
, "raggedright", 0);
2385 AddMacroDef(ltRBRACERAW
, "rbraceraw", 0);
2386 AddMacroDef(ltREF
, "ref", 1);
2387 AddMacroDef(ltREGISTERED
, "registered", 0);
2388 AddMacroDef(ltRE
, "we", 0);
2389 AddMacroDef(ltRHO
, "rho", 0);
2390 AddMacroDef(ltRIGHTARROW
, "rightarrow", 0);
2391 AddMacroDef(ltRIGHTARROW2
, "rightarrow2", 0);
2392 AddMacroDef(ltRMFAMILY
, "rmfamily", 1);
2393 AddMacroDef(ltRM
, "rm", 1);
2394 AddMacroDef(ltROMAN
, "roman", 1);
2395 AddMacroDef(ltROMAN2
, "Roman", 1);
2396 // AddMacroDef(lt"row", 1);
2397 AddMacroDef(ltRTFSP
, "rtfsp", 0);
2398 AddMacroDef(ltRTFIGNORE
, "rtfignore", 1);
2399 AddMacroDef(ltRTFONLY
, "rtfonly", 1);
2400 AddMacroDef(ltRULEDROW
, "ruledrow", 1);
2401 AddMacroDef(ltDRULED
, "druled", 1);
2402 AddMacroDef(ltRULE
, "rule", 2);
2403 AddMacroDef(ltRHEAD
, "rhead", 1);
2404 AddMacroDef(ltRFOOT
, "rfoot", 1);
2405 AddMacroDef(ltROW
, "row", 1);
2407 AddMacroDef(ltSCSHAPE
, "scshape", 1);
2408 AddMacroDef(ltSC
, "sc", 1);
2409 AddMacroDef(ltSECTIONHEADING
, "sectionheading", 1);
2410 AddMacroDef(ltSECTIONSTAR
, "section*", 1);
2411 AddMacroDef(ltSECTION
, "section", 1);
2412 AddMacroDef(ltSETCOUNTER
, "setcounter", 2);
2413 AddMacroDef(ltSFFAMILY
, "sffamily", 1);
2414 AddMacroDef(ltSF
, "sf", 1);
2415 AddMacroDef(ltSHARP
, "sharp", 0);
2416 AddMacroDef(ltSHORTCITE
, "shortcite", 1);
2417 AddMacroDef(ltSIGMA
, "sigma", 0);
2418 AddMacroDef(ltCAP_SIGMA
, "Sigma", 0);
2419 AddMacroDef(ltSIM
, "sim", 0);
2420 AddMacroDef(ltSIMEQ
, "simeq", 0);
2421 AddMacroDef(ltSINGLESPACE
, "singlespace", 1);
2422 AddMacroDef(ltSIZEDBOX
, "sizedbox", 2);
2423 AddMacroDef(ltSIZEDBOXD
, "sizedboxd", 2);
2424 AddMacroDef(ltSLOPPYPAR
, "sloppypar", 1);
2425 AddMacroDef(ltSLOPPY
, "sloppy", 0);
2426 AddMacroDef(ltSLSHAPE
, "slshape", 1);
2427 AddMacroDef(ltSL
, "sl", 1);
2428 AddMacroDef(ltSMALL
, "small", 1);
2429 AddMacroDef(ltSMILE
, "smile", 0);
2430 AddMacroDef(ltSS
, "ss", 0);
2431 AddMacroDef(ltSTAR
, "star", 0);
2432 AddMacroDef(ltSUBITEM
, "subitem", 0);
2433 AddMacroDef(ltSUBPARAGRAPHSTAR
, "subparagraph*", 1);
2434 AddMacroDef(ltSUBPARAGRAPH
, "subparagraph", 1);
2435 AddMacroDef(ltSPECIAL
, "special", 1);
2436 AddMacroDef(ltSUBSECTIONSTAR
, "subsection*", 1);
2437 AddMacroDef(ltSUBSECTION
, "subsection", 1);
2438 AddMacroDef(ltSUBSETEQ
, "subseteq", 0);
2439 AddMacroDef(ltSUBSET
, "subset", 0);
2440 AddMacroDef(ltSUCC
, "succ", 0);
2441 AddMacroDef(ltSUCCEQ
, "succeq", 0);
2442 AddMacroDef(ltSUPSETEQ
, "supseteq", 0);
2443 AddMacroDef(ltSUPSET
, "supset", 0);
2444 AddMacroDef(ltSUBSUBSECTIONSTAR
,"subsubsection*", 1);
2445 AddMacroDef(ltSUBSUBSECTION
, "subsubsection", 1);
2446 AddMacroDef(ltSUPERTABULAR
, "supertabular", 2, FALSE
);
2447 AddMacroDef(ltSURD
, "surd", 0);
2448 AddMacroDef(ltSCRIPTSIZE
, "scriptsize", 1);
2449 AddMacroDef(ltSETHEADER
, "setheader", 6);
2450 AddMacroDef(ltSETFOOTER
, "setfooter", 6);
2451 AddMacroDef(ltSETHOTSPOTCOLOUR
, "sethotspotcolour", 1);
2452 AddMacroDef(ltSETHOTSPOTCOLOR
, "sethotspotcolor", 1);
2453 AddMacroDef(ltSETHOTSPOTUNDERLINE
, "sethotspotunderline", 1);
2454 AddMacroDef(ltSETTRANSPARENCY
, "settransparency", 1);
2455 AddMacroDef(ltSPADESUIT
, "spadesuit", 0);
2457 AddMacroDef(ltTABBING
, "tabbing", 2);
2458 AddMacroDef(ltTABLEOFCONTENTS
, "tableofcontents", 0);
2459 AddMacroDef(ltTABLE
, "table", 1);
2460 AddMacroDef(ltTABULAR
, "tabular", 2, FALSE
);
2461 AddMacroDef(ltTAB
, "tab", 0);
2462 AddMacroDef(ltTAU
, "tau", 0);
2463 AddMacroDef(ltTEXTRM
, "textrm", 1);
2464 AddMacroDef(ltTEXTSF
, "textsf", 1);
2465 AddMacroDef(ltTEXTTT
, "texttt", 1);
2466 AddMacroDef(ltTEXTBF
, "textbf", 1);
2467 AddMacroDef(ltTEXTIT
, "textit", 1);
2468 AddMacroDef(ltTEXTSL
, "textsl", 1);
2469 AddMacroDef(ltTEXTSC
, "textsc", 1);
2470 AddMacroDef(ltTEXTWIDTH
, "textwidth", 1);
2471 AddMacroDef(ltTEXTHEIGHT
, "textheight", 1);
2472 AddMacroDef(ltTEXTCOLOUR
, "textcolour", 1);
2473 AddMacroDef(ltTEX
, "TeX", 0);
2474 AddMacroDef(ltTHEBIBLIOGRAPHY
, "thebibliography", 2);
2475 AddMacroDef(ltTHETA
, "theta", 0);
2476 AddMacroDef(ltTIMES
, "times", 0);
2477 AddMacroDef(ltCAP_THETA
, "Theta", 0);
2478 AddMacroDef(ltTITLEPAGE
, "titlepage", 1);
2479 AddMacroDef(ltTITLE
, "title", 1);
2480 AddMacroDef(ltTINY
, "tiny", 1);
2481 AddMacroDef(ltTODAY
, "today", 0);
2482 AddMacroDef(ltTOPMARGIN
, "topmargin", 1);
2483 AddMacroDef(ltTOPSKIP
, "topskip", 1);
2484 AddMacroDef(ltTRIANGLE
, "triangle", 0);
2485 AddMacroDef(ltTTFAMILY
, "ttfamily", 1);
2486 AddMacroDef(ltTT
, "tt", 1);
2487 AddMacroDef(ltTYPEIN
, "typein", 1);
2488 AddMacroDef(ltTYPEOUT
, "typeout", 1);
2489 AddMacroDef(ltTWOCOLWIDTHA
, "twocolwidtha", 1);
2490 AddMacroDef(ltTWOCOLWIDTHB
, "twocolwidthb", 1);
2491 AddMacroDef(ltTWOCOLSPACING
, "twocolspacing", 1);
2492 AddMacroDef(ltTWOCOLITEMRULED
, "twocolitemruled", 2);
2493 AddMacroDef(ltTWOCOLITEM
, "twocolitem", 2);
2494 AddMacroDef(ltTWOCOLLIST
, "twocollist", 1);
2495 AddMacroDef(ltTWOCOLUMN
, "twocolumn", 0);
2496 AddMacroDef(ltTHEPAGE
, "thepage", 0);
2497 AddMacroDef(ltTHECHAPTER
, "thechapter", 0);
2498 AddMacroDef(ltTHESECTION
, "thesection", 0);
2499 AddMacroDef(ltTHISPAGESTYLE
, "thispagestyle", 1);
2501 AddMacroDef(ltUNDERLINE
, "underline", 1);
2502 AddMacroDef(ltUPSILON
, "upsilon", 0);
2503 AddMacroDef(ltCAP_UPSILON
, "Upsilon", 0);
2504 AddMacroDef(ltUPARROW
, "uparrow", 0);
2505 AddMacroDef(ltUPARROW2
, "Uparrow", 0);
2506 AddMacroDef(ltUPPERCASE
, "uppercase", 1);
2507 AddMacroDef(ltUPSHAPE
, "upshape", 1);
2508 AddMacroDef(ltURLREF
, "urlref", 2);
2509 AddMacroDef(ltUSEPACKAGE
, "usepackage", 1);
2511 AddMacroDef(ltVAREPSILON
, "varepsilon", 0);
2512 AddMacroDef(ltVARPHI
, "varphi", 0);
2513 AddMacroDef(ltVARPI
, "varpi", 0);
2514 AddMacroDef(ltVARRHO
, "varrho", 0);
2515 AddMacroDef(ltVARSIGMA
, "varsigma", 0);
2516 AddMacroDef(ltVARTHETA
, "vartheta", 0);
2517 AddMacroDef(ltVDOTS
, "vdots", 0);
2518 AddMacroDef(ltVEE
, "vee", 0);
2519 AddMacroDef(ltVERBATIMINPUT
, "verbatiminput", 1);
2520 AddMacroDef(ltVERBATIM
, "verbatim", 1);
2521 AddMacroDef(ltVERBSTAR
, "verb*", 1);
2522 AddMacroDef(ltVERB
, "verb", 1);
2523 AddMacroDef(ltVERSE
, "verse", 1);
2524 AddMacroDef(ltVFILL
, "vfill", 0);
2525 AddMacroDef(ltVLINE
, "vline", 0);
2526 AddMacroDef(ltVOID
, "void", 0);
2527 AddMacroDef(ltVDASH
, "vdash", 0);
2528 AddMacroDef(ltVRULE
, "vrule", 0);
2529 AddMacroDef(ltVSPACESTAR
, "vspace*", 1);
2530 AddMacroDef(ltVSKIPSTAR
, "vskip*", 1);
2531 AddMacroDef(ltVSPACE
, "vspace", 1);
2532 AddMacroDef(ltVSKIP
, "vskip", 1);
2534 AddMacroDef(ltWEDGE
, "wedge", 0);
2535 AddMacroDef(ltWXCLIPS
, "wxclips", 0);
2536 AddMacroDef(ltWINHELPIGNORE
, "winhelpignore", 1);
2537 AddMacroDef(ltWINHELPONLY
, "winhelponly", 1);
2538 AddMacroDef(ltWP
, "wp", 0);
2540 AddMacroDef(ltXI
, "xi", 0);
2541 AddMacroDef(ltCAP_XI
, "Xi", 0);
2542 AddMacroDef(ltXLPIGNORE
, "xlpignore", 1);
2543 AddMacroDef(ltXLPONLY
, "xlponly", 1);
2545 AddMacroDef(ltZETA
, "zeta", 0);
2547 AddMacroDef(ltSPACE
, " ", 0);
2548 AddMacroDef(ltBACKSLASHCHAR
, "\\", 0);
2549 AddMacroDef(ltPIPE
, "|", 0);
2550 AddMacroDef(ltFORWARDSLASH
, "/", 0);
2551 AddMacroDef(ltUNDERSCORE
, "_", 0);
2552 AddMacroDef(ltAMPERSAND
, "&", 0);
2553 AddMacroDef(ltPERCENT
, "%", 0);
2554 AddMacroDef(ltDOLLAR
, "$", 0);
2555 AddMacroDef(ltHASH
, "#", 0);
2556 AddMacroDef(ltLPARENTH
, "(", 0);
2557 AddMacroDef(ltRPARENTH
, ")", 0);
2558 AddMacroDef(ltLBRACE
, "{", 0);
2559 AddMacroDef(ltRBRACE
, "}", 0);
2560 // AddMacroDef(ltEQUALS, "=", 0);
2561 AddMacroDef(ltRANGLEBRA
, ">", 0);
2562 AddMacroDef(ltLANGLEBRA
, "<", 0);
2563 AddMacroDef(ltPLUS
, "+", 0);
2564 AddMacroDef(ltDASH
, "-", 0);
2565 AddMacroDef(ltAT_SYMBOL
, "@", 0);
2566 // AddMacroDef(ltSINGLEQUOTE, "'", 0);
2567 // AddMacroDef(ltBACKQUOTE, "`", 0);
2571 * Default behaviour, should be called by client if can't match locally.
2575 // Called on start/end of macro examination
2576 void DefaultOnMacro(int macroId
, int no_args
, bool start
)
2580 // Default behaviour for abstract
2585 // Write the heading
2586 FakeCurrentSection(AbstractNameString
);
2587 OnMacro(ltPAR
, 0, TRUE
);
2588 OnMacro(ltPAR
, 0, FALSE
);
2592 if (DocumentStyle
== LATEX_ARTICLE
)
2600 // Default behaviour for glossary
2601 case ltHELPGLOSSARY
:
2605 // Write the heading
2606 FakeCurrentSection(GlossaryNameString
);
2607 OnMacro(ltPAR
, 0, TRUE
);
2608 OnMacro(ltPAR
, 0, FALSE
);
2609 if ((convertMode
== TEX_RTF
) && !winHelp
)
2611 OnMacro(ltPAR
, 0, TRUE
);
2612 OnMacro(ltPAR
, 0, FALSE
);
2617 case ltSPECIALAMPERSAND
:
2624 TexOutput("<<", TRUE
);
2628 TexOutput(">>", TRUE
);
2632 TexOutput("~", TRUE
);
2636 TexOutput("~", TRUE
);
2638 case ltSPECIALTILDE
:
2640 TexOutput(" ", TRUE
);
2644 TexOutput("_", TRUE
);
2648 TexOutput("#", TRUE
);
2652 TexOutput("&", TRUE
);
2656 TexOutput(" ", TRUE
);
2660 TexOutput("|", TRUE
);
2664 TexOutput("%", TRUE
);
2668 TexOutput("$", TRUE
);
2672 TexOutput("", TRUE
);
2676 TexOutput("", TRUE
);
2680 TexOutput("{", TRUE
);
2684 TexOutput("}", TRUE
);
2688 TexOutput("(c)", TRUE
);
2692 TexOutput("(r)", TRUE
);
2696 TexOutput("\\", TRUE
);
2701 TexOutput("...", TRUE
);
2705 TexOutput("|", TRUE
);
2709 TexOutput("LaTeX", TRUE
);
2713 TexOutput("TeX", TRUE
);
2717 TexOutput("£", TRUE
);
2719 case ltSPECIALDOUBLEDOLLAR
: // Interpret as center
2720 OnMacro(ltCENTER
, no_args
, start
);
2726 OnMacro(ltIT
, no_args
, start
);
2729 case ltPARAGRAPHSTAR
:
2730 case ltSUBPARAGRAPH
:
2731 case ltSUBPARAGRAPHSTAR
:
2732 OnMacro(ltSUBSUBSECTION
, no_args
, start
);
2740 TexOutput(ctime(&when
), TRUE
);
2751 if (start
) TexOutput("alpha");
2754 if (start
) TexOutput("beta");
2757 if (start
) TexOutput("gamma");
2760 if (start
) TexOutput("delta");
2764 if (start
) TexOutput("epsilon");
2767 if (start
) TexOutput("zeta");
2770 if (start
) TexOutput("eta");
2774 if (start
) TexOutput("theta");
2777 if (start
) TexOutput("iota");
2780 if (start
) TexOutput("kappa");
2783 if (start
) TexOutput("lambda");
2786 if (start
) TexOutput("mu");
2789 if (start
) TexOutput("nu");
2792 if (start
) TexOutput("xi");
2796 if (start
) TexOutput("pi");
2800 if (start
) TexOutput("rho");
2804 if (start
) TexOutput("sigma");
2807 if (start
) TexOutput("tau");
2810 if (start
) TexOutput("upsilon");
2814 if (start
) TexOutput("phi");
2817 if (start
) TexOutput("chi");
2820 if (start
) TexOutput("psi");
2823 if (start
) TexOutput("omega");
2826 if (start
) TexOutput("GAMMA");
2829 if (start
) TexOutput("DELTA");
2832 if (start
) TexOutput("THETA");
2835 if (start
) TexOutput("LAMBDA");
2838 if (start
) TexOutput("XI");
2841 if (start
) TexOutput("PI");
2844 if (start
) TexOutput("SIGMA");
2847 if (start
) TexOutput("UPSILON");
2850 if (start
) TexOutput("PHI");
2853 if (start
) TexOutput("PSI");
2856 if (start
) TexOutput("OMEGA");
2859 // Binary operation symbols
2862 if (start
) TexOutput("<=");
2865 if (start
) TexOutput("<<");
2868 if (start
) TexOutput("SUBSET");
2871 if (start
) TexOutput("SUBSETEQ");
2874 if (start
) TexOutput("IN");
2877 if (start
) TexOutput("VDASH");
2880 if (start
) TexOutput("MODELS");
2884 if (start
) TexOutput(">=");
2887 if (start
) TexOutput(">>");
2890 if (start
) TexOutput("SUPSET");
2893 if (start
) TexOutput("SUPSETEQ");
2896 if (start
) TexOutput("NI");
2899 if (start
) TexOutput("DASHV");
2902 if (start
) TexOutput("PERP");
2905 if (start
) TexOutput("NEQ");
2908 if (start
) TexOutput("DOTEQ");
2911 if (start
) TexOutput("APPROX");
2914 if (start
) TexOutput("CONG");
2917 if (start
) TexOutput("EQUIV");
2920 if (start
) TexOutput("PROPTO");
2923 if (start
) TexOutput("PREC");
2926 if (start
) TexOutput("PRECEQ");
2929 if (start
) TexOutput("|");
2932 if (start
) TexOutput("~");
2935 if (start
) TexOutput("SIMEQ");
2938 if (start
) TexOutput("ASYMP");
2941 if (start
) TexOutput(":-)");
2944 if (start
) TexOutput(":-(");
2947 if (start
) TexOutput("SUCC");
2950 if (start
) TexOutput("SUCCEQ");
2953 if (start
) TexOutput("|");
2956 // Negated relation symbols
2958 if (start
) TexOutput("!=");
2961 if (start
) TexOutput("NOTIN");
2964 if (start
) TexOutput("NOTSUBSET");
2969 if (start
) TexOutput("<--");
2972 if (start
) TexOutput("<==");
2975 if (start
) TexOutput("-->");
2978 if (start
) TexOutput("==>");
2980 case ltLEFTRIGHTARROW
:
2981 if (start
) TexOutput("<-->");
2983 case ltLEFTRIGHTARROW2
:
2984 if (start
) TexOutput("<==>");
2987 if (start
) TexOutput("UPARROW");
2990 if (start
) TexOutput("UPARROW2");
2993 if (start
) TexOutput("DOWNARROW");
2996 if (start
) TexOutput("DOWNARROW2");
2998 // Miscellaneous symbols
3000 if (start
) TexOutput("ALEPH");
3003 if (start
) TexOutput("WP");
3006 if (start
) TexOutput("RE");
3009 if (start
) TexOutput("IM");
3012 if (start
) TexOutput("EMPTYSET");
3015 if (start
) TexOutput("NABLA");
3018 if (start
) TexOutput("SURD");
3021 if (start
) TexOutput("PARTIAL");
3024 if (start
) TexOutput("BOT");
3027 if (start
) TexOutput("FORALL");
3030 if (start
) TexOutput("EXISTS");
3033 if (start
) TexOutput("NEG");
3036 if (start
) TexOutput("SHARP");
3039 if (start
) TexOutput("ANGLE");
3042 if (start
) TexOutput("TRIANGLE");
3045 if (start
) TexOutput("CLUBSUIT");
3048 if (start
) TexOutput("DIAMONDSUIT");
3051 if (start
) TexOutput("HEARTSUIT");
3054 if (start
) TexOutput("SPADESUIT");
3057 if (start
) TexOutput("INFTY");
3060 if (start
) TexOutput("PM");
3063 if (start
) TexOutput("MP");
3066 if (start
) TexOutput("TIMES");
3069 if (start
) TexOutput("DIV");
3072 if (start
) TexOutput("CDOT");
3075 if (start
) TexOutput("AST");
3078 if (start
) TexOutput("STAR");
3081 if (start
) TexOutput("CAP");
3084 if (start
) TexOutput("CUP");
3087 if (start
) TexOutput("VEE");
3090 if (start
) TexOutput("WEDGE");
3093 if (start
) TexOutput("CIRC");
3096 if (start
) TexOutput("BULLET");
3099 if (start
) TexOutput("DIAMOND");
3102 if (start
) TexOutput("OSLASH");
3105 if (start
) TexOutput("BOX");
3108 if (start
) TexOutput("DIAMOND2");
3110 case ltBIGTRIANGLEDOWN
:
3111 if (start
) TexOutput("BIGTRIANGLEDOWN");
3114 if (start
) TexOutput("OPLUS");
3117 if (start
) TexOutput("OTIMES");
3120 if (start
) TexOutput("s");
3122 case ltBACKSLASHRAW
:
3123 if (start
) TexOutput("\\");
3126 if (start
) TexOutput("{");
3129 if (start
) TexOutput("}");
3133 if (start
) TexOutput(" ");
3140 // Called on start/end of argument examination
3141 bool DefaultOnArgument(int macroId
, int arg_no
, bool start
)
3147 if (arg_no
== 1 && start
)
3149 char *refName
= GetArgData();
3152 TexRef
*texRef
= FindReference(refName
);
3155 // Must strip the 'section' or 'chapter' or 'figure' text
3156 // from a normal 'ref' reference
3158 strcpy(buf
, texRef
->sectionNumber
);
3159 int len
= strlen(buf
);
3161 if (strcmp(buf
, "??") != 0)
3173 TexOutput(texRef
->sectionNumber
+ i
, TRUE
);
3178 informBuf
.Printf("Warning: unresolved reference '%s'", refName
);
3179 OnInform((char *)informBuf
.c_str());
3182 else TexOutput("??", TRUE
);
3194 if (start
&& (arg_no
== 1))
3195 DocumentAuthor
= GetArgChunk();
3201 if (start
&& (arg_no
== 1))
3202 DocumentDate
= GetArgChunk();
3208 if (start
&& (arg_no
== 1))
3209 DocumentTitle
= GetArgChunk();
3213 case ltDOCUMENTCLASS
:
3214 case ltDOCUMENTSTYLE
:
3216 if (start
&& !IsArgOptional())
3218 DocumentStyleString
= copystring(GetArgData());
3219 if (strncmp(DocumentStyleString
, "art", 3) == 0)
3220 DocumentStyle
= LATEX_ARTICLE
;
3221 else if (strncmp(DocumentStyleString
, "rep", 3) == 0)
3222 DocumentStyle
= LATEX_REPORT
;
3223 else if (strncmp(DocumentStyleString
, "book", 4) == 0 ||
3224 strncmp(DocumentStyleString
, "thesis", 6) == 0)
3225 DocumentStyle
= LATEX_BOOK
;
3226 else if (strncmp(DocumentStyleString
, "letter", 6) == 0)
3227 DocumentStyle
= LATEX_LETTER
;
3228 else if (strncmp(DocumentStyleString
, "slides", 6) == 0)
3229 DocumentStyle
= LATEX_SLIDES
;
3231 if (StringMatch("10", DocumentStyleString
))
3233 else if (StringMatch("11", DocumentStyleString
))
3235 else if (StringMatch("12", DocumentStyleString
))
3238 OnMacro(ltHELPFONTSIZE
, 1, TRUE
);
3239 sprintf(currentArgData
, "%d", normalFont
);
3241 OnArgument(ltHELPFONTSIZE
, 1, TRUE
);
3242 OnArgument(ltHELPFONTSIZE
, 1, FALSE
);
3243 haveArgData
= FALSE
;
3244 OnMacro(ltHELPFONTSIZE
, 1, FALSE
);
3246 else if (start
&& IsArgOptional())
3248 MinorDocumentStyleString
= copystring(GetArgData());
3250 if (StringMatch("10", MinorDocumentStyleString
))
3252 else if (StringMatch("11", MinorDocumentStyleString
))
3254 else if (StringMatch("12", MinorDocumentStyleString
))
3260 case ltBIBLIOGRAPHYSTYLE
:
3262 if (start
&& !IsArgOptional())
3263 BibliographyStyleString
= copystring(GetArgData());
3269 if (start
&& !IsArgOptional())
3271 if (PageStyle
) delete[] PageStyle
;
3272 PageStyle
= copystring(GetArgData());
3280 if (start && !IsArgOptional())
3281 LeftHeader = GetArgChunk();
3287 if (start && !IsArgOptional())
3288 LeftFooter = GetArgChunk();
3294 if (start && !IsArgOptional())
3295 CentreHeader = GetArgChunk();
3301 if (start && !IsArgOptional())
3302 CentreFooter = GetArgChunk();
3308 if (start && !IsArgOptional())
3309 RightHeader = GetArgChunk();
3315 if (start && !IsArgOptional())
3316 RightFooter = GetArgChunk();
3324 if (start
&& !IsArgOptional())
3326 char *citeKeys
= GetArgData();
3328 char *citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3331 AddCitation(citeKey
);
3332 TexRef
*ref
= FindReference(citeKey
);
3335 TexOutput(ref
->sectionNumber
, TRUE
);
3336 if (strcmp(ref
->sectionNumber
, "??") == 0)
3339 informBuf
.Printf("Warning: unresolved citation %s.", citeKey
);
3340 OnInform((char *)informBuf
.c_str());
3343 citeKey
= ParseMultifieldString(citeKeys
, &pos
);
3346 TexOutput(", ", TRUE
);
3355 if (start
&& !IsArgOptional())
3357 char *citeKey
= GetArgData();
3358 AddCitation(citeKey
);
3363 case ltHELPFONTSIZE
:
3367 char *data
= GetArgData();
3368 if (strcmp(data
, "10") == 0)
3370 else if (strcmp(data
, "11") == 0)
3372 else if (strcmp(data
, "12") == 0)
3382 TexOutput(" ??", TRUE
);
3389 if (start
&& arg_no
== 1)
3391 char *data
= GetArgData();
3392 ParSkip
= ParseUnitArgument(data
);
3399 if (start
&& arg_no
== 1)
3401 char *data
= GetArgData();
3402 ParIndent
= ParseUnitArgument(data
);
3409 return OnArgument(ltIT
, arg_no
, start
);
3412 case ltSPECIALDOUBLEDOLLAR
:
3414 return OnArgument(ltCENTER
, arg_no
, start
);
3418 case ltPARAGRAPHSTAR
:
3419 case ltSUBPARAGRAPH
:
3420 case ltSUBPARAGRAPHSTAR
:
3422 return OnArgument(ltSUBSUBSECTION
, arg_no
, start
);
3428 OnInform(GetArgData());
3434 TexOutput(" (", TRUE
);
3436 TexOutput(")", TRUE
);
3439 case ltBIBLIOGRAPHY
:
3447 if ((fd
= fopen(TexBibName
, "r")))
3453 TexOutput(smallBuf
);
3461 OnInform("Run Tex2RTF again to include bibliography.");
3464 // Read in the .bib file, resolve all known references, write out the RTF.
3465 char *allFiles
= GetArgData();
3467 char *bibFile
= ParseMultifieldString(allFiles
, &pos
);
3471 strcpy(fileBuf
, bibFile
);
3472 wxString actualFile
= TexPathList
.FindValidPath(fileBuf
);
3473 if (actualFile
== "")
3475 strcat(fileBuf
, ".bib");
3476 actualFile
= TexPathList
.FindValidPath(fileBuf
);
3478 if (actualFile
!= "")
3480 if (!ReadBib((char*) (const char*) actualFile
))
3483 errBuf
.Printf(".bib file %s not found or malformed", (const char*) actualFile
);
3484 OnError((char *)errBuf
.c_str());
3490 errBuf
.Printf(".bib file %s not found", fileBuf
);
3491 OnError((char *)errBuf
.c_str());
3493 bibFile
= ParseMultifieldString(allFiles
, &pos
);
3496 ResolveBibReferences();
3498 // Write it a new bib section in the appropriate format.
3499 FILE *save1
= CurrentOutput1
;
3500 FILE *save2
= CurrentOutput2
;
3501 FILE *Biblio
= fopen(TexTmpBibName
, "w");
3502 SetCurrentOutput(Biblio
);
3505 if (wxFileExists(TexTmpBibName
))
3507 if (wxFileExists(TexBibName
)) wxRemoveFile(TexBibName
);
3508 wxRenameFile(TexTmpBibName
, TexBibName
);
3510 SetCurrentOutputs(save1
, save2
);
3517 if (start
&& (arg_no
== 3))
3527 if (start
&& (arg_no
== 1))
3529 char *s
= GetArgData();
3532 char *s1
= copystring(s
);
3534 for (i
= 0; i
< (int)strlen(s
); i
++)
3535 s1
[i
] = toupper(s
[i
]);
3548 if (start
&& (arg_no
== 1))
3550 char *s
= GetArgData();
3553 char *s1
= copystring(s
);
3555 for (i
= 0; i
< (int)strlen(s
); i
++)
3556 s1
[i
] = tolower(s
[i
]);
3569 if (start
&& (arg_no
== 1))
3571 char *s
= GetArgData();
3574 char *s1
= copystring(s
);
3576 for (i
= 0; i
< (int)strlen(s
); i
++)
3577 s1
[i
] = toupper(s
[i
]);
3588 case ltPOPREF
: // Ignore second argument by default
3590 if (start
&& (arg_no
== 1))
3600 return ((convertMode
== TEX_XLP
) ? FALSE
: TRUE
);
3603 return ((convertMode
!= TEX_XLP
) ? FALSE
: TRUE
);
3606 return ((convertMode
== TEX_HTML
) ? FALSE
: TRUE
);
3609 return ((convertMode
!= TEX_HTML
) ? FALSE
: TRUE
);
3612 return (((convertMode
== TEX_RTF
) && !winHelp
) ? FALSE
: TRUE
);
3615 return (!((convertMode
== TEX_RTF
) && !winHelp
) ? FALSE
: TRUE
);
3617 case ltWINHELPIGNORE
:
3618 return (winHelp
? FALSE
: TRUE
);
3621 return (!winHelp
? FALSE
: TRUE
);
3636 case ltADDTOCOUNTER
:
3637 case ltADDCONTENTSLINE
:
3641 case ltBASELINESKIP
:
3650 case ltPAGENUMBERING
:
3662 case ltTHISPAGESTYLE
:
3665 case ltEVENSIDEMARGIN
:
3666 case ltODDSIDEMARGIN
:
3668 case ltMARGINPARWIDTH
:
3669 case ltMARGINPARSEP
:
3670 case ltMARGINPAREVEN
:
3671 case ltMARGINPARODD
:
3672 case ltTWOCOLWIDTHA
:
3673 case ltTWOCOLWIDTHB
:
3674 case ltTWOCOLSPACING
:
3681 case ltSETHOTSPOTCOLOUR
:
3682 case ltSETHOTSPOTCOLOR
:
3683 case ltSETHOTSPOTUNDERLINE
:
3684 case ltSETTRANSPARENCY
:
3687 case ltBACKGROUNDCOLOUR
:
3688 case ltBACKGROUNDIMAGE
:
3690 case ltFOLLOWEDLINKCOLOUR
:
3697 case ltINSERTATLEVEL
:
3701 case ltSUPERTABULAR
:
3710 if (arg_no
== 2) return TRUE
;
3717 if (arg_no
== 2) return TRUE
;
3721 case ltDEFINECOLOUR
:
3724 static int redVal
= 0;
3725 static int greenVal
= 0;
3726 static int blueVal
= 0;
3727 static char *colourName
= NULL
;
3734 if (colourName
) delete[] colourName
;
3735 colourName
= copystring(GetArgData());
3740 redVal
= atoi(GetArgData());
3745 greenVal
= atoi(GetArgData());
3750 blueVal
= atoi(GetArgData());
3751 AddColour(colourName
, redVal
, greenVal
, blueVal
);
3767 if (IsArgOptional())