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