]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
#9130 Text in main work area isn't rendered with high resolution
[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                       std::string const & fname)
44                         : error_in_line(line),
45                           error_desc(desc),
46                           error_text(text),
47                           child_name(fname) {}
48                 /// what line in the TeX file the error occured in
49                 int error_in_line;
50                 /// The kind of error
51                 docstring error_desc;
52                 /// The line/cmd that caused the error.
53                 docstring error_text;
54                 /// The name of the child where error occurred, empty otherwise.
55                 std::string child_name;
56         };
57 public:
58         ///
59         typedef std::vector<Error> Errors;
60         ///
61         Errors::const_iterator begin() const { return errors.begin(); }
62         ///
63         Errors::const_iterator end() const { return errors.end(); }
64         ///
65         void insertError(int line, docstring const & error_desc,
66                          docstring const & error_text,
67                          std::string const & child_name = empty_string());
68 private:
69         ///
70         Errors errors;
71 };
72
73
74 class AuxInfo {
75 public:
76         ///
77         AuxInfo() {}
78         ///
79         support::FileName aux_file;
80         ///
81         std::set<std::string> citations;
82         ///
83         std::set<std::string> databases;
84         ///
85         std::set<std::string> styles;
86 };
87
88
89 ///
90 bool operator==(AuxInfo const &, AuxInfo const &);
91 bool operator!=(AuxInfo const &, AuxInfo const &);
92
93
94 /**
95  * Class to run the LaTeX compiler and needed auxiliary programs.
96  * The main .tex file must be in the current directory. The current directory
97  * must not change as long as an object of this class lives.
98  * This is required by the LaTeX compiler, and we also make use of it by
99  * various support::makeAbsPath() calls.
100  */
101 class LaTeX : boost::noncopyable {
102 public:
103         /** Return values from scanLogFile() and run() (to come)
104
105             This enum should be enlarged a bit so that one could
106             get more feedback from the LaTeX run.
107         */
108         enum log_status {
109                 ///
110                 NO_ERRORS = 0,
111                 ///
112                 NO_LOGFILE = 1,
113                 ///
114                 NO_OUTPUT = 2,
115                 ///
116                 UNDEF_REF = 4, // Reference '...' on page ... undefined.
117                 ///
118                 UNDEF_CIT = 8, // Citation '...' on page ... undefined.
119                 ///
120                 RERUN = 16, // Label(s) may have changed. Rerun to get...
121                 ///
122                 TEX_ERROR = 32,
123                 ///
124                 TEX_WARNING = 64,
125                 ///
126                 LATEX_ERROR = 128,
127                 ///
128                 LATEX_WARNING = 256,
129                 ///
130                 PACKAGE_WARNING = 512,
131                 ///
132                 NO_FILE = 1024,
133                 ///
134                 NO_CHANGE = 2048,
135                 ///
136                 TOO_MANY_ERRORS = 4096,
137                 ///
138                 ERROR_RERUN = 8192,
139                 ///
140                 BIBTEX_ERROR = 16384,
141                 ///
142                 //FIXME: BIBTEX_ERROR has been removed from ERRORS for now, since users were irritated
143                 //       about those errors which prevented compilation of previously compiling documents.
144                 //       Think about a "gentle" transfer to BibTeX error reporting.
145                 ERRORS = TEX_ERROR + LATEX_ERROR,
146                 ///
147                 WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
148         };
149
150         /// This signal emits an informative message
151         boost::signal<void(docstring)> message;
152
153
154         /**
155            cmd = the latex command, file = name of the (temporary) latex file,
156            path = name of the files original path.
157         */
158         LaTeX(std::string const & cmd, OutputParams const &,
159               support::FileName const & file,
160               std::string const & path = empty_string());
161
162         /// runs LaTeX several times
163         int run(TeXErrors &);
164
165         ///
166         int getNumErrors() { return num_errors;}
167
168         ///
169         int scanLogFile(TeXErrors &);
170
171 private:
172         /// use this for running LaTeX once
173         int startscript();
174
175         /// The dependency file.
176         support::FileName depfile;
177
178         ///
179         void deplog(DepTable & head);
180
181         ///
182         bool runMakeIndex(std::string const &, OutputParams const &,
183                           std::string const & = std::string());
184
185         ///
186         bool runMakeIndexNomencl(support::FileName const &, 
187                                  std::string const &, std::string const &);
188
189         ///
190         std::vector<AuxInfo> const scanAuxFiles(support::FileName const &);
191
192         ///
193         AuxInfo const scanAuxFile(support::FileName const &);
194
195         ///
196         void scanAuxFile(support::FileName const &, AuxInfo &);
197
198         ///
199         void updateBibtexDependencies(DepTable &,
200                                       std::vector<AuxInfo> const &);
201
202         ///
203         int scanBlgFile(DepTable & head, TeXErrors & terr);
204
205         ///
206         bool runBibTeX(std::vector<AuxInfo> const &,
207                        OutputParams const &);
208
209         ///
210         void deleteFilesOnError() const;
211
212         ///
213         std::string cmd;
214
215         ///
216         support::FileName file;
217
218         ///
219         std::string path;
220
221         /// used by scanLogFile
222         int num_errors;
223
224         /// The name of the final output file.
225         support::FileName output_file;
226
227         ///
228         OutputParams runparams;
229         
230         /// Do we use biber?
231         bool biber;
232 };
233
234
235 } // namespace lyx
236
237 #endif