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"
21 #include "lyxparagraph.h"
22 #include "support/textutils.h"
25 #include "tex-strings.h"
26 #include "bufferparams.h"
27 #include "support/FileInfo.h"
28 #include "support/LAssert.h"
30 #include "LaTeXFeatures.h"
31 #include "insets/insetinclude.h"
32 #include "support/filetools.h"
33 #include "lyx_gui_misc.h"
37 extern void addNewlineAndDepth(string & file, int const depth); // Jug 990923
38 int tex_code_break_column = 72; // needs non-zero initialization. set later.
39 // this is a bad idea, but how can LyXParagraph find its buffer to get
40 // parameters? (JMarc)
41 extern BufferView * current_view;
46 extern string bibitemWidthest();
48 // this is a minibuffer
49 static char minibuffer_char;
50 static LyXFont minibuffer_font;
51 static Inset * minibuffer_inset;
54 // Initialization of the counter for the paragraph id's,
55 // declared in lyxparagraph.h
56 unsigned int LyXParagraph::paragraph_id = 0;
59 LyXParagraph::LyXParagraph()
61 text.reserve(500); // is this number too big?
63 for (int i = 0; i < 10; ++i) setCounter(i , 0);
69 footnoteflag = LyXParagraph::NO_FOOTNOTE;
70 footnotekind = LyXParagraph::FOOTNOTE; // should not be needed
72 align = LYX_ALIGN_BLOCK;
74 /* table stuff -- begin*/
76 /* table stuff -- end*/
78 bibkey = 0; // ale970302
83 // This konstruktor inserts the new paragraph in a list.
84 LyXParagraph::LyXParagraph(LyXParagraph * par)
87 par->text.resize(par->text.size());
89 for (int i = 0; i < 10; ++i) setCounter(i, 0);
93 // double linked list begin
96 next->previous = this;
98 previous->next = this;
100 footnoteflag = LyXParagraph::NO_FOOTNOTE;
101 footnotekind = LyXParagraph::FOOTNOTE;
103 /* table stuff -- begin*/
105 /* table stuff -- end*/
106 id_ = paragraph_id++;
108 bibkey = 0; // ale970302
114 void LyXParagraph::writeFile(ostream & os, BufferParams & params,
115 char footflag, char dth)
117 LyXFont font1, font2;
123 if (footnoteflag != LyXParagraph::NO_FOOTNOTE
125 || previous->footnoteflag == LyXParagraph::NO_FOOTNOTE){
127 // The beginning or the end of a footnote environment?
128 if (footflag != footnoteflag) {
129 footflag = footnoteflag;
131 os << "\n\\begin_float "
132 << string_footnotekinds[footnotekind]
135 os << "\n\\end_float ";
139 // The beginning or end of a deeper (i.e. nested) area?
142 while (depth > dth) {
143 os << "\n\\begin_deeper ";
147 while (depth < dth) {
148 os << "\n\\end_deeper ";
154 // First write the layout
156 << textclasslist.NameOfLayout(params.textclass, layout)
159 // Maybe some vertical spaces.
160 if (added_space_top.kind() != VSpace::NONE)
161 os << "\\added_space_top "
162 << added_space_top.asLyXCommand() << " ";
163 if (added_space_bottom.kind() != VSpace::NONE)
164 os << "\\added_space_bottom "
165 << added_space_bottom.asLyXCommand() << " ";
167 // The labelwidth string used in lists.
168 if (!labelwidthstring.empty())
169 os << "\\labelwidthstring "
170 << labelwidthstring << '\n';
172 // Lines above or below?
176 os << "\\line_bottom ";
178 // Pagebreaks above or below?
180 os << "\\pagebreak_top ";
181 if (pagebreak_bottom)
182 os << "\\pagebreak_bottom ";
184 // Start of appendix?
185 if (start_of_appendix)
186 os << "\\start_of_appendix ";
193 if (align != LYX_ALIGN_LAYOUT) {
195 case LYX_ALIGN_LEFT: h = 1; break;
196 case LYX_ALIGN_RIGHT: h = 2; break;
197 case LYX_ALIGN_CENTER: h = 3; break;
198 default: h = 0; break;
200 os << "\\align " << string_align[h] << " ";
202 if (pextra_type != PEXTRA_NONE) {
203 os << "\\pextra_type " << pextra_type;
204 if (pextra_type == PEXTRA_MINIPAGE) {
205 os << " \\pextra_alignment "
208 os << " \\pextra_hfill "
210 if (pextra_start_minipage)
211 os << " \\pextra_start_minipage "
212 << pextra_start_minipage;
214 if (!pextra_width.empty()) {
215 os << " \\pextra_width "
216 << VSpace(pextra_width).asLyXCommand();
217 } else if (!pextra_widthp.empty()) {
218 os << " \\pextra_widthp "
224 // Dummy layout. This means that a footnote ended.
225 os << "\n\\end_float ";
226 footflag = LyXParagraph::NO_FOOTNOTE;
229 // It might be a table.
231 os << "\\LyXTable\n";
239 font1 = LyXFont(LyXFont::ALL_INHERIT);
242 for (size_type i = 0; i < size(); ++i) {
248 // Write font changes
249 font2 = GetFontSettings(i);
250 if (font2 != font1) {
251 font2.lyxWriteChanges(font1, os);
261 if (inset->DirectWrite()) {
262 // international char, let it write
263 // code directly so it's shorter in
267 os << "\n\\begin_inset ";
269 os << "\n\\end_inset \n\n";
274 os << "\n\\newline \n";
278 os << "\n\\hfill \n";
281 case META_PROTECTED_SEPARATOR:
282 os << "\n\\protected_separator \n";
286 os << "\n\\backslash \n";
290 if (i + 1 < size() && GetChar(i + 1) == ' ') {
297 if ((column > 70 && c == ' ')
302 // this check is to amend a bug. LyX sometimes
303 // inserts '\0' this could cause problems.
307 lyxerr << "ERROR (LyXParagraph::writeFile):"
308 " NULL char in structure." << endl;
314 // now write the next paragraph
316 next->writeFile(os, params, footflag, dth);
320 void LyXParagraph::validate(LaTeXFeatures & features) const
322 // this will be useful later
323 LyXLayout const & layout =
324 textclasslist.Style(current_view->buffer()->params.textclass,
328 if (line_top || line_bottom)
329 features.lyxline = true;
332 features.layout[GetLayout()] = true;
335 for (FontList::const_iterator cit = fontlist.begin();
336 cit != fontlist.end(); ++cit) {
337 if ((*cit).font.noun() == LyXFont::ON) {
338 lyxerr[Debug::LATEX] << "font.noun: "
339 << (*cit).font.noun()
341 features.noun = true;
342 lyxerr[Debug::LATEX] << "Noun enabled. Font: "
343 << (*cit).font.stateText()
346 switch ((*cit).font.color()) {
348 case LyXFont::INHERIT_COLOR:
349 case LyXFont::IGNORE_COLOR:
352 features.color = true;
353 lyxerr[Debug::LATEX] << "Color enabled. Font: "
354 << (*cit).font.stateText()
360 for (InsetList::const_iterator cit = insetlist.begin();
361 cit != insetlist.end(); ++cit) {
363 (*cit).inset->Validate(features);
366 if (table && table->IsLongTable())
367 features.longtable = true;
368 if (pextra_type == PEXTRA_INDENT)
369 features.LyXParagraphIndent = true;
370 if (pextra_type == PEXTRA_FLOATFLT)
371 features.floatflt = true;
372 if (layout.needprotect
373 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
374 features.NeedLyXFootnoteCode = true;
375 if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) &&
376 (pextra_type == LyXParagraph::PEXTRA_MINIPAGE))
377 features.NeedLyXMinipageIndent = true;
378 if (table && table->NeedRotating())
379 features.rotating = true;
380 if (footnoteflag != NO_FOOTNOTE && footnotekind == ALGORITHM)
381 features.algorithm = true;
385 // First few functions needed for cut and paste and paragraph breaking.
386 void LyXParagraph::CopyIntoMinibuffer(LyXParagraph::size_type pos) const
388 minibuffer_char = GetChar(pos);
389 minibuffer_font = GetFontSettings(pos);
390 minibuffer_inset = 0;
391 if (minibuffer_char == LyXParagraph::META_INSET) {
393 minibuffer_inset = GetInset(pos)->Clone();
395 minibuffer_inset = 0;
396 minibuffer_char = ' ';
397 // This reflects what GetInset() does (ARRae)
403 void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos)
405 minibuffer_char = GetChar(pos);
406 minibuffer_font = GetFontSettings(pos);
407 minibuffer_inset = 0;
408 if (minibuffer_char == LyXParagraph::META_INSET) {
410 minibuffer_inset = GetInset(pos);
411 // This is a little hack since I want exactly
412 // the inset, not just a clone. Otherwise
413 // the inset would be deleted when calling Erase(pos)
415 for (InsetList::iterator it = insetlist.begin();
416 it != insetlist.end(); ++it) {
417 if ((*it).pos == pos) {
424 minibuffer_inset = 0;
425 minibuffer_char = ' ';
426 // This reflects what GetInset() does (ARRae)
431 // Erase(pos); now the caller is responsible for that.
435 void LyXParagraph::InsertFromMinibuffer(LyXParagraph::size_type pos)
437 InsertChar(pos, minibuffer_char);
438 SetFont(pos, minibuffer_font);
439 if (minibuffer_char == LyXParagraph::META_INSET)
440 InsertInset(pos, minibuffer_inset);
447 void LyXParagraph::Clear()
452 pagebreak_top = false;
453 pagebreak_bottom = false;
455 added_space_top = VSpace(VSpace::NONE);
456 added_space_bottom = VSpace(VSpace::NONE);
458 align = LYX_ALIGN_LAYOUT;
462 pextra_type = PEXTRA_NONE;
463 pextra_width.clear();
464 pextra_widthp.clear();
465 pextra_alignment = MINIPAGE_ALIGN_TOP;
466 pextra_hfill = false;
467 pextra_start_minipage = false;
470 labelwidthstring.clear();
474 start_of_appendix = false;
478 // the destructor removes the new paragraph from the list
479 LyXParagraph::~LyXParagraph()
482 previous->next = next;
484 next->previous = previous;
486 for (InsetList::iterator it = insetlist.begin();
487 it != insetlist.end(); ++it) {
491 /* table stuff -- begin*/
493 /* table stuff -- end*/
500 void LyXParagraph::Erase(LyXParagraph::size_type pos)
502 // > because last is the next unused position, and you can
503 // use it if you want
505 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
506 NextAfterFootnote()->Erase(pos - text.size() - 1);
508 lyxerr.debug() << "ERROR (LyXParagraph::Erase): "
509 "position does not exist." << endl;
512 if (pos < size()) { // last is free for insertation, but should be empty
513 // if it is an inset, delete the inset entry
514 if (text[pos] == LyXParagraph::META_INSET) {
516 for (InsetList::iterator it = insetlist.begin();
517 it != insetlist.end(); ++it) {
518 if ((*it).pos == pos) {
525 text.erase(text.begin() + pos);
526 // Erase entries in the tables.
527 for (FontList::iterator it = fontlist.begin();
528 it != fontlist.end(); ++it) {
529 if (pos >= (*it).pos && pos <= (*it).pos_end) {
530 if ((*it).pos == (*it).pos_end) {
531 // If it is a multi-character font
532 // entry, we just make it smaller
533 // (see update below), otherwise we
540 // Update all other entries.
541 for (FontList::iterator it = fontlist.begin();
542 it != fontlist.end(); ++it) {
545 if ((*it).pos_end >= pos)
549 // Update the inset table.
550 for (InsetList::iterator it = insetlist.begin();
551 it != insetlist.end(); ++it) {
556 lyxerr << "ERROR (LyXParagraph::Erase): "
557 "can't erase non-existant char." << endl;
562 void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c)
564 // > because last is the next unused position, and you can
565 // use it if you want
568 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
569 NextAfterFootnote()->InsertChar(pos - text.size() - 1,
572 lyxerr.debug() << "ERROR (LyXParagraph::InsertChar): "
573 "position does not exist." << endl;
576 text.insert(text.begin() + pos, c);
577 // Update the font table.
578 for (FontList::iterator it = fontlist.begin();
579 it != fontlist.end(); ++it) {
580 if ((*it).pos >= pos)
582 if ((*it).pos_end >= pos)
586 // Update the inset table.
587 for (InsetList::iterator it = insetlist.begin();
588 it != insetlist.end(); ++it) {
589 if ((*it).pos >= pos)
595 void LyXParagraph::InsertInset(LyXParagraph::size_type pos,
598 // > because last is the next unused position, and you can
599 // use it if you want
602 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
604 ->InsertInset(pos - text.size() - 1, inset);
606 lyxerr << "ERROR (LyXParagraph::InsertInset): "
607 "position does not exist: " << pos << endl;
610 if (text[pos] != LyXParagraph::META_INSET) {
611 lyxerr << "ERROR (LyXParagraph::InsertInset): "
612 "there is no LyXParagraph::META_INSET" << endl;
617 // Add a new entry in the inset table.
618 InsetList::iterator it =
619 insetlist.insert(insetlist.begin(), InsetTable());
626 Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos)
630 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
631 return NextAfterFootnote()
632 ->GetInset(pos - text.size() - 1);
634 lyxerr << "ERROR (LyXParagraph::GetInset): "
635 "position does not exist: "
641 for (InsetList::iterator it = insetlist.begin();
642 it != insetlist.end(); ++it) {
643 if ((*it).pos == pos) {
647 lyxerr << "ERROR (LyXParagraph::GetInset): "
648 "Inset does not exist: " << pos << endl;
649 text[pos] = ' '; // WHY!!! does this set the pos to ' '????
650 // Did this commenting out introduce a bug? So far I have not
651 // see any, please enlighten me. (Lgb)
652 // My guess is that since the inset does not exist, we might
653 // as well replace it with a space to prevent craches. (Asger)
658 Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const
662 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
663 return NextAfterFootnote()
664 ->GetInset(pos - text.size() - 1);
666 lyxerr << "ERROR (LyXParagraph::GetInset): "
667 "position does not exist: "
673 for (InsetList::const_iterator cit = insetlist.begin();
674 cit != insetlist.end(); ++cit) {
675 if ((*cit).pos == pos) {
679 lyxerr << "ERROR (LyXParagraph::GetInset): "
680 "Inset does not exist: " << pos << endl;
681 //text[pos] = ' '; // WHY!!! does this set the pos to ' '????
682 // Did this commenting out introduce a bug? So far I have not
683 // see any, please enlighten me. (Lgb)
684 // My guess is that since the inset does not exist, we might
685 // as well replace it with a space to prevent craches. (Asger)
690 // Gets uninstantiated font setting at position.
691 // Optimized after profiling. (Asger)
692 LyXFont LyXParagraph::GetFontSettings(LyXParagraph::size_type pos) const
695 for (FontList::const_iterator cit = fontlist.begin();
696 cit != fontlist.end(); ++cit) {
697 if (pos >= (*cit).pos && pos <= (*cit).pos_end)
701 // > because last is the next unused position, and you can
702 // use it if you want
703 else if (pos > size()) {
705 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
706 return NextAfterFootnote()
707 ->GetFontSettings(pos - text.size() - 1);
709 // Why is it an error to ask for the font of a
710 // position that does not exist? Would it be
711 // enough for this to be enabled on debug?
712 // We want strict error checking, but it's ok to only
713 // have it when debugging. (Asger)
714 lyxerr << "ERROR (LyXParagraph::GetFontSettings): "
715 "position does not exist. "
716 << pos << " (" << static_cast<int>(pos)
720 return GetFontSettings(pos - 1);
722 return LyXFont(LyXFont::ALL_INHERIT);
726 // Gets the fully instantiated font at a given position in a paragraph
727 // This is basically the same function as LyXText::GetFont() in text2.C.
728 // The difference is that this one is used for generating the LaTeX file,
729 // and thus cosmetic "improvements" are disallowed: This has to deliver
730 // the true picture of the buffer. (Asger)
731 // If position is -1, we get the layout font of the paragraph.
732 // If position is -2, we get the font of the manual label of the paragraph.
733 LyXFont LyXParagraph::getFont(LyXParagraph::size_type pos) const
736 LyXLayout const & layout =
737 textclasslist.Style(current_view->buffer()->params.textclass,
739 LyXParagraph::size_type main_body = 0;
740 if (layout.labeltype == LABEL_MANUAL)
741 main_body = BeginningOfMainBody();
746 layoutfont = layout.labelfont;
748 layoutfont = layout.font;
749 tmpfont = GetFontSettings(pos);
750 tmpfont.realize(layoutfont);
752 // process layoutfont for pos == -1 and labelfont for pos < -1
754 tmpfont = layout.font;
756 tmpfont = layout.labelfont;
757 if (getParDirection() == LYX_DIR_RIGHT_TO_LEFT)
758 tmpfont.setDirection(LyXFont::RTL_DIR);
761 // check for environment font information
762 char par_depth = GetDepth();
763 LyXParagraph const * par = this;
764 while (par && par_depth && !tmpfont.resolved()) {
765 par = par->DepthHook(par_depth - 1);
767 tmpfont.realize(textclasslist.
768 Style(current_view->buffer()->params.textclass,
769 par->GetLayout()).font);
770 par_depth = par->GetDepth();
774 tmpfont.realize(textclasslist
775 .TextClass(current_view->buffer()->params.textclass)
781 /// Returns the height of the highest font in range
783 LyXParagraph::HighestFontInRange(LyXParagraph::size_type startpos,
784 LyXParagraph::size_type endpos) const
786 LyXFont::FONT_SIZE maxsize = LyXFont::SIZE_TINY;
787 for (FontList::const_iterator cit = fontlist.begin();
788 cit != fontlist.end(); ++cit) {
789 if (startpos <= (*cit).pos_end && endpos >= (*cit).pos) {
790 LyXFont::FONT_SIZE size = (*cit).font.size();
791 if (size > maxsize && size <= LyXFont::SIZE_HUGER)
799 char LyXParagraph::GetChar(LyXParagraph::size_type pos)
806 // > because last is the next unused position, and you can
807 // use it if you want
808 else if (pos > size()) {
809 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
810 return NextAfterFootnote()
811 ->GetChar(pos - text.size() - 1);
813 lyxerr << "ERROR (LyXParagraph::GetChar): "
814 "position does not exist."
815 << pos << " (" << static_cast<int>(pos)
817 // Assert(false); // This triggers sometimes...
822 // We should have a footnote environment.
823 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
824 // Notice that LyX does request the
825 // last char from time to time. (Asger)
826 //lyxerr << "ERROR (LyXParagraph::GetChar): "
827 // "expected footnote." << endl;
830 switch (next->footnotekind) {
831 case LyXParagraph::FOOTNOTE:
832 return LyXParagraph::META_FOOTNOTE;
833 case LyXParagraph::MARGIN:
834 return LyXParagraph::META_MARGIN;
835 case LyXParagraph::FIG:
836 case LyXParagraph::WIDE_FIG:
837 return LyXParagraph::META_FIG;
838 case LyXParagraph::TAB:
839 case LyXParagraph::WIDE_TAB:
840 return LyXParagraph::META_TAB;
841 case LyXParagraph::ALGORITHM:
842 return LyXParagraph::META_ALGORITHM;
844 return '\0'; // to shut up gcc
849 char LyXParagraph::GetChar(LyXParagraph::size_type pos) const
856 // > because last is the next unused position, and you can
857 // use it if you want
858 else if (pos > size()) {
859 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
860 return NextAfterFootnote()
861 ->GetChar(pos - text.size() - 1);
863 lyxerr << "ERROR (LyXParagraph::GetChar const): "
864 "position does not exist."
865 << pos << " (" << static_cast<int>(pos)
871 // We should have a footnote environment.
872 if (!next || next->footnoteflag == LyXParagraph::NO_FOOTNOTE) {
873 // Notice that LyX does request the
874 // last char from time to time. (Asger)
875 //lyxerr << "ERROR (LyXParagraph::GetChar): "
876 // "expected footnote." << endl;
879 switch (next->footnotekind) {
880 case LyXParagraph::FOOTNOTE:
881 return LyXParagraph::META_FOOTNOTE;
882 case LyXParagraph::MARGIN:
883 return LyXParagraph::META_MARGIN;
884 case LyXParagraph::FIG:
885 case LyXParagraph::WIDE_FIG:
886 return LyXParagraph::META_FIG;
887 case LyXParagraph::TAB:
888 case LyXParagraph::WIDE_TAB:
889 return LyXParagraph::META_TAB;
890 case LyXParagraph::ALGORITHM:
891 return LyXParagraph::META_ALGORITHM;
893 return '\0'; // to shut up gcc
898 // return an string of the current word, and the end of the word in lastpos.
899 string LyXParagraph::GetWord(LyXParagraph::size_type & lastpos) const
903 // the current word is defined as starting at the first character
904 // from the immediate left of lastpospos which meets the definition
905 // of IsLetter(), continuing to the last character to the right
906 // of this meeting IsLetter.
912 // move back until we have a letter
914 //there's no real reason to have firstpos & lastpos as
915 //separate variables as this is written, but maybe someon
916 // will want to return firstpos in the future.
918 //since someone might have typed a punctuation first
919 int firstpos = lastpos;
921 while ((firstpos >= 0) && !IsLetter(firstpos))
924 // now find the beginning by looking for a nonletter
926 while ((firstpos>= 0) && IsLetter(firstpos))
929 // the above is now pointing to the preceeding non-letter
933 // so copy characters into theword until we get a nonletter
934 // note that this can easily exceed lastpos, wich means
935 // that if used in the middle of a word, the whole word
938 while (IsLetter(lastpos)) theword += GetChar(lastpos++);
945 LyXParagraph::size_type LyXParagraph::Last() const
947 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
948 return text.size() + NextAfterFootnote()->Last() + 1;
949 // the 1 is the symbol
956 LyXParagraph * LyXParagraph::ParFromPos(LyXParagraph::size_type pos)
958 // > because last is the next unused position, and you can
959 // use it if you want
962 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
963 return NextAfterFootnote()
964 ->ParFromPos(pos - text.size() - 1);
966 lyxerr << "ERROR (LyXParagraph::ParFromPos): "
967 "position does not exist." << endl;
974 int LyXParagraph::PositionInParFromPos(LyXParagraph::size_type pos) const
976 // > because last is the next unused position, and you can
977 // use it if you want
980 && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
981 return NextAfterFootnote()
982 ->PositionInParFromPos(pos - text.size() - 1);
985 "ERROR (LyXParagraph::PositionInParFromPos): "
986 "position does not exist." << endl;
994 void LyXParagraph::SetFont(LyXParagraph::size_type pos,
995 LyXFont const & font)
997 // > because last is the next unused position, and you can
998 // use it if you want
1001 next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1002 NextAfterFootnote()->SetFont(pos - text.size() - 1,
1005 lyxerr << "ERROR (LyXParagraph::SetFont): "
1006 "position does not exist." << endl;
1010 LyXFont patternfont(LyXFont::ALL_INHERIT);
1012 // First, reduce font against layout/label font
1013 // Update: The SetCharFont() routine in text2.C already
1014 // reduces font, so we don't need to do that here. (Asger)
1015 // No need to simplify this because it will disappear
1016 // in a new kernel. (Asger)
1017 // Next search font table
1018 FontList::iterator tmp = fontlist.begin();
1019 for (; tmp != fontlist.end(); ++tmp) {
1020 if (pos >= (*tmp).pos && pos <= (*tmp).pos_end) {
1024 if (tmp == fontlist.end()) { // !found
1025 // if we did not find a font entry, but if the font at hand
1026 // is the same as default, we just forget it
1027 if (font == patternfont) return;
1029 // ok, we did not find a font entry. But maybe there is exactly
1030 // the needed font ientry one position left
1031 FontList::iterator tmp2 = fontlist.begin();
1032 for (; tmp2 != fontlist.end(); ++tmp2) {
1033 if (pos - 1 >= (*tmp2).pos
1034 && pos - 1 <= (*tmp2).pos_end)
1037 if (tmp2 != fontlist.end()) {
1038 // ok there is one, maybe it is exactly
1040 if ((*tmp2).font == font) {
1041 // put the position under the font
1046 // Add a new entry in the
1047 // fontlist for the position
1051 ft.font = font; // or patternfont
1052 // It seems that using font instead of patternfont here
1053 // fixes all the problems. This also surfaces a "bug" in
1055 fontlist.insert(fontlist.begin(), ft);
1056 } else if ((*tmp).pos != (*tmp).pos_end) { // we found a font entry. maybe we have to split it and create a new one.
1058 // more than one character
1059 if (pos == (*tmp).pos) {
1060 // maybe we should enlarge the left fonttable
1061 FontList::iterator tmp2 = fontlist.begin();
1062 for (; tmp2 != fontlist.end(); ++tmp2) {
1063 if (pos - 1 >= (*tmp2).pos
1064 && pos - 1 <= (*tmp2).pos_end)
1067 // Is there is one, and is it exactly
1069 if (tmp2 != fontlist.end() &&
1070 (*tmp2).font == font) {
1071 // Put the position under the font
1077 // Add a new entry in the
1078 // fontlist for the position
1081 ft.pos_end = (*tmp).pos_end;
1082 ft.font = (*tmp).font;
1083 (*tmp).pos_end = pos;
1085 fontlist.insert(fontlist.begin(), ft);
1086 } else if (pos == (*tmp).pos_end) {
1087 // Add a new entry in the
1088 // fontlist for the position
1090 ft.pos = (*tmp).pos;
1091 ft.pos_end = (*tmp).pos_end - 1;
1092 ft.font = (*tmp).font;
1093 (*tmp).pos = (*tmp).pos_end;
1095 fontlist.insert(fontlist.begin(), ft);
1097 // Add a new entry in the
1098 // fontlist for the position
1100 ft.pos = (*tmp).pos;
1101 ft.pos_end = pos - 1;
1102 ft.font = (*tmp).font;
1106 ft2.pos_end = (*tmp).pos_end;
1107 ft2.font = (*tmp).font;
1110 (*tmp).pos_end = pos;
1113 fontlist.insert(fontlist.begin(), ft);
1114 fontlist.insert(fontlist.begin(), ft2);
1122 // This function is able to hide closed footnotes.
1123 LyXParagraph * LyXParagraph::Next()
1125 if (next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1126 LyXParagraph * tmp = next;
1128 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1130 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1131 return tmp->Next(); /* there can be more than one
1132 footnote in a logical
1135 return next; // This should never happen!
1141 LyXParagraph * LyXParagraph::NextAfterFootnote()
1143 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1144 LyXParagraph * tmp = next;
1145 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1147 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1148 return tmp; /* there can be more than one footnote
1149 in a logical paragraph */
1151 return next; // This should never happen!
1157 LyXParagraph const * LyXParagraph::NextAfterFootnote() const
1159 if (next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1160 LyXParagraph * tmp = next;
1161 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1163 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1164 return tmp; /* there can be more than one footnote
1165 in a logical paragraph */
1167 return next; // This should never happen!
1173 LyXParagraph * LyXParagraph::PreviousBeforeFootnote()
1176 if (previous && previous->footnoteflag != LyXParagraph::NO_FOOTNOTE) {
1178 while (tmp && tmp->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1179 tmp = tmp->previous;
1180 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1181 return tmp; /* there can be more than one footnote
1182 in a logical paragraph */
1184 return previous; // This should never happen!
1190 LyXParagraph * LyXParagraph::LastPhysicalPar()
1192 if (footnoteflag != LyXParagraph::NO_FOOTNOTE)
1195 LyXParagraph * tmp = this;
1197 && tmp->next->footnoteflag != LyXParagraph::NO_FOOTNOTE)
1198 tmp = tmp->NextAfterFootnote();
1205 LyXParagraph * LyXParagraph::FirstPhysicalPar()
1209 LyXParagraph * tmppar = this;
1213 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1214 tmppar = tmppar->previous;
1223 LyXParagraph const * LyXParagraph::FirstPhysicalPar() const
1227 LyXParagraph const * tmppar = this;
1231 || tmppar->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1232 tmppar = tmppar->previous;
1241 // This function is able to hide closed footnotes.
1242 LyXParagraph * LyXParagraph::Previous()
1244 LyXParagraph * tmp = previous;
1249 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1250 tmp = tmp->previous;
1252 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1253 tmp = tmp->previous;
1254 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1255 return tmp->next->Previous();
1264 // This function is able to hide closed footnotes.
1265 LyXParagraph const * LyXParagraph::Previous() const
1267 LyXParagraph * tmp = previous;
1272 && tmp->previous->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1273 tmp = tmp->previous;
1275 && tmp->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE)
1276 tmp = tmp->previous;
1277 if (tmp && tmp->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE)
1278 return tmp->next->Previous();
1287 void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos,
1290 size_type i, pos_end, pos_first;
1291 // create a new paragraph
1292 LyXParagraph * par = ParFromPos(pos);
1293 LyXParagraph * firstpar = FirstPhysicalPar();
1295 LyXParagraph * tmp = new LyXParagraph(par);
1297 tmp->footnoteflag = footnoteflag;
1298 tmp->footnotekind = footnotekind;
1300 // this is an idea for a more userfriendly layout handling, I will
1301 // see what the users say
1303 // layout stays the same with latex-environments
1305 tmp->SetOnlyLayout(firstpar->layout);
1306 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1309 if (Last() > pos || !Last() || flag == 2) {
1310 tmp->SetOnlyLayout(firstpar->layout);
1311 tmp->align = firstpar->align;
1312 tmp->SetLabelWidthString(firstpar->labelwidthstring);
1314 tmp->line_bottom = firstpar->line_bottom;
1315 firstpar->line_bottom = false;
1316 tmp->pagebreak_bottom = firstpar->pagebreak_bottom;
1317 firstpar->pagebreak_bottom = false;
1318 tmp->added_space_bottom = firstpar->added_space_bottom;
1319 firstpar->added_space_bottom = VSpace(VSpace::NONE);
1321 tmp->depth = firstpar->depth;
1322 tmp->noindent = firstpar->noindent;
1324 // copy everything behind the break-position
1325 // to the new paragraph
1327 while (ParFromPos(pos_first) != par)
1330 pos_end = pos_first + par->text.size() - 1;
1331 // The constructor has already reserved 500 elements
1332 //if (pos_end > pos)
1333 // tmp->text.reserve(pos_end - pos);
1335 for (i = pos; i <= pos_end; ++i) {
1336 par->CutIntoMinibuffer(i - pos_first);
1337 tmp->InsertFromMinibuffer(i - pos);
1339 tmp->text.resize(tmp->text.size());
1340 for (i = pos_end; i >= pos; --i)
1341 par->Erase(i - pos_first);
1343 par->text.resize(par->text.size());
1346 // just an idea of me
1348 tmp->line_top = firstpar->line_top;
1349 tmp->pagebreak_top = firstpar->pagebreak_top;
1350 tmp->added_space_top = firstpar->added_space_top;
1351 tmp->bibkey = firstpar->bibkey;
1353 // layout stays the same with latex-environments
1355 firstpar->SetOnlyLayout(tmp->layout);
1356 firstpar->SetLabelWidthString(tmp->labelwidthstring);
1357 firstpar->depth = tmp->depth;
1363 void LyXParagraph::MakeSameLayout(LyXParagraph const * par)
1365 par = par->FirstPhysicalPar();
1366 footnoteflag = par->footnoteflag;
1367 footnotekind = par->footnotekind;
1369 layout = par->layout;
1370 align = par-> align;
1371 SetLabelWidthString(par->labelwidthstring);
1373 line_bottom = par->line_bottom;
1374 pagebreak_bottom = par->pagebreak_bottom;
1375 added_space_bottom = par->added_space_bottom;
1377 line_top = par->line_top;
1378 pagebreak_top = par->pagebreak_top;
1379 added_space_top = par->added_space_top;
1381 pextra_type = par->pextra_type;
1382 pextra_width = par->pextra_width;
1383 pextra_widthp = par->pextra_widthp;
1384 pextra_alignment = par->pextra_alignment;
1385 pextra_hfill = par->pextra_hfill;
1386 pextra_start_minipage = par->pextra_start_minipage;
1388 noindent = par->noindent;
1393 LyXParagraph * LyXParagraph::FirstSelfrowPar()
1395 LyXParagraph * tmppar = this;
1398 && tmppar->previous->footnoteflag ==
1399 LyXParagraph::CLOSED_FOOTNOTE)
1400 || tmppar->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE))
1401 tmppar = tmppar->previous;
1404 return this; // This should never happen!
1410 LyXParagraph * LyXParagraph::Clone() const
1412 // create a new paragraph
1413 LyXParagraph * result = new LyXParagraph;
1415 result->MakeSameLayout(this);
1417 // this is because of the dummy layout of the paragraphs that
1419 result->layout = layout;
1421 /* table stuff -- begin*/
1423 result->table = table->Clone();
1426 /* table stuff -- end*/
1429 result->bibkey = (bibkey) ? new InsetBibKey(bibkey): 0;
1432 // copy everything behind the break-position to the new paragraph
1434 for (size_type i = 0; i < size(); ++i) {
1435 CopyIntoMinibuffer(i);
1436 result->InsertFromMinibuffer(i);
1438 result->text.resize(result->text.size());
1443 bool LyXParagraph::HasSameLayout(LyXParagraph const * par) const
1445 par = par->FirstPhysicalPar();
1448 par->footnoteflag == footnoteflag &&
1449 par->footnotekind == footnotekind &&
1451 par->layout == layout &&
1453 par->align == align &&
1455 par->line_bottom == line_bottom &&
1456 par->pagebreak_bottom == pagebreak_bottom &&
1457 par->added_space_bottom == added_space_bottom &&
1459 par->line_top == line_top &&
1460 par->pagebreak_top == pagebreak_top &&
1461 par->added_space_top == added_space_top &&
1463 par->pextra_type == pextra_type &&
1464 par->pextra_width == pextra_width &&
1465 par->pextra_widthp == pextra_widthp &&
1466 par->pextra_alignment == pextra_alignment &&
1467 par->pextra_hfill == pextra_hfill &&
1468 par->pextra_start_minipage == pextra_start_minipage &&
1470 par->table == table && // what means: NO TABLE AT ALL
1472 par->noindent == noindent &&
1473 par->depth == depth);
1477 void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos)
1479 // create a new paragraph
1480 LyXParagraph * par = ParFromPos(pos);
1482 LyXParagraph * tmp = new LyXParagraph(par);
1484 tmp->MakeSameLayout(par);
1486 // When can pos < Last()?
1487 // I guess pos == Last() is possible.
1489 // copy everything behind the break-position to the new
1491 size_type pos_first = 0;
1492 while (ParFromPos(pos_first) != par)
1494 size_type pos_end = pos_first + par->text.size() - 1;
1495 // make sure there is enough memory for the now larger
1496 // paragraph. This is not neccessary, because
1497 // InsertFromMinibuffer will enlarge the memory (it uses
1498 // InsertChar of course). But doing it by hand
1499 // is MUCH faster! (only one time, not thousend times!!)
1500 // Not needed since the constructor aleady have
1501 // reserved 500 elements in text.
1502 //if (pos_end > pos)
1503 // tmp->text.reserve(pos_end - pos);
1505 for (size_type i = pos; i <= pos_end; ++i) {
1506 par->CutIntoMinibuffer(i - pos_first);
1507 tmp->InsertFromMinibuffer(i - pos);
1509 tmp->text.resize(tmp->text.size());
1510 for (size_type i = pos_end; i >= pos; --i)
1511 par->Erase(i - pos_first);
1513 par->text.resize(par->text.size());
1518 // Be carefull, this does not make any check at all.
1519 void LyXParagraph::PasteParagraph()
1521 // copy the next paragraph to this one
1522 LyXParagraph * the_next = Next();
1524 LyXParagraph * firstpar = FirstPhysicalPar();
1526 // first the DTP-stuff
1527 firstpar->line_bottom = the_next->line_bottom;
1528 firstpar->added_space_bottom = the_next->added_space_bottom;
1529 firstpar->pagebreak_bottom = the_next->pagebreak_bottom;
1531 size_type pos_end = the_next->text.size() - 1;
1532 size_type pos_insert = Last();
1534 // ok, now copy the paragraph
1535 for (size_type i = 0; i <= pos_end; ++i) {
1536 the_next->CutIntoMinibuffer(i);
1537 InsertFromMinibuffer(pos_insert + i);
1540 // delete the next paragraph
1545 void LyXParagraph::OpenFootnote(LyXParagraph::size_type pos)
1547 LyXParagraph * par = ParFromPos(pos);
1549 while (par && par->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1550 par->footnoteflag = LyXParagraph::OPEN_FOOTNOTE;
1556 void LyXParagraph::CloseFootnote(LyXParagraph::size_type pos)
1558 LyXParagraph * par = ParFromPos(pos);
1560 while (par && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) {
1561 par->footnoteflag = LyXParagraph::CLOSED_FOOTNOTE;
1567 LyXTextClass::LayoutList::size_type LyXParagraph::GetLayout() const
1569 return FirstPhysicalPar()->layout;
1573 char LyXParagraph::GetDepth() const
1575 return FirstPhysicalPar()->depth;
1579 char LyXParagraph::GetAlign() const
1581 return FirstPhysicalPar()->align;
1585 string LyXParagraph::GetLabestring() const
1587 return FirstPhysicalPar()->labelstring;
1591 int LyXParagraph::GetFirstCounter(int i) const
1593 return FirstPhysicalPar()->counter_[i];
1597 // the next two functions are for the manual labels
1598 string LyXParagraph::GetLabelWidthString() const
1600 if (!FirstPhysicalPar()->labelwidthstring.empty())
1601 return FirstPhysicalPar()->labelwidthstring;
1603 return _("Senseless with this layout!");
1607 void LyXParagraph::SetLabelWidthString(string const & s)
1609 LyXParagraph * par = FirstPhysicalPar();
1611 par->labelwidthstring = s;
1615 void LyXParagraph::SetOnlyLayout(LyXTextClass::LayoutList::size_type new_layout)
1617 LyXParagraph * par = FirstPhysicalPar();
1618 LyXParagraph * ppar = 0;
1619 LyXParagraph * npar = 0;
1621 par->layout = new_layout;
1622 /* table stuff -- begin*/
1625 /* table stuff -- end*/
1626 if (par->pextra_type == PEXTRA_NONE) {
1627 if (par->Previous()) {
1628 ppar = par->Previous()->FirstPhysicalPar();
1631 && (ppar->depth > par->depth))
1632 ppar = ppar->Previous()->FirstPhysicalPar();
1635 npar = par->Next()->NextAfterFootnote();
1638 && (npar->depth > par->depth))
1639 npar = npar->Next()->NextAfterFootnote();
1641 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1643 p1 = ppar->pextra_width,
1644 p2 = ppar->pextra_widthp;
1645 ppar->SetPExtraType(ppar->pextra_type,
1646 p1.c_str(), p2.c_str());
1648 if ((par->pextra_type == PEXTRA_NONE) &&
1649 npar && (npar->pextra_type != PEXTRA_NONE)) {
1651 p1 = npar->pextra_width,
1652 p2 = npar->pextra_widthp;
1653 npar->SetPExtraType(npar->pextra_type,
1654 p1.c_str(), p2.c_str());
1660 void LyXParagraph::SetLayout(LyXTextClass::LayoutList::size_type new_layout)
1663 * par = FirstPhysicalPar(),
1667 par->layout = new_layout;
1668 par->labelwidthstring.clear();
1669 par->align = LYX_ALIGN_LAYOUT;
1670 par->added_space_top = VSpace(VSpace::NONE);
1671 par->added_space_bottom = VSpace(VSpace::NONE);
1672 /* table stuff -- begin*/
1675 /* table stuff -- end*/
1676 if (par->pextra_type == PEXTRA_NONE) {
1677 if (par->Previous()) {
1678 ppar = par->Previous()->FirstPhysicalPar();
1681 && (ppar->depth > par->depth))
1682 ppar = ppar->Previous()->FirstPhysicalPar();
1685 npar = par->Next()->NextAfterFootnote();
1688 && (npar->depth > par->depth))
1689 npar = npar->Next()->NextAfterFootnote();
1691 if (ppar && (ppar->pextra_type != PEXTRA_NONE)) {
1693 p1 = ppar->pextra_width,
1694 p2 = ppar->pextra_widthp;
1695 ppar->SetPExtraType(ppar->pextra_type,
1696 p1.c_str(), p2.c_str());
1698 if ((par->pextra_type == PEXTRA_NONE) &&
1699 npar && (npar->pextra_type != PEXTRA_NONE)) {
1701 p1 = npar->pextra_width,
1702 p2 = npar->pextra_widthp;
1703 npar->SetPExtraType(npar->pextra_type,
1704 p1.c_str(), p2.c_str());
1710 // if the layout of a paragraph contains a manual label, the beginning of the
1711 // main body is the beginning of the second word. This is what the par-
1712 // function returns. If the layout does not contain a label, the main
1713 // body always starts with position 0. This differentiation is necessary,
1714 // because there cannot be a newline or a blank <= the beginning of the
1715 // main body in TeX.
1717 int LyXParagraph::BeginningOfMainBody() const
1719 if (FirstPhysicalPar() != this)
1722 // Unroll the first two cycles of the loop
1723 // and remember the previous character to
1724 // remove unnecessary GetChar() calls
1727 && GetChar(i) != LyXParagraph::META_NEWLINE) {
1729 char previous_char, temp;
1731 && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1732 // Yes, this ^ is supposed to be "= " not "=="
1735 && previous_char != ' '
1736 && (temp = GetChar(i)) != LyXParagraph::META_NEWLINE) {
1738 previous_char = temp;
1743 if (i == 0 && i == size() &&
1744 !(footnoteflag == LyXParagraph::NO_FOOTNOTE
1745 && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE))
1746 ++i; /* the cursor should not jump
1747 * to the main body if there
1753 LyXParagraph * LyXParagraph::DepthHook(int deth)
1755 LyXParagraph * newpar = this;
1760 newpar = newpar->FirstPhysicalPar()->Previous();
1761 } while (newpar && newpar->GetDepth() > deth
1762 && newpar->footnoteflag == footnoteflag);
1765 if (Previous() || GetDepth())
1766 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1770 return newpar->FirstPhysicalPar();
1774 LyXParagraph const * LyXParagraph::DepthHook(int deth) const
1776 LyXParagraph const * newpar = this;
1781 newpar = newpar->FirstPhysicalPar()->Previous();
1782 } while (newpar && newpar->GetDepth() > deth
1783 && newpar->footnoteflag == footnoteflag);
1786 if (Previous() || GetDepth())
1787 lyxerr << "ERROR (LyXParagraph::DepthHook): "
1791 return newpar->FirstPhysicalPar();
1795 int LyXParagraph::AutoDeleteInsets()
1797 vector<size_type> tmpvec;
1799 for (InsetList::iterator it = insetlist.begin();
1800 it != insetlist.end(); ++it) {
1801 if ((*it).inset && (*it).inset->AutoDelete()) {
1802 tmpvec.push_back((*it).pos);
1806 for (vector<size_type>::const_iterator cit = tmpvec.begin();
1807 cit != tmpvec.end(); ++cit) {
1814 Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos)
1816 InsetList::iterator it2 = insetlist.end();
1817 for (InsetList::iterator it = insetlist.begin();
1818 it != insetlist.end(); ++it) {
1819 if ((*it).pos >= pos) {
1820 if (it2 == insetlist.end() || (*it).pos < (*it2).pos)
1824 if (it2 != insetlist.end()) {
1826 return (*it2).inset;
1832 // returns -1 if inset not found
1833 int LyXParagraph::GetPositionOfInset(Inset * inset) const
1836 for (InsetList::const_iterator cit = insetlist.begin();
1837 cit != insetlist.end(); ++cit) {
1838 if ((*cit).inset == inset) {
1842 // Think about footnotes.
1843 if (footnoteflag == LyXParagraph::NO_FOOTNOTE
1844 && next && next->footnoteflag == LyXParagraph::CLOSED_FOOTNOTE) {
1846 NextAfterFootnote()->GetPositionOfInset(inset);
1848 return text.size() + 1 + further;
1854 void LyXParagraph::readSimpleWholeFile(istream & is)
1860 InsertChar(text.size(), c);
1865 LyXParagraph * LyXParagraph::TeXOnePar(string & file, TexRow & texrow,
1866 string & foot, TexRow & foot_texrow,
1869 lyxerr[Debug::LATEX] << "TeXOnePar... " << this << endl;
1870 LyXParagraph * par = next;
1871 LyXLayout const & style =
1872 textclasslist.Style(current_view->buffer()->params.textclass,
1875 bool further_blank_line = false;
1877 lyxerr << "ERROR (LyXParagraph::TeXOnePar) is dummy." << endl;
1879 if (start_of_appendix) {
1880 file += "\\appendix\n";
1884 if (tex_code_break_column && style.isCommand()){
1889 if (pagebreak_top) {
1890 file += "\\newpage";
1891 further_blank_line = true;
1893 if (added_space_top.kind() != VSpace::NONE) {
1894 file += added_space_top.asLatexCommand();
1895 further_blank_line = true;
1899 file += "\\lyxline{\\" + getFont(0).latexSize() + '}';
1900 file += "\\vspace{-1\\parskip}";
1901 further_blank_line = true;
1904 if (further_blank_line){
1909 LyXDirection direction = getParDirection();
1910 LyXDirection global_direction =
1911 current_view->buffer()->params.getDocumentDirection();
1912 if (direction != global_direction) {
1913 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1914 file += "\\unsethebrew\n";
1916 file += "\\sethebrew\n";
1921 switch (style.latextype) {
1924 file += style.latexname();
1925 file += style.latexparam();
1927 case LATEX_ITEM_ENVIRONMENT:
1929 bibkey->Latex(file, false);
1933 case LATEX_LIST_ENVIRONMENT:
1940 bool need_par = SimpleTeXOnePar(file, texrow);
1942 // Spit out footnotes
1943 while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE
1944 && par->footnoteflag != footnoteflag) {
1945 par = par->TeXFootnote(file, texrow,
1946 foot, foot_texrow, foot_count,
1948 par->SimpleTeXOnePar(file, texrow);
1952 // Make sure that \\par is done with the font of the last
1953 // character if this has another size as the default.
1954 // This is necessary because LaTeX (and LyX on the screen)
1955 // calculates the space between the baselines according
1956 // to this font. (Matthias)
1957 LyXFont font = getFont(Last()-1);
1959 if (style.resfont.size() != font.size()) {
1961 file += font.latexSize();
1965 } else if (textclasslist.Style(current_view->buffer()->params.textclass,
1966 GetLayout()).isCommand()){
1967 if (style.resfont.size() != font.size()) {
1969 file += font.latexSize();
1973 } else if (style.resfont.size() != font.size()){
1974 file += "{\\" + font.latexSize() + " \\par}";
1977 if (direction != global_direction)
1978 if (direction == LYX_DIR_LEFT_TO_RIGHT)
1979 file += "\\sethebrew";
1981 file += "\\unsethebrew";
1983 switch (style.latextype) {
1984 case LATEX_ITEM_ENVIRONMENT:
1985 case LATEX_LIST_ENVIRONMENT:
1986 if (par && (depth < par->depth)) {
1991 case LATEX_ENVIRONMENT:
1992 // if its the last paragraph of the current environment
1993 // skip it otherwise fall through
1995 && (par->layout != layout
1996 || par->depth != depth
1997 || par->pextra_type != pextra_type))
2000 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE
2001 && footnotekind != LyXParagraph::FOOTNOTE
2002 && footnotekind != LyXParagraph::MARGIN
2006 // don't insert this if we would be adding it
2007 // before or after a table in a float. This
2008 // little trick is needed in order to allow
2009 // use of tables in \subfigures or \subtables.
2015 further_blank_line = false;
2017 file += "\\lyxline{\\" + getFont(Last()-1).latexSize() + '}';
2018 further_blank_line = true;
2021 if (added_space_bottom.kind() != VSpace::NONE) {
2022 file += added_space_bottom.asLatexCommand();
2023 further_blank_line = true;
2026 if (pagebreak_bottom) {
2027 file += "\\newpage";
2028 further_blank_line = true;
2031 if (further_blank_line){
2036 if (!(footnoteflag != LyXParagraph::NO_FOOTNOTE && par &&
2037 par->footnoteflag == LyXParagraph::NO_FOOTNOTE)) {
2042 lyxerr[Debug::LATEX] << "TeXOnePar...done " << par << endl;
2047 // This one spits out the text of the paragraph
2048 bool LyXParagraph::SimpleTeXOnePar(string & file, TexRow & texrow)
2050 lyxerr[Debug::LATEX] << "SimpleTeXOnePar... " << this << endl;
2053 return SimpleTeXOneTablePar(file, texrow);
2056 size_type main_body;
2058 bool return_value = false;
2060 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass, GetLayout());
2061 LyXFont basefont, last_font;
2063 // Maybe we have to create a optional argument.
2064 if (style.labeltype != LABEL_MANUAL)
2067 main_body = BeginningOfMainBody();
2069 if (main_body > 0) {
2071 basefont = getFont(-2); // Get label font
2073 basefont = getFont(-1); // Get layout font
2081 if (style.isCommand()) {
2084 } else if (align != LYX_ALIGN_LAYOUT) {
2087 return_value = true;
2091 // Which font is currently active?
2092 LyXFont running_font = basefont;
2093 // Do we have an open font change?
2094 bool open_font = false;
2096 texrow.start(this, 0);
2098 for (size_type i = 0; i < size(); ++i) {
2100 // First char in paragraph or after label?
2101 if (i == main_body && !IsDummy()) {
2102 if (main_body > 0) {
2104 column += running_font.latexWriteEndChanges(file, basefont, basefont);
2107 basefont = getFont(-1); // Now use the layout font
2108 running_font = basefont;
2112 if (style.isCommand()) {
2115 } else if (align != LYX_ALIGN_LAYOUT) {
2118 return_value = true;
2122 file += "\\noindent ";
2126 case LYX_ALIGN_NONE:
2127 case LYX_ALIGN_BLOCK:
2128 case LYX_ALIGN_LAYOUT:
2129 case LYX_ALIGN_SPECIAL: break;
2130 case LYX_ALIGN_LEFT:
2131 file += "\\raggedright ";
2134 case LYX_ALIGN_RIGHT:
2135 file += "\\raggedleft ";
2138 case LYX_ALIGN_CENTER:
2139 file += "\\centering ";
2147 // Fully instantiated font
2148 LyXFont font = getFont(i);
2149 last_font = running_font;
2151 // Spaces at end of font change are simulated to be
2152 // outside font change, i.e. we write "\textXX{text} "
2153 // rather than "\textXX{text }". (Asger)
2154 if (open_font && c == ' ' && i <= size() - 2
2155 && !getFont(i+1).equalExceptLatex(running_font)
2156 && !getFont(i+1).equalExceptLatex(font)) {
2157 font = getFont(i + 1);
2159 // We end font definition before blanks
2160 if (!font.equalExceptLatex(running_font) && open_font) {
2161 column += running_font.latexWriteEndChanges(file,
2163 (i == main_body-1) ? basefont : font);
2164 running_font = basefont;
2168 // Blanks are printed before start of fontswitch
2170 // Do not print the separation of the optional argument
2171 if (i != main_body - 1) {
2172 SimpleTeXBlanks(file, texrow, i,
2173 column, font, style);
2177 // Do we need to change font?
2178 if (!font.equalExceptLatex(running_font)
2179 && i != main_body-1) {
2180 column += font.latexWriteStartChanges(file, basefont, last_font);
2181 running_font = font;
2185 if (c == LyXParagraph::META_NEWLINE) {
2186 // newlines are handled differently here than
2187 // the default in SimpleTeXSpecialChars().
2188 if (!style.newline_allowed
2189 || font.latex() == LyXFont::ON) {
2193 column += running_font.latexWriteEndChanges(file, basefont, basefont);
2196 basefont = getFont(-1);
2197 running_font = basefont;
2198 if (font.family() ==
2199 LyXFont::TYPEWRITER_FAMILY) {
2205 texrow.start(this, i + 1);
2208 SimpleTeXSpecialChars(file, texrow,
2209 font, running_font, basefont,
2210 open_font, style, i, column, c);
2214 // If we have an open font definition, we have to close it
2216 running_font.latexWriteEndChanges(file, basefont, basefont);
2219 // Needed if there is an optional argument but no contents.
2220 if (main_body > 0 && main_body == size()) {
2222 return_value = false;
2225 lyxerr[Debug::LATEX] << "SimpleTeXOnePar...done " << this << endl;
2226 return return_value;
2230 // This one spits out the text of a table paragraph
2231 bool LyXParagraph::SimpleTeXOneTablePar(string & file, TexRow & texrow)
2233 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar... " << this << endl;
2235 bool return_value = false;
2237 LyXLayout const & style =
2238 textclasslist.Style(current_view->buffer()->params.textclass,
2242 if (!IsDummy()) { // it is dummy if it is in a float!!!
2243 if (style.isCommand()) {
2246 } else if (align != LYX_ALIGN_LAYOUT) {
2249 return_value = true;
2252 file += "\\noindent ";
2256 case LYX_ALIGN_NONE:
2257 case LYX_ALIGN_BLOCK:
2258 case LYX_ALIGN_LAYOUT:
2259 case LYX_ALIGN_SPECIAL: break;
2260 case LYX_ALIGN_LEFT:
2261 file += "\\raggedright ";
2264 case LYX_ALIGN_RIGHT:
2265 file += "\\raggedleft ";
2268 case LYX_ALIGN_CENTER:
2269 file += "\\centering ";
2275 LyXFont basefont = getFont(-1); // Get layout font
2276 // Which font is currently active?
2277 LyXFont running_font = basefont;
2279 // Do we have an open font change?
2280 bool open_font = false;
2281 int current_cell_number = -1;
2282 int tmp = table->TexEndOfCell(file, current_cell_number);
2283 for (; tmp > 0 ; --tmp)
2286 texrow.start(this, 0);
2288 for (size_type i = 0; i < size(); ++i) {
2289 char c = GetChar(i);
2290 if (table->IsContRow(current_cell_number + 1)) {
2291 if (c == LyXParagraph::META_NEWLINE)
2292 ++current_cell_number;
2297 // Fully instantiated font
2298 LyXFont font = getFont(i);
2299 last_font = running_font;
2301 // Spaces at end of font change are simulated to be
2302 // outside font change.
2303 // i.e. we write "\textXX{text} " rather than
2304 // "\textXX{text }". (Asger)
2305 if (open_font && c == ' ' && i <= size() - 2
2306 && getFont(i+1) != running_font && getFont(i+1) != font) {
2307 font = getFont(i+1);
2310 // We end font definition before blanks
2311 if (font != running_font && open_font) {
2312 column += running_font.latexWriteEndChanges(file,
2314 running_font = basefont;
2317 // Blanks are printed before start of fontswitch
2319 SimpleTeXBlanks(file, texrow, i, column, font, style);
2321 // Do we need to change font?
2322 if (font != running_font) {
2323 column += font.latexWriteStartChanges(file, basefont, last_font);
2324 running_font = font;
2327 // Do we need to turn on LaTeX mode?
2328 if (font.latex() != running_font.latex()) {
2329 if (font.latex() == LyXFont::ON
2330 && style.needprotect) {
2331 file += "\\protect ";
2335 if (c == LyXParagraph::META_NEWLINE) {
2336 // special case for inside a table
2337 // different from default case in
2338 // SimpleTeXSpecialChars()
2340 column += running_font
2341 .latexWriteEndChanges(file, basefont, basefont);
2344 basefont = getFont(-1);
2345 running_font = basefont;
2346 ++current_cell_number;
2347 if (table->CellHasContRow(current_cell_number) >= 0) {
2348 TeXContTableRows(file, i + 1,
2349 current_cell_number,
2352 // if this cell follow only ContRows till end don't
2353 // put the EndOfCell because it is put after the
2355 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2356 --current_cell_number;
2359 int tmp = table->TexEndOfCell(file,
2360 current_cell_number);
2363 } else if (tmp < 0) {
2369 texrow.start(this, i + 1);
2371 SimpleTeXSpecialChars(file, texrow,
2372 font, running_font, basefont,
2373 open_font, style, i, column, c);
2377 // If we have an open font definition, we have to close it
2379 running_font.latexWriteEndChanges(file, basefont, basefont);
2381 ++current_cell_number;
2382 tmp = table->TexEndOfCell(file, current_cell_number);
2383 for (; tmp > 0; --tmp)
2385 lyxerr[Debug::LATEX] << "SimpleTeXOneTablePar...done " << this << endl;
2386 return return_value;
2390 // This one spits out the text off ContRows in tables
2391 bool LyXParagraph::TeXContTableRows(string & file,
2392 LyXParagraph::size_type i,
2393 int current_cell_number,
2394 int & column, TexRow & texrow)
2396 lyxerr[Debug::LATEX] << "TeXContTableRows... " << this << endl;
2402 bool return_value = false;
2403 LyXLayout const & style =
2404 textclasslist.Style(current_view->buffer()->params.textclass,
2406 LyXFont basefont = getFont(-1); // Get layout font
2408 // Which font is currently active?
2409 LyXFont running_font = basefont;
2410 // Do we have an open font change?
2411 bool open_font = false;
2413 size_type lastpos = i;
2414 int cell = table->CellHasContRow(current_cell_number);
2415 ++current_cell_number;
2417 // first find the right position
2419 for (; (i < size()) && (current_cell_number<cell); ++i) {
2421 if (c == LyXParagraph::META_NEWLINE)
2422 ++current_cell_number;
2426 if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2430 } else if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2435 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2439 // Fully instantiated font
2440 LyXFont font = getFont(i);
2441 last_font = running_font;
2443 // Spaces at end of font change are simulated to
2444 // be outside font change. i.e. we write
2445 // "\textXX{text} " rather than "\textXX{text }".
2447 if (open_font && c == ' ' && i <= size() - 2
2448 && getFont(i + 1) != running_font
2449 && getFont(i + 1) != font) {
2450 font = getFont(i + 1);
2453 // We end font definition before blanks
2454 if (font != running_font && open_font) {
2455 column += running_font.latexWriteEndChanges(file, basefont, font);
2456 running_font = basefont;
2459 // Blanks are printed before start of fontswitch
2461 SimpleTeXBlanks(file, texrow, i,
2462 column, font, style);
2464 // Do we need to change font?
2465 if (font != running_font) {
2467 font.latexWriteStartChanges(file,
2468 basefont, last_font);
2469 running_font = font;
2472 // Do we need to turn on LaTeX mode?
2473 if (font.latex() != running_font.latex()) {
2474 if (font.latex() == LyXFont::ON
2475 && style.needprotect)
2477 file += "\\protect ";
2481 SimpleTeXSpecialChars(file, texrow, font,
2482 running_font, basefont,
2483 open_font, style, i, column, c);
2485 // If we have an open font definition, we have to close it
2487 running_font.latexWriteEndChanges(file, basefont, basefont);
2490 basefont = getFont(-1);
2491 running_font = basefont;
2492 cell = table->CellHasContRow(current_cell_number);
2494 lyxerr[Debug::LATEX] << "TeXContTableRows...done " << this << endl;
2495 return return_value;
2499 bool LyXParagraph::linuxDocConvertChar(char c, string & sgml_string)
2501 bool retval = false;
2503 case LyXParagraph::META_HFILL:
2504 sgml_string.clear();
2506 case LyXParagraph::META_PROTECTED_SEPARATOR:
2509 case LyXParagraph::META_NEWLINE:
2513 sgml_string = "&";
2516 sgml_string = "<";
2519 sgml_string = ">";
2522 sgml_string = "$";
2525 sgml_string = "#";
2528 sgml_string = "%";
2531 sgml_string = "[";
2534 sgml_string = "]";
2537 sgml_string = "{";
2540 sgml_string = "}";
2543 sgml_string = "˜";
2546 sgml_string = """;
2549 sgml_string = "\";
2555 case '\0': // Ignore :-)
2556 sgml_string.clear();
2566 void LyXParagraph::SimpleDocBookOneTablePar(string & file, string & extra,
2567 int & desc_on, int depth)
2570 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar... " << this << endl;
2572 LyXFont font1, font2;
2575 size_type main_body;
2576 string emph = "emphasis";
2577 bool emph_flag = false;
2579 LyXLayout const & style =
2580 textclasslist.Style(current_view->buffer()->params.textclass,
2583 if (style.labeltype != LABEL_MANUAL)
2586 main_body = BeginningOfMainBody();
2588 // Gets paragraph main font.
2590 font1 = style.labelfont;
2594 int char_line_count = depth;
2595 addNewlineAndDepth(file, depth);
2596 if (footnoteflag == LyXParagraph::NO_FOOTNOTE) {
2597 file += "<INFORMALTABLE>";
2598 addNewlineAndDepth(file, ++depth);
2600 int current_cell_number = -1;
2601 int tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
2603 // Parsing main loop.
2604 for (size_type i = 0; i < size(); ++i) {
2606 if (table->IsContRow(current_cell_number+1)) {
2607 if (c == LyXParagraph::META_NEWLINE)
2608 ++current_cell_number;
2613 // Fully instantiated font
2616 // Handle <emphasis> tag.
2617 if (font1.emph() != font2.emph() && i) {
2618 if (font2.emph() == LyXFont::ON) {
2619 file += "<emphasis>";
2621 } else if (emph_flag) {
2622 file += "</emphasis>";
2626 if (c == LyXParagraph::META_NEWLINE) {
2627 // We have only to control for emphasis open here!
2629 file += "</emphasis>";
2632 font1 = font2 = getFont(-1);
2633 ++current_cell_number;
2634 if (table->CellHasContRow(current_cell_number) >= 0) {
2635 DocBookContTableRows(file, extra, desc_on, i+1,
2636 current_cell_number,
2639 // if this cell follow only ContRows till end don't
2640 // put the EndOfCell because it is put after the
2642 if (table->ShouldBeVeryLastCell(current_cell_number)) {
2643 --current_cell_number;
2646 tmp = table->DocBookEndOfCell(file,
2647 current_cell_number,
2652 } else if (c == LyXParagraph::META_INSET) {
2653 inset = GetInset(i);
2655 inset->DocBook(tmp_out);
2657 // This code needs some explanation:
2658 // Two insets are treated specially
2659 // label if it is the first element in a
2660 // command paragraph
2662 // graphics inside tables or figure floats
2664 // title (the equivalente in latex for this
2666 // and title should come first
2669 if(desc_on != 3 || i != 0) {
2670 if(tmp_out[0] == '@') {
2672 extra += frontStrip(tmp_out,
2675 file += frontStrip(tmp_out,
2680 } else if (font2.latex() == LyXFont::ON) {
2681 // "TeX"-Mode on == > SGML-Mode on.
2687 if (linuxDocConvertChar(c, sgml_string)
2688 && !style.free_spacing) {
2689 // in freespacing mode, spaces are
2690 // non-breaking characters
2695 file += "</term><listitem><para>";
2701 file += sgml_string;
2707 // Needed if there is an optional argument but no contents.
2708 if (main_body > 0 && main_body == size()) {
2713 file += "</emphasis>";
2716 ++current_cell_number;
2717 tmp = table->DocBookEndOfCell(file, current_cell_number, depth);
2718 // Resets description flag correctly.
2721 // <term> not closed...
2725 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
2726 file += "</INFORMALTABLE>";
2728 lyxerr[Debug::LATEX] << "SimpleDocbookOneTablePar...done "
2733 void LyXParagraph::DocBookContTableRows(string & file, string & extra,
2735 LyXParagraph::size_type i,
2736 int current_cell_number, int &column)
2741 lyxerr[Debug::LATEX] << "DocBookContTableRows... " << this << endl;
2746 string emph= "emphasis";
2747 bool emph_flag= false;
2748 int char_line_count= 0;
2750 LyXLayout const & style =
2751 textclasslist.Style(current_view->buffer()->params.textclass,
2754 size_type main_body;
2755 if (style.labeltype != LABEL_MANUAL)
2758 main_body = BeginningOfMainBody();
2760 // Gets paragraph main font.
2763 font1 = style.labelfont;
2767 size_type lastpos = i;
2768 int cell = table->CellHasContRow(current_cell_number);
2769 ++current_cell_number;
2771 // first find the right position
2773 for (; i < size() && current_cell_number < cell; ++i) {
2775 if (c == LyXParagraph::META_NEWLINE)
2776 ++current_cell_number;
2780 // I don't know how to handle this so I comment it
2781 // for the moment (Jug)
2782 // if (table->Linebreaks(table->FirstVirtualCell(cell))) {
2783 // file += " \\\\\n";
2786 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE)) {
2791 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
2795 // Fully instantiated font
2798 // Handle <emphasis> tag.
2799 if (font1.emph() != font2.emph() && i) {
2800 if (font2.emph() == LyXFont::ON) {
2801 file += "<emphasis>";
2803 } else if (emph_flag) {
2804 file += "</emphasis>";
2808 if (c == LyXParagraph::META_INSET) {
2809 inset = GetInset(i);
2811 inset->DocBook(tmp_out);
2813 // This code needs some explanation:
2814 // Two insets are treated specially
2815 // label if it is the first element in a
2816 // command paragraph
2818 // graphics inside tables or figure floats
2819 // can't go on title (the equivalente in
2820 // latex for this case is caption and title
2821 // should come first
2824 if(desc_on != 3 || i != 0) {
2825 if(tmp_out[0] == '@') {
2827 extra += frontStrip(tmp_out, '@');
2829 file += frontStrip(tmp_out, '@');
2833 } else if (font2.latex() == LyXFont::ON) {
2834 // "TeX"-Mode on == > SGML-Mode on.
2840 if (linuxDocConvertChar(c, sgml_string)
2841 && !style.free_spacing) {
2842 // in freespacing mode, spaces are
2843 // non-breaking characters
2848 file += "</term><listitem><para>";
2854 file += sgml_string;
2858 // we have only to control for emphasis open here!
2860 file += "</emphasis>";
2863 font1 = font2 = getFont(-1);
2864 cell = table->CellHasContRow(current_cell_number);
2866 lyxerr[Debug::LATEX] << "DocBookContTableRows...done " << this << endl;
2870 void LyXParagraph::SimpleTeXBlanks(string & file, TexRow & texrow,
2871 LyXParagraph::size_type const i,
2872 int & column, LyXFont const & font,
2873 LyXLayout const & style)
2875 if (column > tex_code_break_column
2877 && GetChar(i - 1) != ' '
2879 // In LaTeX mode, we don't want to
2880 // break lines since some commands
2882 && ! (font.latex() == LyXFont::ON)
2883 // same in FreeSpacing mode
2884 && !style.free_spacing
2885 // In typewriter mode, we want to avoid
2886 // ! . ? : at the end of a line
2887 && !(font.family() == LyXFont::TYPEWRITER_FAMILY
2888 && (GetChar(i-1) == '.'
2889 || GetChar(i-1) == '?'
2890 || GetChar(i-1) == ':'
2891 || GetChar(i-1) == '!'))) {
2892 if (tex_code_break_column == 0) {
2893 // in batchmode we need LaTeX to still
2894 // see it as a space not as an extra '\n'
2900 texrow.start(this, i+1);
2902 } else if (font.latex() == LyXFont::OFF) {
2903 if (style.free_spacing) {
2912 void LyXParagraph::SimpleTeXSpecialChars(string & file, TexRow & texrow,
2914 LyXFont & running_font,
2917 LyXLayout const & style,
2918 LyXParagraph::size_type & i,
2919 int & column, char const c)
2921 // Two major modes: LaTeX or plain
2922 // Handle here those cases common to both modes
2923 // and then split to handle the two modes separately.
2925 case LyXParagraph::META_INSET: {
2926 Inset * inset = GetInset(i);
2929 int len = file.length();
2930 if ((inset->LyxCode() == Inset::GRAPHICS_CODE
2931 || inset->LyxCode() == Inset::MATH_CODE
2932 || inset->LyxCode() == Inset::URL_CODE)
2933 && running_font.getFontDirection()
2934 == LYX_DIR_RIGHT_TO_LEFT) {
2938 int tmp = inset->Latex(file, style.isCommand());
2945 column += file.length() - len;
2954 case LyXParagraph::META_NEWLINE:
2956 column += running_font.latexWriteEndChanges(file,
2957 basefont, basefont);
2960 basefont = getFont(-1);
2961 running_font = basefont;
2964 case LyXParagraph::META_HFILL:
2965 file += "\\hfill{}";
2970 // And now for the special cases within each mode
2971 // Are we in LaTeX mode?
2972 if (font.latex() == LyXFont::ON) {
2973 // at present we only have one option
2974 // but I'll leave it as a switch statement
2975 // so its simpler to extend. (ARRae)
2977 case LyXParagraph::META_PROTECTED_SEPARATOR:
2982 // make sure that we will not print
2983 // error generating chars to the tex
2984 // file. This test would not be needed
2985 // if it were done in the buffer
2993 // Plain mode (i.e. not LaTeX)
2995 case LyXParagraph::META_PROTECTED_SEPARATOR:
3000 file += "\\textbackslash{}";
3004 case '°': case '±': case '²': case '³':
3005 case '×': case '÷': case '¹': case 'ª':
3006 case 'º': case '¬': case 'µ':
3007 if (current_view->buffer()->params.inputenc == "latin1") {
3008 file += "\\ensuremath{";
3017 case '|': case '<': case '>':
3018 // In T1 encoding, these characters exist
3019 if (lyxrc->fontenc == "T1") {
3021 //... but we should avoid ligatures
3022 if ((c == '>' || c == '<')
3024 && GetChar(i+1) == c){
3025 file += "\\textcompwordmark{}";
3030 // Typewriter font also has them
3031 if (font.family() == LyXFont::TYPEWRITER_FAMILY) {
3035 // Otherwise, we use what LaTeX
3039 file += "\\textless{}";
3043 file += "\\textgreater{}";
3047 file += "\\textbar{}";
3053 case '-': // "--" in Typewriter mode -> "-{}-"
3055 && GetChar(i + 1) == '-'
3056 && font.family() == LyXFont::TYPEWRITER_FAMILY) {
3065 file += "\\char`\\\"{}";
3070 if (current_view->buffer()->params.inputenc == "default") {
3071 file += "\\pounds{}";
3079 case '%': case '#': case '{':
3087 file += "\\textasciitilde{}";
3092 file += "\\textasciicircum{}";
3096 case '*': case '[': case ']':
3097 // avoid being mistaken for optional arguments
3105 // Blanks are printed before font switching.
3106 // Sure? I am not! (try nice-latex)
3107 // I am sure it's correct. LyX might be smarter
3108 // in the future, but for now, nothing wrong is
3113 /* idea for labels --- begin*/
3117 && font.family() != LyXFont::TYPEWRITER_FAMILY
3118 && GetChar(i + 1) == 'y'
3119 && GetChar(i + 2) == 'X') {
3127 && font.family() != LyXFont::TYPEWRITER_FAMILY
3128 && GetChar(i + 1) == 'e'
3129 && GetChar(i + 2) == 'X') {
3134 // Check for "LaTeX2e"
3137 && font.family() != LyXFont::TYPEWRITER_FAMILY
3138 && GetChar(i + 1) == 'a'
3139 && GetChar(i + 2) == 'T'
3140 && GetChar(i + 3) == 'e'
3141 && GetChar(i + 4) == 'X'
3142 && GetChar(i + 5) == '2'
3143 && GetChar(i + 6) == 'e') {
3144 file += "\\LaTeXe{}";
3148 // Check for "LaTeX"
3151 && font.family() != LyXFont::TYPEWRITER_FAMILY
3152 && GetChar(i + 1) == 'a'
3153 && GetChar(i + 2) == 'T'
3154 && GetChar(i + 3) == 'e'
3155 && GetChar(i + 4) == 'X') {
3156 file += "\\LaTeX{}";
3159 /* idea for labels --- end*/
3160 } else if (c != '\0') {
3170 bool LyXParagraph::RoffContTableRows(ostream & os,
3171 LyXParagraph::size_type i,
3177 LyXFont font1 = LyXFont(LyXFont::ALL_INHERIT);
3182 string fname2 = TmpFileName(string(), "RAT2");
3184 int cell = table->CellHasContRow(actcell);
3187 // first find the right position
3189 for (; i < size() && actcell < cell; ++i) {
3191 if (c == LyXParagraph::META_NEWLINE)
3196 if ((c != ' ') && (c != LyXParagraph::META_NEWLINE))
3199 && (c = GetChar(i)) != LyXParagraph::META_NEWLINE;
3201 font2 = GetFontSettings(i);
3202 if (font1.latex() != font2.latex()) {
3203 if (font2.latex() != LyXFont::OFF)
3208 case LyXParagraph::META_INSET:
3209 if ((inset = GetInset(i))) {
3210 fstream fs(fname2.c_str(),
3213 WriteAlert(_("LYX_ERROR:"),
3214 _("Cannot open temporary file:"),
3218 inset->Latex(fs, -1);
3231 case LyXParagraph::META_NEWLINE:
3233 case LyXParagraph::META_HFILL:
3235 case LyXParagraph::META_PROTECTED_SEPARATOR:
3244 lyxerr.debug() << "RoffAsciiTable: "
3245 "NULL char in structure."
3250 cell = table->CellHasContRow(actcell);
3256 LyXParagraph * LyXParagraph::TeXDeeper(string & file, TexRow & texrow,
3257 string & foot, TexRow & foot_texrow,
3260 lyxerr[Debug::LATEX] << "TeXDeeper... " << this << endl;
3261 LyXParagraph * par = this;
3263 while (par && par->depth == depth) {
3265 lyxerr << "ERROR (LyXParagraph::TeXDeeper)" << endl;
3266 if (textclasslist.Style(current_view->buffer()->params.textclass,
3267 par->layout).isEnvironment()
3268 || par->pextra_type != PEXTRA_NONE)
3270 par = par->TeXEnvironment(file, texrow,
3274 par = par->TeXOnePar(file, texrow,
3279 lyxerr[Debug::LATEX] << "TeXDeeper...done " << par << endl;
3285 LyXParagraph * LyXParagraph::TeXEnvironment(string & file, TexRow & texrow,
3287 TexRow & foot_texrow,
3290 bool eindent_open = false;
3291 bool foot_this_level = false;
3292 // flags when footnotetext should be appended to file.
3293 static bool minipage_open = false;
3294 static int minipage_open_depth = 0;
3295 char par_sep = current_view->buffer()->params.paragraph_separation;
3297 lyxerr[Debug::LATEX] << "TeXEnvironment... " << this << endl;
3299 lyxerr << "ERROR (LyXParagraph::TeXEnvironment)" << endl;
3301 LyXLayout const & style =
3302 textclasslist.Style(current_view->buffer()->params.textclass,
3305 if (pextra_type == PEXTRA_INDENT) {
3306 if (!pextra_width.empty()) {
3307 file += "\\begin{LyXParagraphIndent}{"
3308 + pextra_width + "}\n";
3310 //float ib = atof(pextra_widthp.c_str())/100;
3311 // string can't handle floats at present (971109)
3312 // so I'll do a conversion by hand knowing that
3313 // the limits are 0.0 to 1.0. ARRae.
3314 file += "\\begin{LyXParagraphIndent}{";
3315 switch (pextra_widthp.length()) {
3321 file += pextra_widthp;
3325 file += pextra_widthp;
3327 file += "\\columnwidth}\n";
3330 eindent_open = true;
3332 if ((pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3333 if (pextra_hfill && Previous() &&
3334 (Previous()->pextra_type == PEXTRA_MINIPAGE)) {
3335 file += "\\hfill{}\n";
3338 if (par_sep == BufferParams::PARSEP_INDENT) {
3339 file += "{\\setlength\\parindent{0pt}\n";
3342 file += "\\begin{minipage}";
3343 switch(pextra_alignment) {
3344 case MINIPAGE_ALIGN_TOP:
3347 case MINIPAGE_ALIGN_MIDDLE:
3350 case MINIPAGE_ALIGN_BOTTOM:
3354 if (!pextra_width.empty()) {
3356 file += pextra_width + "}\n";
3358 //float ib = atof(par->pextra_width.c_str())/100;
3359 // string can't handle floats at present
3360 // so I'll do a conversion by hand knowing that
3361 // the limits are 0.0 to 1.0. ARRae.
3363 switch (pextra_widthp.length()) {
3369 file += pextra_widthp;
3373 file += pextra_widthp;
3375 file += "\\columnwidth}\n";
3378 if (par_sep == BufferParams::PARSEP_INDENT) {
3379 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3382 minipage_open = true;
3383 minipage_open_depth = depth;
3386 #ifdef WITH_WARNINGS
3387 #warning Define FANCY_FOOTNOTE_CODE to re-enable Allan footnote code
3388 //I disabled it because it breaks when lists span on several
3391 if (style.isEnvironment()){
3392 if (style.latextype == LATEX_LIST_ENVIRONMENT) {
3393 #ifdef FANCY_FOOTNOTE_CODE
3394 if (foot_count < 0) {
3395 // flag that footnote[mark][text] should be
3396 // used for any footnotes from now on
3398 foot_this_level = true;
3401 file += "\\begin{" + style.latexname() + "}{"
3402 + labelwidthstring + "}\n";
3403 } else if (style.labeltype == LABEL_BIBLIO) {
3405 file += "\\begin{" + style.latexname() + "}{"
3406 + bibitemWidthest() + "}\n";
3407 } else if (style.latextype == LATEX_ITEM_ENVIRONMENT) {
3408 #ifdef FANCY_FOOTNOTE_CODE
3409 if (foot_count < 0) {
3410 // flag that footnote[mark][text] should be
3411 // used for any footnotes from now on
3413 foot_this_level = true;
3416 file += "\\begin{" + style.latexname() + '}'
3417 + style.latexparam() + '\n';
3419 file += "\\begin{" + style.latexname() + '}'
3420 + style.latexparam() + '\n';
3423 LyXParagraph * par = this;
3425 par = par->TeXOnePar(file, texrow,
3426 foot, foot_texrow, foot_count);
3428 if (minipage_open && par && !style.isEnvironment() &&
3429 (par->pextra_type == PEXTRA_MINIPAGE) &&
3430 par->pextra_start_minipage) {
3431 file += "\\end{minipage}\n";
3433 if (par_sep == BufferParams::PARSEP_INDENT) {
3437 minipage_open = false;
3439 if (par && par->depth > depth) {
3440 if (textclasslist.Style(current_view->buffer()->params.textclass,
3441 par->layout).isParagraph()
3443 && !suffixIs(file, "\n\n")) {
3444 // There should be at least one '\n' already
3445 // but we need there to be two for Standard
3446 // paragraphs that are depth-increment'ed to be
3447 // output correctly. However, tables can
3448 // also be paragraphs so don't adjust them.
3453 par = par->TeXDeeper(file, texrow,
3454 foot, foot_texrow, foot_count);
3456 if (par && par->layout == layout && par->depth == depth &&
3457 (par->pextra_type == PEXTRA_MINIPAGE) && !minipage_open) {
3458 if (par->pextra_hfill && par->Previous() &&
3459 (par->Previous()->pextra_type == PEXTRA_MINIPAGE)){
3460 file += "\\hfill{}\n";
3463 if (par_sep == BufferParams::PARSEP_INDENT) {
3464 file += "{\\setlength\\parindent{0pt}\n";
3467 file += "\\begin{minipage}";
3468 switch(par->pextra_alignment) {
3469 case MINIPAGE_ALIGN_TOP:
3472 case MINIPAGE_ALIGN_MIDDLE:
3475 case MINIPAGE_ALIGN_BOTTOM:
3479 if (!par->pextra_width.empty()) {
3481 file += par->pextra_width;
3484 //float ib = atof(par->pextra_widthp.c_str())/100;
3485 // string can't handle floats at present
3486 // so I'll do a conversion by hand knowing that
3487 // the limits are 0.0 to 1.0. ARRae.
3489 switch (par->pextra_widthp.length()) {
3495 file += par->pextra_widthp;
3499 file += par->pextra_widthp;
3501 file += "\\columnwidth}\n";
3504 if (par_sep == BufferParams::PARSEP_INDENT) {
3505 file += "\\setlength\\parindent{\\LyXMinipageIndent}\n";
3508 minipage_open = true;
3509 minipage_open_depth = par->depth;
3512 && par->layout == layout
3513 && par->depth == depth
3514 && par->pextra_type == pextra_type);
3516 if (style.isEnvironment()) {
3517 file += "\\end{" + style.latexname() + '}';
3518 // maybe this should go after the minipage closes?
3519 if (foot_this_level) {
3520 if (foot_count >= 1) {
3521 if (foot_count > 1) {
3522 file += "\\addtocounter{footnote}{-";
3523 file += tostr(foot_count - 1);
3527 texrow += foot_texrow;
3529 foot_texrow.reset();
3534 if (minipage_open && (minipage_open_depth == depth) &&
3535 (!par || par->pextra_start_minipage ||
3536 par->pextra_type != PEXTRA_MINIPAGE)) {
3537 file += "\\end{minipage}\n";
3539 if (par_sep == BufferParams::PARSEP_INDENT) {
3543 if (par && par->pextra_type != PEXTRA_MINIPAGE) {
3544 file += "\\medskip\n\n";
3548 minipage_open = false;
3551 file += "\\end{LyXParagraphIndent}\n";
3554 if (!(par && (par->pextra_type == PEXTRA_MINIPAGE)
3555 && par->pextra_hfill)) {
3559 lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
3560 return par; // ale970302
3564 LyXParagraph * LyXParagraph::TeXFootnote(string & file, TexRow & texrow,
3565 string & foot, TexRow & foot_texrow,
3567 LyXDirection par_direction)
3569 lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl;
3570 if (footnoteflag == LyXParagraph::NO_FOOTNOTE)
3571 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3572 "No footnote!" << endl;
3574 LyXParagraph * par = this;
3575 LyXLayout const & style = textclasslist.Style(current_view->buffer()->params.textclass,
3576 previous->GetLayout());
3578 if (style.needprotect && footnotekind != LyXParagraph::FOOTNOTE){
3579 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3580 "Float other than footnote in command"
3581 " with moving argument is illegal" << endl;
3584 if (footnotekind != LyXParagraph::FOOTNOTE
3585 && footnotekind != LyXParagraph::MARGIN
3587 && !suffixIs(file, '\n')) {
3588 // we need to ensure that real floats like tables and figures
3589 // have their \begin{} on a new line otherwise we can get
3590 // incorrect results when using the endfloat.sty package
3591 // especially if two floats follow one another. ARRae 981022
3592 // NOTE: if the file is length 0 it must have just been
3593 // written out so we assume it ended with a '\n'
3598 BufferParams * params = ¤t_view->buffer()->params;
3599 bool footer_in_body = true;
3600 switch (footnotekind) {
3601 case LyXParagraph::FOOTNOTE:
3602 if (style.intitle) {
3603 file += "\\thanks{\n";
3604 footer_in_body = false;
3606 if (foot_count == -1) {
3607 // we're at depth 0 so we can use:
3608 file += "\\footnote{%\n";
3609 footer_in_body = false;
3611 file += "\\footnotemark{}%\n";
3613 // we only need this when there are
3614 // multiple footnotes
3615 foot += "\\stepcounter{footnote}";
3617 foot += "\\footnotetext{%\n";
3618 foot_texrow.start(this, 0);
3619 foot_texrow.newline();
3624 case LyXParagraph::MARGIN:
3625 file += "\\marginpar{\n";
3627 case LyXParagraph::FIG:
3628 if (pextra_type == PEXTRA_FLOATFLT
3629 && (!pextra_width.empty()
3630 || !pextra_widthp.empty())) {
3632 if (!pextra_width.empty())
3633 sprintf(bufr, "\\begin{floatingfigure}{%s}\n",
3634 pextra_width.c_str());
3637 "\\begin{floatingfigure}{%f\\textwidth}\n",
3638 atoi(pextra_widthp.c_str())/100.0);
3641 file += "\\begin{figure}";
3642 if (!params->float_placement.empty()) {
3644 file += params->float_placement;
3651 case LyXParagraph::TAB:
3652 file += "\\begin{table}";
3653 if (!params->float_placement.empty()) {
3655 file += params->float_placement;
3661 case LyXParagraph::WIDE_FIG:
3662 file += "\\begin{figure*}";
3663 if (!params->float_placement.empty()) {
3665 file += params->float_placement;
3671 case LyXParagraph::WIDE_TAB:
3672 file += "\\begin{table*}";
3673 if (!params->float_placement.empty()) {
3675 file += params->float_placement;
3681 case LyXParagraph::ALGORITHM:
3682 file += "\\begin{algorithm}\n";
3688 LyXDirection direction = getParDirection();
3689 if (direction != par_direction) {
3690 if (direction == LYX_DIR_LEFT_TO_RIGHT)
3691 file += "\\unsethebrew\n";
3693 file += "\\sethebrew\n";
3697 if (footnotekind != LyXParagraph::FOOTNOTE
3698 || !footer_in_body) {
3699 // Process text for all floats except footnotes in body
3701 LyXLayout const & style =
3702 textclasslist.Style(current_view->buffer()->params.textclass,
3705 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3707 if (style.isEnvironment()
3708 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3709 // Allows the use of minipages within float
3710 // environments. Shouldn't be circular because
3711 // we don't support footnotes inside
3712 // floats (yet). ARRae
3713 par = par->TeXEnvironment(file, texrow,
3717 par = par->TeXOnePar(file, texrow,
3722 if (par && !par->IsDummy() && par->depth > depth) {
3723 par = par->TeXDeeper(file, texrow,
3727 } while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3729 // process footnotes > depth 0 or in environments separately
3730 // NOTE: Currently don't support footnotes within footnotes
3731 // even though that is possible using the \footnotemark
3733 TexRow dummy_texrow;
3734 int dummy_count = 0;
3736 LyXLayout const & style =
3737 textclasslist.Style(current_view->buffer()->params.textclass,
3740 lyxerr << "ERROR (LyXParagraph::TeXFootnote)"
3742 if (style.isEnvironment()
3743 || par->pextra_type == PEXTRA_MINIPAGE) { /* && !minipage_open ?? */
3744 // Allows the use of minipages within float
3745 // environments. Shouldn't be circular because
3746 // we don't support footnotes inside
3747 // floats (yet). ARRae
3748 par = par->TeXEnvironment(foot, foot_texrow,
3749 dummy, dummy_texrow,
3752 par = par->TeXOnePar(foot, foot_texrow,
3753 dummy, dummy_texrow,
3757 if (par && !par->IsDummy() && par->depth > depth) {
3758 par = par->TeXDeeper(foot, foot_texrow,
3759 dummy, dummy_texrow,
3763 && par->footnoteflag != LyXParagraph::NO_FOOTNOTE);
3765 lyxerr << "ERROR (LyXParagraph::TeXFootnote): "
3766 "Footnote in a Footnote -- not supported"
3771 switch (footnotekind) {
3772 case LyXParagraph::FOOTNOTE:
3773 if (footer_in_body) {
3774 // This helps tell which of the multiple
3775 // footnotetexts an error was in.
3777 foot_texrow.newline();
3782 case LyXParagraph::MARGIN:
3785 case LyXParagraph::FIG:
3786 if (pextra_type == PEXTRA_FLOATFLT
3787 && (!pextra_width.empty()
3788 || !pextra_widthp.empty()))
3789 file += "\\end{floatingfigure}";
3791 file += "\\end{figure}";
3793 case LyXParagraph::TAB:
3794 file += "\\end{table}";
3796 case LyXParagraph::WIDE_FIG:
3797 file += "\\end{figure*}";
3799 case LyXParagraph::WIDE_TAB:
3800 file += "\\end{table*}";
3802 case LyXParagraph::ALGORITHM:
3803 file += "\\end{algorithm}";
3807 if (footnotekind != LyXParagraph::FOOTNOTE
3808 && footnotekind != LyXParagraph::MARGIN) {
3809 // we need to ensure that real floats like tables and figures
3810 // have their \end{} on a line of their own otherwise we can
3811 // get incorrect results when using the endfloat.sty package.
3816 lyxerr[Debug::LATEX] << "TeXFootnote...done " << par->next << endl;
3821 void LyXParagraph::SetPExtraType(int type, char const * width,
3822 char const * widthp)
3825 pextra_width = width;
3826 pextra_widthp = widthp;
3828 if (textclasslist.Style(current_view->buffer()->params.textclass,
3829 layout).isEnvironment()) {
3834 while (par && (par->layout == layout)
3835 && (par->depth == depth)) {
3837 par = par->Previous();
3839 par = par->FirstPhysicalPar();
3840 while (par && par->depth > depth) {
3841 par = par->Previous();
3843 par = par->FirstPhysicalPar();
3847 while (par && (par->layout == layout)
3848 && (par->depth == depth)) {
3849 par->pextra_type = type;
3850 par->pextra_width = width;
3851 par->pextra_widthp = widthp;
3852 par = par->NextAfterFootnote();
3853 if (par && (par->depth > depth))
3854 par->SetPExtraType(type, width, widthp);
3855 while (par && ((par->depth > depth) || par->IsDummy()))
3856 par = par->NextAfterFootnote();
3862 void LyXParagraph::UnsetPExtraType()
3864 if (pextra_type == PEXTRA_NONE)
3867 pextra_type = PEXTRA_NONE;
3868 pextra_width.clear();
3869 pextra_widthp.clear();
3871 if (textclasslist.Style(current_view->buffer()->params.textclass,
3872 layout).isEnvironment()) {
3877 while (par && (par->layout == layout)
3878 && (par->depth == depth)) {
3880 par = par->Previous();
3882 par = par->FirstPhysicalPar();
3883 while (par && par->depth > depth) {
3884 par = par->Previous();
3886 par = par->FirstPhysicalPar();
3890 while (par && (par->layout == layout)
3891 && (par->depth == depth)) {
3892 par->pextra_type = PEXTRA_NONE;
3893 par->pextra_width.clear();
3894 par->pextra_widthp.clear();
3895 par = par->NextAfterFootnote();
3896 if (par && (par->depth > depth))
3897 par->UnsetPExtraType();
3898 while (par && ((par->depth > depth) || par->IsDummy()))
3899 par = par->NextAfterFootnote();
3905 bool LyXParagraph::IsHfill(size_type pos) const
3907 return IsHfillChar(GetChar(pos));
3911 bool LyXParagraph::IsInset(size_type pos) const
3913 return IsInsetChar(GetChar(pos));
3917 bool LyXParagraph::IsFloat(size_type pos) const
3919 return IsFloatChar(GetChar(pos));
3923 bool LyXParagraph::IsNewline(size_type pos) const
3927 tmp = IsNewlineChar(GetChar(pos));
3932 bool LyXParagraph::IsSeparator(size_type pos) const
3934 return IsSeparatorChar(GetChar(pos));
3938 bool LyXParagraph::IsLineSeparator(size_type pos) const
3940 return IsLineSeparatorChar(GetChar(pos));
3944 bool LyXParagraph::IsKomma(size_type pos) const
3946 return IsKommaChar(GetChar(pos));
3950 /// Used by the spellchecker
3951 bool LyXParagraph::IsLetter(LyXParagraph::size_type pos) const
3953 unsigned char c = GetChar(pos);
3954 if (IsLetterChar(c))
3956 // '\0' is not a letter, allthough every string contains "" (below)
3959 // We want to pass the ' and escape chars to ispell
3960 string extra = lyxrc->isp_esc_chars + '\'';
3964 return contains(extra, ch);
3968 bool LyXParagraph::IsWord(size_type pos ) const
3970 return IsWordChar(GetChar(pos)) ;