]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
Updates from Bennett and myself.
[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/utility.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         std::string 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 LaTeX : boost::noncopyable {
91 public:
92         /** Return values from scanLogFile() and run() (to come)
93
94             This enum should be enlarged a bit so that one could
95             get more feedback from the LaTeX run.
96         */
97         enum log_status {
98                 ///
99                 NO_ERRORS = 0,
100                 ///
101                 NO_LOGFILE = 1,
102                 ///
103                 NO_OUTPUT = 2,
104                 ///
105                 UNDEF_REF = 4, // Reference '...' on page ... undefined.
106                 ///
107                 UNDEF_CIT = 8, // Citation '...' on page ... undefined.
108                 ///
109                 RERUN = 16, // Label(s) may have changed. Rerun to get...
110                 ///
111                 TEX_ERROR = 32,
112                 ///
113                 TEX_WARNING = 64,
114                 ///
115                 LATEX_ERROR = 128,
116                 ///
117                 LATEX_WARNING = 256,
118                 ///
119                 PACKAGE_WARNING = 512,
120                 ///
121                 NO_FILE = 1024,
122                 ///
123                 NO_CHANGE = 2048,
124                 ///
125                 TOO_MANY_ERRORS = 4096,
126                 ///
127                 ERROR_RERUN = 8192,
128                 ///
129                 ERRORS = TEX_ERROR + LATEX_ERROR,
130                 ///
131                 WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
132         };
133
134         /// This signal emits an informative message
135         boost::signal<void(docstring)> message;
136
137
138         /**
139            cmd = the latex command, file = name of the (temporary) latex file,
140            path = name of the files original path.
141         */
142         LaTeX(std::string const & cmd, OutputParams const &,
143               std::string const & file, std::string const & path);
144
145         /// runs LaTeX several times
146         int run(TeXErrors &);
147
148         ///
149         int getNumErrors() { return num_errors;}
150
151         ///
152         int scanLogFile(TeXErrors &);
153
154 private:
155         /// use this for running LaTeX once
156         int startscript();
157
158         /// The dependency file.
159         support::FileName depfile;
160
161         ///
162         void deplog(DepTable & head);
163
164         ///
165         bool runMakeIndex(std::string const &, OutputParams const &,
166                           std::string const & = std::string());
167
168         ///
169         std::vector<Aux_Info> const scanAuxFiles(std::string const &);
170
171         ///
172         Aux_Info const scanAuxFile(std::string const &);
173
174         ///
175         void scanAuxFile(std::string const &, Aux_Info &);
176
177         ///
178         void updateBibtexDependencies(DepTable &,
179                                       std::vector<Aux_Info> const &);
180
181         ///
182         bool runBibTeX(std::vector<Aux_Info> const &);
183
184         ///
185         void deleteFilesOnError() const;
186
187         ///
188         std::string cmd;
189
190         ///
191         std::string file;
192
193         ///
194         std::string path;
195
196         /// used by scanLogFile
197         int num_errors;
198
199         /// The name of the final output file.
200         std::string output_file;
201
202         ///
203         OutputParams runparams;
204 };
205
206
207 } // namespace lyx
208
209 #endif