]> git.lyx.org Git - lyx.git/blob - src/Format.cpp
c20ac9ed43fbb7896aae91156cc7e9dbee3ac7ee
[lyx.git] / src / Format.cpp
1 /**
2  * \file Format.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Dekel Tsur
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Format.h"
14 #include "Buffer.h"
15 #include "BufferParams.h"
16 #include "LyXRC.h"
17 #include "ServerSocket.h"
18
19 #include "frontends/alert.h" //to be removed?
20
21 #include "support/debug.h"
22 #include "support/filetools.h"
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
25 #include "support/os.h"
26 #include "support/Path.h"
27 #include "support/Systemcall.h"
28 #include "support/textutils.h"
29 #include "support/Translator.h"
30
31 #include <algorithm>
32 #include <map>
33 #include <ctime>
34
35 // FIXME: Q_WS_MACX is not available, it's in Qt
36 #ifdef USE_MACOSX_PACKAGING
37 #include "support/linkback/LinkBackProxy.h"
38 #endif
39
40 #ifdef HAVE_MAGIC_H
41 #include <magic.h>
42 #endif
43
44 using namespace std;
45 using namespace lyx::support;
46
47 namespace lyx {
48
49 namespace Alert = frontend::Alert;
50 namespace os = support::os;
51
52 namespace {
53
54 string const token_from_format("$$i");
55 string const token_path_format("$$p");
56 string const token_socket_format("$$a");
57
58
59 class FormatNamesEqual : public unary_function<Format, bool> {
60 public:
61         FormatNamesEqual(string const & name)
62                 : name_(name) {}
63         bool operator()(Format const & f) const
64         {
65                 return f.name() == name_;
66         }
67 private:
68         string name_;
69 };
70
71
72 class FormatExtensionsEqual : public unary_function<Format, bool> {
73 public:
74         FormatExtensionsEqual(string const & extension)
75                 : extension_(extension) {}
76         bool operator()(Format const & f) const
77         {
78                 return f.hasExtension(extension_);
79         }
80 private:
81         string extension_;
82 };
83
84
85 class FormatMimeEqual : public unary_function<Format, bool> {
86 public:
87         FormatMimeEqual(string const & mime)
88                 : mime_(mime) {}
89         bool operator()(Format const & f) const
90         {
91                 // The test for empty mime strings is needed since we allow
92                 // formats with empty mime types.
93                 return f.mime() == mime_ && !mime_.empty();
94         }
95 private:
96         string mime_;
97 };
98
99
100 class FormatPrettyNameEqual : public unary_function<Format, bool> {
101 public:
102         FormatPrettyNameEqual(string const & prettyname)
103                 : prettyname_(prettyname) {}
104         bool operator()(Format const & f) const
105         {
106                 return f.prettyname() == prettyname_;
107         }
108 private:
109         string prettyname_;
110 };
111
112 } //namespace anon
113
114
115 bool operator<(Format const & a, Format const & b)
116 {
117         return _(a.prettyname()) < _(b.prettyname());
118 }
119
120
121 Format::Format(string const & n, string const & e, string const & p,
122                string const & s, string const & v, string const & ed,
123                string const & m, int flags)
124         : name_(n), prettyname_(p), shortcut_(s), viewer_(v),
125           editor_(ed), mime_(m), flags_(flags)
126 {
127         extension_list_ = getVectorFromString(e, ",");
128         LYXERR(Debug::GRAPHICS, "New Format: n=" << n << ", flags=" << flags);
129 }
130
131
132 bool Format::dummy() const
133 {
134         return extension().empty();
135 }
136
137
138 string const Format::extensions() const
139 {
140         return getStringFromVector(extension_list_, ", ");
141 }
142
143
144 bool Format::hasExtension(string const & e) const
145 {
146         return (find(extension_list_.begin(), extension_list_.end(), e)
147                 != extension_list_.end());
148 }
149
150
151 bool Format::isChildFormat() const
152 {
153         if (name_.empty())
154                 return false;
155         return isDigitASCII(name_[name_.length() - 1]);
156 }
157
158
159 string const Format::parentFormat() const
160 {
161         return name_.substr(0, name_.length() - 1);
162 }
163
164
165 void Format::setExtensions(string const & e)
166 {
167         extension_list_ = getVectorFromString(e, ",");
168 }
169
170
171 // This method should return a reference, and throw an exception
172 // if the format named name cannot be found (Lgb)
173 Format const * Formats::getFormat(string const & name) const
174 {
175         FormatList::const_iterator cit =
176                 find_if(formatlist.begin(), formatlist.end(),
177                         FormatNamesEqual(name));
178         if (cit != formatlist.end())
179                 return &(*cit);
180         else
181                 return 0;
182 }
183
184
185 namespace {
186
187 /** Guess the file format name (as in Format::name()) from contents.
188  *  Normally you don't want to use this directly, but rather
189  *  Formats::getFormatFromFile().
190  */
191 string guessFormatFromContents(FileName const & fn)
192 {
193         // the different filetypes and what they contain in one of the first lines
194         // (dots are any characters).           (Herbert 20020131)
195         // AGR  Grace...
196         // BMP  BM...
197         // EPS  %!PS-Adobe-3.0 EPSF...
198         // FIG  #FIG...
199         // FITS ...BITPIX...
200         // GIF  GIF...
201         // JPG  JFIF
202         // PDF  %PDF-...
203         // PNG  .PNG...
204         // PBM  P1... or P4     (B/W)
205         // PGM  P2... or P5     (Grayscale)
206         // PPM  P3... or P6     (color)
207         // PS   %!PS-Adobe-2.0 or 1.0,  no "EPSF"!
208         // SGI  \001\332...     (decimal 474)
209         // TGIF %TGIF...
210         // TIFF II... or MM...
211         // XBM  ..._bits[]...
212         // XPM  /* XPM */    sometimes missing (f.ex. tgif-export)
213         //      ...static char *...
214         // XWD  \000\000\000\151        (0x00006900) decimal 105
215         //
216         // GZIP \037\213        http://www.ietf.org/rfc/rfc1952.txt
217         // ZIP  PK...                   http://www.halyava.ru/document/ind_arch.htm
218         // Z    \037\235                UNIX compress
219
220         // paranoia check
221         if (fn.empty() || !fn.isReadableFile())
222                 return string();
223
224         ifstream ifs(fn.toFilesystemEncoding().c_str());
225         if (!ifs)
226                 // Couldn't open file...
227                 return string();
228
229         // gnuzip
230         static string const gzipStamp = "\037\213";
231
232         // PKZIP
233         static string const zipStamp = "PK";
234
235         // ZIP containers (koffice, openoffice.org etc).
236         static string const nonzipStamp = "\008\0\0\0mimetypeapplication/";
237
238         // compress
239         static string const compressStamp = "\037\235";
240
241         // Maximum strings to read
242         int const max_count = 50;
243         int count = 0;
244
245         string str;
246         string format;
247         bool firstLine = true;
248         while ((count++ < max_count) && format.empty()) {
249                 if (ifs.eof()) {
250                         LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n"
251                                 << "\tFile type not recognised before EOF!");
252                         break;
253                 }
254
255                 getline(ifs, str);
256                 string const stamp = str.substr(0, 2);
257                 if (firstLine && str.size() >= 2) {
258                         // at first we check for a zipped file, because this
259                         // information is saved in the first bytes of the file!
260                         // also some graphic formats which save the information
261                         // in the first line, too.
262                         if (prefixIs(str, gzipStamp)) {
263                                 format =  "gzip";
264
265                         } else if (stamp == zipStamp &&
266                                    !contains(str, nonzipStamp)) {
267                                 format =  "zip";
268
269                         } else if (stamp == compressStamp) {
270                                 format =  "compress";
271
272                         // the graphics part
273                         } else if (stamp == "BM") {
274                                 format =  "bmp";
275
276                         } else if (stamp == "\001\332") {
277                                 format =  "sgi";
278
279                         // PBM family
280                         // Don't need to use str.at(0), str.at(1) because
281                         // we already know that str.size() >= 2
282                         } else if (str[0] == 'P') {
283                                 switch (str[1]) {
284                                 case '1':
285                                 case '4':
286                                         format =  "pbm";
287                                     break;
288                                 case '2':
289                                 case '5':
290                                         format =  "pgm";
291                                     break;
292                                 case '3':
293                                 case '6':
294                                         format =  "ppm";
295                                 }
296                                 break;
297
298                         } else if ((stamp == "II") || (stamp == "MM")) {
299                                 format =  "tiff";
300
301                         } else if (prefixIs(str,"%TGIF")) {
302                                 format =  "tgif";
303
304                         } else if (prefixIs(str,"#FIG")) {
305                                 format =  "fig";
306
307                         } else if (prefixIs(str,"GIF")) {
308                                 format =  "gif";
309
310                         } else if (str.size() > 3) {
311                                 int const c = ((str[0] << 24) & (str[1] << 16) &
312                                                (str[2] << 8)  & str[3]);
313                                 if (c == 105) {
314                                         format =  "xwd";
315                                 }
316                         }
317
318                         firstLine = false;
319                 }
320
321                 if (!format.empty())
322                     break;
323                 else if (contains(str,"EPSF"))
324                         // dummy, if we have wrong file description like
325                         // %!PS-Adobe-2.0EPSF"
326                         format = "eps";
327
328                 else if (contains(str, "Grace"))
329                         format = "agr";
330
331                 else if (contains(str, "JFIF"))
332                         format = "jpg";
333
334                 else if (contains(str, "%PDF"))
335                         format = "pdf";
336
337                 else if (contains(str, "PNG"))
338                         format = "png";
339
340                 else if (contains(str, "%!PS-Adobe")) {
341                         // eps or ps
342                         ifs >> str;
343                         if (contains(str,"EPSF"))
344                                 format = "eps";
345                         else
346                             format = "ps";
347                 }
348
349                 else if (contains(str, "_bits[]"))
350                         format = "xbm";
351
352                 else if (contains(str, "XPM") || contains(str, "static char *"))
353                         format = "xpm";
354
355                 else if (contains(str, "BITPIX"))
356                         format = "fits";
357         }
358
359         if (!format.empty()) {
360                 LYXERR(Debug::GRAPHICS, "Recognised Fileformat: " << format);
361                 return format;
362         }
363
364         LYXERR(Debug::GRAPHICS, "filetools(getFormatFromContents)\n"
365                 << "\tCouldn't find a known format!");
366         return string();
367 }
368
369 }
370
371
372 string Formats::getFormatFromFile(FileName const & filename) const
373 {
374         if (filename.empty())
375                 return string();
376
377 #ifdef HAVE_MAGIC_H
378         magic_t magic_cookie = magic_open(MAGIC_MIME);
379         if (magic_cookie) {
380                 string format;
381                 if (magic_load(magic_cookie, NULL) != 0) {
382                         LYXERR(Debug::GRAPHICS, "Formats::getFormatFromFile\n"
383                                 << "\tCouldn't load magic database - "
384                                 << magic_error(magic_cookie));
385                 } else {
386                         string mime = magic_file(magic_cookie,
387                                 filename.toFilesystemEncoding().c_str());
388                         mime = token(mime, ';', 0);
389                         // we need our own ps/eps detection
390                         if (mime != "application/postscript") {
391                                 Formats::const_iterator cit =
392                                         find_if(formatlist.begin(), formatlist.end(),
393                                                 FormatMimeEqual(mime));
394                                 if (cit != formats.end()) {
395                                         LYXERR(Debug::GRAPHICS, "\tgot format from MIME type: "
396                                                 << mime << " -> " << cit->name());
397                                         format = cit->name();
398                                 }
399                         }
400                 }
401                 magic_close(magic_cookie);
402                 if (!format.empty())
403                         return format;
404         }
405 #endif
406
407         string const format = guessFormatFromContents(filename);
408         string const ext = getExtension(filename.absFileName());
409         if (isZippedFileFormat(format) && !ext.empty()) {
410                 string const & fmt_name = formats.getFormatFromExtension(ext);
411                 if (!fmt_name.empty()) {
412                         Format const * p_format = formats.getFormat(fmt_name);
413                         if (p_format && p_format->zippedNative())
414                                 return p_format->name();
415                 }
416         }
417         if (!format.empty())
418                 return format;
419
420         // try to find a format from the file extension.
421         return getFormatFromExtension(ext);
422 }
423
424
425 string Formats::getFormatFromExtension(string const & ext) const
426 {
427         if (!ext.empty()) {
428                 // this is ambigous if two formats have the same extension,
429                 // but better than nothing
430                 Formats::const_iterator cit =
431                         find_if(formatlist.begin(), formatlist.end(),
432                                 FormatExtensionsEqual(ext));
433                 if (cit != formats.end()) {
434                         LYXERR(Debug::GRAPHICS, "\twill guess format from file extension: "
435                                 << ext << " -> " << cit->name());
436                         return cit->name();
437                 }
438         }
439         return string();
440 }
441
442
443 string Formats::getFormatFromPrettyName(string const & prettyname) const
444 {
445         if (!prettyname.empty()) {
446                 Formats::const_iterator cit =
447                         find_if(formatlist.begin(), formatlist.end(),
448                                 FormatPrettyNameEqual(prettyname));
449                 if (cit != formats.end())
450                         return cit->name();
451         }
452         return string();
453 }
454
455
456 /// Used to store last timestamp of file and whether it is (was) zipped
457 struct ZippedInfo {
458         bool zipped;
459         std::time_t timestamp;
460         ZippedInfo(bool zipped, std::time_t timestamp)
461         : zipped(zipped), timestamp(timestamp) { }
462 };
463
464
465 /// Mapping absolute pathnames of files to their ZippedInfo metadata.
466 static std::map<std::string, ZippedInfo> zipped_;
467
468
469 bool Formats::isZippedFile(support::FileName const & filename) const {
470         string const & fname = filename.absFileName();
471         time_t timestamp = filename.lastModified();
472         map<string, ZippedInfo>::iterator it = zipped_.find(fname);
473         if (it != zipped_.end() && it->second.timestamp == timestamp)
474                 return it->second.zipped;
475         string const & format = getFormatFromFile(filename);
476         bool zipped = (format == "gzip" || format == "zip");
477         zipped_.insert(pair<string, ZippedInfo>(fname, ZippedInfo(zipped, timestamp)));
478         return zipped;
479 }
480
481
482 bool Formats::isZippedFileFormat(string const & format)
483 {
484         return contains("gzip zip compress", format) && !format.empty();
485 }
486
487
488 bool Formats::isPostScriptFileFormat(string const & format)
489 {
490         return format == "ps" || format == "eps";
491 }
492
493 static string fixCommand(string const & cmd, string const & ext,
494                   os::auto_open_mode mode)
495 {
496         // configure.py says we do not want a viewer/editor
497         if (cmd.empty())
498                 return cmd;
499
500         // Does the OS manage this format?
501         if (os::canAutoOpenFile(ext, mode))
502                 return "auto";
503
504         // if configure.py found nothing, clear the command
505         if (token(cmd, ' ', 0) == "auto")
506                 return string();
507
508         // use the command found by configure.py
509         return cmd;
510 }
511
512
513 void Formats::setAutoOpen()
514 {
515         FormatList::iterator fit = formatlist.begin();
516         FormatList::iterator const fend = formatlist.end();
517         for ( ; fit != fend ; ++fit) {
518                 fit->setViewer(fixCommand(fit->viewer(), fit->extension(), os::VIEW));
519                 fit->setEditor(fixCommand(fit->editor(), fit->extension(), os::EDIT));
520         }
521 }
522
523
524 int Formats::getNumber(string const & name) const
525 {
526         FormatList::const_iterator cit =
527                 find_if(formatlist.begin(), formatlist.end(),
528                         FormatNamesEqual(name));
529         if (cit != formatlist.end())
530                 return distance(formatlist.begin(), cit);
531         else
532                 return -1;
533 }
534
535
536 void Formats::add(string const & name)
537 {
538         if (!getFormat(name))
539                 add(name, name, name, string(), string(), string(),
540                     string(), Format::document);
541 }
542
543
544 void Formats::add(string const & name, string const & extensions,
545                   string const & prettyname, string const & shortcut,
546                   string const & viewer, string const & editor,
547                   string const & mime, int flags)
548 {
549         FormatList::iterator it =
550                 find_if(formatlist.begin(), formatlist.end(),
551                         FormatNamesEqual(name));
552         if (it == formatlist.end())
553                 formatlist.push_back(Format(name, extensions, prettyname,
554                                             shortcut, viewer, editor, mime, flags));
555         else
556                 *it = Format(name, extensions, prettyname, shortcut, viewer,
557                              editor, mime, flags);
558 }
559
560
561 void Formats::erase(string const & name)
562 {
563         FormatList::iterator it =
564                 find_if(formatlist.begin(), formatlist.end(),
565                         FormatNamesEqual(name));
566         if (it != formatlist.end())
567                 formatlist.erase(it);
568 }
569
570
571 void Formats::sort()
572 {
573         std::sort(formatlist.begin(), formatlist.end());
574 }
575
576
577 void Formats::setViewer(string const & name, string const & command)
578 {
579         add(name);
580         FormatList::iterator it =
581                 find_if(formatlist.begin(), formatlist.end(),
582                         FormatNamesEqual(name));
583         if (it != formatlist.end())
584                 it->setViewer(command);
585 }
586
587
588 void Formats::setEditor(string const & name, string const & command)
589 {
590         add(name);
591         FormatList::iterator it =
592                 find_if(formatlist.begin(), formatlist.end(),
593                         FormatNamesEqual(name));
594         if (it != formatlist.end())
595                 it->setEditor(command);
596 }
597
598
599 bool Formats::view(Buffer const & buffer, FileName const & filename,
600                    string const & format_name) const
601 {
602         if (filename.empty() || !filename.exists()) {
603                 Alert::error(_("Cannot view file"),
604                         bformat(_("File does not exist: %1$s"),
605                                 from_utf8(filename.absFileName())));
606                 return false;
607         }
608
609         Format const * format = getFormat(format_name);
610         if (format && format->viewer().empty() &&
611             format->isChildFormat())
612                 format = getFormat(format->parentFormat());
613         if (!format || format->viewer().empty()) {
614 // FIXME: I believe this is the wrong place to show alerts, it should be done
615 // by the caller (this should be "utility" code)
616                 Alert::error(_("Cannot view file"),
617                         bformat(_("No information for viewing %1$s"),
618                                 prettyName(format_name)));
619                 return false;
620         }
621         // viewer is 'auto'
622         if (format->viewer() == "auto") {
623                 if (os::autoOpenFile(filename.absFileName(), os::VIEW, buffer.filePath()))
624                         return true;
625                 else {
626                         Alert::error(_("Cannot view file"),
627                                 bformat(_("Auto-view file %1$s failed"),
628                                         from_utf8(filename.absFileName())));
629                         return false;
630                 }
631         }
632
633         string command = libScriptSearch(format->viewer());
634
635         if (format_name == "dvi" &&
636             !lyxrc.view_dvi_paper_option.empty()) {
637                 string paper_size = buffer.params().paperSizeName(BufferParams::XDVI);
638                 if (!paper_size.empty()) {
639                         command += ' ' + lyxrc.view_dvi_paper_option;
640                         command += ' ' + paper_size;
641                         if (buffer.params().orientation == ORIENTATION_LANDSCAPE &&
642                             buffer.params().papersize != PAPER_CUSTOM)
643                                 command += 'r';
644                 }
645         }
646
647         if (!contains(command, token_from_format))
648                 command += ' ' + token_from_format;
649
650         command = subst(command, token_from_format, quoteName(onlyFileName(filename.toFilesystemEncoding())));
651         command = subst(command, token_path_format, quoteName(onlyPath(filename.toFilesystemEncoding())));
652         command = subst(command, token_socket_format, quoteName(theServerSocket().address()));
653         LYXERR(Debug::FILES, "Executing command: " << command);
654         // FIXME UNICODE utf8 can be wrong for files
655         buffer.message(_("Executing command: ") + from_utf8(command));
656
657         PathChanger p(filename.onlyPath());
658         Systemcall one;
659         one.startscript(Systemcall::DontWait, command, buffer.filePath());
660
661         // we can't report any sort of error, since we aren't waiting
662         return true;
663 }
664
665
666 bool Formats::edit(Buffer const & buffer, FileName const & filename,
667                          string const & format_name) const
668 {
669         if (filename.empty() || !filename.exists()) {
670                 Alert::error(_("Cannot edit file"),
671                         bformat(_("File does not exist: %1$s"),
672                                 from_utf8(filename.absFileName())));
673                 return false;
674         }
675
676         // LinkBack files look like PDF, but have the .linkback extension
677         string const ext = getExtension(filename.absFileName());
678         if (format_name == "pdf" && ext == "linkback") {
679 #ifdef USE_MACOSX_PACKAGING
680                 return editLinkBackFile(filename.absFileName().c_str());
681 #else
682                 Alert::error(_("Cannot edit file"),
683                              _("LinkBack files can only be edited on Apple Mac OSX."));
684                 return false;
685 #endif // USE_MACOSX_PACKAGING
686         }
687
688         Format const * format = getFormat(format_name);
689         if (format && format->editor().empty() &&
690             format->isChildFormat())
691                 format = getFormat(format->parentFormat());
692         if (!format || format->editor().empty()) {
693 // FIXME: I believe this is the wrong place to show alerts, it should
694 // be done by the caller (this should be "utility" code)
695                 Alert::error(_("Cannot edit file"),
696                         bformat(_("No information for editing %1$s"),
697                                 prettyName(format_name)));
698                 return false;
699         }
700
701         // editor is 'auto'
702         if (format->editor() == "auto") {
703                 if (os::autoOpenFile(filename.absFileName(), os::EDIT, buffer.filePath()))
704                         return true;
705                 else {
706                         Alert::error(_("Cannot edit file"),
707                                 bformat(_("Auto-edit file %1$s failed"),
708                                         from_utf8(filename.absFileName())));
709                         return false;
710                 }
711         }
712
713         string command = format->editor();
714
715         if (!contains(command, token_from_format))
716                 command += ' ' + token_from_format;
717
718         command = subst(command, token_from_format, quoteName(filename.toFilesystemEncoding()));
719         command = subst(command, token_path_format, quoteName(onlyPath(filename.toFilesystemEncoding())));
720         command = subst(command, token_socket_format, quoteName(theServerSocket().address()));
721         LYXERR(Debug::FILES, "Executing command: " << command);
722         // FIXME UNICODE utf8 can be wrong for files
723         buffer.message(_("Executing command: ") + from_utf8(command));
724
725         Systemcall one;
726         one.startscript(Systemcall::DontWait, command, buffer.filePath());
727
728         // we can't report any sort of error, since we aren't waiting
729         return true;
730 }
731
732
733 docstring const Formats::prettyName(string const & name) const
734 {
735         Format const * format = getFormat(name);
736         if (format)
737                 return from_utf8(format->prettyname());
738         else
739                 return from_utf8(name);
740 }
741
742
743 string const Formats::extension(string const & name) const
744 {
745         Format const * format = getFormat(name);
746         if (format)
747                 return format->extension();
748         else
749                 return name;
750 }
751
752
753 string const Formats::extensions(string const & name) const
754 {
755         Format const * format = getFormat(name);
756         if (format)
757                 return format->extensions();
758         else
759                 return name;
760 }
761
762
763 namespace {
764 typedef Translator<OutputParams::FLAVOR, string> FlavorTranslator;
765
766 FlavorTranslator initFlavorTranslator()
767 {
768         FlavorTranslator f(OutputParams::LATEX, "latex");
769         f.addPair(OutputParams::DVILUATEX, "dviluatex");
770         f.addPair(OutputParams::LUATEX, "luatex");
771         f.addPair(OutputParams::PDFLATEX, "pdflatex");
772         f.addPair(OutputParams::XETEX, "xetex");
773         f.addPair(OutputParams::XML, "docbook-xml");
774         f.addPair(OutputParams::HTML, "xhtml");
775         f.addPair(OutputParams::TEXT, "text");
776         return f;
777 }
778
779
780 FlavorTranslator const & flavorTranslator()
781 {
782         static FlavorTranslator translator = initFlavorTranslator();
783         return translator;
784 }
785 }
786
787
788 std::string flavor2format(OutputParams::FLAVOR flavor)
789 {
790         return flavorTranslator().find(flavor);
791 }
792
793
794 /* Not currently needed, but I'll leave the code in case it is.
795 OutputParams::FLAVOR format2flavor(std::string fmt)
796 {
797         return flavorTranslator().find(fmt);
798 } */
799
800 Formats formats;
801
802 Formats system_formats;
803
804
805 } // namespace lyx