]> git.lyx.org Git - lyx.git/blob - src/LaTeX.h
Fix text direction issue for InsetInfo in RTL context
[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 #include "support/signals.h"
22
23 #include <vector>
24 #include <set>
25
26
27 namespace lyx {
28
29 class DepTable;
30
31 ///
32 class TeXErrors {
33 private:
34         ///
35         class Error {
36         public:
37                 ///
38                 Error () : error_in_line(0) {}
39                 ///
40                 Error(int line, docstring const & desc, docstring const & text,
41                       std::string const & fname)
42                         : error_in_line(line),
43                           error_desc(desc),
44                           error_text(text),
45                           child_name(fname) {}
46                 /// what line in the TeX file the error occurred 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                 /// The name of the child where error occurred, empty otherwise.
53                 std::string child_name;
54         };
55 public:
56         ///
57         typedef std::vector<Error> Errors;
58         ///
59         Errors::const_iterator begin() const { return errors.begin(); }
60         ///
61         Errors::const_iterator end() const { return errors.end(); }
62         ///
63         void insertError(int line, docstring const & error_desc,
64                          docstring const & error_text,
65                          std::string const & child_name = empty_string());
66         ///
67         void clearErrors() { errors.clear(); }
68 private:
69         ///
70         Errors errors;
71 };
72
73
74 class AuxInfo {
75 public:
76         ///
77         AuxInfo() {}
78         ///
79         support::FileName aux_file;
80         ///
81         std::set<std::string> citations;
82         ///
83         std::set<std::string> databases;
84         ///
85         std::set<std::string> styles;
86 };
87
88
89 ///
90 bool operator==(AuxInfo const &, AuxInfo const &);
91 bool operator!=(AuxInfo const &, AuxInfo const &);
92
93
94 /**
95  * Class to run the LaTeX compiler and needed auxiliary programs.
96  * The main .tex file must be in the current directory. The current directory
97  * must not change as long as an object of this class lives.
98  * This is required by the LaTeX compiler, and we also make use of it by
99  * various support::makeAbsPath() calls.
100  */
101 class LaTeX {
102 public:
103         /** Return values from scanLogFile() and run() (to come)
104
105             This enum should be enlarged a bit so that one could
106             get more feedback from the LaTeX run.
107         */
108         enum log_status {
109                 ///
110                 NO_ERRORS = 0,
111                 ///
112                 NO_LOGFILE = 1,
113                 ///
114                 NO_OUTPUT = 2,
115                 ///
116                 UNDEF_REF = 4, // Reference '...' on page ... undefined.
117                 ///
118                 UNDEF_CIT = 8, // Citation '...' on page ... undefined.
119                 ///
120                 RERUN = 16, // Label(s) may have changed. Rerun to get...
121                 ///
122                 TEX_ERROR = 32,
123                 ///
124                 TEX_WARNING = 64,
125                 ///
126                 LATEX_ERROR = 128,
127                 ///
128                 LATEX_WARNING = 256,
129                 ///
130                 PACKAGE_WARNING = 512,
131                 ///
132                 NO_FILE = 1024,
133                 ///
134                 NO_CHANGE = 2048,
135                 ///
136                 TOO_MANY_ERRORS = 4096,
137                 ///
138                 ERROR_RERUN = 8192,
139                 ///
140                 BIBTEX_ERROR = 16384,
141                 ///
142                 NONZERO_ERROR = 32768, // the command exited with nonzero status
143                 ///
144                 ERRORS = TEX_ERROR + LATEX_ERROR + NONZERO_ERROR + BIBTEX_ERROR,
145                 ///
146                 WARNINGS = TEX_WARNING + LATEX_WARNING + PACKAGE_WARNING
147         };
148
149         /// This signal emits an informative message
150         signals2::signal<void(docstring)> message;
151
152
153         /**
154            cmd = the latex command, file = name of the (temporary) latex file,
155            path = name of the files original path,
156            clean_start = This forces a fresh run by deleting the files in the temp
157                          dir. We set this e.g. if there was an error on previous
158                          preview, which is good if the user installed a package
159                          or changed certain document settings (#9061).
160         */
161         LaTeX(std::string const & cmd, OutputParams const &,
162               support::FileName const & file,
163               std::string const & path = empty_string(),
164               std::string const & lpath = empty_string(),
165               bool allow_cancellation = false,
166               bool const clean_start = false);
167
168         /// runs LaTeX several times
169         int run(TeXErrors &);
170
171         ///
172         int getNumErrors() { return num_errors;}
173
174         ///
175         int scanLogFile(TeXErrors &);
176
177 private:
178         /// noncopyable
179         LaTeX(LaTeX const &);
180         void operator=(LaTeX const &);
181
182         /// use this for running LaTeX once
183         int startscript();
184
185         /// The dependency file.
186         support::FileName depfile;
187
188         ///
189         void deplog(DepTable & head);
190
191         /// returns exit code
192         int runMakeIndex(std::string const &, OutputParams const &,
193                           std::string const & = std::string());
194
195         /// returns exit code
196         int runMakeIndexNomencl(support::FileName const &, 
197                                  std::string const &, std::string const &);
198
199         ///
200         std::vector<AuxInfo> const scanAuxFiles(support::FileName const &,
201                                                 bool const only_childbibs = false);
202
203         ///
204         AuxInfo const scanAuxFile(support::FileName const &);
205
206         ///
207         void scanAuxFile(support::FileName const &, AuxInfo &);
208
209         ///
210         void updateBibtexDependencies(DepTable &,
211                                       std::vector<AuxInfo> const &);
212
213         ///
214         int scanBlgFile(DepTable & head, TeXErrors & terr);
215
216         ///
217         bool runBibTeX(std::vector<AuxInfo> const &,
218                        OutputParams const &, int & exit_code);
219
220         ///
221         void removeAuxiliaryFiles() const;
222
223         ///
224         std::string cmd;
225
226         ///
227         support::FileName file;
228
229         /// The document directory path.
230         std::string path;
231
232         /// Extra path, possibly relative to the document directory path.
233         std::string lpath;
234
235         /// used by scanLogFile
236         int num_errors;
237
238         /// The name of the final output file.
239         support::FileName output_file;
240
241         ///
242         OutputParams runparams;
243
244         /// Do we use biber?
245         bool biber;
246         ///
247         std::vector <std::string> children;
248         ///
249         bool allow_cancel;
250 };
251
252
253 } // namespace lyx
254
255 #endif