]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
Avoid full metrics computation with Update:FitCursor
[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/strfwd.h"
20 #include "support/FileName.h"
21 #include "support/signals.h"
22
23 #include <vector>
24 #include <set>
25
26
27 namespace lyx {
28
29 class DepTable;
30
31 ///
32 class TeXErrors {
33 private:
34         ///
35         class Error {
36         public:
37                 ///
38                 Error () : error_in_line(0) {}
39                 ///
40                 Error(int line, docstring const & desc, docstring const & text,
41                       std::string const & fname)
42                         : error_in_line(line),
43                           error_desc(desc),
44                           error_text(text),
45                           child_name(fname) {}
46                 /// what line in the TeX file the error occurred 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                 /// The name of the child where error occurred, empty otherwise.
53                 std::string child_name;
54         };
55 public:
56         ///
57         typedef std::vector<Error> Errors;
58         ///
59         Errors::const_iterator begin() const { return errors.begin(); }
60         ///
61         Errors::const_iterator end() const { return errors.end(); }
62         ///
63         Errors::const_iterator begin_ref() const { return undef_ref.begin(); }
64         ///
65         Errors::const_iterator end_ref() const { return undef_ref.end(); }
66         ///
67         void insertError(int line, docstring const & error_desc,
68                          docstring const & error_text,
69                          std::string const & child_name = empty_string());
70         ///
71         void clearErrors() { errors.clear(); }
72         ///
73         void insertRef(int line, docstring const & error_desc,
74                          docstring const & error_text,
75                          std::string const & child_name = empty_string());
76         ///
77         void clearRefs() { undef_ref.clear(); }
78 private:
79         ///
80         Errors errors;
81         /// For missing Citation and references
82         Errors undef_ref;
83 };
84
85
86 class AuxInfo {
87 public:
88         ///
89         AuxInfo() {}
90         ///
91         support::FileName aux_file;
92         ///
93         std::set<std::string> citations;
94         ///
95         std::set<std::string> databases;
96         ///
97         std::set<std::string> styles;
98 };
99
100
101 ///
102 bool operator==(AuxInfo const &, AuxInfo const &);
103 bool operator!=(AuxInfo const &, AuxInfo const &);
104
105
106 /**
107  * Class to run the LaTeX compiler and needed auxiliary programs.
108  * The main .tex file must be in the current directory. The current directory
109  * must not change as long as an object of this class lives.
110  * This is required by the LaTeX compiler, and we also make use of it by
111  * various support::makeAbsPath() calls.
112  */
113 class LaTeX {
114 public:
115         /** Return values from scanLogFile() and run() (to come)
116
117             This enum should be enlarged a bit so that one could
118             get more feedback from the LaTeX run.
119         */
120         enum log_status {
121                 ///
122                 NO_ERRORS = 0,
123                 ///
124                 NO_LOGFILE = 1,
125                 ///
126                 NO_OUTPUT = 2,
127                 ///
128                 UNDEF_REF = 4, // Reference '...' on page ... undefined.
129                 ///
130                 UNDEF_CIT = 8, // Citation '...' on page ... undefined.
131                 ///
132                 RERUN = 16, // Label(s) may have changed. Rerun to get...
133                 ///
134                 TEX_ERROR = 32,
135                 ///
136                 TEX_WARNING = 64,
137                 ///
138                 LATEX_ERROR = 128,
139                 ///
140                 LATEX_WARNING = 256,
141                 ///
142                 PACKAGE_WARNING = 512,
143                 ///
144                 NO_FILE = 1024,
145                 ///
146                 NO_CHANGE = 2048,
147                 ///
148                 TOO_MANY_ERRORS = 4096,
149                 ///
150                 ERROR_RERUN = 8192,
151                 ///
152                 BIBTEX_ERROR = 16384,
153                 ///
154                 NONZERO_ERROR = 32768, // the command exited with nonzero status
155                 ///
156                 INDEX_ERROR = 65536,
157                 ///
158                 UNDEF_UNKNOWN_REF = 131072,
159                 ///
160                 ERRORS = TEX_ERROR + LATEX_ERROR + NONZERO_ERROR + BIBTEX_ERROR + INDEX_ERROR,
161                 ///
162                 WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
163         };
164
165         /// This signal emits an informative message
166         signal<void(docstring)> message;
167
168
169         /**
170            cmd = the latex command, file = name of the (temporary) latex file,
171            path = name of the files original path,
172            clean_start = This forces a fresh run by deleting the files in the temp
173                          dir. We set this e.g. if there was an error on previous
174                          preview, which is good if the user installed a package
175                          or changed certain document settings (#9061).
176         */
177         LaTeX(std::string const & cmd, OutputParams const &,
178               support::FileName const & file,
179               std::string const & path = empty_string(),
180               std::string const & lpath = empty_string(),
181               bool allow_cancellation = false,
182               bool const clean_start = false);
183
184         /// runs LaTeX several times
185         int run(TeXErrors &);
186
187         ///
188         int getNumErrors() const { return num_errors;}
189
190         ///
191         int scanLogFile(TeXErrors &);
192
193 private:
194         /// noncopyable
195         LaTeX(LaTeX const &);
196         void operator=(LaTeX const &);
197
198         /// use this for running LaTeX once
199         int startscript();
200
201         /// The dependency file.
202         support::FileName depfile;
203
204         ///
205         void deplog(DepTable & head);
206
207         /// returns exit code
208         int runMakeIndex(std::string const &, OutputParams const &,
209                           std::string const & = std::string());
210
211         /// returns exit code
212         int runMakeIndexNomencl(support::FileName const &, 
213                                  std::string const &, std::string const &);
214
215         ///
216         std::vector<AuxInfo> const scanAuxFiles(support::FileName const &,
217                                                 bool const only_childbibs = false);
218
219         ///
220         AuxInfo const scanAuxFile(support::FileName const &);
221
222         ///
223         void scanAuxFile(support::FileName const &, AuxInfo &);
224
225         ///
226         void updateBibtexDependencies(DepTable &,
227                                       std::vector<AuxInfo> const &);
228
229         ///
230         int scanBlgFile(DepTable & head, TeXErrors & terr);
231
232         ///
233         int scanIlgFile(TeXErrors & terr);
234
235         ///
236         bool runBibTeX(std::vector<AuxInfo> const &,
237                        OutputParams const &, int & exit_code);
238
239         ///
240         void removeAuxiliaryFiles() const;
241
242         ///
243         std::string cmd;
244
245         ///
246         support::FileName file;
247
248         /// The document directory path.
249         std::string path;
250
251         /// Extra path, possibly relative to the document directory path.
252         std::string lpath;
253
254         /// used by scanLogFile
255         int num_errors;
256
257         /// The name of the final output file.
258         support::FileName output_file;
259
260         ///
261         OutputParams runparams;
262
263         /// Do we use biber?
264         bool biber;
265         ///
266         std::vector <std::string> children;
267         ///
268         bool allow_cancel;
269 };
270
271
272 } // namespace lyx
273
274 #endif