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 * ====================================================== */
14 #pragma implementation "lyxparagraph.h"
20 #include "lyxparagraph.h"
21 #include "support/textutils.h"
24 #include "tex-strings.h"
25 #include "bufferparams.h"
26 #include "support/FileInfo.h"
27 #include "support/LAssert.h"
29 #include "LaTeXFeatures.h"
30 #include "insets/insetinclude.h"
31 #include "insets/insetbib.h"
32 #include "support/filetools.h"
33 #include "lyx_gui_misc.h"
35 #include "support/lyxmanip.h"
41 using std::lower_bound;
42 using std::upper_bound;
45 int tex_code_break_column = 72; // needs non-zero initialization. set later.
46 // this is a bad idea, but how can LyXParagraph find its buffer to get
47 // parameters? (JMarc)
48 extern BufferView * current_view;
49 extern string bibitemWidest(Painter &);
51 // this is a minibuffer
52 static char minibuffer_char;
53 static LyXFont minibuffer_font;
54 static Inset * minibuffer_inset;
57 // Initialization of the counter for the paragraph id's,
58 // declared in lyxparagraph.h
59 unsigned int LyXParagraph::paragraph_id = 0;
62 LyXParagraph::LyXParagraph()
64 text.reserve(500); // is this number too big?
66 for (int i = 0; i < 10; ++i) setCounter(i , 0);
72 footnoteflag = LyXParagraph::NO_FOOTNOTE;
73 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
75 align = LYX_ALIGN_BLOCK;
78 /* table stuff -- begin*/
80 /* table stuff -- end*/
84 bibkey = 0; // ale970302
89 // This konstruktor inserts the new paragraph in a list.
90 LyXParagraph::LyXParagraph(LyXParagraph * par)
93 par->text.resize(par->text.size());
95 for (int i = 0; i < 10; ++i) setCounter(i, 0);
99 // double linked list begin
102 next->previous = this;
104 previous->next = this;
106 footnoteflag = LyXParagraph::NO_FOOTNOTE;
107 footnotekind = LyXParagraph::FOOTNOTE;
110 /* table stuff -- begin*/
112 /* table stuff -- end*/
115 id_ = paragraph_id++;
117 bibkey = 0; // ale970302
123 void LyXParagraph::writeFile(Buffer const * buf, ostream & os,
124 BufferParams const & params,
125 char footflag, char dth) const
127 LyXFont font1, font2;
132 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
134 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
136 // The beginning or the end of a footnote environment?
137 if (footflag != footnoteflag) {
138 footflag = footnoteflag;
140 os << "\n\\begin_float "
141 << string_footnotekinds[footnotekind]
144 os << "\n\\end_float ";
148 // The beginning or end of a deeper (i.e. nested) area?
151 while (depth > dth) {
152 os << "\n\\begin_deeper ";
156 while (depth < dth) {
157 os << "\n\\end_deeper ";
163 // First write the layout
165 << textclasslist.NameOfLayout(params.textclass, layout)
168 // Maybe some vertical spaces.
169 if (added_space_top.kind() != VSpace::NONE)
170 os << "\\added_space_top "
171 << added_space_top.asLyXCommand() << " ";
172 if (added_space_bottom.kind() != VSpace::NONE)
173 os << "\\added_space_bottom "
174 << added_space_bottom.asLyXCommand() << " ";
176 // Maybe the paragraph has special spacing
177 spacing.writeFile(os, true);
179 // The labelwidth string used in lists.
180 if (!labelwidthstring.empty())
181 os << "\\labelwidthstring "
182 << labelwidthstring << '\n';
184 // Lines above or below?
188 os << "\\line_bottom ";
190 // Pagebreaks above or below?
192 os << "\\pagebreak_top ";
193 if (pagebreak_bottom)
194 os << "\\pagebreak_bottom ";
196 // Start of appendix?
197 if (start_of_appendix)
198 os << "\\start_of_appendix ";
205 if (align != LYX_ALIGN_LAYOUT) {
207 case LYX_ALIGN_LEFT: h = 1; break;
208 case LYX_ALIGN_RIGHT: h = 2; break;
209 case LYX_ALIGN_CENTER: h = 3; break;
210 default: h = 0; break;
212 os << "\\align " << string_align[h] << " ";
214 if (pextra_type != PEXTRA_NONE) {
215 os << "\\pextra_type " << pextra_type;
216 if (pextra_type == PEXTRA_MINIPAGE) {
217 os << " \\pextra_alignment "
220 os << " \\pextra_hfill "
222 if (pextra_start_minipage)
223 os << " \\pextra_start_minipage "
224 << pextra_start_minipage;
226 if (!pextra_width.empty()) {
227 os << " \\pextra_width "
228 << VSpace(pextra_width).asLyXCommand();
229 } else if (!pextra_widthp.empty()) {
230 os << " \\pextra_widthp "
236 // Dummy layout. This means that a footnote ended.
237 os << "\n\\end_float ";
238 footflag = LyXParagraph::NO_FOOTNOTE;
241 // It might be a table.
243 os << "\\LyXTable\n";
249 bibkey->Write(buf, os);
251 font1 = LyXFont(LyXFont::ALL_INHERIT,params.language_info);
254 for (size_type i = 0; i < size(); ++i) {
260 // Write font changes
261 font2 = GetFontSettings(params, i);
262 if (font2 != font1) {
263 font2.lyxWriteChanges(font1, os);
272 Inset const * inset = GetInset(i);
274 if (inset->DirectWrite()) {
275 // international char, let it write
276 // code directly so it's shorter in
278 inset->Write(buf, os);
280 os << "\n\\begin_inset ";
281 inset->Write(buf, os);
282 os << "\n\\end_inset \n\n";
288 os << "\n\\newline \n";
292 os << "\n\\hfill \n";
296 os << "\n\\backslash \n";
300 if (i + 1 < size() && GetChar(i + 1) == ' ') {
307 if ((column > 70 && c == ' ')
312 // this check is to amend a bug. LyX sometimes
313 // inserts '\0' this could cause problems.
317 lyxerr << "ERROR (LyXParagraph::writeFile):"
318 " NULL char in structure." << endl;
324 // now write the next paragraph
326 next->writeFile(buf, os, params, footflag, dth);
330 void LyXParagraph::validate(LaTeXFeatures & features) const
332 BufferParams const & params = features.bufferParams();
334 // this will be useful later
335 LyXLayout const & layout =
336 textclasslist.Style(params.textclass,
340 if (line_top || line_bottom)
341 features.lyxline = true;
342 if (!spacing.isDefault())
343 features.setspace = true;
346 features.layout[GetLayout()] = true;
349 Language const * doc_language = params.language_info;
351 for (FontList::const_iterator cit = fontlist.begin();
352 cit != fontlist.end(); ++cit) {
353 if ((*cit).font.noun() == LyXFont::ON) {
354 lyxerr[Debug::LATEX] << "font.noun: "
355 << (*cit).font.noun()
357 features.noun = true;
358 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
359 << (*cit).font.stateText(0)
362 switch ((*cit).font.color()) {
364 case LColor::inherit:
368 features.color = true;
369 lyxerr[Debug::LATEX] << "Color enabled. Font: "
370 << (*cit).font.stateText(0)
374 Language const * language = (*cit).font.language();
375 if (language != doc_language) {
376 features.UsedLanguages.insert(language);
377 lyxerr[Debug::LATEX] << "Found language "
378 << language->lang << endl;
383 // This is not efficient. I plan to use the code above, after I
384 // change the fontlist handling.
385 for (size_type i = 0; i < size(); ++i) {
386 Language const * language =
387 GetFontSettings(params, i).language();
388 if (language != doc_language)
389 features.UsedLanguages.insert(language);
393 for (InsetList::const_iterator cit = insetlist.begin();
394 cit != insetlist.end(); ++cit) {
396 (*cit).inset->Validate(features);
399 if (table && table->IsLongTable())
400 features.longtable = true;
401 if (pextra_type == PEXTRA_INDENT)
402 features.LyXParagraphIndent = true;
403 if (pextra_type == PEXTRA_FLOATFLT)
404 features.floatflt = true;
405 if (layout.needprotect
406 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
407 features.NeedLyXFootnoteCode = true;
408 if (params.paragraph_separation == BufferParams::PARSEP_INDENT
409 && pextra_type == LyXParagraph::PEXTRA_MINIPAGE)
410 features.NeedLyXMinipageIndent = true;
411 if (table && table->NeedRotating())
412 features.rotating = true;
413 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
414 features.algorithm = true;
418 // First few functions needed for cut and paste and paragraph breaking.
419 void LyXParagraph::CopyIntoMinibuffer(BufferParams const & bparams,
420 LyXParagraph::size_type pos) const
422 minibuffer_char = GetChar(pos);
423 minibuffer_font = GetFontSettings(bparams, pos);
424 minibuffer_inset = 0;
425 if (minibuffer_char == LyXParagraph::META_INSET) {
427 minibuffer_inset = GetInset(pos)->Clone();
429 minibuffer_inset = 0;
430 minibuffer_char = ' ';
431 // This reflects what GetInset() does (ARRae)
437 void LyXParagraph::CutIntoMinibuffer(BufferParams const & bparams,
438 LyXParagraph::size_type pos)
440 minibuffer_char = GetChar(pos);
441 minibuffer_font = GetFontSettings(bparams, pos);
442 minibuffer_inset = 0;
443 if (minibuffer_char == LyXParagraph::META_INSET) {
445 minibuffer_inset = GetInset(pos);
446 // This is a little hack since I want exactly
447 // the inset, not just a clone. Otherwise
448 // the inset would be deleted when calling Erase(pos)
450 InsetList::iterator it = lower_bound(insetlist.begin(),
453 if (it != insetlist.end() && (*it).pos == pos)
456 minibuffer_inset = 0;
457 minibuffer_char = ' ';
458 // This reflects what GetInset() does (ARRae)
463 // Erase(pos); now the caller is responsible for that.
467 bool LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
469 if ((minibuffer_char == LyXParagraph::META_INSET) &&
470 !InsertInsetAllowed(minibuffer_inset))
472 InsertChar(pos, minibuffer_char);
473 SetFont(pos, minibuffer_font);
474 if (minibuffer_char == LyXParagraph::META_INSET)
475 InsertInset(pos, minibuffer_inset);
483 void LyXParagraph::Clear()
488 pagebreak_top = false;
489 pagebreak_bottom = false;
491 added_space_top = VSpace(VSpace::NONE);
492 added_space_bottom = VSpace(VSpace::NONE);
493 spacing.set(Spacing::Default);
495 align = LYX_ALIGN_LAYOUT;
499 pextra_type = PEXTRA_NONE;
500 pextra_width.erase();
501 pextra_widthp.erase();
502 pextra_alignment = MINIPAGE_ALIGN_TOP;
503 pextra_hfill = false;
504 pextra_start_minipage = false;
507 labelwidthstring.erase();
511 start_of_appendix = false;
515 // the destructor removes the new paragraph from the list
516 LyXParagraph::~LyXParagraph()
519 previous->next = next;
521 next->previous = previous;
523 for (InsetList::iterator it = insetlist.begin();
524 it != insetlist.end(); ++it) {
528 /* table stuff -- begin*/
530 /* table stuff -- end*/
536 //lyxerr << "LyXParagraph::paragraph_id = "
537 // << LyXParagraph::paragraph_id << endl;
541 void LyXParagraph::Erase(LyXParagraph::size_type pos)
543 // > because last is the next unused position, and you can
544 // use it if you want
546 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
547 NextAfterFootnote()->Erase(pos - text.size() - 1);
549 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
550 "position does not exist." << endl;
553 if (pos < size()) { // last is free for insertation, but should be empty
554 // if it is an inset, delete the inset entry
555 if (text[pos] == LyXParagraph::META_INSET) {
557 InsetList::iterator it = lower_bound(insetlist.begin(),
560 if (it != insetlist.end() && (*it).pos == pos) {
565 text.erase(text.begin() + pos);
566 // Erase entries in the tables.
567 for (FontList::iterator it = fontlist.begin();
568 it != fontlist.end(); ++it) {
569 if (pos >= (*it).pos && pos <= (*it).pos_end) {
570 if ((*it).pos == (*it).pos_end) {
571 // If it is a multi-character font
572 // entry, we just make it smaller
573 // (see update below), otherwise we
580 // Update all other entries.
581 for (FontList::iterator it = fontlist.begin();
582 it != fontlist.end(); ++it) {
585 if ((*it).pos_end >= pos)
589 // Update the inset table.
590 for (InsetList::iterator it = upper_bound(insetlist.begin(),
593 it != insetlist.end(); ++it)
596 lyxerr << "ERROR (LyXParagraph::Erase): "
597 "can't erase non-existant char." << endl;
602 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
604 // > because last is the next unused position, and you can
605 // use it if you want
608 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
609 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
612 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
613 "position does not exist." << endl;
616 text.insert(text.begin() + pos, c);
617 // Update the font table.
618 for (FontList::iterator it = fontlist.begin();
619 it != fontlist.end(); ++it) {
620 if ((*it).pos >= pos)
622 if ((*it).pos_end >= pos)
626 // Update the inset table.
627 for (InsetList::iterator it = lower_bound(insetlist.begin(),
630 it != insetlist.end(); ++it)
635 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
638 // > because last is the next unused position, and you can
639 // use it if you want
642 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
644 ->InsertInset(pos - text.size() - 1, inset);
646 lyxerr << "ERROR (LyXParagraph::InsertInset): "
647 "position does not exist: " << pos << endl;
650 if (text[pos] != LyXParagraph::META_INSET) {
651 lyxerr << "ERROR (LyXParagraph::InsertInset): "
652 "there is no LyXParagraph::META_INSET" << endl;
657 // Add a new entry in the inset table.
658 InsetList::iterator it = lower_bound(insetlist.begin(),
661 if (it != insetlist.end() && (*it).pos == pos)
662 lyxerr << "ERROR (LyXParagraph::InsertInset): "
663 "there is an inset in position: " << pos << endl;
665 insetlist.insert(it, InsetTable(pos,inset));
667 inset->setOwner(inset_owner);
672 bool LyXParagraph::InsertInsetAllowed(Inset * inset)
675 return inset_owner->InsertInsetAllowed(inset);
680 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
684 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
685 return NextAfterFootnote()
686 ->GetInset(pos - text.size() - 1);
688 lyxerr << "ERROR (LyXParagraph::GetInset): "
689 "position does not exist: "
695 InsetList::iterator it = lower_bound(insetlist.begin(),
698 if (it != insetlist.end() && (*it).pos == pos)
701 lyxerr << "ERROR (LyXParagraph::GetInset): "
702 "Inset does not exist: " << pos << endl;
703 // text[pos] = ' '; // WHY!!! does this set the pos to ' '????
704 // Did this commenting out introduce a bug? So far I have not
705 // see any, please enlighten me. (Lgb)
706 // My guess is that since the inset does not exist, we might
707 // as well replace it with a space to prevent craches. (Asger)
712 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
716 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
717 return NextAfterFootnote()
718 ->GetInset(pos - text.size() - 1);
720 lyxerr << "ERROR (LyXParagraph::GetInset): "
721 "position does not exist: "
727 InsetList::const_iterator cit = lower_bound(insetlist.begin(),
730 if (cit != insetlist.end() && (*cit).pos == pos)
733 lyxerr << "ERROR (LyXParagraph::GetInset): "
734 "Inset does not exist: " << pos << endl;
735 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
736 // Did this commenting out introduce a bug? So far I have not
737 // see any, please enlighten me. (Lgb)
738 // My guess is that since the inset does not exist, we might
739 // as well replace it with a space to prevent craches. (Asger)
744 // Gets uninstantiated font setting at position.
745 // Optimized after profiling. (Asger)
746 LyXFont LyXParagraph::GetFontSettings(BufferParams const & bparams,
747 LyXParagraph::size_type pos) const
750 #ifdef SORTED_FONT_LIST
751 for (FontList::const_iterator cit = fontlist.begin();
752 cit != fontlist.end() && pos <= (*cit).pos_end; ++cit)
753 if (pos >= (*cit).pos)
756 for (FontList::const_iterator cit = fontlist.begin();
757 cit != fontlist.end(); ++cit)
758 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
762 // > because last is the next unused position, and you can
763 // use it if you want
764 else if (pos > size()) {
766 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
767 return NextAfterFootnote()
768 ->GetFontSettings(bparams,
769 pos - text.size() - 1);
771 // Why is it an error to ask for the font of a
772 // position that does not exist? Would it be
773 // enough for this to be enabled on debug?
774 // We want strict error checking, but it's ok to only
775 // have it when debugging. (Asger)
776 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
777 "position does not exist. "
778 << pos << " (" << static_cast<int>(pos)
781 } else if (pos > 0) {
782 return GetFontSettings(bparams, pos - 1);
783 } else // pos = size() = 0
784 return LyXFont(LyXFont::ALL_INHERIT, getParLanguage(bparams));
786 return LyXFont(LyXFont::ALL_INHERIT);
789 // Gets uninstantiated font setting at position 0
790 LyXFont LyXParagraph::GetFirstFontSettings() const
793 #ifdef SORTED_FONT_LIST
794 if (!fontlist.empty() && fontlist.front().pos == 0)
795 return fontlist.front().font;
797 for (FontList::const_iterator cit = fontlist.begin();
798 cit != fontlist.end(); ++cit)
799 if (0 >= (*cit).pos && 0 <= (*cit).pos_end)
802 } else if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
803 return NextAfterFootnote()->GetFirstFontSettings();
804 return LyXFont(LyXFont::ALL_INHERIT);
808 // Gets the fully instantiated font at a given position in a paragraph
809 // This is basically the same function as LyXText::GetFont() in text2.C.
810 // The difference is that this one is used for generating the LaTeX file,
811 // and thus cosmetic "improvements" are disallowed: This has to deliver
812 // the true picture of the buffer. (Asger)
813 // If position is -1, we get the layout font of the paragraph.
814 // If position is -2, we get the font of the manual label of the paragraph.
815 LyXFont LyXParagraph::getFont(BufferParams const & bparams,
816 LyXParagraph::size_type pos) const
819 LyXLayout const & layout =
820 textclasslist.Style(bparams.textclass,
822 LyXParagraph::size_type main_body = 0;
823 if (layout.labeltype == LABEL_MANUAL)
824 main_body = BeginningOfMainBody();
829 layoutfont = layout.labelfont;
831 layoutfont = layout.font;
832 tmpfont = GetFontSettings(bparams, pos);
833 tmpfont.realize(layoutfont);
835 // process layoutfont for pos == -1 and labelfont for pos < -1
837 tmpfont = layout.font;
839 tmpfont = layout.labelfont;
840 tmpfont.setLanguage(getParLanguage(bparams));
843 // check for environment font information
844 char par_depth = GetDepth();
845 LyXParagraph const * par = this;
846 while (par && par_depth && !tmpfont.resolved()) {
847 par = par->DepthHook(par_depth - 1);
849 tmpfont.realize(textclasslist.
850 Style(bparams.textclass,
851 par->GetLayout()).font);
852 par_depth = par->GetDepth();
856 tmpfont.realize(textclasslist
857 .TextClass(bparams.textclass)
863 /// Returns the height of the highest font in range
865 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
866 LyXParagraph::size_type endpos) const
868 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
869 for (FontList::const_iterator cit = fontlist.begin();
870 cit != fontlist.end(); ++cit) {
871 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
872 LyXFont::FONT_SIZE size = (*cit).font.size();
873 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
881 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
888 // > because last is the next unused position, and you can
889 // use it if you want
890 else if (pos > size()) {
891 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
892 return NextAfterFootnote()
893 ->GetChar(pos - text.size() - 1);
895 lyxerr << "ERROR (LyXParagraph::GetChar): "
896 "position does not exist."
897 << pos << " (" << static_cast<int>(pos)
899 // Assert(false); // This triggers sometimes...
904 // We should have a footnote environment.
905 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
906 // Notice that LyX does request the
907 // last char from time to time. (Asger)
908 //lyxerr << "ERROR (LyXParagraph::GetChar): "
909 // "expected footnote." << endl;
912 switch (next->footnotekind) {
913 case LyXParagraph::FOOTNOTE:
914 return LyXParagraph::META_FOOTNOTE;
915 case LyXParagraph::MARGIN:
916 return LyXParagraph::META_MARGIN;
917 case LyXParagraph::FIG:
918 case LyXParagraph::WIDE_FIG:
919 return LyXParagraph::META_FIG;
920 case LyXParagraph::TAB:
921 case LyXParagraph::WIDE_TAB:
922 return LyXParagraph::META_TAB;
923 case LyXParagraph::ALGORITHM:
924 return LyXParagraph::META_ALGORITHM;
926 return '\0'; // to shut up gcc
931 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
938 // > because last is the next unused position, and you can
939 // use it if you want
940 else if (pos > size()) {
941 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
942 return NextAfterFootnote()
943 ->GetChar(pos - text.size() - 1);
945 lyxerr << "ERROR (LyXParagraph::GetChar const): "
946 "position does not exist."
947 << pos << " (" << static_cast<int>(pos)
953 // We should have a footnote environment.
954 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
955 // Notice that LyX does request the
956 // last char from time to time. (Asger)
957 //lyxerr << "ERROR (LyXParagraph::GetChar): "
958 // "expected footnote." << endl;
961 switch (next->footnotekind) {
962 case LyXParagraph::FOOTNOTE:
963 return LyXParagraph::META_FOOTNOTE;
964 case LyXParagraph::MARGIN:
965 return LyXParagraph::META_MARGIN;
966 case LyXParagraph::FIG:
967 case LyXParagraph::WIDE_FIG:
968 return LyXParagraph::META_FIG;
969 case LyXParagraph::TAB:
970 case LyXParagraph::WIDE_TAB:
971 return LyXParagraph::META_TAB;
972 case LyXParagraph::ALGORITHM:
973 return LyXParagraph::META_ALGORITHM;
975 return '\0'; // to shut up gcc
980 // return an string of the current word, and the end of the word in lastpos.
981 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
985 // the current word is defined as starting at the first character
986 // from the immediate left of lastpospos which meets the definition
987 // of IsLetter(), continuing to the last character to the right
988 // of this meeting IsLetter.
994 // move back until we have a letter
996 //there's no real reason to have firstpos & lastpos as
997 //separate variables as this is written, but maybe someon
998 // will want to return firstpos in the future.
1000 //since someone might have typed a punctuation first
1001 int firstpos = lastpos;
1003 while ((firstpos >= 0) && !IsLetter(firstpos))
1006 // now find the beginning by looking for a nonletter
1008 while ((firstpos>= 0) && IsLetter(firstpos))
1011 // the above is now pointing to the preceeding non-letter
1015 // so copy characters into theword until we get a nonletter
1016 // note that this can easily exceed lastpos, wich means
1017 // that if used in the middle of a word, the whole word
1020 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
1027 LyXParagraph::size_type LyXParagraph::Last() const
1029 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1030 return text.size() + NextAfterFootnote()->Last() + 1;
1031 // the 1 is the symbol
1038 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
1040 // > because last is the next unused position, and you can
1041 // use it if you want
1044 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1045 return NextAfterFootnote()
1046 ->ParFromPos(pos - text.size() - 1);
1048 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
1049 "position does not exist." << endl;
1056 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
1058 // > because last is the next unused position, and you can
1059 // use it if you want
1062 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1063 return NextAfterFootnote()
1064 ->PositionInParFromPos(pos - text.size() - 1);
1067 "ERROR (LyXParagraph::PositionInParFromPos): "
1068 "position does not exist." << endl;
1076 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
1077 LyXFont const & font)
1079 // > because last is the next unused position, and you can
1080 // use it if you want
1083 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1084 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1087 lyxerr << "ERROR (LyXParagraph::SetFont): "
1088 "position does not exist." << endl;
1092 LyXFont patternfont(LyXFont::ALL_INHERIT);
1094 // First, reduce font against layout/label font
1095 // Update: The SetCharFont() routine in text2.C already
1096 // reduces font, so we don't need to do that here. (Asger)
1097 // No need to simplify this because it will disappear
1098 // in a new kernel. (Asger)
1099 // Next search font table
1100 FontList::iterator tmp = fontlist.begin();
1101 for (; tmp != fontlist.end(); ++tmp) {
1102 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1106 if (tmp == fontlist.end()) { // !found
1107 // if we did not find a font entry, but if the font at hand
1108 // is the same as default, we just forget it
1109 if (font == patternfont) return;
1111 // ok, we did not find a font entry. But maybe there is exactly
1112 // the needed font ientry one position left
1113 FontList::iterator tmp2 = fontlist.begin();
1114 for (; tmp2 != fontlist.end(); ++tmp2) {
1115 if (pos - 1 >= (*tmp2).pos
1116 && pos - 1 <= (*tmp2).pos_end)
1119 if (tmp2 != fontlist.end()) {
1120 // ok there is one, maybe it is exactly
1122 if ((*tmp2).font == font) {
1123 // put the position under the font
1128 // Add a new entry in the
1129 // fontlist for the position
1133 ft.font = font; // or patternfont
1134 // It seems that using font instead of patternfont here
1135 // fixes all the problems. This also surfaces a "bug" in
1137 fontlist.insert(fontlist.begin(), ft);
1138 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1140 // more than one character
1141 if (pos == (*tmp).pos) {
1142 // maybe we should enlarge the left fonttable
1143 FontList::iterator tmp2 = fontlist.begin();
1144 for (; tmp2 != fontlist.end(); ++tmp2) {
1145 if (pos - 1 >= (*tmp2).pos
1146 && pos - 1 <= (*tmp2).pos_end)
1149 // Is there is one, and is it exactly
1151 if (tmp2 != fontlist.end() &&
1152 (*tmp2).font == font) {
1153 // Put the position under the font
1159 // Add a new entry in the
1160 // fontlist for the position
1163 ft.pos_end = (*tmp).pos_end;
1164 ft.font = (*tmp).font;
1165 (*tmp).pos_end = pos;
1167 fontlist.insert(fontlist.begin(), ft);
1168 } else if (pos == (*tmp).pos_end) {
1169 // Add a new entry in the
1170 // fontlist for the position
1172 ft.pos = (*tmp).pos;
1173 ft.pos_end = (*tmp).pos_end - 1;
1174 ft.font = (*tmp).font;
1175 (*tmp).pos = (*tmp).pos_end;
1177 fontlist.insert(fontlist.begin(), ft);
1179 // Add a new entry in the
1180 // fontlist for the position
1182 ft.pos = (*tmp).pos;
1183 ft.pos_end = pos - 1;
1184 ft.font = (*tmp).font;
1188 ft2.pos_end = (*tmp).pos_end;
1189 ft2.font = (*tmp).font;
1192 (*tmp).pos_end = pos;
1195 fontlist.insert(fontlist.begin(), ft);
1196 fontlist.insert(fontlist.begin(), ft2);
1204 // This function is able to hide closed footnotes.
1205 LyXParagraph * LyXParagraph::Next()
1207 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1208 LyXParagraph * tmp = next;
1210 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1212 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1213 return tmp->Next(); /* there can be more than one
1214 footnote in a logical
1217 return next; // This should never happen!
1223 LyXParagraph * LyXParagraph::NextAfterFootnote()
1225 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1226 LyXParagraph * tmp = next;
1227 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1229 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1230 return tmp; /* there can be more than one footnote
1231 in a logical paragraph */
1233 return next; // This should never happen!
1239 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1241 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1242 LyXParagraph * tmp = next;
1243 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1245 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1246 return tmp; /* there can be more than one footnote
1247 in a logical paragraph */
1249 return next; // This should never happen!
1255 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1258 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1260 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1261 tmp = tmp->previous;
1262 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1263 return tmp; /* there can be more than one footnote
1264 in a logical paragraph */
1266 return previous; // This should never happen!
1272 LyXParagraph * LyXParagraph::LastPhysicalPar()
1274 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1277 LyXParagraph * tmp = this;
1279 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1280 tmp = tmp->NextAfterFootnote();
1285 LyXParagraph const * LyXParagraph::LastPhysicalPar() const
1287 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1290 LyXParagraph const * tmp = this;
1292 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1293 tmp = tmp->NextAfterFootnote();
1298 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1302 LyXParagraph * tmppar = this;
1306 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1307 tmppar = tmppar->previous;
1316 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1320 LyXParagraph const * tmppar = this;
1324 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1325 tmppar = tmppar->previous;
1334 // This function is able to hide closed footnotes.
1335 LyXParagraph * LyXParagraph::Previous()
1337 LyXParagraph * tmp = previous;
1342 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1343 tmp = tmp->previous;
1345 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1346 tmp = tmp->previous;
1347 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1348 return tmp->next->Previous();
1357 // This function is able to hide closed footnotes.
1358 LyXParagraph const * LyXParagraph::Previous() const
1360 LyXParagraph * tmp = previous;
1365 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1366 tmp = tmp->previous;
1368 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1369 tmp = tmp->previous;
1370 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1371 return tmp->next->Previous();
1380 void LyXParagraph::BreakParagraph(BufferParams const & bparams,
1381 LyXParagraph::size_type pos,
1384 size_type i, j, pos_end, pos_first;
1385 // create a new paragraph
1386 LyXParagraph * par = ParFromPos(pos);
1387 LyXParagraph * firstpar = FirstPhysicalPar();
1389 LyXParagraph * tmp = new LyXParagraph(par);
1391 tmp->footnoteflag = footnoteflag;
1392 tmp->footnotekind = footnotekind;
1394 // this is an idea for a more userfriendly layout handling, I will
1395 // see what the users say
1397 // layout stays the same with latex-environments
1399 tmp->SetOnlyLayout(bparams, firstpar->layout);
1400 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1403 if (Last() > pos || !Last() || flag == 2) {
1404 tmp->SetOnlyLayout(bparams, firstpar->layout);
1405 tmp->align = firstpar->align;
1406 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1408 tmp->line_bottom = firstpar->line_bottom;
1409 firstpar->line_bottom = false;
1410 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1411 firstpar->pagebreak_bottom = false;
1412 tmp->added_space_bottom = firstpar->added_space_bottom;
1413 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1415 tmp->depth = firstpar->depth;
1416 tmp->noindent = firstpar->noindent;
1418 // copy everything behind the break-position
1419 // to the new paragraph
1421 while (ParFromPos(pos_first) != par)
1424 pos_end = pos_first + par->text.size() - 1;
1426 for (i = j = pos; i <= pos_end; ++i) {
1427 par->CutIntoMinibuffer(bparams, i - pos_first);
1428 if (tmp->InsertFromMinibuffer(j - pos))
1431 tmp->text.resize(tmp->text.size());
1432 for (i = pos_end; i >= pos; --i)
1433 par->Erase(i - pos_first);
1435 par->text.resize(par->text.size());
1438 // just an idea of me
1440 tmp->line_top = firstpar->line_top;
1441 tmp->pagebreak_top = firstpar->pagebreak_top;
1442 tmp->added_space_top = firstpar->added_space_top;
1443 tmp->bibkey = firstpar->bibkey;
1445 // layout stays the same with latex-environments
1447 firstpar->SetOnlyLayout(bparams, tmp->layout);
1448 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1449 firstpar->depth = tmp->depth;
1455 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1457 par = par->FirstPhysicalPar();
1458 footnoteflag = par->footnoteflag;
1459 footnotekind = par->footnotekind;
1461 layout = par->layout;
1462 align = par-> align;
1463 SetLabelWidthString(par->labelwidthstring);
1465 line_bottom = par->line_bottom;
1466 pagebreak_bottom = par->pagebreak_bottom;
1467 added_space_bottom = par->added_space_bottom;
1469 line_top = par->line_top;
1470 pagebreak_top = par->pagebreak_top;
1471 added_space_top = par->added_space_top;
1473 spacing = par->spacing;
1475 pextra_type = par->pextra_type;
1476 pextra_width = par->pextra_width;
1477 pextra_widthp = par->pextra_widthp;
1478 pextra_alignment = par->pextra_alignment;
1479 pextra_hfill = par->pextra_hfill;
1480 pextra_start_minipage = par->pextra_start_minipage;
1482 noindent = par->noindent;
1487 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1489 LyXParagraph * tmppar = this;
1492 && tmppar->previous->footnoteflag ==
1493 LyXParagraph::CLOSED_FOOTNOTE)
1494 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1495 tmppar = tmppar->previous;
1498 return this; // This should never happen!
1503 int LyXParagraph::StripLeadingSpaces(LyXTextClassList::size_type tclass)
1505 if (textclasslist.Style(tclass, GetLayout()).free_spacing)
1509 if (!IsDummy() && !table){
1511 && (IsNewline(0) || IsLineSeparator(0))){
1520 LyXParagraph * LyXParagraph::Clone() const
1522 // create a new paragraph
1523 LyXParagraph * result = new LyXParagraph;
1525 result->MakeSameLayout(this);
1527 // this is because of the dummy layout of the paragraphs that
1529 result->layout = layout;
1532 /* table stuff -- begin*/
1534 result->table = table->Clone();
1537 /* table stuff -- end*/
1539 result->inset_owner = inset_owner;
1542 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1545 // copy everything behind the break-position to the new paragraph
1547 result->text = text;
1548 result->fontlist = fontlist;
1549 result->insetlist = insetlist;
1550 for (InsetList::iterator it = result->insetlist.begin();
1551 it != result->insetlist.end(); ++it)
1552 (*it).inset = (*it).inset->Clone();
1557 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1559 par = par->FirstPhysicalPar();
1562 par->footnoteflag == footnoteflag &&
1563 par->footnotekind == footnotekind &&
1565 par->layout == layout &&
1567 par->align == align &&
1569 par->line_bottom == line_bottom &&
1570 par->pagebreak_bottom == pagebreak_bottom &&
1571 par->added_space_bottom == added_space_bottom &&
1573 par->line_top == line_top &&
1574 par->pagebreak_top == pagebreak_top &&
1575 par->added_space_top == added_space_top &&
1577 par->spacing == spacing &&
1579 par->pextra_type == pextra_type &&
1580 par->pextra_width == pextra_width &&
1581 par->pextra_widthp == pextra_widthp &&
1582 par->pextra_alignment == pextra_alignment &&
1583 par->pextra_hfill == pextra_hfill &&
1584 par->pextra_start_minipage == pextra_start_minipage &&
1586 par->table == table && // what means: NO TABLE AT ALL
1589 par->noindent == noindent &&
1590 par->depth == depth);
1594 void LyXParagraph::BreakParagraphConservative(BufferParams const & bparams,
1595 LyXParagraph::size_type pos)
1597 // create a new paragraph
1598 LyXParagraph * par = ParFromPos(pos);
1600 LyXParagraph * tmp = new LyXParagraph(par);
1602 tmp->MakeSameLayout(par);
1604 // When can pos < Last()?
1605 // I guess pos == Last() is possible.
1607 // copy everything behind the break-position to the new
1609 size_type pos_first = 0;
1610 while (ParFromPos(pos_first) != par)
1612 size_type pos_end = pos_first + par->text.size() - 1;
1615 for (i = j = pos; i <= pos_end; ++i) {
1616 par->CutIntoMinibuffer(bparams, i - pos_first);
1617 if (tmp->InsertFromMinibuffer(j - pos))
1620 tmp->text.resize(tmp->text.size());
1621 for (size_type i = pos_end; i >= pos; --i)
1622 par->Erase(i - pos_first);
1624 par->text.resize(par->text.size());
1629 // Be carefull, this does not make any check at all.
1630 void LyXParagraph::PasteParagraph(BufferParams const & bparams)
1632 // copy the next paragraph to this one
1633 LyXParagraph * the_next = Next();
1635 LyXParagraph * firstpar = FirstPhysicalPar();
1637 // first the DTP-stuff
1638 firstpar->line_bottom = the_next->line_bottom;
1639 firstpar->added_space_bottom = the_next->added_space_bottom;
1640 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1642 size_type pos_end = the_next->text.size() - 1;
1643 size_type pos_insert = Last();
1645 // ok, now copy the paragraph
1647 for (i = j = 0; i <= pos_end; ++i) {
1648 the_next->CutIntoMinibuffer(bparams, i);
1649 if (InsertFromMinibuffer(pos_insert + j))
1653 // delete the next paragraph
1654 LyXParagraph *ppar = the_next->previous;
1655 LyXParagraph *npar = the_next->next;
1661 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1663 LyXParagraph * par = ParFromPos(pos);
1665 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1666 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1672 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1674 LyXParagraph * par = ParFromPos(pos);
1676 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1677 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1682 int LyXParagraph::GetEndLabel(BufferParams const & bparams) const
1684 LyXParagraph const * par = this;
1685 int par_depth = GetDepth();
1687 LyXTextClass::LayoutList::size_type layout = par->GetLayout();
1689 textclasslist.Style(bparams.textclass,
1690 layout).endlabeltype;
1691 if (endlabeltype != END_LABEL_NO_LABEL) {
1692 LyXParagraph const * last = this;
1693 if( footnoteflag == NO_FOOTNOTE)
1694 last = LastPhysicalPar();
1695 else if (next->footnoteflag == NO_FOOTNOTE)
1696 return endlabeltype;
1698 if (!last || !last->next)
1699 return endlabeltype;
1701 int next_depth = last->next->GetDepth();
1702 if (par_depth > next_depth ||
1703 (par_depth == next_depth && layout != last->next->GetLayout() ))
1704 return endlabeltype;
1709 par = par->DepthHook(par_depth - 1);
1711 par_depth = par->GetDepth();
1713 return END_LABEL_NO_LABEL;
1717 LyXTextClass::size_type LyXParagraph::GetLayout() const
1719 return FirstPhysicalPar()->layout;
1723 char LyXParagraph::GetDepth() const
1725 return FirstPhysicalPar()->depth;
1729 char LyXParagraph::GetAlign() const
1731 return FirstPhysicalPar()->align;
1735 string LyXParagraph::GetLabelstring() const
1737 return FirstPhysicalPar()->labelstring;
1741 int LyXParagraph::GetFirstCounter(int i) const
1743 return FirstPhysicalPar()->counter_[i];
1747 // the next two functions are for the manual labels
1748 string LyXParagraph::GetLabelWidthString() const
1750 if (!FirstPhysicalPar()->labelwidthstring.empty())
1751 return FirstPhysicalPar()->labelwidthstring;
1753 return _("Senseless with this layout!");
1757 void LyXParagraph::SetLabelWidthString(string const & s)
1759 LyXParagraph * par = FirstPhysicalPar();
1761 par->labelwidthstring = s;
1765 void LyXParagraph::SetOnlyLayout(BufferParams const & bparams,
1766 LyXTextClass::size_type new_layout)
1768 LyXParagraph * par = FirstPhysicalPar();
1769 LyXParagraph * ppar = 0;
1770 LyXParagraph * npar = 0;
1772 par->layout = new_layout;
1774 /* table stuff -- begin*/
1777 /* table stuff -- end*/
1779 if (par->pextra_type == PEXTRA_NONE) {
1780 if (par->Previous()) {
1781 ppar = par->Previous()->FirstPhysicalPar();
1784 && (ppar->depth > par->depth))
1785 ppar = ppar->Previous()->FirstPhysicalPar();
1788 npar = par->Next()->NextAfterFootnote();
1791 && (npar->depth > par->depth))
1792 npar = npar->Next()->NextAfterFootnote();
1794 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1796 p1 = ppar->pextra_width,
1797 p2 = ppar->pextra_widthp;
1798 ppar->SetPExtraType(bparams, ppar->pextra_type,
1799 p1.c_str(), p2.c_str());
1801 if ((par->pextra_type == PEXTRA_NONE) &&
1802 npar && (npar->pextra_type != PEXTRA_NONE)) {
1804 p1 = npar->pextra_width,
1805 p2 = npar->pextra_widthp;
1806 npar->SetPExtraType(bparams, npar->pextra_type,
1807 p1.c_str(), p2.c_str());
1813 void LyXParagraph::SetLayout(BufferParams const & bparams,
1814 LyXTextClass::size_type new_layout)
1817 * par = FirstPhysicalPar(),
1821 par->layout = new_layout;
1822 par->labelwidthstring.erase();
1823 par->align = LYX_ALIGN_LAYOUT;
1824 par->added_space_top = VSpace(VSpace::NONE);
1825 par->added_space_bottom = VSpace(VSpace::NONE);
1826 par->spacing.set(Spacing::Default);
1829 /* table stuff -- begin*/
1832 /* table stuff -- end*/
1834 if (par->pextra_type == PEXTRA_NONE) {
1835 if (par->Previous()) {
1836 ppar = par->Previous()->FirstPhysicalPar();
1839 && (ppar->depth > par->depth))
1840 ppar = ppar->Previous()->FirstPhysicalPar();
1843 npar = par->Next()->NextAfterFootnote();
1846 && (npar->depth > par->depth))
1847 npar = npar->Next()->NextAfterFootnote();
1849 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1851 p1 = ppar->pextra_width,
1852 p2 = ppar->pextra_widthp;
1853 ppar->SetPExtraType(bparams, ppar->pextra_type,
1854 p1.c_str(), p2.c_str());
1856 if ((par->pextra_type == PEXTRA_NONE) &&
1857 npar && (npar->pextra_type != PEXTRA_NONE)) {
1859 p1 = npar->pextra_width,
1860 p2 = npar->pextra_widthp;
1861 npar->SetPExtraType(bparams, npar->pextra_type,
1862 p1.c_str(), p2.c_str());
1868 // if the layout of a paragraph contains a manual label, the beginning of the
1869 // main body is the beginning of the second word. This is what the par-
1870 // function returns. If the layout does not contain a label, the main
1871 // body always starts with position 0. This differentiation is necessary,
1872 // because there cannot be a newline or a blank <= the beginning of the
1873 // main body in TeX.
1875 int LyXParagraph::BeginningOfMainBody() const
1877 if (FirstPhysicalPar() != this)
1880 // Unroll the first two cycles of the loop
1881 // and remember the previous character to
1882 // remove unnecessary GetChar() calls
1885 && GetChar(i) != LyXParagraph::META_NEWLINE
1888 char previous_char = 0, temp = 0;
1890 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1891 // Yes, this ^ is supposed to be "= " not "=="
1894 && previous_char != ' '
1895 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1897 previous_char = temp;
1902 if (i == 0 && i == size() &&
1903 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1904 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1905 ++i; /* the cursor should not jump
1906 * to the main body if there
1912 LyXParagraph * LyXParagraph::DepthHook(int deth)
1914 LyXParagraph * newpar = this;
1919 newpar = newpar->FirstPhysicalPar()->Previous();
1920 } while (newpar && newpar->GetDepth() > deth
1921 && newpar->footnoteflag == footnoteflag);
1924 if (Previous() || GetDepth())
1925 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1929 return newpar->FirstPhysicalPar();
1933 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1935 LyXParagraph const * newpar = this;
1940 newpar = newpar->FirstPhysicalPar()->Previous();
1941 } while (newpar && newpar->GetDepth() > deth
1942 && newpar->footnoteflag == footnoteflag);
1945 if (Previous() || GetDepth())
1946 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1950 return newpar->FirstPhysicalPar();
1954 int LyXParagraph::AutoDeleteInsets()
1957 InsetList::size_type index = 0;
1958 while (index < insetlist.size()) {
1959 if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) {
1960 Erase(insetlist[index].pos);
1961 // Erase() calls to insetlist.erase(&insetlist[index])
1962 // so index shouldn't be increased.
1971 LyXParagraph::inset_iterator LyXParagraph::InsetIterator(LyXParagraph::size_type pos)
1973 InsetList::iterator it = lower_bound(insetlist.begin(),
1976 return inset_iterator(it);
1980 // returns -1 if inset not found
1981 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1984 // We could use lower_bound here too, we just need to add
1985 // the approp. operator() to matchIT (and change the name
1986 // of that struct). Code would then be:
1987 // InsetList::const_iterator cit = lower_bound(insetlist.begin(),
1989 // inset, matchIT());
1990 // if ((*cit).inset == inset) {
1991 // return (*cit).pos;
1993 for (InsetList::const_iterator cit = insetlist.begin();
1994 cit != insetlist.end(); ++cit) {
1995 if ((*cit).inset == inset) {
1999 // Think about footnotes.
2000 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
2001 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
2003 NextAfterFootnote()->GetPositionOfInset(inset);
2005 return text.size() + 1 + further;
2011 LyXParagraph * LyXParagraph::TeXOnePar(Buffer const * buf,
2012 BufferParams const & bparams,
2013 ostream & os, TexRow & texrow,
2016 TexRow & foot_texrow,
2019 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
2020 LyXLayout const & style =
2021 textclasslist.Style(bparams.textclass,
2024 bool further_blank_line = false;
2026 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
2028 if (start_of_appendix) {
2029 os << "\\appendix\n";
2033 if (!spacing.isDefault()
2034 && (!Previous() || !Previous()->HasSameLayout(this))) {
2035 os << spacing.writeEnvirBegin() << "\n";
2039 if (tex_code_break_column && style.isCommand()){
2044 if (pagebreak_top) {
2046 further_blank_line = true;
2048 if (added_space_top.kind() != VSpace::NONE) {
2049 os << added_space_top.asLatexCommand(bparams);
2050 further_blank_line = true;
2054 os << "\\lyxline{\\" << getFont(bparams, 0).latexSize() << '}'
2055 << "\\vspace{-1\\parskip}";
2056 further_blank_line = true;
2059 if (further_blank_line){
2064 Language const * language = getParLanguage(bparams);
2065 Language const * doc_language = bparams.language_info;
2066 if (language != doc_language &&
2067 (!previous || previous->getParLanguage(bparams) != language)) {
2068 os << subst(lyxrc.language_command_begin, "$$lang",
2074 switch (style.latextype) {
2077 << style.latexname()
2078 << style.latexparam();
2080 case LATEX_ITEM_ENVIRONMENT:
2082 bibkey->Latex(buf, os, false, false);
2086 case LATEX_LIST_ENVIRONMENT:
2093 bool need_par = SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2095 // Spit out footnotes
2096 LyXParagraph * par = next;
2097 if (lyxrc.rtl_support) {
2098 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2099 && next->footnoteflag != footnoteflag) {
2100 LyXParagraph * p = 0;
2101 bool is_rtl = (size() > 0)
2102 ? GetFontSettings(bparams,
2103 size()-1).isRightToLeft()
2104 : language->RightToLeft();
2105 if ( (p = NextAfterFootnote()) != 0 &&
2107 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2108 is_rtl = getParLanguage(bparams)->RightToLeft();
2109 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2110 && par->footnoteflag != footnoteflag) {
2111 par = par->TeXFootnote(buf, bparams,
2113 foot_texrow, foot_count,
2115 par->SimpleTeXOnePar(buf, bparams,
2116 os, texrow, moving_arg);
2117 is_rtl = (par->size() > 0)
2118 ? par->GetFontSettings(bparams,
2119 par->size()-1).isRightToLeft()
2120 : language->RightToLeft();
2122 par->next->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2123 (p = par->NextAfterFootnote()) != 0 &&
2125 p->GetFontSettings(bparams, 0).isRightToLeft() != is_rtl)
2126 is_rtl = language->RightToLeft();
2131 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
2132 && par->footnoteflag != footnoteflag) {
2133 par = par->TeXFootnote(buf, bparams,
2135 foot, foot_texrow, foot_count,
2137 par->SimpleTeXOnePar(buf, bparams, os, texrow, moving_arg);
2142 // Make sure that \\par is done with the font of the last
2143 // character if this has another size as the default.
2144 // This is necessary because LaTeX (and LyX on the screen)
2145 // calculates the space between the baselines according
2146 // to this font. (Matthias)
2147 LyXFont font = getFont(bparams, Last() - 1);
2149 if (style.resfont.size() != font.size()) {
2155 } else if (textclasslist.Style(bparams.textclass,
2156 GetLayout()).isCommand()) {
2157 if (style.resfont.size() != font.size()) {
2163 } else if (style.resfont.size() != font.size()){
2164 os << "{\\" << font.latexSize() << " \\par}";
2167 if (language != doc_language &&
2169 || (footnoteflag != NO_FOOTNOTE && par->footnoteflag != footnoteflag)
2170 || par->getParLanguage(bparams) != language)) {
2172 << subst(lyxrc.language_command_end, "$$lang",
2173 doc_language->lang());
2176 switch (style.latextype) {
2177 case LATEX_ITEM_ENVIRONMENT:
2178 case LATEX_LIST_ENVIRONMENT:
2179 if (par && (depth < par->depth)) {
2184 case LATEX_ENVIRONMENT:
2185 // if its the last paragraph of the current environment
2186 // skip it otherwise fall through
2188 && (par->layout != layout
2189 || par->depth != depth
2190 || par->pextra_type != pextra_type))
2193 // we don't need it for the last paragraph!!!
2194 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE
2195 && footnotekind != LyXParagraph::FOOTNOTE
2196 && footnotekind != LyXParagraph::MARGIN
2200 // don't insert this if we would be adding it
2201 // before or after a table in a float. This
2202 // little trick is needed in order to allow
2203 // use of tables in \subfigures or \subtables.
2209 further_blank_line = false;
2211 os << "\\lyxline{\\" << getFont(bparams, Last() - 1).latexSize() << '}';
2212 further_blank_line = true;
2215 if (added_space_bottom.kind() != VSpace::NONE) {
2216 os << added_space_bottom.asLatexCommand(bparams);
2217 further_blank_line = true;
2220 if (pagebreak_bottom) {
2222 further_blank_line = true;
2225 if (further_blank_line){
2230 if (!spacing.isDefault()
2231 && (!par || !par->HasSameLayout(this))) {
2232 os << spacing.writeEnvirEnd() << "\n";
2236 // we don't need it for the last paragraph!!!
2237 if (next && !(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2238 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2243 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2248 // This one spits out the text of the paragraph
2249 bool LyXParagraph::SimpleTeXOnePar(Buffer const * buf,
2250 BufferParams const & bparams,
2251 ostream & os, TexRow & texrow,
2254 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2258 return SimpleTeXOneTablePar(buf, bparams, os, texrow);
2261 bool return_value = false;
2263 LyXLayout const & style =
2264 textclasslist.Style(bparams.textclass,
2266 LyXFont basefont, last_font;
2268 // Maybe we have to create a optional argument.
2269 size_type main_body;
2270 if (style.labeltype != LABEL_MANUAL)
2273 main_body = BeginningOfMainBody();
2275 if (main_body > 0) {
2277 basefont = getFont(bparams, -2); // Get label font
2279 basefont = getFont(bparams, -1); // Get layout font
2287 if (style.isCommand()) {
2290 } else if (align != LYX_ALIGN_LAYOUT) {
2293 return_value = true;
2297 moving_arg |= style.needprotect;
2299 // Which font is currently active?
2300 LyXFont running_font(basefont);
2301 // Do we have an open font change?
2302 bool open_font = false;
2304 texrow.start(this, 0);
2306 for (size_type i = 0; i < size(); ++i) {
2308 // First char in paragraph or after label?
2309 if (i == main_body && !IsDummy()) {
2310 if (main_body > 0) {
2312 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2315 basefont = getFont(bparams, -1); // Now use the layout font
2316 running_font = basefont;
2320 if (style.isCommand()) {
2323 } else if (align != LYX_ALIGN_LAYOUT) {
2326 return_value = true;
2330 os << "\\noindent ";
2334 case LYX_ALIGN_NONE:
2335 case LYX_ALIGN_BLOCK:
2336 case LYX_ALIGN_LAYOUT:
2337 case LYX_ALIGN_SPECIAL:
2339 case LYX_ALIGN_LEFT:
2340 if (getParLanguage(bparams)->lang() != "hebrew") {
2341 os << "\\raggedright ";
2344 os << "\\raggedleft ";
2348 case LYX_ALIGN_RIGHT:
2349 if (getParLanguage(bparams)->lang() != "hebrew") {
2350 os << "\\raggedleft ";
2353 os << "\\raggedright ";
2357 case LYX_ALIGN_CENTER:
2358 os << "\\centering ";
2366 // Fully instantiated font
2367 LyXFont font = getFont(bparams, i);
2368 LyXParagraph * p = 0;
2369 if (i == 0 && previous &&
2370 previous->footnoteflag != LyXParagraph::NO_FOOTNOTE &&
2371 (p = PreviousBeforeFootnote()) != 0)
2372 last_font = p->getFont(bparams, p->size()-1);
2374 last_font = running_font;
2376 // Spaces at end of font change are simulated to be
2377 // outside font change, i.e. we write "\textXX{text} "
2378 // rather than "\textXX{text }". (Asger)
2379 if (open_font && c == ' ' && i <= size() - 2
2380 && !getFont(bparams, i + 1).equalExceptLatex(running_font)
2381 && !getFont(bparams, i + 1).equalExceptLatex(font)) {
2382 font = getFont(bparams, i + 1);
2384 // We end font definition before blanks
2385 if (!font.equalExceptLatex(running_font) && open_font) {
2386 column += running_font.latexWriteEndChanges(os,
2388 (i == main_body-1) ? basefont : font);
2389 running_font = basefont;
2393 // Blanks are printed before start of fontswitch
2395 // Do not print the separation of the optional argument
2396 if (i != main_body - 1) {
2397 SimpleTeXBlanks(os, texrow, i,
2398 column, font, style);
2402 // Do we need to change font?
2403 if (!font.equalExceptLatex(running_font)
2404 && i != main_body-1) {
2405 column += font.latexWriteStartChanges(os, basefont,
2407 running_font = font;
2411 if (c == LyXParagraph::META_NEWLINE) {
2412 // newlines are handled differently here than
2413 // the default in SimpleTeXSpecialChars().
2414 if (!style.newline_allowed
2415 || font.latex() == LyXFont::ON) {
2419 column += running_font.latexWriteEndChanges(os, basefont, basefont);
2422 basefont = getFont(bparams, -1);
2423 running_font = basefont;
2424 if (font.family() ==
2425 LyXFont::TYPEWRITER_FAMILY) {
2433 texrow.start(this, i + 1);
2436 SimpleTeXSpecialChars(buf, bparams,
2437 os, texrow, moving_arg,
2438 font, running_font, basefont,
2439 open_font, style, i, column, c);
2443 // If we have an open font definition, we have to close it
2445 LyXParagraph * p = 0;
2446 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
2447 && (p = NextAfterFootnote()) != 0)
2448 running_font.latexWriteEndChanges(os, basefont,
2449 p->getFont(bparams, 0));
2451 running_font.latexWriteEndChanges(os, basefont, basefont);
2454 // Needed if there is an optional argument but no contents.
2455 if (main_body > 0 && main_body == size()) {
2457 return_value = false;
2460 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2461 return return_value;
2465 // This one spits out the text of a table paragraph
2466 bool LyXParagraph::SimpleTeXOneTablePar(Buffer const * buf,
2467 BufferParams const & bparams,
2468 ostream & os, TexRow & texrow)
2470 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2472 bool return_value = false;
2474 LyXLayout const & style =
2475 textclasslist.Style(bparams.textclass, GetLayout());
2478 if (!IsDummy()) { // it is dummy if it is in a float!!!
2479 if (style.isCommand()) {
2482 } else if (align != LYX_ALIGN_LAYOUT) {
2485 return_value = true;
2488 os << "\\noindent ";
2492 case LYX_ALIGN_NONE:
2493 case LYX_ALIGN_BLOCK:
2494 case LYX_ALIGN_LAYOUT:
2495 case LYX_ALIGN_SPECIAL: break;
2496 case LYX_ALIGN_LEFT:
2497 os << "\\raggedright ";
2500 case LYX_ALIGN_RIGHT:
2501 os << "\\raggedleft ";
2504 case LYX_ALIGN_CENTER:
2505 os << "\\centering ";
2511 LyXFont basefont = getFont(bparams, -1); // Get layout font
2512 // Which font is currently active?
2513 LyXFont running_font = basefont;
2515 // Do we have an open font change?
2516 bool open_font = false;
2517 int current_cell_number = -1;
2518 int tmp = table->TexEndOfCell(os, current_cell_number);
2519 for (; tmp > 0 ; --tmp)
2522 texrow.start(this, 0);
2524 bool is_rtl = getParLanguage(bparams)->RightToLeft();
2525 bool first_in_cell = true;
2527 for (size_type i = 0; i < size(); ++i) {
2528 char c = GetChar(i);
2529 if (table->IsContRow(current_cell_number + 1)) {
2530 if (c == LyXParagraph::META_NEWLINE)
2531 ++current_cell_number;
2536 if (first_in_cell && is_rtl) {
2539 first_in_cell = false;
2542 // Fully instantiated font
2543 LyXFont font = getFont(bparams, i);
2544 last_font = running_font;
2546 // Spaces at end of font change are simulated to be
2547 // outside font change.
2548 // i.e. we write "\textXX{text} " rather than
2549 // "\textXX{text }". (Asger)
2550 if (open_font && c == ' ' && i <= size() - 2
2551 && getFont(bparams, i + 1) != running_font
2552 && getFont(bparams, i + 1) != font) {
2553 font = getFont(bparams, i + 1);
2556 // We end font definition before blanks
2557 if (font != running_font && open_font) {
2558 column += running_font.latexWriteEndChanges(os,
2561 running_font = basefont;
2564 // Blanks are printed before start of fontswitch
2566 SimpleTeXBlanks(os, texrow, i, column, font, style);
2568 // Do we need to change font?
2569 if (font != running_font) {
2570 column += font.latexWriteStartChanges(os, basefont,
2572 running_font = font;
2575 // Do we need to turn on LaTeX mode?
2576 if (font.latex() != running_font.latex()) {
2577 if (font.latex() == LyXFont::ON
2578 && style.needprotect) {
2583 if (c == LyXParagraph::META_NEWLINE) {
2584 // special case for inside a table
2585 // different from default case in
2586 // SimpleTeXSpecialChars()
2588 column += running_font
2589 .latexWriteEndChanges(os, basefont,
2593 basefont = getFont(bparams, -1);
2594 running_font = basefont;
2595 ++current_cell_number;
2596 if (table->CellHasContRow(current_cell_number) >= 0) {
2597 TeXContTableRows(buf, bparams, os, i + 1,
2598 current_cell_number,
2601 if (is_rtl && !first_in_cell) {
2603 first_in_cell = true;
2606 // if this cell follow only ContRows till end don't
2607 // put the EndOfCell because it is put after the
2609 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2610 --current_cell_number;
2613 int tmp = table->TexEndOfCell(os,
2614 current_cell_number);
2617 } else if (tmp < 0) {
2623 texrow.start(this, i + 1);
2625 SimpleTeXSpecialChars(buf, bparams,
2627 font, running_font, basefont,
2628 open_font, style, i, column, c);
2632 // If we have an open font definition, we have to close it
2634 running_font.latexWriteEndChanges(os, basefont, basefont);
2636 ++current_cell_number;
2637 if (is_rtl && !first_in_cell)
2639 tmp = table->TexEndOfCell(os, current_cell_number);
2640 for (; tmp > 0; --tmp)
2642 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2643 return return_value;
2647 // This one spits out the text off ContRows in tables
2648 bool LyXParagraph::TeXContTableRows(Buffer const * buf,
2649 BufferParams const & bparams,
2651 LyXParagraph::size_type i,
2652 int current_cell_number,
2653 int & column, TexRow & texrow)
2655 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2659 bool return_value = false;
2660 LyXLayout const & style =
2661 textclasslist.Style(bparams.textclass,
2663 LyXFont basefont = getFont(bparams, -1); // Get layout font
2665 // Which font is currently active?
2666 LyXFont running_font = basefont;
2667 // Do we have an open font change?
2668 bool open_font = false;
2670 size_type lastpos = i;
2671 int cell = table->CellHasContRow(current_cell_number);
2672 ++current_cell_number;
2675 // first find the right position
2677 for (; (i < size()) && (current_cell_number<cell); ++i) {
2679 if (c == LyXParagraph::META_NEWLINE)
2680 ++current_cell_number;
2684 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2688 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2693 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2697 // Fully instantiated font
2698 LyXFont font = getFont(bparams, i);
2699 last_font = running_font;
2701 // Spaces at end of font change are simulated to
2702 // be outside font change. i.e. we write
2703 // "\textXX{text} " rather than "\textXX{text }".
2705 if (open_font && c == ' ' && i <= size() - 2
2706 && getFont(bparams, i + 1) != running_font
2707 && getFont(bparams, i + 1) != font) {
2708 font = getFont(bparams, i + 1);
2711 // We end font definition before blanks
2712 if (font != running_font && open_font) {
2713 column += running_font.latexWriteEndChanges(os, basefont, font);
2714 running_font = basefont;
2717 // Blanks are printed before start of fontswitch
2719 SimpleTeXBlanks(os, texrow, i,
2720 column, font, style);
2722 // Do we need to change font?
2723 if (font != running_font) {
2725 font.latexWriteStartChanges(os,
2728 running_font = font;
2731 // Do we need to turn on LaTeX mode?
2732 if (font.latex() != running_font.latex()) {
2733 if (font.latex() == LyXFont::ON
2734 && style.needprotect) {
2739 SimpleTeXSpecialChars(buf, bparams,
2740 os, texrow, false, font,
2741 running_font, basefont,
2742 open_font, style, i, column, c);
2744 // If we have an open font definition, we have to close it
2746 running_font.latexWriteEndChanges(os, basefont,
2750 basefont = getFont(bparams, -1);
2751 running_font = basefont;
2752 cell = table->CellHasContRow(current_cell_number);
2754 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2755 return return_value;
2759 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2761 bool retval = false;
2763 case LyXParagraph::META_HFILL:
2764 sgml_string.erase();
2766 case LyXParagraph::META_NEWLINE:
2770 sgml_string = "&";
2773 sgml_string = "<";
2776 sgml_string = ">";
2779 sgml_string = "$";
2782 sgml_string = "#";
2785 sgml_string = "%";
2788 sgml_string = "[";
2791 sgml_string = "]";
2794 sgml_string = "{";
2797 sgml_string = "}";
2800 sgml_string = "˜";
2803 sgml_string = """;
2806 sgml_string = "\";
2812 case '\0': // Ignore :-)
2813 sgml_string.erase();
2823 void LyXParagraph::SimpleDocBookOneTablePar(Buffer const * buffer,
2824 ostream & os, string & extra,
2825 int & desc_on, int depth)
2827 BufferParams const & bparams = buffer->params;
2829 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2831 LyXFont font1, font2;
2834 size_type main_body;
2835 bool emph_flag = false;
2837 LyXLayout const & style =
2838 textclasslist.Style(bparams.textclass,
2841 if (style.labeltype != LABEL_MANUAL)
2844 main_body = BeginningOfMainBody();
2846 // Gets paragraph main font.
2848 font1 = style.labelfont;
2852 int char_line_count = depth;
2853 os << newlineAndDepth(depth);
2854 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2855 os << "<INFORMALTABLE>"
2856 << newlineAndDepth(++depth);
2858 int current_cell_number = -1;
2859 int tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2861 // Parsing main loop.
2862 for (size_type i = 0; i < size(); ++i) {
2864 if (table->IsContRow(current_cell_number+1)) {
2865 if (c == LyXParagraph::META_NEWLINE)
2866 ++current_cell_number;
2871 // Fully instantiated font
2872 font2 = getFont(bparams, i);
2874 // Handle <emphasis> tag.
2875 if (font1.emph() != font2.emph() && i) {
2876 if (font2.emph() == LyXFont::ON) {
2879 } else if (emph_flag) {
2880 os << "</emphasis>";
2884 if (c == LyXParagraph::META_NEWLINE) {
2885 // We have only to control for emphasis open here!
2887 os << "</emphasis>";
2890 font1 = font2 = getFont(bparams, -1);
2891 ++current_cell_number;
2892 if (table->CellHasContRow(current_cell_number) >= 0) {
2893 DocBookContTableRows(buffer,
2894 os, extra, desc_on, i + 1,
2895 current_cell_number,
2898 // if this cell follow only ContRows till end don't
2899 // put the EndOfCell because it is put after the
2901 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2902 --current_cell_number;
2905 tmp = table->DocBookEndOfCell(os,
2906 current_cell_number,
2911 } else if (c == LyXParagraph::META_INSET) {
2912 inset = GetInset(i);
2914 std::ostringstream ost;
2915 inset->DocBook(buffer, ost);
2916 string tmp_out = ost.str().c_str();
2919 inset->DocBook(buffer, ost);
2921 char * ctmp = ost.str();
2922 string tmp_out(ctmp);
2926 // This code needs some explanation:
2927 // Two insets are treated specially
2928 // label if it is the first element in a
2929 // command paragraph
2931 // graphics inside tables or figure floats
2933 // title (the equivalente in latex for this
2935 // and title should come first
2938 if(desc_on != 3 || i != 0) {
2939 if(tmp_out[0] == '@') {
2941 extra += frontStrip(tmp_out,
2944 os << frontStrip(tmp_out,
2949 } else if (font2.latex() == LyXFont::ON) {
2950 // "TeX"-Mode on == > SGML-Mode on.
2956 if (linuxDocConvertChar(c, sgml_string)
2957 && !style.free_spacing) {
2958 // in freespacing mode, spaces are
2959 // non-breaking characters
2964 << "</term><listitem><para>";
2976 // Needed if there is an optional argument but no contents.
2977 if (main_body > 0 && main_body == size()) {
2982 os << "</emphasis>";
2985 ++current_cell_number;
2986 tmp = table->DocBookEndOfCell(os, current_cell_number, depth);
2987 // Resets description flag correctly.
2990 // <term> not closed...
2994 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2995 os << "</INFORMALTABLE>";
2997 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
3002 void LyXParagraph::DocBookContTableRows(Buffer const * buffer,
3003 ostream & os, string & extra,
3005 LyXParagraph::size_type i,
3006 int current_cell_number, int &column)
3011 BufferParams const & bparams = buffer->params;
3013 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
3018 //string emph = "emphasis";
3019 bool emph_flag = false;
3020 int char_line_count = 0;
3022 LyXLayout const & style =
3023 textclasslist.Style(bparams.textclass,
3026 size_type main_body;
3027 if (style.labeltype != LABEL_MANUAL)
3030 main_body = BeginningOfMainBody();
3032 // Gets paragraph main font.
3035 font1 = style.labelfont;
3039 size_type lastpos = i;
3040 int cell = table->CellHasContRow(current_cell_number);
3041 ++current_cell_number;
3043 // first find the right position
3045 for (; i < size() && current_cell_number < cell; ++i) {
3047 if (c == LyXParagraph::META_NEWLINE)
3048 ++current_cell_number;
3052 // I don't know how to handle this so I comment it
3053 // for the moment (Jug)
3054 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
3055 // file += " \\\\\n";
3058 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
3063 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3067 // Fully instantiated font
3068 font2 = getFont(bparams, i);
3070 // Handle <emphasis> tag.
3071 if (font1.emph() != font2.emph() && i) {
3072 if (font2.emph() == LyXFont::ON) {
3075 } else if (emph_flag) {
3076 os << "</emphasis>";
3080 if (c == LyXParagraph::META_INSET) {
3081 inset = GetInset(i);
3083 std::ostringstream ost;
3084 inset->DocBook(buffer, ost);
3085 string tmp_out = ost.str().c_str();
3088 inset->DocBook(buffer, ost);
3090 char * ctmp = ost.str();
3091 string tmp_out(ctmp);
3095 // This code needs some explanation:
3096 // Two insets are treated specially
3097 // label if it is the first element in a
3098 // command paragraph
3100 // graphics inside tables or figure floats
3101 // can't go on title (the equivalente in
3102 // latex for this case is caption and title
3103 // should come first
3106 if(desc_on != 3 || i != 0) {
3107 if(tmp_out[0] == '@') {
3109 extra += frontStrip(tmp_out, '@');
3111 os << frontStrip(tmp_out, '@');
3115 } else if (font2.latex() == LyXFont::ON) {
3116 // "TeX"-Mode on == > SGML-Mode on.
3122 if (linuxDocConvertChar(c, sgml_string)
3123 && !style.free_spacing) {
3124 // in freespacing mode, spaces are
3125 // non-breaking characters
3130 << "</term><listitem><para>";
3140 // we have only to control for emphasis open here!
3142 os << "</emphasis>";
3145 font1 = font2 = getFont(bparams, -1);
3146 cell = table->CellHasContRow(current_cell_number);
3148 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
3152 void LyXParagraph::SimpleTeXBlanks(ostream & os, TexRow & texrow,
3153 LyXParagraph::size_type const i,
3154 int & column, LyXFont const & font,
3155 LyXLayout const & style)
3157 if (column > tex_code_break_column
3159 && GetChar(i - 1) != ' '
3161 // In LaTeX mode, we don't want to
3162 // break lines since some commands
3164 && ! (font.latex() == LyXFont::ON)
3165 // same in FreeSpacing mode
3166 && !style.free_spacing
3167 // In typewriter mode, we want to avoid
3168 // ! . ? : at the end of a line
3169 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
3170 && (GetChar(i-1) == '.'
3171 || GetChar(i-1) == '?'
3172 || GetChar(i-1) == ':'
3173 || GetChar(i-1) == '!'))) {
3174 if (tex_code_break_column == 0) {
3175 // in batchmode we need LaTeX to still
3176 // see it as a space not as an extra '\n'
3182 texrow.start(this, i + 1);
3184 } else if (font.latex() == LyXFont::OFF) {
3185 if (style.free_spacing) {
3194 void LyXParagraph::SimpleTeXSpecialChars(Buffer const * buf,
3195 BufferParams const & bparams,
3196 ostream & os, TexRow & texrow,
3199 LyXFont & running_font,
3202 LyXLayout const & style,
3203 LyXParagraph::size_type & i,
3204 int & column, char const c)
3206 // Two major modes: LaTeX or plain
3207 // Handle here those cases common to both modes
3208 // and then split to handle the two modes separately.
3210 case LyXParagraph::META_INSET: {
3211 Inset * inset = GetInset(i);
3214 int len = os.tellp();
3215 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
3216 || inset->LyxCode() == Inset::MATH_CODE
3217 || inset->LyxCode() == Inset::URL_CODE)
3218 && running_font.isRightToLeft()) {
3223 int tmp = inset->Latex(buf, os, moving_arg,
3224 style.free_spacing);
3232 column += os.tellp() - len;
3241 case LyXParagraph::META_NEWLINE:
3243 column += running_font.latexWriteEndChanges(os,
3248 basefont = getFont(bparams, -1);
3249 running_font = basefont;
3252 case LyXParagraph::META_HFILL:
3258 // And now for the special cases within each mode
3259 // Are we in LaTeX mode?
3260 if (font.latex() == LyXFont::ON) {
3261 // at present we only have one option
3262 // but I'll leave it as a switch statement
3263 // so its simpler to extend. (ARRae)
3266 // make sure that we will not print
3267 // error generating chars to the tex
3268 // file. This test would not be needed
3269 // if it were done in the buffer
3277 // Plain mode (i.e. not LaTeX)
3280 os << "\\textbackslash{}";
3284 case '°': case '±': case '²': case '³':
3285 case '×': case '÷': case '¹': case 'ª':
3286 case 'º': case '¬': case 'µ':
3287 if (bparams.inputenc == "latin1") {
3288 os << "\\ensuremath{"
3297 case '|': case '<': case '>':
3298 // In T1 encoding, these characters exist
3299 if (lyxrc.fontenc == "T1") {
3301 //... but we should avoid ligatures
3302 if ((c == '>' || c == '<')
3304 && GetChar(i + 1) == c){
3305 os << "\\textcompwordmark{}";
3310 // Typewriter font also has them
3311 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3315 // Otherwise, we use what LaTeX
3319 os << "\\textless{}";
3323 os << "\\textgreater{}";
3327 os << "\\textbar{}";
3333 case '-': // "--" in Typewriter mode -> "-{}-"
3335 && GetChar(i + 1) == '-'
3336 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3345 os << "\\char`\\\"{}";
3350 if (bparams.inputenc == "default") {
3359 case '%': case '#': case '{':
3366 os << "\\textasciitilde{}";
3371 os << "\\textasciicircum{}";
3375 case '*': case '[': case ']':
3376 // avoid being mistaken for optional arguments
3377 os << '{' << c << '}';
3382 // Blanks are printed before font switching.
3383 // Sure? I am not! (try nice-latex)
3384 // I am sure it's correct. LyX might be smarter
3385 // in the future, but for now, nothing wrong is
3390 /* idea for labels --- begin*/
3394 && font.family() != LyXFont::TYPEWRITER_FAMILY
3395 && GetChar(i + 1) == 'y'
3396 && GetChar(i + 2) == 'X') {
3404 && font.family() != LyXFont::TYPEWRITER_FAMILY
3405 && GetChar(i + 1) == 'e'
3406 && GetChar(i + 2) == 'X') {
3411 // Check for "LaTeX2e"
3414 && font.family() != LyXFont::TYPEWRITER_FAMILY
3415 && GetChar(i + 1) == 'a'
3416 && GetChar(i + 2) == 'T'
3417 && GetChar(i + 3) == 'e'
3418 && GetChar(i + 4) == 'X'
3419 && GetChar(i + 5) == '2'
3420 && GetChar(i + 6) == 'e') {
3425 // Check for "LaTeX"
3428 && font.family() != LyXFont::TYPEWRITER_FAMILY
3429 && GetChar(i + 1) == 'a'
3430 && GetChar(i + 2) == 'T'
3431 && GetChar(i + 3) == 'e'
3432 && GetChar(i + 4) == 'X') {
3436 /* idea for labels --- end*/
3437 } else if (c != '\0') {
3448 bool LyXParagraph::RoffContTableRows(ostream & os,
3449 LyXParagraph::size_type i,
3455 LyXFont font1(LyXFont::ALL_INHERIT);
3460 string fname2 = TmpFileName(string(), "RAT2");
3462 int cell = table->CellHasContRow(actcell);
3465 // first find the right position
3467 for (; i < size() && actcell < cell; ++i) {
3469 if (c == LyXParagraph::META_NEWLINE)
3474 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3477 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3479 font2 = GetFontSettings(i);
3480 if (font1.latex() != font2.latex()) {
3481 if (font2.latex() != LyXFont::OFF)
3486 case LyXParagraph::META_INSET:
3487 if ((inset = GetInset(i))) {
3489 stringstream ss(ios::in | ios::out);
3490 inset->Ascii(buffer, ss);
3502 inset->Ascii(buffer, ss);
3516 case LyXParagraph::META_NEWLINE:
3518 case LyXParagraph::META_HFILL:
3527 lyxerr.debug() << "RoffAsciiTable: "
3528 "NULL char in structure."
3533 cell = table->CellHasContRow(actcell);
3540 LyXParagraph * LyXParagraph::TeXDeeper(Buffer const * buf,
3541 BufferParams const & bparams,
3542 ostream & os, TexRow & texrow,
3544 TexRow & foot_texrow,
3547 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3548 LyXParagraph * par = this;
3551 (par->depth == depth) &&
3552 (par->footnoteflag == footnoteflag)) {
3554 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3555 if (textclasslist.Style(bparams.textclass,
3556 par->layout).isEnvironment()
3557 || par->pextra_type != PEXTRA_NONE) {
3558 par = par->TeXEnvironment(buf, bparams,
3563 par = par->TeXOnePar(buf, bparams,
3569 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3575 LyXParagraph * LyXParagraph::TeXEnvironment(Buffer const * buf,
3576 BufferParams const & bparams,
3577 ostream & os, TexRow & texrow,
3579 TexRow & foot_texrow,
3582 bool eindent_open = false;
3583 bool foot_this_level = false;
3584 // flags when footnotetext should be appended to file.
3585 static bool minipage_open = false;
3586 static int minipage_open_depth = 0;
3587 char par_sep = bparams.paragraph_separation;
3589 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3591 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3593 LyXLayout const & style =
3594 textclasslist.Style(bparams.textclass,
3597 if (pextra_type == PEXTRA_INDENT) {
3598 if (!pextra_width.empty()) {
3599 os << "\\begin{LyXParagraphIndent}{"
3600 << pextra_width << "}\n";
3602 //float ib = atof(pextra_widthp.c_str())/100;
3603 // string can't handle floats at present (971109)
3604 // so I'll do a conversion by hand knowing that
3605 // the limits are 0.0 to 1.0. ARRae.
3606 os << "\\begin{LyXParagraphIndent}{";
3607 switch (pextra_widthp.length()) {
3619 os << "\\columnwidth}\n";
3622 eindent_open = true;
3624 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3625 if (pextra_hfill && Previous() &&
3626 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3627 os << "\\hfill{}\n";
3630 if (par_sep == BufferParams::PARSEP_INDENT) {
3631 os << "{\\setlength\\parindent{0pt}\n";
3634 os << "\\begin{minipage}";
3635 switch(pextra_alignment) {
3636 case MINIPAGE_ALIGN_TOP:
3639 case MINIPAGE_ALIGN_MIDDLE:
3642 case MINIPAGE_ALIGN_BOTTOM:
3646 if (!pextra_width.empty()) {
3647 os << '{' << pextra_width << "}\n";
3649 //float ib = atof(par->pextra_width.c_str())/100;
3650 // string can't handle floats at present
3651 // so I'll do a conversion by hand knowing that
3652 // the limits are 0.0 to 1.0. ARRae.
3654 switch (pextra_widthp.length()) {
3666 os << "\\columnwidth}\n";
3669 if (par_sep == BufferParams::PARSEP_INDENT) {
3670 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3673 minipage_open = true;
3674 minipage_open_depth = depth;
3677 #ifdef WITH_WARNINGS
3678 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3679 //I disabled it because it breaks when lists span on several
3682 if (style.isEnvironment()){
3683 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3684 #ifdef FANCY_FOOTNOTE_CODE
3685 if (foot_count < 0) {
3686 // flag that footnote[mark][text] should be
3687 // used for any footnotes from now on
3689 foot_this_level = true;
3692 os << "\\begin{" << style.latexname() << "}{"
3693 << labelwidthstring << "}\n";
3694 } else if (style.labeltype == LABEL_BIBLIO) {
3696 os << "\\begin{" << style.latexname() << "}{"
3697 << bibitemWidest(current_view->painter())
3699 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3700 #ifdef FANCY_FOOTNOTE_CODE
3701 if (foot_count < 0) {
3702 // flag that footnote[mark][text] should be
3703 // used for any footnotes from now on
3705 foot_this_level = true;
3708 os << "\\begin{" << style.latexname() << '}'
3709 << style.latexparam() << '\n';
3711 os << "\\begin{" << style.latexname() << '}'
3712 << style.latexparam() << '\n';
3715 LyXParagraph * par = this;
3717 par = par->TeXOnePar(buf, bparams,
3719 foot, foot_texrow, foot_count);
3721 if (minipage_open && par && !style.isEnvironment() &&
3722 (par->pextra_type == PEXTRA_MINIPAGE) &&
3723 par->pextra_start_minipage) {
3724 os << "\\end{minipage}\n";
3726 if (par_sep == BufferParams::PARSEP_INDENT) {
3730 minipage_open = false;
3732 if (par && par->depth > depth) {
3733 if (textclasslist.Style(bparams.textclass,
3734 par->layout).isParagraph()
3737 // How to handle this? (Lgb)
3738 //&& !suffixIs(os, "\n\n")
3740 // There should be at least one '\n' already
3741 // but we need there to be two for Standard
3742 // paragraphs that are depth-increment'ed to be
3743 // output correctly. However, tables can
3744 // also be paragraphs so don't adjust them.
3747 // Will it ever harm to have one '\n' too
3748 // many? i.e. that we sometimes will have
3749 // three in a row. (Lgb)
3753 par = par->TeXDeeper(buf, bparams, os, texrow,
3754 foot, foot_texrow, foot_count);
3756 if (par && par->layout == layout && par->depth == depth &&
3757 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3758 if (par->pextra_hfill && par->Previous() &&
3759 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3760 os << "\\hfill{}\n";
3763 if (par_sep == BufferParams::PARSEP_INDENT) {
3764 os << "{\\setlength\\parindent{0pt}\n";
3767 os << "\\begin{minipage}";
3768 switch(par->pextra_alignment) {
3769 case MINIPAGE_ALIGN_TOP:
3772 case MINIPAGE_ALIGN_MIDDLE:
3775 case MINIPAGE_ALIGN_BOTTOM:
3779 if (!par->pextra_width.empty()) {
3780 os << '{' << par->pextra_width << "}\n";
3782 //float ib = atof(par->pextra_widthp.c_str())/100;
3783 // string can't handle floats at present
3784 // so I'll do a conversion by hand knowing that
3785 // the limits are 0.0 to 1.0. ARRae.
3787 switch (par->pextra_widthp.length()) {
3792 os << "0." << par->pextra_widthp;
3795 os << "0.0" << par->pextra_widthp;
3797 os << "\\columnwidth}\n";
3800 if (par_sep == BufferParams::PARSEP_INDENT) {
3801 os << "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3804 minipage_open = true;
3805 minipage_open_depth = par->depth;
3808 && par->layout == layout
3809 && par->depth == depth
3810 && par->pextra_type == pextra_type
3811 && par->footnoteflag == footnoteflag);
3813 if (style.isEnvironment()) {
3814 os << "\\end{" << style.latexname() << '}';
3815 // maybe this should go after the minipage closes?
3816 if (foot_this_level) {
3817 if (foot_count >= 1) {
3818 if (foot_count > 1) {
3819 os << "\\addtocounter{footnote}{-"
3824 texrow += foot_texrow;
3826 foot_texrow.reset();
3831 if (minipage_open && (minipage_open_depth == depth) &&
3832 (!par || par->pextra_start_minipage ||
3833 par->pextra_type != PEXTRA_MINIPAGE)) {
3834 os << "\\end{minipage}\n";
3836 if (par_sep == BufferParams::PARSEP_INDENT) {
3840 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3841 os << "\\medskip\n\n";
3845 minipage_open = false;
3848 os << "\\end{LyXParagraphIndent}\n";
3851 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3852 && par->pextra_hfill)) {
3856 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3857 return par; // ale970302
3861 LyXParagraph * LyXParagraph::TeXFootnote(Buffer const * buf,
3862 BufferParams const & bparams,
3863 ostream & os, TexRow & texrow,
3864 ostream & foot, TexRow & foot_texrow,
3868 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3869 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3870 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3871 "No footnote!" << endl;
3873 LyXParagraph * par = this;
3874 LyXLayout const & style =
3875 textclasslist.Style(bparams.textclass,
3876 previous->GetLayout());
3878 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3879 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3880 "Float other than footnote in command"
3881 " with moving argument is illegal" << endl;
3884 if (footnotekind != LyXParagraph::FOOTNOTE
3885 && footnotekind != LyXParagraph::MARGIN
3888 // How to solve this?
3889 //&& !suffixIs(file, '\n')
3891 // we need to ensure that real floats like tables and figures
3892 // have their \begin{} on a new line otherwise we can get
3893 // incorrect results when using the endfloat.sty package
3894 // especially if two floats follow one another. ARRae 981022
3895 // NOTE: if the file is length 0 it must have just been
3896 // written out so we assume it ended with a '\n'
3898 // As far as I can see there is never any harm in writing
3899 // a '\n' too much. Please tell me if I am wrong. (Lgb)
3904 bool moving_arg = false;
3905 bool need_closing = false;
3906 bool is_rtl = isRightToLeftPar(bparams);
3908 if (is_rtl != parent_is_rtl) {
3913 need_closing = true;
3916 //BufferParams * params = ¤t_view->buffer()->params;
3917 bool footer_in_body = true;
3918 switch (footnotekind) {
3919 case LyXParagraph::FOOTNOTE:
3920 if (style.intitle) {
3921 os << "\\thanks{\n";
3922 footer_in_body = false;
3925 if (foot_count == -1) {
3926 // we're at depth 0 so we can use:
3927 os << "\\footnote{%\n";
3928 footer_in_body = false;
3930 os << "\\footnotemark{}%\n";
3932 // we only need this when there are
3933 // multiple footnotes
3934 os << "\\stepcounter{footnote}";
3936 os << "\\footnotetext{%\n";
3937 foot_texrow.start(this, 0);
3938 foot_texrow.newline();
3943 case LyXParagraph::MARGIN:
3944 os << "\\marginpar{\n";
3946 case LyXParagraph::FIG:
3947 if (pextra_type == PEXTRA_FLOATFLT
3948 && (!pextra_width.empty()
3949 || !pextra_widthp.empty())) {
3950 if (!pextra_width.empty())
3951 os << "\\begin{floatingfigure}{"
3952 << pextra_width << "}\n";
3954 os << "\\begin{floatingfigure}{"
3955 << atoi(pextra_widthp.c_str())/100.0
3956 << "\\textwidth}\n";
3958 os << "\\begin{figure}";
3959 if (!bparams.float_placement.empty()) {
3960 os << '[' << bparams.float_placement << "]\n";
3966 case LyXParagraph::TAB:
3967 os << "\\begin{table}";
3968 if (!bparams.float_placement.empty()) {
3969 os << '[' << bparams.float_placement << "]\n";
3974 case LyXParagraph::WIDE_FIG:
3975 os << "\\begin{figure*}";
3976 if (!bparams.float_placement.empty()) {
3977 os << '[' << bparams.float_placement << "]\n";
3982 case LyXParagraph::WIDE_TAB:
3983 os << "\\begin{table*}";
3984 if (!bparams.float_placement.empty()) {
3985 os << '[' << bparams.float_placement << "]\n";
3990 case LyXParagraph::ALGORITHM:
3991 os << "\\begin{algorithm}\n";
3996 if (footnotekind != LyXParagraph::FOOTNOTE
3997 || !footer_in_body) {
3998 // Process text for all floats except footnotes in body
4000 LyXLayout const & style =
4002 .Style(bparams.textclass, par->layout);
4004 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4006 if (style.isEnvironment()
4007 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4008 // Allows the use of minipages within float
4009 // environments. Shouldn't be circular because
4010 // we don't support footnotes inside
4011 // floats (yet). ARRae
4012 par = par->TeXEnvironment(buf, bparams, os,
4017 par = par->TeXOnePar(buf, bparams,
4018 os, texrow, moving_arg,
4023 if (par && !par->IsDummy() && par->depth > depth) {
4024 par = par->TeXDeeper(buf, bparams, os, texrow,
4028 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4030 // process footnotes > depth 0 or in environments separately
4031 // NOTE: Currently don't support footnotes within footnotes
4032 // even though that is possible using the \footnotemark
4034 std::ostringstream dummy;
4038 TexRow dummy_texrow;
4039 int dummy_count = 0;
4041 LyXLayout const & style =
4043 .Style(bparams.textclass, par->layout);
4045 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
4047 if (style.isEnvironment()
4048 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
4049 // Allows the use of minipages within float
4050 // environments. Shouldn't be circular because
4051 // we don't support footnotes inside
4052 // floats (yet). ARRae
4053 par = par->TeXEnvironment(buf, bparams,
4055 dummy, dummy_texrow,
4058 par = par->TeXOnePar(buf, bparams,
4061 dummy, dummy_texrow,
4065 if (par && !par->IsDummy() && par->depth > depth) {
4066 par = par->TeXDeeper(buf, bparams,
4068 dummy, dummy_texrow,
4072 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4074 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
4075 "Footnote in a Footnote -- not supported"
4078 #ifndef HAVE_OSTREAM
4079 delete [] dummy.str();
4083 switch (footnotekind) {
4084 case LyXParagraph::FOOTNOTE:
4085 if (footer_in_body) {
4086 // This helps tell which of the multiple
4087 // footnotetexts an error was in.
4089 foot_texrow.newline();
4094 case LyXParagraph::MARGIN:
4097 case LyXParagraph::FIG:
4098 if (pextra_type == PEXTRA_FLOATFLT
4099 && (!pextra_width.empty()
4100 || !pextra_widthp.empty()))
4101 os << "\\end{floatingfigure}";
4103 os << "\\end{figure}";
4105 case LyXParagraph::TAB:
4106 os << "\\end{table}";
4108 case LyXParagraph::WIDE_FIG:
4109 os << "\\end{figure*}";
4111 case LyXParagraph::WIDE_TAB:
4112 os << "\\end{table*}";
4114 case LyXParagraph::ALGORITHM:
4115 os << "\\end{algorithm}";
4122 if (footnotekind != LyXParagraph::FOOTNOTE
4123 && footnotekind != LyXParagraph::MARGIN) {
4124 // we need to ensure that real floats like tables and figures
4125 // have their \end{} on a line of their own otherwise we can
4126 // get incorrect results when using the endfloat.sty package.
4131 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
4136 bool LyXParagraph::IsDummy() const
4138 return (footnoteflag == LyXParagraph::NO_FOOTNOTE && previous
4139 && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE);
4143 void LyXParagraph::SetPExtraType(BufferParams const & bparams,
4144 int type, char const * width,
4145 char const * widthp)
4148 pextra_width = width;
4149 pextra_widthp = widthp;
4151 if (textclasslist.Style(bparams.textclass,
4152 layout).isEnvironment()) {
4157 while (par && (par->layout == layout)
4158 && (par->depth == depth)) {
4160 par = par->Previous();
4162 par = par->FirstPhysicalPar();
4163 while (par && par->depth > depth) {
4164 par = par->Previous();
4166 par = par->FirstPhysicalPar();
4170 while (par && (par->layout == layout)
4171 && (par->depth == depth)) {
4172 par->pextra_type = type;
4173 par->pextra_width = width;
4174 par->pextra_widthp = widthp;
4175 par = par->NextAfterFootnote();
4176 if (par && (par->depth > depth))
4177 par->SetPExtraType(bparams,
4178 type, width, widthp);
4179 while (par && ((par->depth > depth) || par->IsDummy()))
4180 par = par->NextAfterFootnote();
4186 void LyXParagraph::UnsetPExtraType(BufferParams const & bparams)
4188 if (pextra_type == PEXTRA_NONE)
4191 pextra_type = PEXTRA_NONE;
4192 pextra_width.erase();
4193 pextra_widthp.erase();
4195 if (textclasslist.Style(bparams.textclass,
4196 layout).isEnvironment()) {
4201 while (par && (par->layout == layout)
4202 && (par->depth == depth)) {
4204 par = par->Previous();
4206 par = par->FirstPhysicalPar();
4207 while (par && par->depth > depth) {
4208 par = par->Previous();
4210 par = par->FirstPhysicalPar();
4214 while (par && (par->layout == layout)
4215 && (par->depth == depth)) {
4216 par->pextra_type = PEXTRA_NONE;
4217 par->pextra_width.erase();
4218 par->pextra_widthp.erase();
4219 par = par->NextAfterFootnote();
4220 if (par && (par->depth > depth))
4221 par->UnsetPExtraType(bparams);
4222 while (par && ((par->depth > depth) || par->IsDummy()))
4223 par = par->NextAfterFootnote();
4229 bool LyXParagraph::IsHfill(size_type pos) const
4231 return IsHfillChar(GetChar(pos));
4235 bool LyXParagraph::IsInset(size_type pos) const
4237 return IsInsetChar(GetChar(pos));
4241 bool LyXParagraph::IsFloat(size_type pos) const
4243 return IsFloatChar(GetChar(pos));
4247 bool LyXParagraph::IsNewline(size_type pos) const
4249 return pos >= 0 && IsNewlineChar(GetChar(pos));
4253 bool LyXParagraph::IsSeparator(size_type pos) const
4255 return IsSeparatorChar(GetChar(pos));
4259 bool LyXParagraph::IsLineSeparator(size_type pos) const
4261 return IsLineSeparatorChar(GetChar(pos));
4265 bool LyXParagraph::IsKomma(size_type pos) const
4267 return IsKommaChar(GetChar(pos));
4271 /// Used by the spellchecker
4272 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
4274 unsigned char c = GetChar(pos);
4275 if (IsLetterChar(c))
4277 // '\0' is not a letter, allthough every string contains "" (below)
4280 // We want to pass the ' and escape chars to ispell
4281 string extra = lyxrc.isp_esc_chars + '\'';
4285 return contains(extra, ch);
4289 bool LyXParagraph::IsWord(size_type pos ) const
4291 return IsWordChar(GetChar(pos)) ;
4296 LyXParagraph::getParLanguage(BufferParams const & bparams) const
4299 return FirstPhysicalPar()->getParLanguage(bparams);
4300 else if (size() > 0)
4304 return GetFirstFontSettings().language();
4307 for (size_type pos = 0; pos < size(); ++pos)
4309 return GetFontSettings(bparams, pos).language();
4310 return GetFirstFontSettings().language();
4314 return previous->getParLanguage(bparams);
4316 return bparams.language_info;
4320 bool LyXParagraph::isRightToLeftPar(BufferParams const & bparams) const
4322 return lyxrc.rtl_support && !table
4323 && getParLanguage(bparams)->RightToLeft();
4327 void LyXParagraph::ChangeLanguage(BufferParams const & bparams,
4328 Language const * from, Language const * to)
4330 for(size_type i = 0; i < size(); ++i) {
4331 LyXFont font = GetFontSettings(bparams, i);
4332 if (font.language() == from) {
4333 font.setLanguage(to);
4340 bool LyXParagraph::isMultiLingual(BufferParams const & bparams)
4342 Language const * doc_language =
4343 bparams.language_info;
4344 for(size_type i = 0; i < size(); ++i) {
4345 LyXFont font = GetFontSettings(bparams, i);
4346 if (font.language() != doc_language)
4353 // Convert the paragraph to a string.
4354 // Used for building the table of contents
4355 string LyXParagraph::String(Buffer const * buffer, bool label)
4357 BufferParams const & bparams = buffer->params;
4359 if (label && !IsDummy() && !labelstring.empty())
4360 s += labelstring + ' ';
4361 string::size_type len = s.size();
4363 for (LyXParagraph::size_type i = 0; i < size(); ++i) {
4364 unsigned char c = GetChar(i);
4367 else if (c == META_INSET &&
4368 GetInset(i)->LyxCode() == Inset::MATH_CODE) {
4370 std::ostringstream ost;
4371 GetInset(i)->Ascii(buffer, ost);
4374 GetInset(i)->Ascii(buffer, ost);
4377 s += subst(ost.str(),'\n',' ');
4381 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE
4382 && footnoteflag == LyXParagraph::NO_FOOTNOTE)
4383 s += NextAfterFootnote()->String(buffer, false);
4386 if (isRightToLeftPar(bparams))
4387 reverse(s.begin() + len,s.end());
4393 string LyXParagraph::String(Buffer const * buffer,
4394 LyXParagraph::size_type beg,
4395 LyXParagraph::size_type end)
4402 for (LyXParagraph::size_type i = 0; i < beg; ++i)
4404 if (cell >= table->NumberOfCellsInRow(actcell))
4412 if (beg == 0 && !IsDummy() && !labelstring.empty())
4413 s += labelstring + ' ';
4415 for (LyXParagraph::size_type i = beg; i < end; ++i) {
4416 unsigned char c = GetChar(i);
4419 else if (c == META_INSET) {
4421 std::ostringstream ost;
4422 GetInset(i)->Ascii(buffer, ost);
4425 GetInset(i)->Ascii(buffer, ost);
4429 } else if (table && IsNewlineChar(c)) {
4430 if (cell >= table->NumberOfCellsInRow(actcell)) {
4441 //if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
4442 // s += NextAfterFootnote()->String(false);