]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
1f52dab188386e791f2380f2467bca8715d83957
[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
21 #include <boost/utility.hpp>
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, std::string const & desc, std::string const & text)
42                         : error_in_line(line),
43                           error_desc(desc),
44                           error_text(text) {}
45                 /// what line in the TeX file the error occured in
46                 int error_in_line;
47                 /// The kind of error
48                 std::string error_desc;
49                 /// The line/cmd that caused the error.
50                 std::string error_text;
51         };
52 public:
53         ///
54         typedef std::vector<Error> Errors;
55         ///
56         Errors::const_iterator begin() const { return errors.begin(); }
57         ///
58         Errors::const_iterator end() const { return errors.end(); }
59         ///
60         void insertError(int line, std::string const & error_desc,
61                          std::string const & error_text);
62 private:
63         ///
64         Errors errors;
65 };
66
67
68 class Aux_Info {
69 public:
70         ///
71         Aux_Info() {}
72         ///
73         std::string aux_file;
74         ///
75         std::set<std::string> citations;
76         ///
77         std::set<std::string> databases;
78         ///
79         std::set<std::string> styles;
80 };
81
82
83 ///
84 bool operator==(Aux_Info const &, Aux_Info const &);
85 bool operator!=(Aux_Info const &, Aux_Info const &);
86
87
88 ///
89 class LaTeX : boost::noncopyable {
90 public:
91         /** Return values from scanLogFile() and run() (to come)
92
93             This enum should be enlarged a bit so that one could
94             get more feedback from the LaTeX run.
95         */
96         enum log_status {
97                 ///
98                 NO_ERRORS = 0,
99                 ///
100                 NO_LOGFILE = 1,
101                 ///
102                 NO_OUTPUT = 2,
103                 ///
104                 UNDEF_REF = 4, // Reference '...' on page ... undefined.
105                 ///
106                 UNDEF_CIT = 8, // Citation '...' on page ... undefined.
107                 ///
108                 RERUN = 16, // Label(s) may have changed. Rerun to get...
109                 ///
110                 TEX_ERROR = 32,
111                 ///
112                 TEX_WARNING = 64,
113                 ///
114                 LATEX_ERROR = 128,
115                 ///
116                 LATEX_WARNING = 256,
117                 ///
118                 PACKAGE_WARNING = 512,
119                 ///
120                 NO_FILE = 1024,
121                 ///
122                 NO_CHANGE = 2048,
123                 ///
124                 TOO_MANY_ERRORS = 4096,
125                 ///
126                 ERROR_RERUN = 8192,
127                 ///
128                 ERRORS = TEX_ERROR + LATEX_ERROR,
129                 ///
130                 WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
131         };
132
133         /// This signal emits an informative message
134         boost::signal<void(docstring)> message;
135
136
137         /**
138            cmd = the latex command, file = name of the (temporary) latex file,
139            path = name of the files original path.
140         */
141         LaTeX(std::string const & cmd, OutputParams const &,
142               std::string const & file, std::string const & path);
143
144         /// runs LaTeX several times
145         int run(TeXErrors &);
146
147         ///
148         int getNumErrors() { return num_errors;}
149
150         ///
151         int scanLogFile(TeXErrors &);
152
153 private:
154         /// use this for running LaTeX once
155         int startscript();
156
157         /// The dependency file.
158         std::string depfile;
159
160         ///
161         void deplog(DepTable & head);
162
163         ///
164         bool runMakeIndex(std::string const &, OutputParams const &,
165                           std::string const & = std::string());
166
167         ///
168         std::vector<Aux_Info> const scanAuxFiles(std::string const &);
169
170         ///
171         Aux_Info const scanAuxFile(std::string const &);
172
173         ///
174         void scanAuxFile(std::string const &, Aux_Info &);
175
176         ///
177         void updateBibtexDependencies(DepTable &,
178                                       std::vector<Aux_Info> const &);
179
180         ///
181         bool runBibTeX(std::vector<Aux_Info> const &);
182
183         ///
184         void deleteFilesOnError() const;
185
186         ///
187         std::string cmd;
188
189         ///
190         std::string file;
191
192         ///
193         std::string path;
194
195         /// used by scanLogFile
196         int num_errors;
197
198         /// The name of the final output file.
199         std::string output_file;
200
201         ///
202         OutputParams runparams;
203 };
204
205
206 } // namespace lyx
207
208 #endif