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