]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
99e3a56e26a8c7eb7c105c0552007519c508bfe6
[lyx.git] / src / LaTeX.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor         
6  *           Copyright 1995 Matthias Ettrich
7  *           Copyright 1995-1996 The Lyx Team
8  *
9  *           This file is Copyright (C) 1996-1999
10  *           Lars Gullik Bjønnes
11  *
12  *======================================================
13  */
14
15 #ifndef LATEX_H
16 #define LATEX_H
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 #include "LString.h"
23 #include "DepTable.h"
24
25 class LyXLex;
26 class MiniBuffer;
27
28 ///
29 class TeXErrors {
30 public:
31         ///
32         TeXErrors() {
33                 errors = 0;
34                 next_error = 0;
35                 status = 0;
36                 number_of_errors = 0;
37         }
38         ///
39         ~TeXErrors(); 
40         ///
41         void scanError(LyXLex &);
42         ///
43         bool getFirstError(int *line, string *text);
44         ///
45         bool getNextError(int *line, string *text);
46         ///
47         void insertError(int line, string const &error_desc,
48                          string const &error_text);
49         ///
50         void printErrors();
51         ///
52         void printWarnings();
53         ///
54         void printStatus();
55         ///
56         int getStatus() { return status; }
57 private:
58         ///
59         friend class LaTeX;
60         ///
61         int status;
62         ///
63         int number_of_errors;
64         ///
65         struct Error {
66                 ///
67                 Error () {
68                         next_error = 0;
69                         error_in_line = 0;
70                 }
71                 ///
72                 Error(int line, string const &desc, string const &text) {
73                         next_error = 0;
74                         error_in_line = line;
75                         error_desc = desc;
76                         error_text = text;
77                 }
78                 ///
79                 ~Error() {
80                 }
81                 ///
82                 Error *next_error;
83                 /// what line in the TeX file the error occured in
84                 int error_in_line;
85                 /// The kind of error
86                 string error_desc;
87                 /// The line/cmd that caused the error.
88                 string error_text;
89         };
90         ///
91         Error *errors;
92         ///
93         Error *next_error;
94 };
95
96
97 ///
98 class LaTeX {
99 public:
100         /** All the different files produced by TeX.
101           
102           This is the files mentioned on page 208-9 in Lamports book +
103           .ltx and .tex files.
104          */
105         enum TEX_FILES {
106                 ///
107                 NO_FILES = 0,
108                 /// used for table of contents et.al.
109                 AUX = 1,
110                 /// written by BibTeX
111                 BBL = 2,
112                 /// LaTeX's output
113                 DVI = 4,
114                 /// glossary (not supported by LyX so far)
115                 GLO = 8,
116                 ///index
117                 IDX = 16,
118                 /// written by makeindex
119                 IND = 32,
120                 /// list of figures
121                 LOF = 64,
122                 /// the LaTeX log file
123                 LOG = 128,
124                 /// list of tables
125                 LOT = 256,
126                 /// table of contents
127                 TOC = 512,
128                 /// latex files
129                 LTX = 1024,
130                 /// tex files
131                 TEX = 2048,
132                 /// list of algorithms
133                 LOA = 4096
134         };
135         
136         /** Return values from scanLogFile() and run() (to come)
137
138           This enum should be enlarged a bit so that one could
139           get more feedback from the LaTeX run.
140           */
141         enum log_status {
142                 ///
143                 NO_ERRORS = 0,
144                 ///
145                 NO_LOGFILE = 1,
146                 ///
147                 NO_OUTPUT = 2,
148                 ///
149                 UNDEF_REF = 4, // Reference '...' on page ... undefined.
150                 ///
151                 UNDEF_CIT = 8, // Citation '...' on page ... undefined.
152                 ///
153                 RERUN = 16, // Label(s) may have changed. Rerun to get...
154                 ///
155                 TEX_ERROR = 32,
156                 ///
157                 TEX_WARNING = 64,
158                 ///
159                 LATEX_ERROR = 128,
160                 ///
161                 LATEX_WARNING = 256,
162                 ///
163                 PACKAGE_WARNING = 512,
164                 ///
165                 NO_FILE = 1024,
166                 ///
167                 NO_CHANGE = 2048,
168                 ///
169                 TOO_MANY_ERRORS = 4096,
170                 ///
171                 ERRORS = TEX_ERROR + LATEX_ERROR,
172                 ///
173                 WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
174         };
175         
176
177         /**
178           cmd = the latex command, file = name of the (temporary) latex file,
179           path = name of the files original path.
180           */
181         LaTeX(string const & cmd, string const & file, string const & path);
182         
183         /// runs LaTeX several times
184         int run(TeXErrors &, MiniBuffer *);
185
186         ///
187         int getNumErrors() { return num_errors;}
188
189         /// use this for running LaTeX once
190         int operator() ();
191 protected:
192         /** The dependency file.
193           
194           We store the file dependencies in this file.
195           the depency file is on the format:
196           <file> <new checksum> <old checksum>
197         */
198         string depfile;
199
200         ///
201         LaTeX() {}
202         
203         ///
204         LaTeX(LaTeX const &) {}
205         
206         ///
207         void deplog(DepTable & head);
208
209         ///
210         void deptex(DepTable & head);
211         
212         ///
213         int scanLogFile(TeXErrors &);
214
215         ///
216         bool runMakeIndex(string const &);
217
218         ///
219         bool runBibTeX(string const &);
220         
221         ///
222         string cmd;
223
224         ///
225         string file;
226         
227         ///
228         string path;
229         ///
230         TEX_FILES tex_files;
231         
232         ///
233         int file_count;
234
235         // used by scanLogFile
236         int num_errors;
237 };
238
239 #endif