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