]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
mathed13.diff
[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 inline
96 bool operator!=(Aux_Info const & a, Aux_Info const & o)
97 {
98         return !(a == o);
99 }
100
101
102 ///
103 class LaTeX : public noncopyable {
104 public:
105         /** Return values from scanLogFile() and run() (to come)
106             
107             This enum should be enlarged a bit so that one could
108             get more feedback from the LaTeX run.
109         */
110         enum log_status {
111                 ///
112                 NO_ERRORS = 0,
113                 ///
114                 NO_LOGFILE = 1,
115                 ///
116                 NO_OUTPUT = 2,
117                 ///
118                 UNDEF_REF = 4, // Reference '...' on page ... undefined.
119                 ///
120                 UNDEF_CIT = 8, // Citation '...' on page ... undefined.
121                 ///
122                 RERUN = 16, // Label(s) may have changed. Rerun to get...
123                 ///
124                 TEX_ERROR = 32,
125                 ///
126                 TEX_WARNING = 64,
127                 ///
128                 LATEX_ERROR = 128,
129                 ///
130                 LATEX_WARNING = 256,
131                 ///
132                 PACKAGE_WARNING = 512,
133                 ///
134                 NO_FILE = 1024,
135                 ///
136                 NO_CHANGE = 2048,
137                 ///
138                 TOO_MANY_ERRORS = 4096,
139                 ///
140                 ERROR_RERUN = 8192,
141                 ///
142                 ERRORS = TEX_ERROR + LATEX_ERROR,
143                 ///
144                 WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
145         };
146         
147
148         /**
149            cmd = the latex command, file = name of the (temporary) latex file,
150            path = name of the files original path.
151         */
152         LaTeX(string const & cmd, string const & file, string const & path);
153
154         ///
155         virtual ~LaTeX() {}
156         
157         /// runs LaTeX several times
158         int run(TeXErrors &, MiniBuffer *);
159
160         ///
161         int getNumErrors() { return num_errors;}
162
163         /// use this for running LaTeX once
164         int operator() ();
165
166         ///
167         int scanLogFile(TeXErrors &);
168
169 protected:
170         /// The dependency file.
171         string depfile;
172
173         ///
174         void deplog(DepTable & head);
175
176         ///
177         bool runMakeIndex(string const &);
178
179         ///
180         std::vector<Aux_Info> const scanAuxFiles(string const &);
181
182         ///
183         Aux_Info const scanAuxFile(string const &);
184
185         ///
186         void scanAuxFile(string const &, Aux_Info &);
187         
188         ///
189         void updateBibtexDependencies(DepTable &,
190                                       std::vector<Aux_Info> const &);
191
192         ///
193         bool runBibTeX(std::vector<Aux_Info> const &);
194
195         ///
196         void deleteFilesOnError() const;
197         
198         ///
199         string cmd;
200
201         ///
202         string file;
203         
204         ///
205         string path;
206
207         /// used by scanLogFile
208         int num_errors;
209 };
210
211 #endif