]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
dfa5937ddb5ccfb6a79c776b7951b4014ead5be4
[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-2000 The Lyx Team
8  *
9  *           This file is Copyright 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 #include <vector>
25 #include <set>
26
27 #include <boost/utility.hpp>
28
29 class MiniBuffer;
30
31 ///
32 class TeXErrors {
33 private:
34         ///
35         struct Error {
36                 ///
37                 Error () : error_in_line(0) {}
38                 ///
39                 Error(int line, string const & desc, string const & text)
40                         : error_in_line(line),
41                           error_desc(desc),
42                           error_text(text) {}
43                 /// what line in the TeX file the error occured in
44                 int error_in_line;
45                 /// The kind of error
46                 string error_desc;
47                 /// The line/cmd that caused the error.
48                 string error_text;
49         };
50 public:
51         ///
52         typedef std::vector<Error> Errors;
53         ///
54         Errors::const_iterator begin() const { return errors.begin(); }
55         ///
56         Errors::const_iterator end() const { return errors.end(); }
57         ///
58         void insertError(int line, string const & error_desc,
59                          string const & error_text);
60 private:
61         ///
62         Errors errors;
63 };
64
65 class Aux_Info {
66 public:
67         ///
68         Aux_Info() {}
69         ///
70         string aux_file;
71         ///
72         std::set<string> citations;
73         ///
74         std::set<string> databases;
75         ///
76         std::set<string> styles;
77         ///
78         friend
79         bool operator==(Aux_Info const & a, Aux_Info const & o);
80 };
81
82
83 ///
84 inline
85 bool operator==(Aux_Info const & a, Aux_Info const & o)
86 {
87         return a.aux_file == o.aux_file &&
88                 a.citations == o.citations &&
89                 a.databases == o.databases &&
90                 a.styles == o.styles;
91 }
92
93
94 ///
95 class LaTeX : public noncopyable {
96 public:
97         /** Return values from scanLogFile() and run() (to come)
98             
99             This enum should be enlarged a bit so that one could
100             get more feedback from the LaTeX run.
101         */
102         enum log_status {
103                 ///
104                 NO_ERRORS = 0,
105                 ///
106                 NO_LOGFILE = 1,
107                 ///
108                 NO_OUTPUT = 2,
109                 ///
110                 UNDEF_REF = 4, // Reference '...' on page ... undefined.
111                 ///
112                 UNDEF_CIT = 8, // Citation '...' on page ... undefined.
113                 ///
114                 RERUN = 16, // Label(s) may have changed. Rerun to get...
115                 ///
116                 TEX_ERROR = 32,
117                 ///
118                 TEX_WARNING = 64,
119                 ///
120                 LATEX_ERROR = 128,
121                 ///
122                 LATEX_WARNING = 256,
123                 ///
124                 PACKAGE_WARNING = 512,
125                 ///
126                 NO_FILE = 1024,
127                 ///
128                 NO_CHANGE = 2048,
129                 ///
130                 TOO_MANY_ERRORS = 4096,
131                 ///
132                 ERROR_RERUN = 8192,
133                 ///
134                 ERRORS = TEX_ERROR + LATEX_ERROR,
135                 ///
136                 WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
137         };
138         
139
140         /**
141            cmd = the latex command, file = name of the (temporary) latex file,
142            path = name of the files original path.
143         */
144         LaTeX(string const & cmd, string const & file, string const & path);
145
146         ///
147         virtual ~LaTeX() {}
148         
149         /// runs LaTeX several times
150         int run(TeXErrors &, MiniBuffer *);
151
152         ///
153         int getNumErrors() { return num_errors;}
154
155         /// use this for running LaTeX once
156         int operator() ();
157
158         ///
159         int scanLogFile(TeXErrors &);
160
161 protected:
162         /// The dependency file.
163         string depfile;
164
165         ///
166         void deplog(DepTable & head);
167
168         ///
169         bool runMakeIndex(string const &);
170
171         ///
172         std::vector<Aux_Info> const scanAuxFiles(string const &);
173
174         ///
175         Aux_Info const scanAuxFile(string const &);
176
177         ///
178         void scanAuxFile(string const &, Aux_Info &);
179         
180         ///
181         void updateBibtexDependencies(DepTable &,
182                                       std::vector<Aux_Info> const &);
183
184         ///
185         bool runBibTeX(vector<Aux_Info> const &);
186
187         ///
188         void deleteFilesOnError() const;
189         
190         ///
191         string cmd;
192
193         ///
194         string file;
195         
196         ///
197         string path;
198
199         /// used by scanLogFile
200         int num_errors;
201 };
202
203 #endif