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