1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * This file is Copyright 1996-1999
12 * ======================================================
26 #include <sys/types.h>
36 #pragma implementation "buffer.h"
40 #include "bufferlist.h"
42 #include "lyx_gui_misc.h"
43 #include "LyXAction.h"
46 #include "tex-strings.h"
48 #include "bufferview_funcs.h"
49 #include "minibuffer.h"
52 #include "mathed/formulamacro.h"
53 #include "insets/lyxinset.h"
54 #include "insets/inseterror.h"
55 #include "insets/insetlabel.h"
56 #include "insets/insetref.h"
57 #include "insets/inseturl.h"
58 #include "insets/insetinfo.h"
59 #include "insets/insetquotes.h"
60 #include "insets/insetlatexaccent.h"
61 #include "insets/insetbib.h"
62 #include "insets/insetcite.h"
63 #include "insets/insetexternal.h"
64 #include "insets/insetindex.h"
65 #include "insets/insetinclude.h"
66 #include "insets/insettoc.h"
67 #include "insets/insetparent.h"
68 #include "insets/insetspecialchar.h"
69 #include "insets/figinset.h"
70 #include "insets/insettext.h"
71 #include "insets/insetert.h"
72 #include "insets/insetgraphics.h"
73 #include "insets/insetfoot.h"
74 #include "insets/insetmarginal.h"
75 #include "insets/insetminipage.h"
76 #include "insets/insetfloat.h"
77 #include "insets/insetlist.h"
78 #include "insets/insettabular.h"
79 #include "insets/insettheorem.h"
80 #include "insets/insetcaption.h"
81 #include "support/filetools.h"
82 #include "support/path.h"
87 #include "LaTeXFeatures.h"
88 #include "support/syscall.h"
89 #include "support/lyxlib.h"
90 #include "support/FileInfo.h"
91 #include "support/lyxmanip.h"
95 #include "lyx_gui_misc.h" // WarnReadonly()
96 #include "frontends/Dialogs.h"
100 #include "converter.h"
102 using std::stringstream;
111 using std::make_pair;
120 // all these externs should eventually be removed.
121 extern BufferList bufferlist;
123 extern LyXAction lyxaction;
127 const int LYX_FORMAT = 218;
131 extern int tex_code_break_column;
134 Buffer::Buffer(string const & file, bool ronly)
136 lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
138 filepath = OnlyPath(file);
147 if (read_only || (lyxrc.use_tempdir)) {
148 tmppath = CreateBufferTmpDir();
149 } else tmppath.erase();
155 lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
156 // here the buffer should take care that it is
157 // saved properly, before it goes into the void.
159 // make sure that views using this buffer
164 if (!tmppath.empty()) {
165 DestroyBufferTmpDir(tmppath);
168 LyXParagraph * par = paragraph;
169 LyXParagraph * tmppar;
178 tmppar = par->next();
187 string const Buffer::getLatexName(bool no_path) const
190 return OnlyFilename(ChangeExtension(MakeLatexName(filename),
193 return ChangeExtension(MakeLatexName(filename),
198 pair<Buffer::LogType, string> const Buffer::getLogName(void) const
200 string const filename = getLatexName(false);
202 if (filename.empty())
203 return make_pair(Buffer::latexlog, string());
205 string path = OnlyPath(filename);
207 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1))
210 string const fname = AddName(path,
211 OnlyFilename(ChangeExtension(filename,
214 AddName(path, OnlyFilename(
215 ChangeExtension(filename,
216 formats.Extension("literate") + ".out")));
218 // If no Latex log or Build log is newer, show Build log
220 FileInfo const f_fi(fname);
221 FileInfo const b_fi(bname);
224 (!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
225 lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
226 return make_pair(Buffer::buildlog, bname);
228 lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
229 return make_pair(Buffer::latexlog, fname);
233 void Buffer::setReadonly(bool flag)
235 if (read_only != flag) {
238 users->owner()->getDialogs()->updateBufferDependent(false);
241 WarnReadonly(filename);
246 bool Buffer::saveParamsAsDefaults() // const
248 string const fname = AddName(AddPath(user_lyxdir, "templates/"),
250 Buffer defaults = Buffer(fname);
252 // Use the current buffer's parameters as default
253 defaults.params = params;
255 // add an empty paragraph. Is this enough?
256 defaults.paragraph = new LyXParagraph;
258 return defaults.writeFile(defaults.filename, false);
262 /// Update window titles of all users
263 // Should work on a list
264 void Buffer::updateTitles() const
266 if (users) users->owner()->updateWindowTitle();
270 /// Reset autosave timer of all users
271 // Should work on a list
272 void Buffer::resetAutosaveTimers() const
274 if (users) users->owner()->resetAutosaveTimer();
278 void Buffer::setFileName(string const & newfile)
280 filename = MakeAbsPath(newfile);
281 filepath = OnlyPath(filename);
282 setReadonly(IsFileWriteable(filename) == 0);
287 // candidate for move to BufferView
288 // (at least some parts in the beginning of the func)
291 // changed to be public and have one parameter
292 // if par = 0 normal behavior
293 // else insert behavior
294 // Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
295 bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par)
298 char depth = 0; // signed or unsigned?
300 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
301 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
303 bool the_end_read = false;
305 LyXParagraph * return_par = 0;
306 LyXFont font(LyXFont::ALL_INHERIT, params.language);
307 if (file_format < 216 && params.language->lang() == "hebrew")
308 font.setLanguage(default_language);
309 // If we are inserting, we cheat and get a token in advance
310 bool has_token = false;
314 par = new LyXParagraph;
316 users->text->BreakParagraph(users);
317 return_par = users->text->FirstParagraph();
320 // We don't want to adopt the parameters from the
321 // document we insert, so we skip until the text begins:
324 pretoken = lex.GetString();
325 if (pretoken == "\\layout") {
337 pretoken = lex.GetString();
340 if (pretoken.empty()) continue;
343 parseSingleLyXformat2Token(lex, par, return_par,
344 pretoken, pos, depth,
356 paragraph = return_par;
362 // We'll remove this later. (Lgb)
365 string last_inset_read;
371 Buffer::parseSingleLyXformat2Token(LyXLex & lex, LyXParagraph *& par,
372 LyXParagraph *& return_par,
373 string const & token, int & pos,
374 char & depth, LyXFont & font
376 , LyXParagraph::footnote_flag & footnoteflag,
377 LyXParagraph::footnote_kind & footnotekind
381 bool the_end_read = false;
382 #ifndef NO_PEXTRA_REALLY
384 // This is super temporary but is needed to get the compability
385 // mode for minipages work correctly together with new tabulars.
386 static int call_depth = 0;
389 bool checkminipage = false;
390 static LyXParagraph * minipar = 0;
391 static LyXParagraph * parBeforeMinipage = 0;
394 if (token[0] != '\\') {
395 for (string::const_iterator cit = token.begin();
396 cit != token.end(); ++cit)
398 par->InsertChar(pos, (*cit), font);
401 checkminipage = true;
402 } else if (token == "\\i") {
403 Inset * inset = new InsetLatexAccent;
404 inset->Read(this, lex);
405 par->InsertInset(pos, inset, font);
407 } else if (token == "\\layout") {
413 par = new LyXParagraph(par);
417 string const layoutname = lex.GetString();
418 pair<bool, LyXTextClass::LayoutList::size_type> pp
419 = textclasslist.NumberOfLayout(params.textclass,
422 par->layout = pp.second;
423 } else { // layout not found
424 // use default layout "Standard" (0)
427 // Test whether the layout is obsolete.
428 LyXLayout const & layout =
429 textclasslist.Style(params.textclass,
431 if (!layout.obsoleted_by().empty())
433 textclasslist.NumberOfLayout(params.textclass,
434 layout.obsoleted_by()).second;
435 par->footnoteflag = footnoteflag;
436 par->footnotekind = footnotekind;
437 par->params.depth(depth);
438 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
439 if (file_format < 216 && params.language->lang() == "hebrew")
440 font.setLanguage(default_language);
443 string const layoutname = lex.GetString();
444 pair<bool, LyXTextClass::LayoutList::size_type> pp
445 = textclasslist.NumberOfLayout(params.textclass,
449 // The is the compability reading of layout caption.
450 // It can be removed in LyX version 1.3.0. (Lgb)
451 if (compare_no_case(layoutname, "caption") == 0) {
452 // We expect that the par we are now working on is
453 // really inside a InsetText inside a InsetFloat.
454 // We also know that captions can only be
455 // one paragraph. (Lgb)
457 // We should now read until the next "\layout"
459 // This is probably not good enough, what if the
460 // caption is the last par in the document (Lgb)
461 istream & ist = lex.getStream();
467 if (prefixIs(line, "\\layout")) {
471 if (prefixIs(line, "\\begin_inset"))
473 if (prefixIs(line, "\\end_inset")) {
484 // Now we should have the whole layout in ss
485 // we should now be able to give this to the
487 ss << "\\end_inset\n";
489 // This seems like a bug in stringstream.
490 // We really should be able to use ss
492 istringstream is(ss.str());
494 tmplex.setStream(is);
495 Inset * inset = new InsetCaption;
496 inset->Read(this, tmplex);
497 par->InsertInset(pos, inset, font);
505 par = new LyXParagraph(par);
509 par->layout = pp.second;
512 // use default layout "Standard" (0)
515 // Test whether the layout is obsolete.
516 LyXLayout const & layout =
517 textclasslist.Style(params.textclass,
519 if (!layout.obsoleted_by().empty())
520 par->layout = textclasslist
521 .NumberOfLayout(params.textclass,
522 layout.obsoleted_by())
524 par->params.depth(depth);
525 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
526 if (file_format < 216
527 && params.language->lang() == "hebrew")
528 font.setLanguage(default_language);
534 } else if (token == "\\end_float") {
539 par = new LyXParagraph(par);
541 footnotekind = LyXParagraph::FOOTNOTE;
542 footnoteflag = LyXParagraph::NO_FOOTNOTE;
545 par->layout = LYX_DUMMY_LAYOUT;
546 font = LyXFont(LyXFont::ALL_INHERIT, params.language);
547 if (file_format < 216 && params.language->lang() == "hebrew")
548 font.setLanguage(default_language);
549 } else if (token == "\\begin_float") {
550 int tmpret = lex.FindToken(string_footnotekinds);
551 if (tmpret == -1) ++tmpret;
552 if (tmpret != LYX_LAYOUT_DEFAULT)
553 footnotekind = static_cast<LyXParagraph::footnote_kind>(tmpret); // bad
554 if (footnotekind == LyXParagraph::FOOTNOTE
555 || footnotekind == LyXParagraph::MARGIN)
556 footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
558 footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
560 } else if (token == "\\begin_float") {
561 // This is the compability reader. It can be removed in
562 // LyX version 1.3.0. (Lgb)
564 string const tmptok = lex.GetString();
565 //lyxerr << "old float: " << tmptok << endl;
568 stringstream old_float;
570 if (tmptok == "footnote") {
571 inset = new InsetFoot;
572 } else if (tmptok == "margin") {
573 inset = new InsetMarginal;
574 } else if (tmptok == "fig") {
575 inset = new InsetFloat("figure");
576 old_float << "placement htbp\n";
577 } else if (tmptok == "tab") {
578 inset = new InsetFloat("table");
579 old_float << "placement htbp\n";
580 } else if (tmptok == "alg") {
581 inset = new InsetFloat("algorithm");
582 old_float << "placement htbp\n";
583 } else if (tmptok == "wide-fig") {
584 InsetFloat * tmp = new InsetFloat("figure");
587 old_float << "placement htbp\n";
588 } else if (tmptok == "wide-tab") {
589 InsetFloat * tmp = new InsetFloat("table");
592 old_float << "placement htbp\n";
597 return false; // no end read yet
600 old_float << "collapsed true\n";
602 // Here we need to check for \end_deeper and handle that
603 // before we do the footnote parsing.
604 // This _is_ a hack! (Lgb)
607 string const tmp = lex.GetString();
608 if (tmp == "\\end_deeper") {
609 //lyxerr << "\\end_deeper caught!" << endl;
611 lex.printError("\\end_deeper: "
612 "depth is already null");
617 old_float << tmp << ' ';
622 old_float << lex.getLongString("\\end_float")
623 << "\n\\end_inset\n";
624 //lyxerr << "Float Body:\n" << old_float.str() << endl;
625 // That this does not work seems like a bug
626 // in stringstream. (Lgb)
627 istringstream istr(old_float.str());
629 nylex.setStream(istr);
630 inset->Read(this, nylex);
631 par->InsertInset(pos, inset, font);
634 } else if (token == "\\begin_deeper") {
636 } else if (token == "\\end_deeper") {
638 lex.printError("\\end_deeper: "
639 "depth is already null");
643 } else if (token == "\\begin_preamble") {
644 params.readPreamble(lex);
645 } else if (token == "\\textclass") {
647 pair<bool, LyXTextClassList::size_type> pp =
648 textclasslist.NumberOfClass(lex.GetString());
650 params.textclass = pp.second;
652 WriteAlert(string(_("Textclass error")),
653 string(_("The document uses an unknown textclass \"")) +
654 lex.GetString() + string("\"."),
655 string(_("LyX will not be able to produce output correctly.")));
656 params.textclass = 0;
658 if (!textclasslist.Load(params.textclass)) {
659 // if the textclass wasn't loaded properly
660 // we need to either substitute another
661 // or stop loading the file.
662 // I can substitute but I don't see how I can
663 // stop loading... ideas?? ARRae980418
664 WriteAlert(_("Textclass Loading Error!"),
665 string(_("Can't load textclass ")) +
666 textclasslist.NameOfClass(params.textclass),
667 _("-- substituting default"));
668 params.textclass = 0;
670 } else if (token == "\\options") {
672 params.options = lex.GetString();
673 } else if (token == "\\language") {
674 params.readLanguage(lex);
675 } else if (token == "\\fontencoding") {
677 } else if (token == "\\inputencoding") {
679 params.inputenc = lex.GetString();
680 } else if (token == "\\graphics") {
681 params.readGraphicsDriver(lex);
682 } else if (token == "\\fontscheme") {
684 params.fonts = lex.GetString();
685 } else if (token == "\\noindent") {
686 par->params.noindent(true);
687 } else if (token == "\\fill_top") {
688 par->params.spaceTop(VSpace(VSpace::VFILL));
689 } else if (token == "\\fill_bottom") {
690 par->params.spaceBottom(VSpace(VSpace::VFILL));
691 } else if (token == "\\line_top") {
692 par->params.lineTop(true);
693 } else if (token == "\\line_bottom") {
694 par->params.lineBottom(true);
695 } else if (token == "\\pagebreak_top") {
696 par->params.pagebreakTop(true);
697 } else if (token == "\\pagebreak_bottom") {
698 par->params.pagebreakBottom(true);
699 } else if (token == "\\start_of_appendix") {
700 par->params.startOfAppendix(true);
701 } else if (token == "\\paragraph_separation") {
702 int tmpret = lex.FindToken(string_paragraph_separation);
703 if (tmpret == -1) ++tmpret;
704 if (tmpret != LYX_LAYOUT_DEFAULT)
705 params.paragraph_separation =
706 static_cast<BufferParams::PARSEP>(tmpret);
707 } else if (token == "\\defskip") {
709 params.defskip = VSpace(lex.GetString());
710 } else if (token == "\\epsfig") { // obsolete
711 // Indeed it is obsolete, but we HAVE to be backwards
712 // compatible until 0.14, because otherwise all figures
713 // in existing documents are irretrivably lost. (Asger)
714 params.readGraphicsDriver(lex);
715 } else if (token == "\\quotes_language") {
716 int tmpret = lex.FindToken(string_quotes_language);
717 if (tmpret == -1) ++tmpret;
718 if (tmpret != LYX_LAYOUT_DEFAULT) {
719 InsetQuotes::quote_language tmpl =
720 InsetQuotes::EnglishQ;
723 tmpl = InsetQuotes::EnglishQ;
726 tmpl = InsetQuotes::SwedishQ;
729 tmpl = InsetQuotes::GermanQ;
732 tmpl = InsetQuotes::PolishQ;
735 tmpl = InsetQuotes::FrenchQ;
738 tmpl = InsetQuotes::DanishQ;
741 params.quotes_language = tmpl;
743 } else if (token == "\\quotes_times") {
745 switch (lex.GetInteger()) {
747 params.quotes_times = InsetQuotes::SingleQ;
750 params.quotes_times = InsetQuotes::DoubleQ;
753 } else if (token == "\\papersize") {
754 int tmpret = lex.FindToken(string_papersize);
758 params.papersize2 = tmpret;
759 } else if (token == "\\paperpackage") {
760 int tmpret = lex.FindToken(string_paperpackages);
763 params.paperpackage = BufferParams::PACKAGE_NONE;
765 params.paperpackage = tmpret;
766 } else if (token == "\\use_geometry") {
768 params.use_geometry = lex.GetInteger();
769 } else if (token == "\\use_amsmath") {
771 params.use_amsmath = lex.GetInteger();
772 } else if (token == "\\paperorientation") {
773 int tmpret = lex.FindToken(string_orientation);
774 if (tmpret == -1) ++tmpret;
775 if (tmpret != LYX_LAYOUT_DEFAULT)
776 params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
777 } else if (token == "\\paperwidth") {
779 params.paperwidth = lex.GetString();
780 } else if (token == "\\paperheight") {
782 params.paperheight = lex.GetString();
783 } else if (token == "\\leftmargin") {
785 params.leftmargin = lex.GetString();
786 } else if (token == "\\topmargin") {
788 params.topmargin = lex.GetString();
789 } else if (token == "\\rightmargin") {
791 params.rightmargin = lex.GetString();
792 } else if (token == "\\bottommargin") {
794 params.bottommargin = lex.GetString();
795 } else if (token == "\\headheight") {
797 params.headheight = lex.GetString();
798 } else if (token == "\\headsep") {
800 params.headsep = lex.GetString();
801 } else if (token == "\\footskip") {
803 params.footskip = lex.GetString();
804 } else if (token == "\\paperfontsize") {
806 params.fontsize = strip(lex.GetString());
807 } else if (token == "\\papercolumns") {
809 params.columns = lex.GetInteger();
810 } else if (token == "\\papersides") {
812 switch (lex.GetInteger()) {
814 case 1: params.sides = LyXTextClass::OneSide; break;
815 case 2: params.sides = LyXTextClass::TwoSides; break;
817 } else if (token == "\\paperpagestyle") {
819 params.pagestyle = strip(lex.GetString());
820 } else if (token == "\\bullet") {
822 int const index = lex.GetInteger();
824 int temp_int = lex.GetInteger();
825 params.user_defined_bullets[index].setFont(temp_int);
826 params.temp_bullets[index].setFont(temp_int);
828 temp_int = lex.GetInteger();
829 params.user_defined_bullets[index].setCharacter(temp_int);
830 params.temp_bullets[index].setCharacter(temp_int);
832 temp_int = lex.GetInteger();
833 params.user_defined_bullets[index].setSize(temp_int);
834 params.temp_bullets[index].setSize(temp_int);
836 string const temp_str = lex.GetString();
837 if (temp_str != "\\end_bullet") {
838 // this element isn't really necessary for
839 // parsing but is easier for humans
840 // to understand bullets. Put it back and
841 // set a debug message?
842 lex.printError("\\end_bullet expected, got" + temp_str);
843 //how can I put it back?
845 } else if (token == "\\bulletLaTeX") {
847 int const index = lex.GetInteger();
849 string temp_str = lex.GetString();
851 while (temp_str != "\\end_bullet") {
852 // this loop structure is needed when user
853 // enters an empty string since the first
854 // thing returned will be the \\end_bullet
856 // if the LaTeX entry has spaces. Each element
857 // therefore needs to be read in turn
860 temp_str = lex.GetString();
862 params.user_defined_bullets[index].setText(sum_str);
863 params.temp_bullets[index].setText(sum_str);
864 } else if (token == "\\secnumdepth") {
866 params.secnumdepth = lex.GetInteger();
867 } else if (token == "\\tocdepth") {
869 params.tocdepth = lex.GetInteger();
870 } else if (token == "\\spacing") {
872 string const tmp = strip(lex.GetString());
873 Spacing::Space tmp_space = Spacing::Default;
875 if (tmp == "single") {
876 tmp_space = Spacing::Single;
877 } else if (tmp == "onehalf") {
878 tmp_space = Spacing::Onehalf;
879 } else if (tmp == "double") {
880 tmp_space = Spacing::Double;
881 } else if (tmp == "other") {
883 tmp_space = Spacing::Other;
884 tmp_val = lex.GetFloat();
886 lex.printError("Unknown spacing token: '$$Token'");
888 // Small hack so that files written with klyx will be
891 par->params.spacing(Spacing(tmp_space, tmp_val));
893 params.spacing.set(tmp_space, tmp_val);
895 } else if (token == "\\paragraph_spacing") {
897 string const tmp = strip(lex.GetString());
898 if (tmp == "single") {
899 par->params.spacing(Spacing(Spacing::Single));
900 } else if (tmp == "onehalf") {
901 par->params.spacing(Spacing(Spacing::Onehalf));
902 } else if (tmp == "double") {
903 par->params.spacing(Spacing(Spacing::Double));
904 } else if (tmp == "other") {
906 par->params.spacing(Spacing(Spacing::Other,
909 lex.printError("Unknown spacing token: '$$Token'");
911 } else if (token == "\\float_placement") {
913 params.float_placement = lex.GetString();
914 } else if (token == "\\family") {
916 font.setLyXFamily(lex.GetString());
917 } else if (token == "\\series") {
919 font.setLyXSeries(lex.GetString());
920 } else if (token == "\\shape") {
922 font.setLyXShape(lex.GetString());
923 } else if (token == "\\size") {
925 font.setLyXSize(lex.GetString());
926 } else if (token == "\\latex") {
928 string const tok = lex.GetString();
929 // This is dirty, but gone with LyX3. (Asger)
930 if (tok == "no_latex")
931 font.setLatex(LyXFont::OFF);
932 else if (tok == "latex")
933 font.setLatex(LyXFont::ON);
934 else if (tok == "default")
935 font.setLatex(LyXFont::INHERIT);
937 lex.printError("Unknown LaTeX font flag "
939 } else if (token == "\\lang") {
941 string const tok = lex.GetString();
942 Language const * lang = languages.getLanguage(tok);
944 font.setLanguage(lang);
946 font.setLanguage(params.language);
947 lex.printError("Unknown language `$$Token'");
949 } else if (token == "\\numeric") {
951 font.setNumber(font.setLyXMisc(lex.GetString()));
952 } else if (token == "\\emph") {
954 font.setEmph(font.setLyXMisc(lex.GetString()));
955 } else if (token == "\\bar") {
957 string const tok = lex.GetString();
958 // This is dirty, but gone with LyX3. (Asger)
960 font.setUnderbar(LyXFont::ON);
961 else if (tok == "no")
962 font.setUnderbar(LyXFont::OFF);
963 else if (tok == "default")
964 font.setUnderbar(LyXFont::INHERIT);
966 lex.printError("Unknown bar font flag "
968 } else if (token == "\\noun") {
970 font.setNoun(font.setLyXMisc(lex.GetString()));
971 } else if (token == "\\color") {
973 font.setLyXColor(lex.GetString());
974 } else if (token == "\\align") {
975 int tmpret = lex.FindToken(string_align);
976 if (tmpret == -1) ++tmpret;
977 if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
978 int const tmpret2 = int(pow(2.0, tmpret));
979 //lyxerr << "Tmpret2 = " << tmpret2 << endl;
980 par->params.align(LyXAlignment(tmpret2));
982 } else if (token == "\\added_space_top") {
984 par->params.spaceTop(VSpace(lex.GetString()));
985 } else if (token == "\\added_space_bottom") {
987 par->params.spaceBottom(VSpace(lex.GetString()));
988 #ifndef NO_PEXTRA_REALLY
989 } else if (token == "\\pextra_type") {
991 par->params.pextraType(lex.GetInteger());
992 } else if (token == "\\pextra_width") {
994 par->params.pextraWidth(lex.GetString());
995 } else if (token == "\\pextra_widthp") {
997 par->params.pextraWidthp(lex.GetString());
998 } else if (token == "\\pextra_alignment") {
1000 par->params.pextraAlignment(lex.GetInteger());
1001 } else if (token == "\\pextra_hfill") {
1003 par->params.pextraHfill(lex.GetInteger());
1004 } else if (token == "\\pextra_start_minipage") {
1006 par->params.pextraStartMinipage(lex.GetInteger());
1008 } else if (token == "\\labelwidthstring") {
1010 par->params.labelWidthString(lex.GetString());
1011 // do not delete this token, it is still needed!
1012 } else if (token == "\\end_inset") {
1013 lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
1014 << "Last inset read was: " << last_inset_read
1016 // Simply ignore this. The insets do not have
1018 // But insets should read it, it is a part of
1019 // the inset isn't it? Lgb.
1020 } else if (token == "\\begin_inset") {
1021 readInset(lex, par, pos, font);
1022 } else if (token == "\\SpecialChar") {
1023 LyXLayout const & layout =
1024 textclasslist.Style(params.textclass,
1027 // Insets don't make sense in a free-spacing context! ---Kayvan
1028 if (layout.free_spacing) {
1031 string next_token = lex.GetString();
1032 if (next_token == "\\-") {
1033 par->InsertChar(pos, '-', font);
1034 } else if (next_token == "\\protected_separator"
1035 || next_token == "~") {
1036 par->InsertChar(pos, ' ', font);
1038 lex.printError("Token `$$Token' "
1040 "paragraph layout!");
1045 Inset * inset = new InsetSpecialChar;
1046 inset->Read(this, lex);
1047 par->InsertInset(pos, inset, font);
1050 } else if (token == "\\newline") {
1051 par->InsertChar(pos, LyXParagraph::META_NEWLINE, font);
1053 } else if (token == "\\LyXTable") {
1054 Inset * inset = new InsetTabular(*this);
1055 inset->Read(this, lex);
1056 par->InsertInset(pos, inset, font);
1058 // because of OLD_TABULAR_READ where tabulars have been
1060 checkminipage = true;
1061 } else if (token == "\\hfill") {
1062 par->InsertChar(pos, LyXParagraph::META_HFILL, font);
1064 } else if (token == "\\protected_separator") { // obsolete
1065 // This is a backward compability thingie. (Lgb)
1066 // Remove it later some time...introduced with fileformat
1068 LyXLayout const & layout =
1069 textclasslist.Style(params.textclass,
1072 if (layout.free_spacing) {
1073 par->InsertChar(pos, ' ', font);
1075 Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
1076 par->InsertInset(pos, inset, font);
1079 } else if (token == "\\bibitem") { // ale970302
1081 InsetCommandParams p("bibitem", "dummy");
1082 par->bibkey = new InsetBibKey(p);
1084 par->bibkey->Read(this, lex);
1085 } else if (token == "\\backslash") {
1086 par->InsertChar(pos, '\\', font);
1088 } else if (token == "\\the_end") {
1089 the_end_read = true;
1090 minipar = parBeforeMinipage = 0;
1092 // This should be insurance for the future: (Asger)
1093 lex.printError("Unknown token `$$Token'. "
1094 "Inserting as text.");
1095 string::const_iterator cit = token.begin();
1096 string::const_iterator end = token.end();
1097 for (; cit != end; ++cit) {
1098 par->InsertChar(pos, (*cit), font);
1102 #ifndef NO_PEXTRA_REALLY
1103 // now check if we have a minipage paragraph as at this
1104 // point we already read all the necessary data!
1105 // this cannot be done in layout because there we did
1106 // not read yet the paragraph PEXTRA-params (Jug)
1108 // BEGIN pextra_minipage compability
1109 // This should be removed in 1.3.x (Lgb)
1111 // This compability code is not perfect. In a couple
1112 // of rand cases it fails. When the minipage par is
1113 // the first par in the document, and when there are
1114 // none or only one regular paragraphs after the
1115 // minipage. Currently I am not investing any effort
1116 // in fixing those cases.
1118 //lyxerr << "Call depth: " << call_depth << endl;
1119 if (checkminipage && (call_depth == 1)) {
1120 checkminipage = false;
1121 if (minipar && (minipar != par) &&
1122 (par->params.pextraType()==LyXParagraph::PEXTRA_MINIPAGE))
1124 lyxerr << "minipages in a row" << endl;
1125 if (par->params.pextraStartMinipage()) {
1126 lyxerr << "start new minipage" << endl;
1127 // minipages in a row
1128 par->previous()->next(0);
1131 LyXParagraph * tmp = minipar;
1133 tmp->params.pextraType(0);
1134 tmp->params.pextraWidth(string());
1135 tmp->params.pextraWidthp(string());
1136 tmp->params.pextraAlignment(0);
1137 tmp->params.pextraHfill(false);
1138 tmp->params.pextraStartMinipage(false);
1141 // create a new paragraph to insert the
1142 // minipages in the following case
1143 if (par->params.pextraStartMinipage() &&
1144 !par->params.pextraHfill())
1146 LyXParagraph * p = new LyXParagraph;
1148 p->previous(parBeforeMinipage);
1149 parBeforeMinipage->next(p);
1151 p->params.depth(parBeforeMinipage->params.depth());
1152 parBeforeMinipage = p;
1154 InsetMinipage * mini = new InsetMinipage;
1155 mini->pos(static_cast<InsetMinipage::Position>(par->params.pextraAlignment()));
1156 mini->width(par->params.pextraWidth());
1157 mini->widthp(par->params.pextraWidthp());
1158 mini->inset->par = par;
1159 // Insert the minipage last in the
1160 // previous paragraph.
1161 if (par->params.pextraHfill()) {
1162 parBeforeMinipage->InsertChar
1163 (parBeforeMinipage->size(), LyXParagraph::META_HFILL);
1165 parBeforeMinipage->InsertInset
1166 (parBeforeMinipage->size(), mini);
1170 lyxerr << "new minipage par" << endl;
1171 //nothing to do just continue reading
1174 } else if (minipar && (minipar != par)) {
1175 lyxerr << "last minipage par read" << endl;
1176 // The last paragraph read was not part of a
1177 // minipage but the par linked list is...
1178 // So we need to remove the last par from the
1180 if (par->previous())
1181 par->previous()->next(0);
1182 par->previous(parBeforeMinipage);
1183 parBeforeMinipage->next(par);
1184 LyXParagraph * tmp = minipar;
1186 tmp->params.pextraType(0);
1187 tmp->params.pextraWidth(string());
1188 tmp->params.pextraWidthp(string());
1189 tmp->params.pextraAlignment(0);
1190 tmp->params.pextraHfill(false);
1191 tmp->params.pextraStartMinipage(false);
1194 depth = parBeforeMinipage->params.depth();
1195 minipar = parBeforeMinipage = 0;
1196 } else if (!minipar &&
1197 (par->params.pextraType() == LyXParagraph::PEXTRA_MINIPAGE))
1199 // par is the first paragraph in a minipage
1200 lyxerr << "begin minipage" << endl;
1201 // To minimize problems for
1202 // the users we will insert
1203 // the first minipage in
1204 // a sequence of minipages
1205 // in its own paragraph.
1206 LyXParagraph * p = new LyXParagraph;
1208 p->previous(par->previous());
1210 p->params.depth(depth);
1211 par->params.depth(0);
1213 if (par->previous())
1214 par->previous()->next(p);
1216 parBeforeMinipage = p;
1218 if (!return_par || (return_par == par))
1221 InsetMinipage * mini = new InsetMinipage;
1222 mini->pos(static_cast<InsetMinipage::Position>(minipar->params.pextraAlignment()));
1223 mini->width(minipar->params.pextraWidth());
1224 mini->widthp(minipar->params.pextraWidthp());
1225 mini->inset->par = minipar;
1227 // Insert the minipage last in the
1228 // previous paragraph.
1229 if (minipar->params.pextraHfill()) {
1230 parBeforeMinipage->InsertChar
1231 (parBeforeMinipage->size(),LyXParagraph::META_HFILL);
1233 parBeforeMinipage->InsertInset
1234 (parBeforeMinipage->size(), mini);
1237 // End of pextra_minipage compability
1240 return the_end_read;
1244 void Buffer::readInset(LyXLex & lex, LyXParagraph *& par,
1245 int & pos, LyXFont & font)
1247 // consistency check
1248 if (lex.GetString() != "\\begin_inset") {
1249 lyxerr << "Buffer::readInset: Consistency check failed."
1256 string const tmptok = lex.GetString();
1257 last_inset_read = tmptok;
1259 // test the different insets
1260 if (tmptok == "LatexCommand") {
1261 InsetCommandParams inscmd;
1264 if (inscmd.getCmdName() == "cite") {
1265 inset = new InsetCitation(inscmd);
1266 } else if (inscmd.getCmdName() == "bibitem") {
1267 lex.printError("Wrong place for bibitem");
1268 inset = new InsetBibKey(inscmd);
1269 } else if (inscmd.getCmdName() == "BibTeX") {
1270 inset = new InsetBibtex(inscmd);
1271 } else if (inscmd.getCmdName() == "index") {
1272 inset = new InsetIndex(inscmd);
1273 } else if (inscmd.getCmdName() == "include") {
1274 inset = new InsetInclude(inscmd, *this);
1275 } else if (inscmd.getCmdName() == "label") {
1276 inset = new InsetLabel(inscmd);
1277 } else if (inscmd.getCmdName() == "url"
1278 || inscmd.getCmdName() == "htmlurl") {
1279 inset = new InsetUrl(inscmd);
1280 } else if (inscmd.getCmdName() == "ref"
1281 || inscmd.getCmdName() == "pageref"
1282 || inscmd.getCmdName() == "vref"
1283 || inscmd.getCmdName() == "vpageref"
1284 || inscmd.getCmdName() == "prettyref") {
1285 if (!inscmd.getOptions().empty()
1286 || !inscmd.getContents().empty()) {
1287 inset = new InsetRef(inscmd, *this);
1289 } else if (inscmd.getCmdName() == "tableofcontents"
1290 || inscmd.getCmdName() == "listofalgorithms"
1291 || inscmd.getCmdName() == "listoffigures"
1292 || inscmd.getCmdName() == "listoftables") {
1293 inset = new InsetTOC(inscmd);
1294 } else if (inscmd.getCmdName() == "printindex") {
1295 inset = new InsetPrintIndex(inscmd);
1296 } else if (inscmd.getCmdName() == "lyxparent") {
1297 inset = new InsetParent(inscmd, *this);
1300 if (tmptok == "Quotes") {
1301 inset = new InsetQuotes;
1302 } else if (tmptok == "External") {
1303 inset = new InsetExternal;
1304 } else if (tmptok == "FormulaMacro") {
1305 inset = new InsetFormulaMacro;
1306 } else if (tmptok == "Formula") {
1307 inset = new InsetFormula;
1308 } else if (tmptok == "Figure") {
1309 inset = new InsetFig(100, 100, *this);
1310 } else if (tmptok == "Info") {
1311 inset = new InsetInfo;
1312 } else if (tmptok == "Include") {
1313 InsetCommandParams p( "Include" );
1314 inset = new InsetInclude(p, *this);
1315 } else if (tmptok == "ERT") {
1316 inset = new InsetERT;
1317 } else if (tmptok == "Tabular") {
1318 inset = new InsetTabular(*this);
1319 } else if (tmptok == "Text") {
1320 inset = new InsetText;
1321 } else if (tmptok == "Foot") {
1322 inset = new InsetFoot;
1323 } else if (tmptok == "Marginal") {
1324 inset = new InsetMarginal;
1325 } else if (tmptok == "Minipage") {
1326 inset = new InsetMinipage;
1327 } else if (tmptok == "Float") {
1329 string tmptok = lex.GetString();
1330 inset = new InsetFloat(tmptok);
1331 } else if (tmptok == "List") {
1332 inset = new InsetList;
1333 } else if (tmptok == "Theorem") {
1334 inset = new InsetList;
1335 } else if (tmptok == "Caption") {
1336 inset = new InsetCaption;
1337 } else if (tmptok == "GRAPHICS") {
1338 inset = new InsetGraphics;
1341 if (inset) inset->Read(this, lex);
1345 par->InsertInset(pos, inset, font);
1351 bool Buffer::readFile(LyXLex & lex, LyXParagraph * par)
1355 string const token(lex.GetString());
1356 if (token == "\\lyxformat") { // the first token _must_ be...
1358 string tmp_format = lex.GetString();
1359 //lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
1360 // if present remove ".," from string.
1361 string::size_type dot = tmp_format.find_first_of(".,");
1362 //lyxerr << " dot found at " << dot << endl;
1363 if (dot != string::npos)
1364 tmp_format.erase(dot, 1);
1365 file_format = strToInt(tmp_format);
1366 if (file_format == LYX_FORMAT) {
1368 } else if (file_format > LYX_FORMAT) {
1370 WriteAlert(_("Warning!"),
1371 _("LyX file format is newer that what"),
1372 _("is supported in this LyX version. Expect some problems."));
1374 } else if (file_format < LYX_FORMAT) {
1376 if (file_format < 200) {
1377 WriteAlert(_("ERROR!"),
1378 _("Old LyX file format found. "
1379 "Use LyX 0.10.x to read this!"));
1383 bool the_end = readLyXformat2(lex, par);
1385 // the_end was added in 213
1386 if (file_format < 213)
1390 WriteAlert(_("Warning!"),
1391 _("Reading of document is not complete"),
1392 _("Maybe the document is truncated"));
1394 } else { // "\\lyxformat" not found
1395 WriteAlert(_("ERROR!"), _("Not a LyX file!"));
1398 WriteAlert(_("ERROR!"), _("Unable to read file!"));
1404 // Should probably be moved to somewhere else: BufferView? LyXView?
1405 bool Buffer::save() const
1407 // We don't need autosaves in the immediate future. (Asger)
1408 resetAutosaveTimers();
1412 if (lyxrc.make_backup) {
1413 s = fileName() + '~';
1414 if (!lyxrc.backupdir_path.empty())
1415 s = AddName(lyxrc.backupdir_path,
1416 subst(CleanupPath(s),'/','!'));
1418 // Rename is the wrong way of making a backup,
1419 // this is the correct way.
1420 /* truss cp fil fil2:
1421 lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
1422 stat("LyXVC.lyx", 0xEFFFF688) = 0
1423 open("LyXVC.lyx", O_RDONLY) = 3
1424 open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
1425 fstat(4, 0xEFFFF508) = 0
1426 fstat(3, 0xEFFFF508) = 0
1427 read(3, " # T h i s f i l e w".., 8192) = 5579
1428 write(4, " # T h i s f i l e w".., 5579) = 5579
1429 read(3, 0xEFFFD4A0, 8192) = 0
1432 chmod("LyXVC3.lyx", 0100644) = 0
1433 lseek(0, 0, SEEK_CUR) = 46440
1437 // Should proabaly have some more error checking here.
1438 // Should be cleaned up in 0.13, at least a bit.
1439 // Doing it this way, also makes the inodes stay the same.
1440 // This is still not a very good solution, in particular we
1441 // might loose the owner of the backup.
1442 FileInfo finfo(fileName());
1443 if (finfo.exist()) {
1444 mode_t fmode = finfo.getMode();
1445 struct utimbuf times = {
1446 finfo.getAccessTime(),
1447 finfo.getModificationTime() };
1449 ifstream ifs(fileName().c_str());
1450 ofstream ofs(s.c_str(), ios::out|ios::trunc);
1455 ::chmod(s.c_str(), fmode);
1457 if (::utime(s.c_str(), ×)) {
1458 lyxerr << "utime error." << endl;
1461 lyxerr << "LyX was not able to make "
1462 "backupcopy. Beware." << endl;
1467 if (writeFile(fileName(), false)) {
1469 removeAutosaveFile(fileName());
1471 // Saving failed, so backup is not backup
1472 if (lyxrc.make_backup) {
1473 lyx::rename(s, fileName());
1481 // Returns false if unsuccesful
1482 bool Buffer::writeFile(string const & fname, bool flag) const
1484 // if flag is false writeFile will not create any GUI
1485 // warnings, only cerr.
1486 // Needed for autosave in background or panic save (Matthias 120496)
1488 if (read_only && (fname == filename)) {
1489 // Here we should come with a question if we should
1490 // perform the write anyway.
1492 lyxerr << _("Error! Document is read-only: ")
1495 WriteAlert(_("Error! Document is read-only: "),
1500 FileInfo finfo(fname);
1501 if (finfo.exist() && !finfo.writable()) {
1502 // Here we should come with a question if we should
1503 // try to do the save anyway. (i.e. do a chmod first)
1505 lyxerr << _("Error! Cannot write file: ")
1508 WriteFSAlert(_("Error! Cannot write file: "),
1513 ofstream ofs(fname.c_str());
1516 lyxerr << _("Error! Cannot open file: ")
1519 WriteFSAlert(_("Error! Cannot open file: "),
1525 // Use the standard "C" locale for file output.
1526 ofs.imbue(std::locale::classic());
1529 // The top of the file should not be written by params.
1531 // write out a comment in the top of the file
1532 ofs << '#' << LYX_DOCVERSION
1533 << " created this file. For more info see http://www.lyx.org/\n"
1534 << "\\lyxformat " << LYX_FORMAT << "\n";
1536 // now write out the buffer paramters.
1537 params.writeFile(ofs);
1539 char footnoteflag = 0;
1542 // this will write out all the paragraphs
1543 // using recursive descent.
1544 paragraph->writeFile(this, ofs, params, footnoteflag, depth);
1546 // Write marker that shows file is complete
1547 ofs << "\n\\the_end" << endl;
1551 // how to check if close went ok?
1552 // Following is an attempt... (BE 20001011)
1554 // good() returns false if any error occured, including some
1555 // formatting error.
1556 // bad() returns true if something bad happened in the buffer,
1557 // which should include file system full errors.
1564 lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
1566 lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
1576 string const Buffer::asciiParagraph(LyXParagraph const * par,
1577 unsigned int linelen) const
1579 ostringstream buffer;
1582 Inset const * inset;
1585 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1589 int ltype_depth = 0;
1590 unsigned int currlinelen = 0;
1591 bool ref_printed = false;
1596 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE ||
1598 || par->previous()->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
1599 /* begins a footnote environment ? */
1600 if (footnoteflag != par->footnoteflag) {
1601 footnoteflag = par->footnoteflag;
1603 size_t const j = strlen(string_footnotekinds[par->footnotekind]) + 4;
1604 if ((linelen > 0) &&
1605 ((currlinelen + j) > linelen)) {
1610 << string_footnotekinds[par->footnotekind]
1616 if (!par->previous()) {
1618 /* begins or ends a deeper area ?*/
1619 if (depth != par->params.depth()) {
1620 if (par->params.depth() > depth) {
1621 while (par->params.depth() > depth) {
1625 while (par->params.depth() < depth) {
1631 /* First write the layout */
1632 string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
1633 if (tmp == "Itemize") {
1635 ltype_depth = depth + 1;
1636 } else if (tmp == "Enumerate") {
1638 ltype_depth = depth + 1;
1639 } else if (strstr(tmp.c_str(), "ection")) {
1641 ltype_depth = depth + 1;
1642 } else if (strstr(tmp.c_str(), "aragraph")) {
1644 ltype_depth = depth + 1;
1645 } else if (tmp == "Description") {
1647 ltype_depth = depth + 1;
1648 } else if (tmp == "Abstract") {
1651 } else if (tmp == "Bibliography") {
1659 /* maybe some vertical spaces */
1661 /* the labelwidthstring used in lists */
1665 /* some pagebreaks? */
1669 /* what about the alignment */
1672 /* dummy layout, that means a footnote ended */
1673 footnoteflag = LyXParagraph::NO_FOOTNOTE;
1677 lyxerr << "Should this ever happen?" << endl;
1681 font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
1682 for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
1690 for (char j = 0; j < depth; ++j)
1692 currlinelen = depth * 2;
1694 case 0: /* Standard */
1695 case 4: /* (Sub)Paragraph */
1696 case 5: /* Description */
1698 case 6: /* Abstract */
1700 buffer << "Abstract\n\n";
1702 buffer << "Abstract: ";
1704 case 7: /* Bibliography */
1707 buffer << "References\n\n";
1709 buffer << "References: ";
1714 buffer << par->params.labelString() << " ";
1717 if (ltype_depth > depth) {
1718 for (char j = ltype_depth - 1; j > depth; --j)
1720 currlinelen += (ltype_depth-depth)*2;
1723 font2 = par->GetFontSettings(params, i);
1724 if (font1.latex() != font2.latex()) {
1725 if (font2.latex() == LyXFont::OFF)
1732 c = par->GetUChar(params, i);
1736 case LyXParagraph::META_INSET:
1737 if ((inset = par->GetInset(i))) {
1738 if (!inset->Ascii(this, buffer)) {
1740 string s = rsplit(buffer.str().c_str(),
1742 currlinelen += s.length();
1744 // to be sure it breaks paragraph
1745 currlinelen += linelen;
1749 case LyXParagraph::META_NEWLINE:
1752 for (char j = 0; j < depth; ++j)
1755 currlinelen = depth * 2;
1756 if (ltype_depth > depth) {
1757 for (char j = ltype_depth;
1760 currlinelen += (ltype_depth - depth) * 2;
1763 case LyXParagraph::META_HFILL:
1770 if ((linelen > 0) && (currlinelen > (linelen - 10)) &&
1771 (c == ' ') && ((i + 2) < par->size()))
1774 for (char j = 0; j < depth; ++j)
1776 currlinelen = depth * 2;
1777 if (ltype_depth > depth) {
1778 for (char j = ltype_depth;
1781 currlinelen += (ltype_depth-depth)*2;
1783 } else if (c != '\0')
1786 lyxerr.debug() << "writeAsciiFile: NULL char in structure." << endl;
1791 return buffer.str().c_str();
1795 void Buffer::writeFileAscii(string const & fname, int linelen)
1797 ofstream ofs(fname.c_str());
1799 WriteFSAlert(_("Error: Cannot write file:"), fname);
1802 writeFileAscii(ofs, linelen);
1806 void Buffer::writeFileAscii(ostream & ofs, int linelen)
1808 LyXParagraph * par = paragraph;
1810 ofs << asciiParagraph(par, linelen);
1818 void Buffer::makeLaTeXFile(string const & fname,
1819 string const & original_path,
1820 bool nice, bool only_body)
1822 lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
1824 niceFile = nice; // this will be used by Insetincludes.
1826 tex_code_break_column = lyxrc.ascii_linelen;
1828 LyXTextClass const & tclass =
1829 textclasslist.TextClass(params.textclass);
1831 ofstream ofs(fname.c_str());
1833 WriteFSAlert(_("Error: Cannot open file: "), fname);
1837 // validate the buffer.
1838 lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
1839 LaTeXFeatures features(params, tclass.numLayouts());
1841 lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
1844 // The starting paragraph of the coming rows is the
1845 // first paragraph of the document. (Asger)
1846 texrow.start(paragraph, 0);
1848 if (!only_body && nice) {
1849 ofs << "%% " LYX_DOCVERSION " created this file. "
1850 "For more info, see http://www.lyx.org/.\n"
1851 "%% Do not edit unless you really know what "
1856 lyxerr.debug() << "lyx header finished" << endl;
1857 // There are a few differences between nice LaTeX and usual files:
1858 // usual is \batchmode and has a
1859 // special input@path to allow the including of figures
1860 // with either \input or \includegraphics (what figinsets do).
1861 // batchmode is not set if there is a tex_code_break_column.
1862 // In this case somebody is interested in the generated LaTeX,
1863 // so this is OK. input@path is set when the actual parameter
1864 // original_path is set. This is done for usual tex-file, but not
1865 // for nice-latex-file. (Matthias 250696)
1868 // code for usual, NOT nice-latex-file
1869 ofs << "\\batchmode\n"; // changed
1870 // from \nonstopmode
1873 if (!original_path.empty()) {
1874 ofs << "\\makeatletter\n"
1875 << "\\def\\input@path{{"
1876 << original_path << "/}}\n"
1877 << "\\makeatother\n";
1883 ofs << "\\documentclass";
1885 string options; // the document class options.
1887 if (tokenPos(tclass.opt_fontsize(),
1888 '|', params.fontsize) >= 0) {
1889 // only write if existing in list (and not default)
1890 options += params.fontsize;
1895 if (!params.use_geometry &&
1896 (params.paperpackage == BufferParams::PACKAGE_NONE)) {
1897 switch (params.papersize) {
1898 case BufferParams::PAPER_A4PAPER:
1899 options += "a4paper,";
1901 case BufferParams::PAPER_USLETTER:
1902 options += "letterpaper,";
1904 case BufferParams::PAPER_A5PAPER:
1905 options += "a5paper,";
1907 case BufferParams::PAPER_B5PAPER:
1908 options += "b5paper,";
1910 case BufferParams::PAPER_EXECUTIVEPAPER:
1911 options += "executivepaper,";
1913 case BufferParams::PAPER_LEGALPAPER:
1914 options += "legalpaper,";
1920 if (params.sides != tclass.sides()) {
1921 switch (params.sides) {
1922 case LyXTextClass::OneSide:
1923 options += "oneside,";
1925 case LyXTextClass::TwoSides:
1926 options += "twoside,";
1933 if (params.columns != tclass.columns()) {
1934 if (params.columns == 2)
1935 options += "twocolumn,";
1937 options += "onecolumn,";
1940 if (!params.use_geometry
1941 && params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
1942 options += "landscape,";
1944 // language should be a parameter to \documentclass
1946 string language_options;
1947 if (params.language->babel() == "hebrew"
1948 && default_language->babel() != "hebrew")
1949 // This seems necessary
1950 features.UsedLanguages.insert(default_language);
1952 if (lyxrc.language_use_babel ||
1953 params.language->lang() != lyxrc.default_language ||
1954 !features.UsedLanguages.empty()) {
1956 for (LaTeXFeatures::LanguageList::const_iterator cit =
1957 features.UsedLanguages.begin();
1958 cit != features.UsedLanguages.end(); ++cit)
1959 language_options += (*cit)->babel() + ',';
1960 language_options += params.language->babel();
1961 if (lyxrc.language_global_options)
1962 options += language_options + ',';
1965 // the user-defined options
1966 if (!params.options.empty()) {
1967 options += params.options + ',';
1970 if (!options.empty()){
1971 options = strip(options, ',');
1972 ofs << '[' << options << ']';
1976 << textclasslist.LatexnameOfClass(params.textclass)
1979 // end of \documentclass defs
1981 // font selection must be done before loading fontenc.sty
1982 // The ae package is not needed when using OT1 font encoding.
1983 if (params.fonts != "default" &&
1984 (params.fonts != "ae" || lyxrc.fontenc != "default")) {
1985 ofs << "\\usepackage{" << params.fonts << "}\n";
1987 if (params.fonts == "ae") {
1988 ofs << "\\usepackage{aecompl}\n";
1992 // this one is not per buffer
1993 if (lyxrc.fontenc != "default") {
1994 ofs << "\\usepackage[" << lyxrc.fontenc
1999 if (params.inputenc == "auto") {
2000 string const doc_encoding =
2001 params.language->encoding()->LatexName();
2003 // Create a list with all the input encodings used
2005 set<string> encodings;
2006 for (LaTeXFeatures::LanguageList::const_iterator it =
2007 features.UsedLanguages.begin();
2008 it != features.UsedLanguages.end(); ++it)
2009 if ((*it)->encoding()->LatexName() != doc_encoding)
2010 encodings.insert((*it)->encoding()->LatexName());
2012 ofs << "\\usepackage[";
2013 std::copy(encodings.begin(), encodings.end(),
2014 std::ostream_iterator<string>(ofs, ","));
2015 ofs << doc_encoding << "]{inputenc}\n";
2017 } else if (params.inputenc != "default") {
2018 ofs << "\\usepackage[" << params.inputenc
2023 // At the very beginning the text parameters.
2024 if (params.paperpackage != BufferParams::PACKAGE_NONE) {
2025 switch (params.paperpackage) {
2026 case BufferParams::PACKAGE_A4:
2027 ofs << "\\usepackage{a4}\n";
2030 case BufferParams::PACKAGE_A4WIDE:
2031 ofs << "\\usepackage{a4wide}\n";
2034 case BufferParams::PACKAGE_WIDEMARGINSA4:
2035 ofs << "\\usepackage[widemargins]{a4}\n";
2040 if (params.use_geometry) {
2041 ofs << "\\usepackage{geometry}\n";
2043 ofs << "\\geometry{verbose";
2044 if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
2045 ofs << ",landscape";
2046 switch (params.papersize2) {
2047 case BufferParams::VM_PAPER_CUSTOM:
2048 if (!params.paperwidth.empty())
2049 ofs << ",paperwidth="
2050 << params.paperwidth;
2051 if (!params.paperheight.empty())
2052 ofs << ",paperheight="
2053 << params.paperheight;
2055 case BufferParams::VM_PAPER_USLETTER:
2056 ofs << ",letterpaper";
2058 case BufferParams::VM_PAPER_USLEGAL:
2059 ofs << ",legalpaper";
2061 case BufferParams::VM_PAPER_USEXECUTIVE:
2062 ofs << ",executivepaper";
2064 case BufferParams::VM_PAPER_A3:
2067 case BufferParams::VM_PAPER_A4:
2070 case BufferParams::VM_PAPER_A5:
2073 case BufferParams::VM_PAPER_B3:
2076 case BufferParams::VM_PAPER_B4:
2079 case BufferParams::VM_PAPER_B5:
2083 // default papersize ie BufferParams::VM_PAPER_DEFAULT
2084 switch (lyxrc.default_papersize) {
2085 case BufferParams::PAPER_DEFAULT: // keep compiler happy
2086 case BufferParams::PAPER_USLETTER:
2087 ofs << ",letterpaper";
2089 case BufferParams::PAPER_LEGALPAPER:
2090 ofs << ",legalpaper";
2092 case BufferParams::PAPER_EXECUTIVEPAPER:
2093 ofs << ",executivepaper";
2095 case BufferParams::PAPER_A3PAPER:
2098 case BufferParams::PAPER_A4PAPER:
2101 case BufferParams::PAPER_A5PAPER:
2104 case BufferParams::PAPER_B5PAPER:
2109 if (!params.topmargin.empty())
2110 ofs << ",tmargin=" << params.topmargin;
2111 if (!params.bottommargin.empty())
2112 ofs << ",bmargin=" << params.bottommargin;
2113 if (!params.leftmargin.empty())
2114 ofs << ",lmargin=" << params.leftmargin;
2115 if (!params.rightmargin.empty())
2116 ofs << ",rmargin=" << params.rightmargin;
2117 if (!params.headheight.empty())
2118 ofs << ",headheight=" << params.headheight;
2119 if (!params.headsep.empty())
2120 ofs << ",headsep=" << params.headsep;
2121 if (!params.footskip.empty())
2122 ofs << ",footskip=" << params.footskip;
2126 if (features.amsstyle
2127 && !tclass.provides(LyXTextClass::amsmath)) {
2128 ofs << "\\usepackage{amsmath}\n";
2132 if (tokenPos(tclass.opt_pagestyle(),
2133 '|', params.pagestyle) >= 0) {
2134 if (params.pagestyle == "fancy") {
2135 ofs << "\\usepackage{fancyhdr}\n";
2138 ofs << "\\pagestyle{" << params.pagestyle << "}\n";
2142 // We try to load babel late, in case it interferes
2143 // with other packages.
2145 string tmp = lyxrc.language_package;
2146 if (!lyxrc.language_global_options
2147 && tmp == "\\usepackage{babel}")
2148 tmp = "\\usepackage[" +
2149 language_options + "]{babel}";
2154 if (params.secnumdepth != tclass.secnumdepth()) {
2155 ofs << "\\setcounter{secnumdepth}{"
2156 << params.secnumdepth
2160 if (params.tocdepth != tclass.tocdepth()) {
2161 ofs << "\\setcounter{tocdepth}{"
2167 if (params.paragraph_separation) {
2168 switch (params.defskip.kind()) {
2169 case VSpace::SMALLSKIP:
2170 ofs << "\\setlength\\parskip{\\smallskipamount}\n";
2172 case VSpace::MEDSKIP:
2173 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2175 case VSpace::BIGSKIP:
2176 ofs << "\\setlength\\parskip{\\bigskipamount}\n";
2178 case VSpace::LENGTH:
2179 ofs << "\\setlength\\parskip{"
2180 << params.defskip.length().asLatexString()
2183 default: // should never happen // Then delete it.
2184 ofs << "\\setlength\\parskip{\\medskipamount}\n";
2189 ofs << "\\setlength\\parindent{0pt}\n";
2193 // Now insert the LyX specific LaTeX commands...
2195 // The optional packages;
2196 string preamble(features.getPackages());
2198 // this might be useful...
2199 preamble += "\n\\makeatletter\n";
2201 // Some macros LyX will need
2202 string tmppreamble(features.getMacros());
2204 if (!tmppreamble.empty()) {
2205 preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2206 "LyX specific LaTeX commands.\n"
2207 + tmppreamble + '\n';
2210 // the text class specific preamble
2211 tmppreamble = features.getTClassPreamble();
2212 if (!tmppreamble.empty()) {
2213 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2214 "Textclass specific LaTeX commands.\n"
2215 + tmppreamble + '\n';
2218 /* the user-defined preamble */
2219 if (!params.preamble.empty()) {
2220 preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
2221 "User specified LaTeX commands.\n"
2222 + params.preamble + '\n';
2225 preamble += "\\makeatother\n";
2227 // Itemize bullet settings need to be last in case the user
2228 // defines their own bullets that use a package included
2229 // in the user-defined preamble -- ARRae
2230 // Actually it has to be done much later than that
2231 // since some packages like frenchb make modifications
2232 // at \begin{document} time -- JMarc
2234 for (int i = 0; i < 4; ++i) {
2235 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
2236 if (bullets_def.empty())
2237 bullets_def="\\AtBeginDocument{\n";
2238 bullets_def += " \\renewcommand{\\labelitemi";
2240 // `i' is one less than the item to modify
2247 bullets_def += "ii";
2253 bullets_def += "}{" +
2254 params.user_defined_bullets[i].getText()
2259 if (!bullets_def.empty())
2260 preamble += bullets_def + "}\n\n";
2262 for (int j = countChar(preamble, '\n'); j-- ;) {
2269 ofs << "\\begin{document}\n";
2272 lyxerr.debug() << "preamble finished, now the body." << endl;
2274 if (!lyxrc.language_auto_begin) {
2275 ofs << subst(lyxrc.language_command_begin, "$$lang",
2276 params.language->babel())
2281 latexParagraphs(ofs, paragraph, 0, texrow);
2283 // add this just in case after all the paragraphs
2287 if (!lyxrc.language_auto_end) {
2288 ofs << subst(lyxrc.language_command_end, "$$lang",
2289 params.language->babel())
2295 ofs << "\\end{document}\n";
2298 lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
2300 lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
2304 // Just to be sure. (Asger)
2307 // tex_code_break_column's value is used to decide
2308 // if we are in batchmode or not (within mathed_write()
2309 // in math_write.C) so we must set it to a non-zero
2310 // value when we leave otherwise we save incorrect .lyx files.
2311 tex_code_break_column = lyxrc.ascii_linelen;
2315 lyxerr << "File was not closed properly." << endl;
2318 lyxerr.debug() << "Finished making latex file." << endl;
2323 // LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
2325 void Buffer::latexParagraphs(ostream & ofs, LyXParagraph * par,
2326 LyXParagraph * endpar, TexRow & texrow) const
2328 bool was_title = false;
2329 bool already_title = false;
2330 std::ostringstream ftnote;
2335 while (par != endpar) {
2338 lyxerr[Debug::LATEX] << "Error in latexParagraphs."
2341 LyXLayout const & layout =
2342 textclasslist.Style(params.textclass,
2345 if (layout.intitle) {
2346 if (already_title) {
2347 lyxerr <<"Error in latexParagraphs: You"
2348 " should not mix title layouts"
2349 " with normal ones." << endl;
2352 } else if (was_title && !already_title) {
2353 ofs << "\\maketitle\n";
2355 already_title = true;
2358 // We are at depth 0 so we can just use
2359 // ordinary \footnote{} generation
2360 // flag this with ftcount
2362 if (layout.isEnvironment()
2364 || par->params.pextraType() != LyXParagraph::PEXTRA_NONE
2367 par = par->TeXEnvironment(this, params, ofs, texrow
2369 ,ftnote, ft_texrow, ftcount
2373 par = par->TeXOnePar(this, params, ofs, texrow, false
2376 ftnote, ft_texrow, ftcount
2381 // Write out what we've generated...
2384 ofs << "\\addtocounter{footnote}{-"
2388 ofs << ftnote.str();
2389 texrow += ft_texrow;
2391 // The extra .c_str() is needed when we use
2392 // lyxstring instead of the STL string class.
2393 ftnote.str(string().c_str());
2398 // It might be that we only have a title in this document
2399 if (was_title && !already_title) {
2400 ofs << "\\maketitle\n";
2406 bool Buffer::isLatex() const
2408 return textclasslist.TextClass(params.textclass).outputType() == LATEX;
2412 bool Buffer::isLinuxDoc() const
2414 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
2418 bool Buffer::isLiterate() const
2420 return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
2424 bool Buffer::isDocBook() const
2426 return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2430 bool Buffer::isSGML() const
2432 return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
2433 textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
2437 void Buffer::sgmlOpenTag(ostream & os, int depth,
2438 string const & latexname) const
2440 if (!latexname.empty() && latexname != "!-- --")
2441 os << string(depth, ' ') << "<" << latexname << ">\n";
2445 void Buffer::sgmlCloseTag(ostream & os, int depth,
2446 string const & latexname) const
2448 if (!latexname.empty() && latexname != "!-- --")
2449 os << string(depth, ' ') << "</" << latexname << ">\n";
2453 void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
2455 ofstream ofs(fname.c_str());
2458 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
2462 niceFile = nice; // this will be used by included files.
2464 LyXTextClass const & tclass =
2465 textclasslist.TextClass(params.textclass);
2467 LaTeXFeatures features(params, tclass.numLayouts());
2472 string top_element = textclasslist.LatexnameOfClass(params.textclass);
2475 string sgml_includedfiles=features.getIncludedFiles(fname);
2477 if (params.preamble.empty() && sgml_includedfiles.empty()) {
2478 ofs << "<!doctype linuxdoc system>\n\n";
2480 ofs << "<!doctype linuxdoc system [ "
2481 << params.preamble << sgml_includedfiles << " \n]>\n\n";
2484 if (params.options.empty())
2485 sgmlOpenTag(ofs, 0, top_element);
2487 string top = top_element;
2489 top += params.options;
2490 sgmlOpenTag(ofs, 0, top);
2494 ofs << "<!-- " << LYX_DOCVERSION
2495 << " created this file. For more info see http://www.lyx.org/"
2498 int depth = 0; // paragraph depth
2499 LyXParagraph * par = paragraph;
2501 vector<string> environment_stack(5);
2504 LyXLayout const & style =
2505 textclasslist.Style(params.textclass,
2508 // treat <toc> as a special case for compatibility with old code
2509 if (par->GetChar(0) == LyXParagraph::META_INSET) {
2510 Inset * inset = par->GetInset(0);
2511 Inset::Code lyx_code = inset->LyxCode();
2512 if (lyx_code == Inset::TOC_CODE){
2513 string const temp = "toc";
2514 sgmlOpenTag(ofs, depth, temp);
2518 linuxDocHandleFootnote(ofs, par, depth);
2526 // environment tag closing
2527 for (; depth > par->params.depth(); --depth) {
2528 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2529 environment_stack[depth].erase();
2532 // write opening SGML tags
2533 switch (style.latextype) {
2534 case LATEX_PARAGRAPH:
2535 if (depth == par->params.depth()
2536 && !environment_stack[depth].empty()) {
2537 sgmlCloseTag(ofs, depth, environment_stack[depth]);
2538 environment_stack[depth].erase();
2544 sgmlOpenTag(ofs, depth, style.latexname());
2549 LinuxDocError(par, 0,
2550 _("Error : Wrong depth for"
2551 " LatexType Command.\n"));
2553 if (!environment_stack[depth].empty()){
2554 sgmlCloseTag(ofs, depth,
2555 environment_stack[depth]);
2559 environment_stack[depth].erase();
2560 sgmlOpenTag(ofs, depth, style.latexname());
2563 case LATEX_ENVIRONMENT:
2564 case LATEX_ITEM_ENVIRONMENT:
2565 if (depth == par->params.depth()
2566 && environment_stack[depth] != style.latexname()) {
2567 sgmlCloseTag(ofs, depth,
2568 environment_stack[depth]);
2569 environment_stack[depth].erase();
2571 if (depth < par->params.depth()) {
2572 depth = par->params.depth();
2573 environment_stack[depth].erase();
2575 if (environment_stack[depth] != style.latexname()) {
2577 sgmlOpenTag(ofs, depth, "p");
2579 sgmlOpenTag(ofs, depth, style.latexname());
2581 if (environment_stack.size() == depth+1)
2582 environment_stack.push_back("!-- --");
2583 environment_stack[depth] = style.latexname();
2586 if (style.latexparam() == "CDATA")
2589 if (style.latextype == LATEX_ENVIRONMENT) break;
2591 if (style.labeltype == LABEL_MANUAL)
2596 sgmlOpenTag(ofs, depth + 1, item_name);
2599 sgmlOpenTag(ofs, depth, style.latexname());
2605 SimpleLinuxDocOnePar(ofs, par, depth);
2608 linuxDocHandleFootnote(ofs, par, depth);
2610 while(par && par->IsDummy());
2612 SimpleLinuxDocOnePar(ofs, par, depth);
2618 // write closing SGML tags
2619 switch (style.latextype) {
2622 case LATEX_ENVIRONMENT:
2623 case LATEX_ITEM_ENVIRONMENT:
2624 if (style.latexparam() == "CDATA")
2628 sgmlCloseTag(ofs, depth, style.latexname());
2634 for (int i=depth; i >= 0; --i)
2635 sgmlCloseTag(ofs, depth, environment_stack[i]);
2639 sgmlCloseTag(ofs, 0, top_element);
2643 // How to check for successful close
2648 void Buffer::linuxDocHandleFootnote(ostream & os, LyXParagraph * & par,
2651 string const tag = "footnote";
2653 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2654 sgmlOpenTag(os, depth + 1, tag);
2655 SimpleLinuxDocOnePar(os, par, 0, depth + 1);
2656 sgmlCloseTag(os, depth + 1, tag);
2663 void Buffer::DocBookHandleCaption(ostream & os, string & inner_tag,
2664 int depth, int desc_on,
2665 LyXParagraph * & par)
2667 LyXParagraph * tpar = par;
2670 && (tpar->footnoteflag != LyXParagraph::NO_FOOTNOTE)
2671 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2676 && (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
2678 tpar = tpar->next();
2681 tpar->layout == textclasslist.NumberOfLayout(params.textclass,
2682 "Caption").second) {
2683 sgmlOpenTag(os, depth + 1, inner_tag);
2685 SimpleDocBookOnePar(os, extra_par, tpar,
2686 desc_on, depth + 2);
2687 sgmlCloseTag(os, depth+1, inner_tag);
2688 if (!extra_par.empty())
2695 void Buffer::DocBookHandleFootnote(ostream & os, LyXParagraph * & par,
2698 string tag, inner_tag;
2699 string tmp_par, extra_par;
2700 bool inner_span = false;
2703 // Someone should give this enum a proper name (Lgb)
2711 SOME_ENUM last = NO_ONE;
2712 SOME_ENUM present = FOOTNOTE_LIKE;
2714 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
2715 if (last == present) {
2717 if (!tmp_par.empty()) {
2720 sgmlCloseTag(os, depth + 1, inner_tag);
2721 sgmlOpenTag(os, depth + 1, inner_tag);
2728 if (!inner_tag.empty()) sgmlCloseTag(os, depth + 1,
2730 if (!extra_par.empty()) os << extra_par;
2731 if (!tag.empty()) sgmlCloseTag(os, depth, tag);
2734 switch (par->footnotekind) {
2735 case LyXParagraph::FOOTNOTE:
2736 case LyXParagraph::ALGORITHM:
2739 present = FOOTNOTE_LIKE;
2742 case LyXParagraph::MARGIN:
2745 present = MARGIN_LIKE;
2748 case LyXParagraph::FIG:
2749 case LyXParagraph::WIDE_FIG:
2751 inner_tag = "title";
2755 case LyXParagraph::TAB:
2756 case LyXParagraph::WIDE_TAB:
2758 inner_tag = "title";
2763 sgmlOpenTag(os, depth, tag);
2764 if ((present == TAB_LIKE) || (present == FIG_LIKE)) {
2765 DocBookHandleCaption(os, inner_tag, depth,
2769 sgmlOpenTag(os, depth + 1, inner_tag);
2772 // ignore all caption here, we processed them above!!!
2773 if (par->layout != textclasslist
2774 .NumberOfLayout(params.textclass,
2775 "Caption").second) {
2776 std::ostringstream ost;
2777 SimpleDocBookOnePar(ost, extra_par, par,
2778 desc_on, depth + 2);
2779 tmp_par += ost.str().c_str();
2781 tmp_par = frontStrip(strip(tmp_par));
2787 if (!inner_tag.empty()) sgmlCloseTag(os, depth + 1, inner_tag);
2788 if (!extra_par.empty()) os << extra_par;
2789 if (!tag.empty()) sgmlCloseTag(os, depth, tag);
2794 // checks, if newcol chars should be put into this line
2795 // writes newline, if necessary.
2798 void linux_doc_line_break(ostream & os, string::size_type & colcount,
2799 string::size_type newcol)
2802 if (colcount > lyxrc.ascii_linelen) {
2804 colcount = newcol; // assume write after this call
2811 // Handle internal paragraph parsing -- layout already processed.
2812 void Buffer::SimpleLinuxDocOnePar(ostream & os,
2813 LyXParagraph * par, int /*depth*/)
2815 LyXLayout const & style = textclasslist.Style(params.textclass,
2817 string::size_type char_line_count = 5; // Heuristic choice ;-)
2819 // gets paragraph main font
2822 if (style.labeltype == LABEL_MANUAL) {
2823 font_old = style.labelfont;
2826 font_old = style.font;
2830 LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
2831 LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
2832 LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
2844 char const * tag_name[] = {"tt","sf","bf","it","sl","em"};
2846 stack<int> tag_state;
2847 // parsing main loop
2848 for (LyXParagraph::size_type i = 0; i < par->size(); ++i) {
2850 bitset<LAST> tag_close;
2853 LyXFont const font = par->getFont(params, i);
2855 if (font_old.family() != font.family()) {
2856 switch (family_type) {
2857 case LyXFont::SANS_FAMILY:
2860 case LyXFont::TYPEWRITER_FAMILY:
2867 family_type = font.family();
2869 switch (family_type) {
2870 case LyXFont::SANS_FAMILY:
2871 tag_open.push_back(SF);
2873 case LyXFont::TYPEWRITER_FAMILY:
2874 tag_open.push_back(TT);
2881 if (font_old.series() != font.series()) {
2882 switch (series_type) {
2883 case LyXFont::BOLD_SERIES:
2890 series_type = font.series();
2892 switch (series_type) {
2893 case LyXFont::BOLD_SERIES:
2894 tag_open.push_back(BF);
2902 if (font_old.shape() != font.shape()) {
2903 switch (shape_type) {
2904 case LyXFont::ITALIC_SHAPE:
2907 case LyXFont::SLANTED_SHAPE:
2914 shape_type = font.shape();
2916 switch (shape_type) {
2917 case LyXFont::ITALIC_SHAPE:
2918 tag_open.push_back(IT);
2920 case LyXFont::SLANTED_SHAPE:
2921 tag_open.push_back(SL);
2928 if (font_old.emph() != font.emph()) {
2929 if (font.emph() == LyXFont::ON) {
2930 tag_open.push_back(EM);
2939 while (!tag_state.empty() && tag_close.any()) {
2940 int k = tag_state.top();
2942 os << "</" << tag_name[k] << ">";
2949 for (list<int>::const_iterator j = temp.begin();
2950 j != temp.end(); ++j) {
2952 os << "<" << tag_name[*j] << ">";
2955 for (list<int>::const_iterator j = tag_open.begin();
2956 j != tag_open.end(); ++j) {
2958 os << "<" << tag_name[*j] << ">";
2961 char c = par->GetChar(i);
2963 if (c == LyXParagraph::META_INSET) {
2964 Inset * inset = par->GetInset(i);
2965 inset->Linuxdoc(this, os);
2970 if (font.latex() == LyXFont::ON || style.latexparam() == "CDATA") {
2971 // "TeX"-Mode on == > SGML-Mode on.
2977 if (par->linuxDocConvertChar(c, sgml_string)
2978 && !style.free_spacing) {
2979 // in freespacing mode, spaces are
2980 // non-breaking characters
2981 if (desc_on) {// if char is ' ' then...
2984 linux_doc_line_break(os, char_line_count, 6);
2988 linux_doc_line_break(os, char_line_count, 1);
2993 char_line_count += sgml_string.length();
2999 while (!tag_state.empty()) {
3000 os << "</" << tag_name[tag_state.top()] << ">";
3004 // resets description flag correctly
3006 // <tag> not closed...
3007 linux_doc_line_break(os, char_line_count, 6);
3013 // Print an error message.
3014 void Buffer::LinuxDocError(LyXParagraph * par, int pos,
3015 string const & message)
3017 // insert an error marker in text
3018 InsetError * new_inset = new InsetError(message);
3019 par->InsertInset(pos, new_inset);
3023 void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
3025 LyXParagraph * par = paragraph;
3027 niceFile = nice; // this will be used by Insetincludes.
3029 string top_element = textclasslist.LatexnameOfClass(params.textclass);
3031 vector <string> environment_stack;
3032 vector <string> environment_inner;
3033 vector <string> command_stack;
3035 bool command_flag = false;
3036 int command_depth = 0;
3037 int command_base = 0;
3041 string command_name;
3046 int depth = 0; // paragraph depth
3047 LyXTextClass const & tclass =
3048 textclasslist.TextClass(params.textclass);
3050 LaTeXFeatures features(params, tclass.numLayouts());
3054 tex_code_break_column = lyxrc.ascii_linelen;
3056 //tex_code_break_column = 0;
3058 ofstream ofs(fname.c_str());
3060 WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
3067 string sgml_includedfiles=features.getIncludedFiles(fname);
3069 ofs << "<!doctype " << top_element
3070 << " public \"-//OASIS//DTD DocBook V3.1//EN\"";
3072 if (params.preamble.empty() && sgml_includedfiles.empty())
3075 ofs << "\n [ " << params.preamble
3076 << sgml_includedfiles << " \n]>\n\n";
3079 string top = top_element;
3081 top += params.language->code();
3084 if (!params.options.empty()) {
3086 top += params.options;
3088 sgmlOpenTag(ofs, 0, top);
3090 ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
3091 << "\n See http://www.lyx.org/ for more information -->\n";
3094 int desc_on = 0; // description mode
3095 LyXLayout const & style =
3096 textclasslist.Style(params.textclass,
3099 // environment tag closing
3100 for (; depth > par->params.depth(); --depth) {
3101 if (environment_inner[depth] != "!-- --") {
3102 item_name= "listitem";
3103 sgmlCloseTag(ofs, command_depth + depth,
3105 if (environment_inner[depth] == "varlistentry")
3106 sgmlCloseTag(ofs, depth+command_depth,
3107 environment_inner[depth]);
3109 sgmlCloseTag(ofs, depth + command_depth,
3110 environment_stack[depth]);
3111 environment_stack[depth].erase();
3112 environment_inner[depth].erase();
3115 if (depth == par->params.depth()
3116 && environment_stack[depth] != style.latexname()
3117 && !environment_stack[depth].empty()) {
3118 if (environment_inner[depth] != "!-- --") {
3119 item_name= "listitem";
3120 sgmlCloseTag(ofs, command_depth+depth,
3122 if (environment_inner[depth] == "varlistentry")
3124 depth + command_depth,
3125 environment_inner[depth]);
3128 sgmlCloseTag(ofs, depth + command_depth,
3129 environment_stack[depth]);
3131 environment_stack[depth].erase();
3132 environment_inner[depth].erase();
3135 // Write opening SGML tags.
3136 switch (style.latextype) {
3137 case LATEX_PARAGRAPH:
3138 sgmlOpenTag(ofs, depth+command_depth, style.latexname());
3143 LinuxDocError(par, 0,
3144 _("Error : Wrong depth for "
3145 "LatexType Command.\n"));
3147 command_name = style.latexname();
3149 tmps = style.latexparam();
3150 c_params = split(tmps, c_depth,'|');
3152 cmd_depth= lyx::atoi(c_depth);
3155 if (cmd_depth<command_base) {
3156 for (int j = command_depth;
3157 j >= command_base; --j)
3158 if (!command_stack[j].empty())
3159 sgmlCloseTag(ofs, j, command_stack[j]);
3160 command_depth= command_base= cmd_depth;
3161 } else if (cmd_depth <= command_depth) {
3162 for (int j = command_depth;
3163 j >= cmd_depth; --j)
3165 if (!command_stack[j].empty())
3166 sgmlCloseTag(ofs, j, command_stack[j]);
3167 command_depth= cmd_depth;
3169 command_depth= cmd_depth;
3171 command_depth = command_base = cmd_depth;
3172 command_flag = true;
3174 command_stack[command_depth]= command_name;
3176 // treat label as a special case for
3177 // more WYSIWYM handling.
3178 if (par->GetChar(0) == LyXParagraph::META_INSET) {
3179 Inset * inset = par->GetInset(0);
3180 Inset::Code lyx_code = inset->LyxCode();
3181 if (lyx_code == Inset::LABEL_CODE){
3182 command_name += " id=\"";
3183 command_name += (static_cast<InsetCommand *>(inset))->getContents();
3184 command_name += "\"";
3189 sgmlOpenTag(ofs, depth + command_depth, command_name);
3190 if (c_params.empty())
3191 item_name = "title";
3193 item_name = c_params;
3194 sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
3197 case LATEX_ENVIRONMENT:
3198 case LATEX_ITEM_ENVIRONMENT:
3199 if (depth < par->params.depth()) {
3200 depth = par->params.depth();
3201 environment_stack[depth].erase();
3204 if (environment_stack[depth] != style.latexname()) {
3205 environment_stack[depth] = style.latexname();
3206 environment_inner[depth] = "!-- --";
3207 sgmlOpenTag(ofs, depth + command_depth,
3208 environment_stack[depth]);
3210 if (environment_inner[depth] != "!-- --") {
3211 item_name= "listitem";
3213 command_depth + depth,
3215 if (environment_inner[depth] == "varlistentry")
3217 depth + command_depth,
3218 environment_inner[depth]);
3222 if (style.latextype == LATEX_ENVIRONMENT) {
3223 if (!style.latexparam().empty()) {
3224 if(style.latexparam() == "CDATA")
3227 sgmlOpenTag(ofs, depth + command_depth,
3228 style.latexparam());
3233 desc_on = (style.labeltype == LABEL_MANUAL);
3236 environment_inner[depth]= "varlistentry";
3238 environment_inner[depth]= "listitem";
3240 sgmlOpenTag(ofs, depth + 1 + command_depth,
3241 environment_inner[depth]);
3245 sgmlOpenTag(ofs, depth + 1 + command_depth,
3249 sgmlOpenTag(ofs, depth + 1 + command_depth,
3254 sgmlOpenTag(ofs, depth + command_depth,
3262 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3263 depth + 1 + command_depth);
3265 DocBookHandleFootnote(ofs, par,
3266 depth + 1 + command_depth);
3267 } while(par && par->IsDummy());
3270 SimpleDocBookOnePar(ofs, extra_par, par, desc_on,
3271 depth + 1 + command_depth);
3275 // write closing SGML tags
3276 switch (style.latextype) {
3278 if (c_params.empty())
3282 sgmlCloseTag(ofs, depth + command_depth, end_tag);
3284 case LATEX_ENVIRONMENT:
3285 if (!style.latexparam().empty()) {
3286 if(style.latexparam() == "CDATA")
3289 sgmlCloseTag(ofs, depth + command_depth,
3290 style.latexparam());
3293 case LATEX_ITEM_ENVIRONMENT:
3294 if (desc_on == 1) break;
3296 sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
3298 case LATEX_PARAGRAPH:
3299 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3302 sgmlCloseTag(ofs, depth + command_depth, style.latexname());
3308 for (; depth >= 0; --depth) {
3309 if (!environment_stack[depth].empty()) {
3310 if (environment_inner[depth] != "!-- --") {
3311 item_name= "listitem";
3312 sgmlCloseTag(ofs, command_depth + depth,
3314 if (environment_inner[depth] == "varlistentry")
3315 sgmlCloseTag(ofs, depth + command_depth,
3316 environment_inner[depth]);
3319 sgmlCloseTag(ofs, depth + command_depth,
3320 environment_stack[depth]);
3324 for (int j = command_depth; j >= command_base; --j)
3325 if (!command_stack[j].empty())
3326 sgmlCloseTag(ofs, j, command_stack[j]);
3329 sgmlCloseTag(ofs, 0, top_element);
3332 // How to check for successful close
3336 void Buffer::SimpleDocBookOnePar(ostream & os, string & extra,
3337 LyXParagraph * par, int & desc_on,
3340 bool emph_flag = false;
3342 LyXLayout const & style = textclasslist.Style(params.textclass,
3345 LyXParagraph::size_type main_body;
3346 if (style.labeltype != LABEL_MANUAL)
3349 main_body = par->BeginningOfMainBody();
3351 // gets paragraph main font
3352 LyXFont font1 = main_body > 0 ? style.labelfont : style.font;
3354 int char_line_count = depth;
3355 if (!style.free_spacing)
3356 for (int j = 0; j < depth; ++j)
3359 // parsing main loop
3360 for (LyXParagraph::size_type i = 0;
3361 i < par->size(); ++i) {
3362 LyXFont font2 = par->getFont(params, i);
3364 // handle <emphasis> tag
3365 if (font1.emph() != font2.emph()) {
3366 if (font2.emph() == LyXFont::ON) {
3370 os << "</emphasis>";
3375 char c = par->GetChar(i);
3377 if (c == LyXParagraph::META_INSET) {
3378 Inset * inset = par->GetInset(i);
3379 std::ostringstream ost;
3380 inset->DocBook(this, ost);
3381 string tmp_out = ost.str().c_str();
3384 // This code needs some explanation:
3385 // Two insets are treated specially
3386 // label if it is the first element in a command paragraph
3388 // graphics inside tables or figure floats can't go on
3389 // title (the equivalente in latex for this case is caption
3390 // and title should come first
3393 if (desc_on!= 3 || i!= 0) {
3394 if (!tmp_out.empty() && tmp_out[0] == '@') {
3396 extra += frontStrip(tmp_out, '@');
3398 os << frontStrip(tmp_out, '@');
3403 } else if (font2.latex() == LyXFont::ON) {
3404 // "TeX"-Mode on ==> SGML-Mode on.
3410 if (par->linuxDocConvertChar(c, sgml_string)
3411 && !style.free_spacing) { // in freespacing
3413 // non-breaking characters
3417 os << "\n</term><listitem><para>";
3429 // needed if there is an optional argument but no contents
3430 if (main_body > 0 && main_body == par->size()) {
3434 os << "</emphasis>";
3437 // resets description flag correctly
3440 // <term> not closed...
3448 // This should be enabled when the Chktex class is implemented. (Asger)
3449 // chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
3450 // Other flags: -wall -v0 -x
3451 int Buffer::runChktex()
3453 if (!users->text) return 0;
3455 ProhibitInput(users);
3457 // get LaTeX-Filename
3458 string const name = getLatexName();
3459 string path = OnlyPath(filename);
3461 string const org_path = path;
3462 if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
3466 Path p(path); // path to LaTeX file
3467 users->owner()->getMiniBuffer()->Set(_("Running chktex..."));
3469 // Remove all error insets
3470 bool const removedErrorInsets = users->removeAutoInsets();
3472 // Generate the LaTeX file if neccessary
3473 makeLaTeXFile(name, org_path, false);
3476 Chktex chktex(lyxrc.chktex_command, name, filepath);
3477 int res = chktex.run(terr); // run chktex
3480 WriteAlert(_("chktex did not work!"),
3481 _("Could not run with file:"), name);
3482 } else if (res > 0) {
3483 // Insert all errors as errors boxes
3484 users->insertErrors(terr);
3487 // if we removed error insets before we ran chktex or if we inserted
3488 // error insets after we ran chktex, this must be run:
3489 if (removedErrorInsets || res){
3491 users->fitCursor(users->text);
3499 void Buffer::validate(LaTeXFeatures & features) const
3501 LyXParagraph * par = paragraph;
3502 LyXTextClass const & tclass =
3503 textclasslist.TextClass(params.textclass);
3505 // AMS Style is at document level
3507 features.amsstyle = (params.use_amsmath ||
3508 tclass.provides(LyXTextClass::amsmath));
3511 // We don't use "lyxerr.debug" because of speed. (Asger)
3512 if (lyxerr.debugging(Debug::LATEX))
3513 lyxerr << "Paragraph: " << par << endl;
3515 // Now just follow the list of paragraphs and run
3516 // validate on each of them.
3517 par->validate(features);
3519 // and then the next paragraph
3527 // the bullet shapes are buffer level not paragraph level
3528 // so they are tested here
3529 for (int i = 0; i < 4; ++i) {
3530 if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
3531 int const font = params.user_defined_bullets[i].getFont();
3533 int const c = params
3534 .user_defined_bullets[i]
3541 features.latexsym = true;
3543 } else if (font == 1) {
3544 features.amssymb = true;
3545 } else if ((font >= 2 && font <= 5)) {
3546 features.pifont = true;
3551 if (lyxerr.debugging(Debug::LATEX)) {
3552 features.showStruct();
3557 void Buffer::setPaperStuff()
3559 params.papersize = BufferParams::PAPER_DEFAULT;
3560 char const c1 = params.paperpackage;
3561 if (c1 == BufferParams::PACKAGE_NONE) {
3562 char const c2 = params.papersize2;
3563 if (c2 == BufferParams::VM_PAPER_USLETTER)
3564 params.papersize = BufferParams::PAPER_USLETTER;
3565 else if (c2 == BufferParams::VM_PAPER_USLEGAL)
3566 params.papersize = BufferParams::PAPER_LEGALPAPER;
3567 else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
3568 params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
3569 else if (c2 == BufferParams::VM_PAPER_A3)
3570 params.papersize = BufferParams::PAPER_A3PAPER;
3571 else if (c2 == BufferParams::VM_PAPER_A4)
3572 params.papersize = BufferParams::PAPER_A4PAPER;
3573 else if (c2 == BufferParams::VM_PAPER_A5)
3574 params.papersize = BufferParams::PAPER_A5PAPER;
3575 else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
3576 (c2 == BufferParams::VM_PAPER_B5))
3577 params.papersize = BufferParams::PAPER_B5PAPER;
3578 } else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
3579 (c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
3580 params.papersize = BufferParams::PAPER_A4PAPER;
3584 // This function should be in Buffer because it's a buffer's property (ale)
3585 string const Buffer::getIncludeonlyList(char delim)
3588 for (inset_iterator it = inset_iterator_begin();
3589 it != inset_iterator_end(); ++it) {
3590 if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3591 InsetInclude * insetinc =
3592 static_cast<InsetInclude *>(*it);
3593 if (insetinc->isIncludeOnly()) {
3596 lst += insetinc->getRelFileBaseName();
3600 lyxerr.debug() << "Includeonly(" << lst << ')' << endl;
3605 vector<string> const Buffer::getLabelList()
3607 /// if this is a child document and the parent is already loaded
3608 /// Use the parent's list instead [ale990407]
3609 if (!params.parentname.empty()
3610 && bufferlist.exists(params.parentname)) {
3611 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3613 return tmp->getLabelList();
3616 vector<string> label_list;
3617 for (inset_iterator it = inset_iterator_begin();
3618 it != inset_iterator_end(); ++it) {
3619 vector<string> const l = (*it)->getLabelList();
3620 label_list.insert(label_list.end(), l.begin(), l.end());
3626 Buffer::Lists const Buffer::getLists() const
3629 LyXParagraph * par = paragraph;
3632 LyXTextClassList::size_type cap;
3633 boost::tie(found, cap) = textclasslist
3634 .NumberOfLayout(params.textclass, "Caption");
3639 if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
3640 if (textclasslist.Style(params.textclass,
3641 par->GetLayout()).labeltype
3642 == LABEL_SENSITIVE) {
3644 switch (par->footnotekind) {
3645 case LyXParagraph::FIG:
3646 case LyXParagraph::WIDE_FIG:
3649 case LyXParagraph::TAB:
3650 case LyXParagraph::WIDE_TAB:
3653 case LyXParagraph::ALGORITHM:
3656 case LyXParagraph::FOOTNOTE:
3657 case LyXParagraph::MARGIN:
3660 if (!type.empty()) {
3661 SingleList & item = l[type];
3663 tostr(item.size()+1) + ". " + par->String(this, false);
3664 item.push_back(TocItem(par, 0, str));
3667 } else if (!par->IsDummy()) {
3669 char const labeltype =
3670 textclasslist.Style(params.textclass,
3671 par->GetLayout()).labeltype;
3673 if (labeltype >= LABEL_COUNTER_CHAPTER
3674 && labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
3675 // insert this into the table of contents
3676 SingleList & item = l["TOC"];
3679 textclasslist.TextClass(params.textclass).maxcounter());
3680 item.push_back(TocItem(par, depth, par->String(this, true)));
3683 // For each paragrph, traverse its insets and look for
3687 LyXParagraph::inset_iterator it =
3688 par->inset_iterator_begin();
3689 LyXParagraph::inset_iterator end =
3690 par->inset_iterator_end();
3692 for (; it != end; ++it) {
3693 if ((*it)->LyxCode() == Inset::FLOAT_CODE) {
3695 static_cast<InsetFloat*>(*it);
3697 string const type = il->type();
3699 // Now find the caption in the float...
3700 // We now tranverse the paragraphs of
3702 LyXParagraph * tmp = il->inset->par;
3704 if (tmp->layout == cap) {
3705 SingleList & item = l[type];
3707 tostr(item.size()+1) + ". " + tmp->String(this, false);
3708 item.push_back(TocItem(tmp, 0 , str));
3715 lyxerr << "caption not found" << endl;
3730 // This is also a buffer property (ale)
3731 vector<pair<string, string> > const Buffer::getBibkeyList()
3733 /// if this is a child document and the parent is already loaded
3734 /// Use the parent's list instead [ale990412]
3735 if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
3736 Buffer * tmp = bufferlist.getBuffer(params.parentname);
3738 return tmp->getBibkeyList();
3741 vector<pair<string, string> > keys;
3742 LyXParagraph * par = paragraph;
3745 keys.push_back(pair<string, string>(par->bibkey->getContents(),
3746 par->String(this, false)));
3754 // Might be either using bibtex or a child has bibliography
3756 for (inset_iterator it = inset_iterator_begin();
3757 it != inset_iterator_end(); ++it) {
3758 // Search for Bibtex or Include inset
3759 if ((*it)->LyxCode() == Inset::BIBTEX_CODE) {
3760 vector<pair<string,string> > tmp =
3761 static_cast<InsetBibtex*>(*it)->getKeys(this);
3762 keys.insert(keys.end(), tmp.begin(), tmp.end());
3763 } else if ((*it)->LyxCode() == Inset::INCLUDE_CODE) {
3764 vector<pair<string,string> > const tmp =
3765 static_cast<InsetInclude*>(*it)->getKeys();
3766 keys.insert(keys.end(), tmp.begin(), tmp.end());
3775 bool Buffer::isDepClean(string const & name) const
3777 DEPCLEAN * item = dep_clean;
3778 while (item && item->master != name)
3780 if (!item) return true;
3785 void Buffer::markDepClean(string const & name)
3788 dep_clean = new DEPCLEAN;
3789 dep_clean->clean = true;
3790 dep_clean->master = name;
3791 dep_clean->next = 0;
3793 DEPCLEAN * item = dep_clean;
3794 while (item && item->master != name)
3799 item = new DEPCLEAN;
3801 item->master = name;
3808 bool Buffer::Dispatch(string const & command)
3810 // Split command string into command and argument
3812 string line = frontStrip(command);
3813 string const arg = strip(frontStrip(split(line, cmd, ' ')));
3815 return Dispatch(lyxaction.LookupFunc(cmd), arg);
3819 bool Buffer::Dispatch(int action, string const & argument)
3821 bool dispatched = true;
3824 Exporter::Export(this, argument, false);
3834 void Buffer::resize()
3836 /// resize the BufferViews!
3842 void Buffer::resizeInsets(BufferView * bv)
3844 /// then remove all LyXText in text-insets
3845 LyXParagraph * par = paragraph;
3847 for (; par; par = par->next_) {
3848 par->resizeInsetsLyXText(bv);
3851 for (; par; par = par->next()) {
3852 par->resizeInsetsLyXText(bv);
3858 void Buffer::ChangeLanguage(Language const * from, Language const * to)
3861 LyXParagraph * par = paragraph;
3863 par->ChangeLanguage(params, from, to);
3873 bool Buffer::isMultiLingual()
3875 LyXParagraph * par = paragraph;
3877 if (par->isMultiLingual(params))
3889 Buffer::inset_iterator::inset_iterator(LyXParagraph * paragraph,
3890 LyXParagraph::size_type pos)
3893 it = par->InsetIterator(pos);
3894 if (it == par->inset_iterator_end()) {
3905 void Buffer::inset_iterator::SetParagraph()
3908 it = par->inset_iterator_begin();
3909 if (it != par->inset_iterator_end())
3918 // We maintain an invariant that whenever par = 0 then it = 0