]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
rename assert.h to lassert.h
[lyx.git] / src / LaTeX.h
1 // -*- C++ -*-
2 /**
3  * \file LaTeX.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Angus Leeming
9  * \author Dekel Tsur
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef LATEX_H
15 #define LATEX_H
16
17 #include "OutputParams.h"
18
19 #include "support/docstring.h"
20 #include "support/FileName.h"
21
22 #include <boost/noncopyable.hpp>
23 #include <boost/signal.hpp>
24
25 #include <vector>
26 #include <set>
27
28
29 namespace lyx {
30
31 class DepTable;
32
33 ///
34 class TeXErrors {
35 private:
36         ///
37         class Error {
38         public:
39                 ///
40                 Error () : error_in_line(0) {}
41                 ///
42                 Error(int line, docstring const & desc, docstring const & text)
43                         : error_in_line(line),
44                           error_desc(desc),
45                           error_text(text) {}
46                 /// what line in the TeX file the error occured in
47                 int error_in_line;
48                 /// The kind of error
49                 docstring error_desc;
50                 /// The line/cmd that caused the error.
51                 docstring error_text;
52         };
53 public:
54         ///
55         typedef std::vector<Error> Errors;
56         ///
57         Errors::const_iterator begin() const { return errors.begin(); }
58         ///
59         Errors::const_iterator end() const { return errors.end(); }
60         ///
61         void insertError(int line, docstring const & error_desc,
62                          docstring const & error_text);
63 private:
64         ///
65         Errors errors;
66 };
67
68
69 class Aux_Info {
70 public:
71         ///
72         Aux_Info() {}
73         ///
74         support::FileName aux_file;
75         ///
76         std::set<std::string> citations;
77         ///
78         std::set<std::string> databases;
79         ///
80         std::set<std::string> styles;
81 };
82
83
84 ///
85 bool operator==(Aux_Info const &, Aux_Info const &);
86 bool operator!=(Aux_Info const &, Aux_Info const &);
87
88
89 /**
90  * Class to run the LaTeX compiler and needed auxiliary programs.
91  * The main .tex file must be in the current directory. The current directory
92  * must not change as long as an object of this class lives.
93  * This is required by the LaTeX compiler, and we also make use of it by
94  * various support::makeAbsPath() calls.
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         /// This signal emits an informative message
141         boost::signal<void(docstring)> message;
142
143
144         /**
145            cmd = the latex command, file = name of the (temporary) latex file,
146            path = name of the files original path.
147         */
148         LaTeX(std::string const & cmd, OutputParams const &,
149               support::FileName const & file);
150
151         /// runs LaTeX several times
152         int run(TeXErrors &);
153
154         ///
155         int getNumErrors() { return num_errors;}
156
157         ///
158         int scanLogFile(TeXErrors &);
159
160 private:
161         /// use this for running LaTeX once
162         int startscript();
163
164         /// The dependency file.
165         support::FileName depfile;
166
167         ///
168         void deplog(DepTable & head);
169
170         ///
171         bool runMakeIndex(std::string const &, OutputParams const &,
172                           std::string const & = std::string());
173
174         ///
175         bool runMakeIndexNomencl(support::FileName const &, OutputParams const &,
176                                  std::string const &, std::string const &);
177
178         ///
179         std::vector<Aux_Info> const scanAuxFiles(support::FileName const &);
180
181         ///
182         Aux_Info const scanAuxFile(support::FileName const &);
183
184         ///
185         void scanAuxFile(support::FileName const &, Aux_Info &);
186
187         ///
188         void updateBibtexDependencies(DepTable &,
189                                       std::vector<Aux_Info> const &);
190
191         ///
192         bool runBibTeX(std::vector<Aux_Info> const &);
193
194         ///
195         void deleteFilesOnError() const;
196
197         ///
198         std::string cmd;
199
200         ///
201         support::FileName file;
202
203         /// used by scanLogFile
204         int num_errors;
205
206         /// The name of the final output file.
207         support::FileName output_file;
208
209         ///
210         OutputParams runparams;
211 };
212
213
214 } // namespace lyx
215
216 #endif