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