]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
Correct early return position for if use_pixmap_cache_ check
[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/signal.hpp>
23
24 #include <vector>
25 #include <set>
26
27
28 namespace lyx {
29
30 class DepTable;
31
32 ///
33 class TeXErrors {
34 private:
35         ///
36         class Error {
37         public:
38                 ///
39                 Error () : error_in_line(0) {}
40                 ///
41                 Error(int line, docstring const & desc, docstring const & text,
42                       std::string const & fname)
43                         : error_in_line(line),
44                           error_desc(desc),
45                           error_text(text),
46                           child_name(fname) {}
47                 /// what line in the TeX file the error occurred in
48                 int error_in_line;
49                 /// The kind of error
50                 docstring error_desc;
51                 /// The line/cmd that caused the error.
52                 docstring error_text;
53                 /// The name of the child where error occurred, empty otherwise.
54                 std::string child_name;
55         };
56 public:
57         ///
58         typedef std::vector<Error> Errors;
59         ///
60         Errors::const_iterator begin() const { return errors.begin(); }
61         ///
62         Errors::const_iterator end() const { return errors.end(); }
63         ///
64         void insertError(int line, docstring const & error_desc,
65                          docstring const & error_text,
66                          std::string const & child_name = empty_string());
67 private:
68         ///
69         Errors errors;
70 };
71
72
73 class AuxInfo {
74 public:
75         ///
76         AuxInfo() {}
77         ///
78         support::FileName aux_file;
79         ///
80         std::set<std::string> citations;
81         ///
82         std::set<std::string> databases;
83         ///
84         std::set<std::string> styles;
85 };
86
87
88 ///
89 bool operator==(AuxInfo const &, AuxInfo const &);
90 bool operator!=(AuxInfo const &, AuxInfo const &);
91
92
93 /**
94  * Class to run the LaTeX compiler and needed auxiliary programs.
95  * The main .tex file must be in the current directory. The current directory
96  * must not change as long as an object of this class lives.
97  * This is required by the LaTeX compiler, and we also make use of it by
98  * various support::makeAbsPath() calls.
99  */
100 class LaTeX {
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                 BIBTEX_ERROR = 16384,
140                 ///
141                 NONZERO_ERROR = 32768, // the command exited with nonzero status
142                 ///
143                 ERRORS = TEX_ERROR + LATEX_ERROR + NONZERO_ERROR + BIBTEX_ERROR,
144                 ///
145                 WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
146         };
147
148         /// This signal emits an informative message
149         boost::signal<void(docstring)> message;
150
151
152         /**
153            cmd = the latex command, file = name of the (temporary) latex file,
154            path = name of the files original path,
155            clean_start = This forces a fresh run by deleting the files in the temp
156                          dir. We set this e.g. if there was an error on previous
157                          preview, which is good if the user installed a package
158                          or changed certain document settings (#9061).
159         */
160         LaTeX(std::string const & cmd, OutputParams const &,
161               support::FileName const & file,
162               std::string const & path = empty_string(),
163               std::string const & lpath = empty_string(),
164               bool const clean_start = false);
165
166         /// runs LaTeX several times
167         int run(TeXErrors &);
168
169         ///
170         int getNumErrors() { return num_errors;}
171
172         ///
173         int scanLogFile(TeXErrors &);
174
175 private:
176         /// noncopyable
177         LaTeX(LaTeX const &);
178         void operator=(LaTeX const &);
179
180         /// use this for running LaTeX once
181         int startscript();
182
183         /// The dependency file.
184         support::FileName depfile;
185
186         ///
187         void deplog(DepTable & head);
188
189         ///
190         bool runMakeIndex(std::string const &, OutputParams const &,
191                           std::string const & = std::string());
192
193         ///
194         bool runMakeIndexNomencl(support::FileName const &, 
195                                  std::string const &, std::string const &);
196
197         ///
198         std::vector<AuxInfo> const scanAuxFiles(support::FileName const &);
199
200         ///
201         AuxInfo const scanAuxFile(support::FileName const &);
202
203         ///
204         void scanAuxFile(support::FileName const &, AuxInfo &);
205
206         ///
207         void updateBibtexDependencies(DepTable &,
208                                       std::vector<AuxInfo> const &);
209
210         ///
211         int scanBlgFile(DepTable & head, TeXErrors & terr);
212
213         ///
214         bool runBibTeX(std::vector<AuxInfo> const &,
215                        OutputParams const &);
216
217         ///
218         void removeAuxiliaryFiles() const;
219
220         ///
221         std::string cmd;
222
223         ///
224         support::FileName file;
225
226         /// The document directory path.
227         std::string path;
228
229         /// Extra path, possibly relative to the document directory path.
230         std::string lpath;
231
232         /// used by scanLogFile
233         int num_errors;
234
235         /// The name of the final output file.
236         support::FileName output_file;
237
238         ///
239         OutputParams runparams;
240         
241         /// Do we use biber?
242         bool biber;
243 };
244
245
246 } // namespace lyx
247
248 #endif