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