1999-09-27 18:44:28 +00:00
|
|
|
|
/* This file is part of
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
|
|
|
|
*
|
1999-10-02 16:21:10 +00:00
|
|
|
|
* Copyright 1995 Matthias Ettrich
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* Copyright 1995-2001 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* This file is Copyright 1996-2001
|
1999-09-27 18:44:28 +00:00
|
|
|
|
* Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
*
|
1999-11-15 12:01:38 +00:00
|
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <iomanip>
|
2001-03-11 18:39:00 +00:00
|
|
|
|
#include <map>
|
2001-03-21 23:38:07 +00:00
|
|
|
|
#include <stack>
|
2001-03-23 08:37:44 +00:00
|
|
|
|
#include <list>
|
1999-12-07 10:49:58 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include <cstdlib>
|
2000-11-21 15:46:13 +00:00
|
|
|
|
#include <cmath>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include <unistd.h>
|
2000-02-22 00:36:17 +00:00
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <utime.h>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-05-19 16:46:01 +00:00
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#ifdef HAVE_LOCALE
|
|
|
|
|
#include <locale>
|
|
|
|
|
#endif
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#ifdef __GNUG__
|
2001-05-03 14:31:33 +00:00
|
|
|
|
#pragma implementation
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
|
|
|
|
#include "bufferlist.h"
|
|
|
|
|
#include "lyx_main.h"
|
|
|
|
|
#include "lyx_gui_misc.h"
|
1999-12-10 00:07:59 +00:00
|
|
|
|
#include "LyXAction.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "lyxrc.h"
|
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
#include "tex-strings.h"
|
|
|
|
|
#include "layout.h"
|
2000-04-12 14:20:08 +00:00
|
|
|
|
#include "bufferview_funcs.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "lyxfont.h"
|
1999-12-15 17:42:22 +00:00
|
|
|
|
#include "version.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "mathed/formulamacro.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "mathed/formula.h"
|
|
|
|
|
#include "insets/inset.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "insets/inseterror.h"
|
|
|
|
|
#include "insets/insetlabel.h"
|
|
|
|
|
#include "insets/insetref.h"
|
|
|
|
|
#include "insets/inseturl.h"
|
|
|
|
|
#include "insets/insetinfo.h"
|
|
|
|
|
#include "insets/insetquotes.h"
|
|
|
|
|
#include "insets/insetlatexaccent.h"
|
|
|
|
|
#include "insets/insetbib.h"
|
2000-06-07 08:53:40 +00:00
|
|
|
|
#include "insets/insetcite.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
|
#include "insets/insetexternal.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "insets/insetindex.h"
|
|
|
|
|
#include "insets/insetinclude.h"
|
|
|
|
|
#include "insets/insettoc.h"
|
|
|
|
|
#include "insets/insetparent.h"
|
|
|
|
|
#include "insets/insetspecialchar.h"
|
|
|
|
|
#include "insets/figinset.h"
|
2000-02-25 12:06:15 +00:00
|
|
|
|
#include "insets/insettext.h"
|
|
|
|
|
#include "insets/insetert.h"
|
2000-02-29 02:19:17 +00:00
|
|
|
|
#include "insets/insetgraphics.h"
|
2000-03-08 13:52:57 +00:00
|
|
|
|
#include "insets/insetfoot.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
#include "insets/insetmarginal.h"
|
|
|
|
|
#include "insets/insetminipage.h"
|
|
|
|
|
#include "insets/insetfloat.h"
|
|
|
|
|
#include "insets/insetlist.h"
|
2000-05-04 08:14:34 +00:00
|
|
|
|
#include "insets/insettabular.h"
|
2000-07-04 19:16:35 +00:00
|
|
|
|
#include "insets/insettheorem.h"
|
2000-07-18 17:45:27 +00:00
|
|
|
|
#include "insets/insetcaption.h"
|
2001-05-04 10:36:36 +00:00
|
|
|
|
#include "insets/insetfloatlist.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/filetools.h"
|
1999-10-13 17:32:46 +00:00
|
|
|
|
#include "support/path.h"
|
2001-05-17 15:11:01 +00:00
|
|
|
|
#include "support/os.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "LaTeX.h"
|
|
|
|
|
#include "Chktex.h"
|
|
|
|
|
#include "LyXView.h"
|
1999-10-07 18:44:17 +00:00
|
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
|
#include "support/syscall.h"
|
|
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
#include "support/FileInfo.h"
|
2000-10-11 21:06:43 +00:00
|
|
|
|
#include "support/lyxmanip.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "gettext.h"
|
2000-03-17 10:14:46 +00:00
|
|
|
|
#include "language.h"
|
2000-06-12 11:27:15 +00:00
|
|
|
|
#include "lyx_gui_misc.h" // WarnReadonly()
|
|
|
|
|
#include "frontends/Dialogs.h"
|
2000-07-04 20:32:37 +00:00
|
|
|
|
#include "encoding.h"
|
2000-08-30 03:40:51 +00:00
|
|
|
|
#include "exporter.h"
|
2000-09-26 15:25:14 +00:00
|
|
|
|
#include "Lsstream.h"
|
2001-02-06 17:41:42 +00:00
|
|
|
|
#include "converter.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "ParagraphParameters.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-12 09:30:12 +00:00
|
|
|
|
using std::stringstream;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::ofstream;
|
|
|
|
|
using std::ifstream;
|
|
|
|
|
using std::fstream;
|
|
|
|
|
using std::ios;
|
|
|
|
|
using std::setw;
|
2000-03-28 02:18:55 +00:00
|
|
|
|
using std::endl;
|
2000-04-04 00:19:15 +00:00
|
|
|
|
using std::pair;
|
2001-02-09 15:54:30 +00:00
|
|
|
|
using std::make_pair;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
using std::vector;
|
2001-03-12 08:52:37 +00:00
|
|
|
|
using std::map;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
using std::max;
|
2000-07-04 20:32:37 +00:00
|
|
|
|
using std::set;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
using std::stack;
|
|
|
|
|
using std::list;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// all these externs should eventually be removed.
|
|
|
|
|
extern BufferList bufferlist;
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
extern LyXAction lyxaction;
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2001-07-08 13:00:28 +00:00
|
|
|
|
const int LYX_FORMAT = 220;
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
|
|
} // namespace anon
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
extern int tex_code_break_column;
|
|
|
|
|
|
|
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
|
Buffer::Buffer(string const & file, bool ronly)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
filename = file;
|
|
|
|
|
filepath = OnlyPath(file);
|
1999-10-02 16:21:10 +00:00
|
|
|
|
paragraph = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lyx_clean = true;
|
|
|
|
|
bak_clean = true;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
dep_clean = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
read_only = ronly;
|
2000-07-26 13:43:16 +00:00
|
|
|
|
unnamed = false;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
users = 0;
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxvc.buffer(this);
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (read_only || (lyxrc.use_tempdir)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
tmppath = CreateBufferTmpDir();
|
2000-05-04 10:57:00 +00:00
|
|
|
|
} else tmppath.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Buffer::~Buffer()
|
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Buffer::~Buffer()" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// here the buffer should take care that it is
|
|
|
|
|
// saved properly, before it goes into the void.
|
|
|
|
|
|
|
|
|
|
// make sure that views using this buffer
|
|
|
|
|
// forgets it.
|
|
|
|
|
if (users)
|
1999-11-09 23:52:04 +00:00
|
|
|
|
users->buffer(0);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
if (!tmppath.empty()) {
|
|
|
|
|
DestroyBufferTmpDir(tmppath);
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
|
|
|
|
Paragraph * tmppar;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (par) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
tmppar = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
delete par;
|
|
|
|
|
par = tmppar;
|
|
|
|
|
}
|
1999-10-02 16:21:10 +00:00
|
|
|
|
paragraph = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const Buffer::getLatexName(bool no_path) const
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
string name = ChangeExtension(MakeLatexName(filename), ".tex");
|
2000-05-11 16:12:46 +00:00
|
|
|
|
if (no_path)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return OnlyFilename(name);
|
2000-05-11 16:12:46 +00:00
|
|
|
|
else
|
2001-06-25 00:06:33 +00:00
|
|
|
|
return name;
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
|
2001-02-09 15:54:30 +00:00
|
|
|
|
pair<Buffer::LogType, string> const Buffer::getLogName(void) const
|
2001-02-06 17:41:42 +00:00
|
|
|
|
{
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string const filename = getLatexName(false);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
|
|
|
|
if (filename.empty())
|
2001-02-09 15:54:30 +00:00
|
|
|
|
return make_pair(Buffer::latexlog, string());
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string path = OnlyPath(filename);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
|
|
|
|
if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1))
|
2001-02-09 15:54:30 +00:00
|
|
|
|
path = tmppath;
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
string const fname = AddName(path,
|
|
|
|
|
OnlyFilename(ChangeExtension(filename,
|
|
|
|
|
".log")));
|
|
|
|
|
string const bname =
|
|
|
|
|
AddName(path, OnlyFilename(
|
|
|
|
|
ChangeExtension(filename,
|
|
|
|
|
formats.Extension("literate") + ".out")));
|
2001-02-06 17:41:42 +00:00
|
|
|
|
|
|
|
|
|
// If no Latex log or Build log is newer, show Build log
|
2001-02-09 15:54:30 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
FileInfo const f_fi(fname);
|
|
|
|
|
FileInfo const b_fi(bname);
|
2001-02-09 15:54:30 +00:00
|
|
|
|
|
2001-02-06 17:41:42 +00:00
|
|
|
|
if (b_fi.exist() &&
|
2001-03-14 14:54:30 +00:00
|
|
|
|
(!f_fi.exist() || f_fi.getModificationTime() < b_fi.getModificationTime())) {
|
2001-02-09 15:54:30 +00:00
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as : " << bname << endl;
|
|
|
|
|
return make_pair(Buffer::buildlog, bname);
|
|
|
|
|
}
|
|
|
|
|
lyxerr[Debug::FILES] << "Log name calculated as : " << fname << endl;
|
|
|
|
|
return make_pair(Buffer::latexlog, fname);
|
2001-02-06 17:41:42 +00:00
|
|
|
|
}
|
2000-04-08 17:02:02 +00:00
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
void Buffer::setReadonly(bool flag)
|
2000-04-08 17:02:02 +00:00
|
|
|
|
{
|
|
|
|
|
if (read_only != flag) {
|
|
|
|
|
read_only = flag;
|
|
|
|
|
updateTitles();
|
2000-10-13 05:57:05 +00:00
|
|
|
|
users->owner()->getDialogs()->updateBufferDependent(false);
|
2000-04-08 17:02:02 +00:00
|
|
|
|
}
|
|
|
|
|
if (read_only) {
|
|
|
|
|
WarnReadonly(filename);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
bool Buffer::saveParamsAsDefaults() // const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const fname = AddName(AddPath(user_lyxdir, "templates/"),
|
2000-04-26 13:57:28 +00:00
|
|
|
|
"defaults.lyx");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
Buffer defaults = Buffer(fname);
|
|
|
|
|
|
|
|
|
|
// Use the current buffer's parameters as default
|
1999-11-15 12:01:38 +00:00
|
|
|
|
defaults.params = params;
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// add an empty paragraph. Is this enough?
|
2001-06-25 00:06:33 +00:00
|
|
|
|
defaults.paragraph = new Paragraph;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
return defaults.writeFile(defaults.filename, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Update window titles of all users
|
|
|
|
|
// Should work on a list
|
2000-02-22 00:36:17 +00:00
|
|
|
|
void Buffer::updateTitles() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
if (users) users->owner()->updateWindowTitle();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Reset autosave timer of all users
|
|
|
|
|
// Should work on a list
|
2000-02-22 00:36:17 +00:00
|
|
|
|
void Buffer::resetAutosaveTimers() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-09 23:52:04 +00:00
|
|
|
|
if (users) users->owner()->resetAutosaveTimer();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-12 00:11:06 +00:00
|
|
|
|
void Buffer::setFileName(string const & newfile)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
filename = MakeAbsPath(newfile);
|
|
|
|
|
filepath = OnlyPath(filename);
|
|
|
|
|
setReadonly(IsFileWriteable(filename) == 0);
|
|
|
|
|
updateTitles();
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
|
|
|
|
// candidate for move to BufferView
|
|
|
|
|
// (at least some parts in the beginning of the func)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Uwe C. Schroeder
|
|
|
|
|
// changed to be public and have one parameter
|
1999-10-02 16:21:10 +00:00
|
|
|
|
// if par = 0 normal behavior
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// else insert behavior
|
|
|
|
|
// Returns false if "\the_end" is not read for formats >= 2.13. (Asger)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool Buffer::readLyXformat2(LyXLex & lex, Paragraph * par)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
int pos = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool the_end_read = false;
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * return_par = 0;
|
2000-10-10 12:36:36 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT, params.language);
|
2001-01-11 11:06:10 +00:00
|
|
|
|
if (file_format < 216 && params.language->lang() == "hebrew")
|
|
|
|
|
font.setLanguage(default_language);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// If we are inserting, we cheat and get a token in advance
|
|
|
|
|
bool has_token = false;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string pretoken;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par = new Paragraph;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// We are inserting into an existing document
|
|
|
|
|
users->text->breakParagraph(users);
|
|
|
|
|
return_par = users->text->firstParagraph();
|
1999-11-15 12:01:38 +00:00
|
|
|
|
pos = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
markDirty();
|
|
|
|
|
// We don't want to adopt the parameters from the
|
|
|
|
|
// document we insert, so we skip until the text begins:
|
|
|
|
|
while (lex.IsOK()) {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
pretoken = lex.GetString();
|
|
|
|
|
if (pretoken == "\\layout") {
|
|
|
|
|
has_token = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (lex.IsOK()) {
|
|
|
|
|
if (has_token) {
|
|
|
|
|
has_token = false;
|
|
|
|
|
} else {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
pretoken = lex.GetString();
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
if (pretoken.empty()) continue;
|
|
|
|
|
|
|
|
|
|
the_end_read =
|
|
|
|
|
parseSingleLyXformat2Token(lex, par, return_par,
|
|
|
|
|
pretoken, pos, depth,
|
|
|
|
|
font
|
|
|
|
|
);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!return_par)
|
|
|
|
|
return_par = par;
|
|
|
|
|
|
|
|
|
|
paragraph = return_par;
|
|
|
|
|
|
|
|
|
|
return the_end_read;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
// We'll remove this later. (Lgb)
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
string last_inset_read;
|
2001-07-08 12:52:16 +00:00
|
|
|
|
string inset_ert_contents;
|
|
|
|
|
bool ert_active = false;
|
2001-03-20 01:22:46 +00:00
|
|
|
|
|
|
|
|
|
} // anon
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
|
|
|
|
|
2001-07-08 12:52:16 +00:00
|
|
|
|
void Buffer::insertErtContents(Paragraph * par, int & pos,
|
|
|
|
|
LyXFont const & font, bool set_inactive)
|
|
|
|
|
{
|
|
|
|
|
if (!inset_ert_contents.empty()) {
|
|
|
|
|
lyxerr[Debug::INSETS] << "ERT contents:\n"
|
|
|
|
|
<< inset_ert_contents << endl;
|
|
|
|
|
Inset * inset = new InsetERT(inset_ert_contents);
|
|
|
|
|
par->insertInset(pos++, inset, font);
|
|
|
|
|
inset_ert_contents.erase();
|
|
|
|
|
}
|
|
|
|
|
if (set_inactive) {
|
|
|
|
|
ert_active = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
bool
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Buffer::parseSingleLyXformat2Token(LyXLex & lex, Paragraph *& par,
|
|
|
|
|
Paragraph *& return_par,
|
2000-04-24 20:58:23 +00:00
|
|
|
|
string const & token, int & pos,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type & depth,
|
|
|
|
|
LyXFont & font
|
2000-07-19 17:16:27 +00:00
|
|
|
|
)
|
2000-03-01 14:13:21 +00:00
|
|
|
|
{
|
2001-03-22 15:45:15 +00:00
|
|
|
|
bool the_end_read = false;
|
|
|
|
|
#ifndef NO_PEXTRA_REALLY
|
2001-03-14 14:54:30 +00:00
|
|
|
|
// This is super temporary but is needed to get the compability
|
|
|
|
|
// mode for minipages work correctly together with new tabulars.
|
2001-06-04 23:57:32 +00:00
|
|
|
|
static int call_depth;
|
2001-03-14 14:54:30 +00:00
|
|
|
|
++call_depth;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
bool checkminipage = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
static Paragraph * minipar;
|
|
|
|
|
static Paragraph * parBeforeMinipage;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
#endif
|
2000-07-15 23:51:46 +00:00
|
|
|
|
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (token[0] != '\\') {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
if (ert_active) {
|
|
|
|
|
inset_ert_contents += token;
|
|
|
|
|
} else {
|
|
|
|
|
#endif
|
2000-04-24 20:58:23 +00:00
|
|
|
|
for (string::const_iterator cit = token.begin();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
cit != token.end(); ++cit) {
|
|
|
|
|
par->insertChar(pos, (*cit), font);
|
2000-01-24 18:34:46 +00:00
|
|
|
|
++pos;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
2001-03-22 15:45:15 +00:00
|
|
|
|
checkminipage = true;
|
2001-07-08 12:52:16 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\i") {
|
2000-04-24 20:58:23 +00:00
|
|
|
|
Inset * inset = new InsetLatexAccent;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->read(this, lex);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\layout") {
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
// Do the insetert.
|
2001-07-08 12:52:16 +00:00
|
|
|
|
insertErtContents(par, pos, font);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#endif
|
2001-03-11 03:20:44 +00:00
|
|
|
|
lex.EatLine();
|
|
|
|
|
string const layoutname = lex.GetString();
|
|
|
|
|
pair<bool, LyXTextClass::LayoutList::size_type> pp
|
|
|
|
|
= textclasslist.NumberOfLayout(params.textclass,
|
|
|
|
|
layoutname);
|
|
|
|
|
|
2001-07-08 12:52:16 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
if (compare_no_case(layoutname, "latex") == 0) {
|
|
|
|
|
ert_active = true;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-03-11 03:20:44 +00:00
|
|
|
|
#ifdef USE_CAPTION
|
|
|
|
|
// The is the compability reading of layout caption.
|
|
|
|
|
// It can be removed in LyX version 1.3.0. (Lgb)
|
|
|
|
|
if (compare_no_case(layoutname, "caption") == 0) {
|
|
|
|
|
// We expect that the par we are now working on is
|
|
|
|
|
// really inside a InsetText inside a InsetFloat.
|
|
|
|
|
// We also know that captions can only be
|
|
|
|
|
// one paragraph. (Lgb)
|
|
|
|
|
|
|
|
|
|
// We should now read until the next "\layout"
|
|
|
|
|
// is reached.
|
|
|
|
|
// This is probably not good enough, what if the
|
|
|
|
|
// caption is the last par in the document (Lgb)
|
|
|
|
|
istream & ist = lex.getStream();
|
|
|
|
|
stringstream ss;
|
|
|
|
|
string line;
|
|
|
|
|
int begin = 0;
|
|
|
|
|
while (true) {
|
|
|
|
|
getline(ist, line);
|
|
|
|
|
if (prefixIs(line, "\\layout")) {
|
|
|
|
|
lex.pushToken(line);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (prefixIs(line, "\\begin_inset"))
|
|
|
|
|
++begin;
|
|
|
|
|
if (prefixIs(line, "\\end_inset")) {
|
|
|
|
|
if (begin)
|
|
|
|
|
--begin;
|
|
|
|
|
else {
|
|
|
|
|
lex.pushToken(line);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ss << line << '\n';
|
|
|
|
|
}
|
|
|
|
|
// Now we should have the whole layout in ss
|
|
|
|
|
// we should now be able to give this to the
|
|
|
|
|
// caption inset.
|
|
|
|
|
ss << "\\end_inset\n";
|
|
|
|
|
|
|
|
|
|
// This seems like a bug in stringstream.
|
|
|
|
|
// We really should be able to use ss
|
|
|
|
|
// directly. (Lgb)
|
|
|
|
|
istringstream is(ss.str());
|
|
|
|
|
LyXLex tmplex(0, 0);
|
|
|
|
|
tmplex.setStream(is);
|
|
|
|
|
Inset * inset = new InsetCaption;
|
|
|
|
|
inset->Read(this, tmplex);
|
|
|
|
|
par->InsertInset(pos, inset, font);
|
|
|
|
|
++pos;
|
|
|
|
|
} else {
|
|
|
|
|
#endif
|
|
|
|
|
if (!return_par)
|
|
|
|
|
return_par = par;
|
|
|
|
|
else {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par = new Paragraph(par);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
pos = 0;
|
|
|
|
|
if (pp.first) {
|
|
|
|
|
par->layout = pp.second;
|
|
|
|
|
} else {
|
|
|
|
|
// layout not found
|
|
|
|
|
// use default layout "Standard" (0)
|
|
|
|
|
par->layout = 0;
|
|
|
|
|
}
|
|
|
|
|
// Test whether the layout is obsolete.
|
|
|
|
|
LyXLayout const & layout =
|
|
|
|
|
textclasslist.Style(params.textclass,
|
|
|
|
|
par->layout);
|
|
|
|
|
if (!layout.obsoleted_by().empty())
|
|
|
|
|
par->layout = textclasslist
|
|
|
|
|
.NumberOfLayout(params.textclass,
|
|
|
|
|
layout.obsoleted_by())
|
|
|
|
|
.second;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().depth(depth);
|
2001-03-11 03:20:44 +00:00
|
|
|
|
font = LyXFont(LyXFont::ALL_INHERIT, params.language);
|
|
|
|
|
if (file_format < 216
|
|
|
|
|
&& params.language->lang() == "hebrew")
|
|
|
|
|
font.setLanguage(default_language);
|
2001-03-14 14:54:30 +00:00
|
|
|
|
#if USE_CAPTION
|
2001-03-11 03:20:44 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (token == "\\begin_float") {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// This is the compability reader. It can be removed in
|
|
|
|
|
// LyX version 1.3.0. (Lgb)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const tmptok = lex.GetString();
|
2000-06-28 13:35:52 +00:00
|
|
|
|
//lyxerr << "old float: " << tmptok << endl;
|
|
|
|
|
|
|
|
|
|
Inset * inset = 0;
|
2001-03-11 03:20:44 +00:00
|
|
|
|
stringstream old_float;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
|
|
if (tmptok == "footnote") {
|
|
|
|
|
inset = new InsetFoot;
|
|
|
|
|
} else if (tmptok == "margin") {
|
|
|
|
|
inset = new InsetMarginal;
|
|
|
|
|
} else if (tmptok == "fig") {
|
2000-07-15 23:51:46 +00:00
|
|
|
|
inset = new InsetFloat("figure");
|
2001-06-13 14:47:08 +00:00
|
|
|
|
old_float << "placement htbp\n"
|
|
|
|
|
<< "wide false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "tab") {
|
2000-07-15 23:51:46 +00:00
|
|
|
|
inset = new InsetFloat("table");
|
2001-06-13 14:47:08 +00:00
|
|
|
|
old_float << "placement htbp\n"
|
|
|
|
|
<< "wide false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "alg") {
|
2000-07-15 23:51:46 +00:00
|
|
|
|
inset = new InsetFloat("algorithm");
|
2001-06-13 14:47:08 +00:00
|
|
|
|
old_float << "placement htbp\n"
|
|
|
|
|
<< "wide false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "wide-fig") {
|
2001-06-13 14:47:08 +00:00
|
|
|
|
inset = new InsetFloat("figure");
|
|
|
|
|
//InsetFloat * tmp = new InsetFloat("figure");
|
|
|
|
|
//tmp->wide(true);
|
|
|
|
|
//inset = tmp;
|
|
|
|
|
old_float << "placement htbp\n"
|
|
|
|
|
<< "wide true\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
} else if (tmptok == "wide-tab") {
|
2001-06-13 14:47:08 +00:00
|
|
|
|
inset = new InsetFloat("table");
|
|
|
|
|
//InsetFloat * tmp = new InsetFloat("table");
|
|
|
|
|
//tmp->wide(true);
|
|
|
|
|
//inset = tmp;
|
|
|
|
|
old_float << "placement htbp\n"
|
|
|
|
|
<< "wide true\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-14 14:54:30 +00:00
|
|
|
|
if (!inset) {
|
|
|
|
|
--call_depth;
|
|
|
|
|
return false; // no end read yet
|
|
|
|
|
}
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2001-03-11 03:20:44 +00:00
|
|
|
|
old_float << "collapsed true\n";
|
2000-07-21 14:59:00 +00:00
|
|
|
|
|
|
|
|
|
// Here we need to check for \end_deeper and handle that
|
|
|
|
|
// before we do the footnote parsing.
|
|
|
|
|
// This _is_ a hack! (Lgb)
|
2001-03-11 03:20:44 +00:00
|
|
|
|
while (true) {
|
2000-07-21 14:59:00 +00:00
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const tmp = lex.GetString();
|
2000-07-21 14:59:00 +00:00
|
|
|
|
if (tmp == "\\end_deeper") {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
//lyxerr << "\\end_deeper caught!" << endl;
|
2000-07-21 14:59:00 +00:00
|
|
|
|
if (!depth) {
|
|
|
|
|
lex.printError("\\end_deeper: "
|
|
|
|
|
"depth is already null");
|
|
|
|
|
} else
|
|
|
|
|
--depth;
|
|
|
|
|
|
|
|
|
|
} else {
|
2001-03-11 03:20:44 +00:00
|
|
|
|
old_float << tmp << ' ';
|
2000-07-21 14:59:00 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-11 03:20:44 +00:00
|
|
|
|
old_float << lex.getLongString("\\end_float")
|
|
|
|
|
<< "\n\\end_inset\n";
|
|
|
|
|
//lyxerr << "Float Body:\n" << old_float.str() << endl;
|
|
|
|
|
// That this does not work seems like a bug
|
|
|
|
|
// in stringstream. (Lgb)
|
|
|
|
|
istringstream istr(old_float.str());
|
2000-06-28 13:35:52 +00:00
|
|
|
|
LyXLex nylex(0, 0);
|
|
|
|
|
nylex.setStream(istr);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->read(this, nylex);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
++pos;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\begin_deeper") {
|
|
|
|
|
++depth;
|
|
|
|
|
} else if (token == "\\end_deeper") {
|
|
|
|
|
if (!depth) {
|
|
|
|
|
lex.printError("\\end_deeper: "
|
|
|
|
|
"depth is already null");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
--depth;
|
|
|
|
|
} else if (token == "\\begin_preamble") {
|
|
|
|
|
params.readPreamble(lex);
|
|
|
|
|
} else if (token == "\\textclass") {
|
|
|
|
|
lex.EatLine();
|
|
|
|
|
pair<bool, LyXTextClassList::size_type> pp =
|
|
|
|
|
textclasslist.NumberOfClass(lex.GetString());
|
|
|
|
|
if (pp.first) {
|
|
|
|
|
params.textclass = pp.second;
|
|
|
|
|
} else {
|
2000-11-29 15:34:56 +00:00
|
|
|
|
WriteAlert(string(_("Textclass error")),
|
|
|
|
|
string(_("The document uses an unknown textclass \"")) +
|
|
|
|
|
lex.GetString() + string("\"."),
|
|
|
|
|
string(_("LyX will not be able to produce output correctly.")));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
params.textclass = 0;
|
|
|
|
|
}
|
|
|
|
|
if (!textclasslist.Load(params.textclass)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// if the textclass wasn't loaded properly
|
|
|
|
|
// we need to either substitute another
|
|
|
|
|
// or stop loading the file.
|
|
|
|
|
// I can substitute but I don't see how I can
|
|
|
|
|
// stop loading... ideas?? ARRae980418
|
2000-03-01 14:13:21 +00:00
|
|
|
|
WriteAlert(_("Textclass Loading Error!"),
|
|
|
|
|
string(_("Can't load textclass ")) +
|
|
|
|
|
textclasslist.NameOfClass(params.textclass),
|
|
|
|
|
_("-- substituting default"));
|
|
|
|
|
params.textclass = 0;
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\options") {
|
|
|
|
|
lex.EatLine();
|
|
|
|
|
params.options = lex.GetString();
|
|
|
|
|
} else if (token == "\\language") {
|
|
|
|
|
params.readLanguage(lex);
|
|
|
|
|
} else if (token == "\\fontencoding") {
|
|
|
|
|
lex.EatLine();
|
|
|
|
|
} else if (token == "\\inputencoding") {
|
|
|
|
|
lex.EatLine();
|
|
|
|
|
params.inputenc = lex.GetString();
|
|
|
|
|
} else if (token == "\\graphics") {
|
|
|
|
|
params.readGraphicsDriver(lex);
|
|
|
|
|
} else if (token == "\\fontscheme") {
|
|
|
|
|
lex.EatLine();
|
|
|
|
|
params.fonts = lex.GetString();
|
|
|
|
|
} else if (token == "\\noindent") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().noindent(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\fill_top") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spaceTop(VSpace(VSpace::VFILL));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\fill_bottom") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spaceBottom(VSpace(VSpace::VFILL));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\line_top") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().lineTop(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\line_bottom") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().lineBottom(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pagebreak_top") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pagebreakTop(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pagebreak_bottom") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pagebreakBottom(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\start_of_appendix") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().startOfAppendix(true);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\paragraph_separation") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
int tmpret = lex.FindToken(string_paragraph_separation);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret == -1) ++tmpret;
|
|
|
|
|
if (tmpret != LYX_LAYOUT_DEFAULT)
|
|
|
|
|
params.paragraph_separation =
|
|
|
|
|
static_cast<BufferParams::PARSEP>(tmpret);
|
|
|
|
|
} else if (token == "\\defskip") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
params.defskip = VSpace(lex.GetString());
|
|
|
|
|
} else if (token == "\\epsfig") { // obsolete
|
|
|
|
|
// Indeed it is obsolete, but we HAVE to be backwards
|
|
|
|
|
// compatible until 0.14, because otherwise all figures
|
|
|
|
|
// in existing documents are irretrivably lost. (Asger)
|
|
|
|
|
params.readGraphicsDriver(lex);
|
|
|
|
|
} else if (token == "\\quotes_language") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
int tmpret = lex.FindToken(string_quotes_language);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret == -1) ++tmpret;
|
|
|
|
|
if (tmpret != LYX_LAYOUT_DEFAULT) {
|
|
|
|
|
InsetQuotes::quote_language tmpl =
|
|
|
|
|
InsetQuotes::EnglishQ;
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (tmpret) {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
case 0:
|
|
|
|
|
tmpl = InsetQuotes::EnglishQ;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
case 1:
|
|
|
|
|
tmpl = InsetQuotes::SwedishQ;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
case 2:
|
|
|
|
|
tmpl = InsetQuotes::GermanQ;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
tmpl = InsetQuotes::PolishQ;
|
|
|
|
|
break;
|
|
|
|
|
case 4:
|
|
|
|
|
tmpl = InsetQuotes::FrenchQ;
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
|
|
|
|
tmpl = InsetQuotes::DanishQ;
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
params.quotes_language = tmpl;
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\quotes_times") {
|
|
|
|
|
lex.nextToken();
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (lex.GetInteger()) {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
case 1:
|
|
|
|
|
params.quotes_times = InsetQuotes::SingleQ;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
params.quotes_times = InsetQuotes::DoubleQ;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\papersize") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
int tmpret = lex.FindToken(string_papersize);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret == -1)
|
|
|
|
|
++tmpret;
|
|
|
|
|
else
|
|
|
|
|
params.papersize2 = tmpret;
|
|
|
|
|
} else if (token == "\\paperpackage") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
int tmpret = lex.FindToken(string_paperpackages);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret == -1) {
|
|
|
|
|
++tmpret;
|
|
|
|
|
params.paperpackage = BufferParams::PACKAGE_NONE;
|
|
|
|
|
} else
|
|
|
|
|
params.paperpackage = tmpret;
|
|
|
|
|
} else if (token == "\\use_geometry") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
params.use_geometry = lex.GetInteger();
|
|
|
|
|
} else if (token == "\\use_amsmath") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
params.use_amsmath = lex.GetInteger();
|
|
|
|
|
} else if (token == "\\paperorientation") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
int tmpret = lex.FindToken(string_orientation);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret == -1) ++tmpret;
|
|
|
|
|
if (tmpret != LYX_LAYOUT_DEFAULT)
|
|
|
|
|
params.orientation = static_cast<BufferParams::PAPER_ORIENTATION>(tmpret);
|
|
|
|
|
} else if (token == "\\paperwidth") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params.paperwidth = lex.GetString();
|
|
|
|
|
} else if (token == "\\paperheight") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params.paperheight = lex.GetString();
|
|
|
|
|
} else if (token == "\\leftmargin") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params.leftmargin = lex.GetString();
|
|
|
|
|
} else if (token == "\\topmargin") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params.topmargin = lex.GetString();
|
|
|
|
|
} else if (token == "\\rightmargin") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params.rightmargin = lex.GetString();
|
|
|
|
|
} else if (token == "\\bottommargin") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params.bottommargin = lex.GetString();
|
|
|
|
|
} else if (token == "\\headheight") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params.headheight = lex.GetString();
|
|
|
|
|
} else if (token == "\\headsep") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params.headsep = lex.GetString();
|
|
|
|
|
} else if (token == "\\footskip") {
|
|
|
|
|
lex.next();
|
|
|
|
|
params.footskip = lex.GetString();
|
|
|
|
|
} else if (token == "\\paperfontsize") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
params.fontsize = strip(lex.GetString());
|
|
|
|
|
} else if (token == "\\papercolumns") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
params.columns = lex.GetInteger();
|
|
|
|
|
} else if (token == "\\papersides") {
|
|
|
|
|
lex.nextToken();
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (lex.GetInteger()) {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
default:
|
|
|
|
|
case 1: params.sides = LyXTextClass::OneSide; break;
|
|
|
|
|
case 2: params.sides = LyXTextClass::TwoSides; break;
|
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\paperpagestyle") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
params.pagestyle = strip(lex.GetString());
|
|
|
|
|
} else if (token == "\\bullet") {
|
|
|
|
|
lex.nextToken();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
int const index = lex.GetInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
lex.nextToken();
|
|
|
|
|
int temp_int = lex.GetInteger();
|
|
|
|
|
params.user_defined_bullets[index].setFont(temp_int);
|
|
|
|
|
params.temp_bullets[index].setFont(temp_int);
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
temp_int = lex.GetInteger();
|
|
|
|
|
params.user_defined_bullets[index].setCharacter(temp_int);
|
|
|
|
|
params.temp_bullets[index].setCharacter(temp_int);
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
temp_int = lex.GetInteger();
|
|
|
|
|
params.user_defined_bullets[index].setSize(temp_int);
|
|
|
|
|
params.temp_bullets[index].setSize(temp_int);
|
|
|
|
|
lex.nextToken();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const temp_str = lex.GetString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (temp_str != "\\end_bullet") {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// this element isn't really necessary for
|
|
|
|
|
// parsing but is easier for humans
|
|
|
|
|
// to understand bullets. Put it back and
|
|
|
|
|
// set a debug message?
|
2000-03-01 14:13:21 +00:00
|
|
|
|
lex.printError("\\end_bullet expected, got" + temp_str);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
//how can I put it back?
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\bulletLaTeX") {
|
|
|
|
|
lex.nextToken();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
int const index = lex.GetInteger();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string temp_str = lex.GetString();
|
|
|
|
|
string sum_str;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
while (temp_str != "\\end_bullet") {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// this loop structure is needed when user
|
|
|
|
|
// enters an empty string since the first
|
|
|
|
|
// thing returned will be the \\end_bullet
|
|
|
|
|
// OR
|
|
|
|
|
// if the LaTeX entry has spaces. Each element
|
|
|
|
|
// therefore needs to be read in turn
|
2000-03-01 14:13:21 +00:00
|
|
|
|
sum_str += temp_str;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lex.next();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
temp_str = lex.GetString();
|
|
|
|
|
}
|
|
|
|
|
params.user_defined_bullets[index].setText(sum_str);
|
|
|
|
|
params.temp_bullets[index].setText(sum_str);
|
|
|
|
|
} else if (token == "\\secnumdepth") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
params.secnumdepth = lex.GetInteger();
|
|
|
|
|
} else if (token == "\\tocdepth") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
params.tocdepth = lex.GetInteger();
|
|
|
|
|
} else if (token == "\\spacing") {
|
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const tmp = strip(lex.GetString());
|
2000-04-24 20:58:23 +00:00
|
|
|
|
Spacing::Space tmp_space = Spacing::Default;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
float tmp_val = 0.0;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmp == "single") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
tmp_space = Spacing::Single;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (tmp == "onehalf") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
tmp_space = Spacing::Onehalf;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (tmp == "double") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
tmp_space = Spacing::Double;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (tmp == "other") {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
lex.next();
|
2000-04-26 13:57:28 +00:00
|
|
|
|
tmp_space = Spacing::Other;
|
|
|
|
|
tmp_val = lex.GetFloat();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Unknown spacing token: '$$Token'");
|
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
// Small hack so that files written with klyx will be
|
|
|
|
|
// parsed correctly.
|
|
|
|
|
if (return_par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(tmp_space, tmp_val));
|
2000-04-24 20:58:23 +00:00
|
|
|
|
} else {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
params.spacing.set(tmp_space, tmp_val);
|
2000-04-24 20:58:23 +00:00
|
|
|
|
}
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else if (token == "\\paragraph_spacing") {
|
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const tmp = strip(lex.GetString());
|
2000-04-11 22:55:29 +00:00
|
|
|
|
if (tmp == "single") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(Spacing::Single));
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else if (tmp == "onehalf") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(Spacing::Onehalf));
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else if (tmp == "double") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(Spacing::Double));
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else if (tmp == "other") {
|
|
|
|
|
lex.next();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spacing(Spacing(Spacing::Other,
|
2001-03-06 14:07:14 +00:00
|
|
|
|
lex.GetFloat()));
|
2000-04-11 22:55:29 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Unknown spacing token: '$$Token'");
|
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\float_placement") {
|
|
|
|
|
lex.nextToken();
|
|
|
|
|
params.float_placement = lex.GetString();
|
|
|
|
|
} else if (token == "\\family") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXFamily(lex.GetString());
|
|
|
|
|
} else if (token == "\\series") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXSeries(lex.GetString());
|
|
|
|
|
} else if (token == "\\shape") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXShape(lex.GetString());
|
|
|
|
|
} else if (token == "\\size") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXSize(lex.GetString());
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#ifndef NO_LATEX
|
|
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
|
#warning compatability hack needed
|
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\latex") {
|
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const tok = lex.GetString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
// This is dirty, but gone with LyX3. (Asger)
|
|
|
|
|
if (tok == "no_latex")
|
|
|
|
|
font.setLatex(LyXFont::OFF);
|
|
|
|
|
else if (tok == "latex")
|
|
|
|
|
font.setLatex(LyXFont::ON);
|
|
|
|
|
else if (tok == "default")
|
|
|
|
|
font.setLatex(LyXFont::INHERIT);
|
|
|
|
|
else
|
|
|
|
|
lex.printError("Unknown LaTeX font flag "
|
|
|
|
|
"`$$Token'");
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#else
|
|
|
|
|
} else if (token == "\\latex") {
|
|
|
|
|
lex.next();
|
|
|
|
|
string const tok = lex.GetString();
|
|
|
|
|
if (tok == "no_latex") {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
// Do the insetert.
|
|
|
|
|
insertErtContents(par, pos, font);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else if (tok == "latex") {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
ert_active = true;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else if (tok == "default") {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
// Do the insetert.
|
|
|
|
|
insertErtContents(par, pos, font);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Unknown LaTeX font flag "
|
|
|
|
|
"`$$Token'");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2000-03-17 10:14:46 +00:00
|
|
|
|
} else if (token == "\\lang") {
|
2000-03-01 14:13:21 +00:00
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const tok = lex.GetString();
|
2000-10-10 12:36:36 +00:00
|
|
|
|
Language const * lang = languages.getLanguage(tok);
|
|
|
|
|
if (lang) {
|
|
|
|
|
font.setLanguage(lang);
|
2000-03-17 10:14:46 +00:00
|
|
|
|
} else {
|
2000-10-10 12:36:36 +00:00
|
|
|
|
font.setLanguage(params.language);
|
2000-03-17 10:14:46 +00:00
|
|
|
|
lex.printError("Unknown language `$$Token'");
|
|
|
|
|
}
|
2000-10-09 12:30:52 +00:00
|
|
|
|
} else if (token == "\\numeric") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setNumber(font.setLyXMisc(lex.GetString()));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\emph") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setEmph(font.setLyXMisc(lex.GetString()));
|
|
|
|
|
} else if (token == "\\bar") {
|
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const tok = lex.GetString();
|
2000-03-01 14:13:21 +00:00
|
|
|
|
// This is dirty, but gone with LyX3. (Asger)
|
|
|
|
|
if (tok == "under")
|
|
|
|
|
font.setUnderbar(LyXFont::ON);
|
|
|
|
|
else if (tok == "no")
|
|
|
|
|
font.setUnderbar(LyXFont::OFF);
|
|
|
|
|
else if (tok == "default")
|
|
|
|
|
font.setUnderbar(LyXFont::INHERIT);
|
|
|
|
|
else
|
|
|
|
|
lex.printError("Unknown bar font flag "
|
|
|
|
|
"`$$Token'");
|
|
|
|
|
} else if (token == "\\noun") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setNoun(font.setLyXMisc(lex.GetString()));
|
|
|
|
|
} else if (token == "\\color") {
|
|
|
|
|
lex.next();
|
|
|
|
|
font.setLyXColor(lex.GetString());
|
|
|
|
|
} else if (token == "\\align") {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
int tmpret = lex.FindToken(string_align);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
if (tmpret == -1) ++tmpret;
|
|
|
|
|
if (tmpret != LYX_LAYOUT_DEFAULT) { // tmpret != 99 ???
|
2000-11-21 21:51:25 +00:00
|
|
|
|
int const tmpret2 = int(pow(2.0, tmpret));
|
2000-11-21 22:16:14 +00:00
|
|
|
|
//lyxerr << "Tmpret2 = " << tmpret2 << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().align(LyXAlignment(tmpret2));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
}
|
|
|
|
|
} else if (token == "\\added_space_top") {
|
|
|
|
|
lex.nextToken();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spaceTop(VSpace(lex.GetString()));
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\added_space_bottom") {
|
|
|
|
|
lex.nextToken();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().spaceBottom(VSpace(lex.GetString()));
|
2001-03-16 00:09:53 +00:00
|
|
|
|
#ifndef NO_PEXTRA_REALLY
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_type") {
|
|
|
|
|
lex.nextToken();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pextraType(lex.GetInteger());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_width") {
|
|
|
|
|
lex.nextToken();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pextraWidth(lex.GetString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_widthp") {
|
|
|
|
|
lex.nextToken();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pextraWidthp(lex.GetString());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_alignment") {
|
|
|
|
|
lex.nextToken();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pextraAlignment(lex.GetInteger());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_hfill") {
|
|
|
|
|
lex.nextToken();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pextraHfill(lex.GetInteger());
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\pextra_start_minipage") {
|
|
|
|
|
lex.nextToken();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().pextraStartMinipage(lex.GetInteger());
|
2001-03-16 00:09:53 +00:00
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\labelwidthstring") {
|
|
|
|
|
lex.EatLine();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->params().labelWidthString(lex.GetString());
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// do not delete this token, it is still needed!
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\end_inset") {
|
2000-07-15 23:51:46 +00:00
|
|
|
|
lyxerr << "Solitary \\end_inset. Missing \\begin_inset?.\n"
|
|
|
|
|
<< "Last inset read was: " << last_inset_read
|
|
|
|
|
<< endl;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// Simply ignore this. The insets do not have
|
|
|
|
|
// to read this.
|
|
|
|
|
// But insets should read it, it is a part of
|
|
|
|
|
// the inset isn't it? Lgb.
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\begin_inset") {
|
2000-07-24 21:49:58 +00:00
|
|
|
|
readInset(lex, par, pos, font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\SpecialChar") {
|
2000-03-09 03:36:48 +00:00
|
|
|
|
LyXLayout const & layout =
|
|
|
|
|
textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
2000-03-09 03:36:48 +00:00
|
|
|
|
|
|
|
|
|
// Insets don't make sense in a free-spacing context! ---Kayvan
|
2000-04-24 20:58:23 +00:00
|
|
|
|
if (layout.free_spacing) {
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
|
lex.next();
|
2000-07-15 23:51:46 +00:00
|
|
|
|
string next_token = lex.GetString();
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (next_token == "\\-") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, '-', font);
|
2000-05-05 11:42:00 +00:00
|
|
|
|
} else if (next_token == "\\protected_separator"
|
2000-05-05 12:27:42 +00:00
|
|
|
|
|| next_token == "~") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, ' ', font);
|
2000-03-09 03:36:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
lex.printError("Token `$$Token' "
|
|
|
|
|
"is in free space "
|
|
|
|
|
"paragraph layout!");
|
2000-04-24 20:58:23 +00:00
|
|
|
|
--pos;
|
2000-03-09 03:36:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
} else {
|
|
|
|
|
Inset * inset = new InsetSpecialChar;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->read(this, lex);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-03-09 03:36:48 +00:00
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
2000-04-24 20:58:23 +00:00
|
|
|
|
} else if (token == "\\newline") {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
// Since we cannot know it this is only a regular newline or a
|
|
|
|
|
// tabular cell delimter we have to handle the ERT here.
|
|
|
|
|
insertErtContents(par, pos, font, false);
|
|
|
|
|
#endif
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, Paragraph::META_NEWLINE, font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\LyXTable") {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
Inset * inset = new InsetTabular(*this);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->read(this, lex);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-05-17 14:43:09 +00:00
|
|
|
|
++pos;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
// because of OLD_TABULAR_READ where tabulars have been
|
|
|
|
|
// one paragraph.
|
|
|
|
|
checkminipage = true;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else if (token == "\\hfill") {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, Paragraph::META_HFILL, font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\protected_separator") { // obsolete
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// This is a backward compability thingie. (Lgb)
|
|
|
|
|
// Remove it later some time...introduced with fileformat
|
|
|
|
|
// 2.16. (Lgb)
|
2000-03-09 03:36:48 +00:00
|
|
|
|
LyXLayout const & layout =
|
|
|
|
|
textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
2000-03-09 03:36:48 +00:00
|
|
|
|
|
|
|
|
|
if (layout.free_spacing) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, ' ', font);
|
2000-03-09 03:36:48 +00:00
|
|
|
|
} else {
|
2000-04-24 20:58:23 +00:00
|
|
|
|
Inset * inset = new InsetSpecialChar(InsetSpecialChar::PROTECTED_SEPARATOR);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-03-09 03:36:48 +00:00
|
|
|
|
}
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
|
|
|
|
} else if (token == "\\bibitem") { // ale970302
|
2000-08-04 13:12:30 +00:00
|
|
|
|
if (!par->bibkey) {
|
2001-01-31 11:46:13 +00:00
|
|
|
|
InsetCommandParams p("bibitem", "dummy");
|
2000-08-04 13:12:30 +00:00
|
|
|
|
par->bibkey = new InsetBibKey(p);
|
|
|
|
|
}
|
2001-06-28 10:25:20 +00:00
|
|
|
|
par->bibkey->read(this, lex);
|
2000-08-05 05:17:18 +00:00
|
|
|
|
} else if (token == "\\backslash") {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
if (ert_active) {
|
|
|
|
|
inset_ert_contents += "\\";
|
|
|
|
|
} else {
|
|
|
|
|
#endif
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, '\\', font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
2001-07-08 12:52:16 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2000-08-05 05:17:18 +00:00
|
|
|
|
} else if (token == "\\the_end") {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
//<2F>If we still have some ert active here we have to insert
|
|
|
|
|
// it so we don't loose it. (Lgb)
|
|
|
|
|
insertErtContents(par, pos, font);
|
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
the_end_read = true;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
minipar = parBeforeMinipage = 0;
|
2000-03-01 14:13:21 +00:00
|
|
|
|
} else {
|
2001-07-08 12:52:16 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
if (ert_active) {
|
|
|
|
|
inset_ert_contents += token;
|
|
|
|
|
} else {
|
|
|
|
|
#endif
|
2000-03-01 14:13:21 +00:00
|
|
|
|
// This should be insurance for the future: (Asger)
|
|
|
|
|
lex.printError("Unknown token `$$Token'. "
|
|
|
|
|
"Inserting as text.");
|
2000-08-05 05:17:18 +00:00
|
|
|
|
string::const_iterator cit = token.begin();
|
|
|
|
|
string::const_iterator end = token.end();
|
2000-11-04 10:00:12 +00:00
|
|
|
|
for (; cit != end; ++cit) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertChar(pos, (*cit), font);
|
2000-03-01 14:13:21 +00:00
|
|
|
|
++pos;
|
|
|
|
|
}
|
2001-07-08 12:52:16 +00:00
|
|
|
|
#ifdef NO_LATEX
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-22 15:45:15 +00:00
|
|
|
|
#ifndef NO_PEXTRA_REALLY
|
|
|
|
|
// now check if we have a minipage paragraph as at this
|
|
|
|
|
// point we already read all the necessary data!
|
|
|
|
|
// this cannot be done in layout because there we did
|
|
|
|
|
// not read yet the paragraph PEXTRA-params (Jug)
|
|
|
|
|
//
|
|
|
|
|
// BEGIN pextra_minipage compability
|
|
|
|
|
// This should be removed in 1.3.x (Lgb)
|
|
|
|
|
|
|
|
|
|
// This compability code is not perfect. In a couple
|
|
|
|
|
// of rand cases it fails. When the minipage par is
|
|
|
|
|
// the first par in the document, and when there are
|
|
|
|
|
// none or only one regular paragraphs after the
|
|
|
|
|
// minipage. Currently I am not investing any effort
|
|
|
|
|
// in fixing those cases.
|
|
|
|
|
|
|
|
|
|
//lyxerr << "Call depth: " << call_depth << endl;
|
|
|
|
|
if (checkminipage && (call_depth == 1)) {
|
|
|
|
|
checkminipage = false;
|
|
|
|
|
if (minipar && (minipar != par) &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
(par->params().pextraType()==Paragraph::PEXTRA_MINIPAGE))
|
2001-03-22 15:45:15 +00:00
|
|
|
|
{
|
|
|
|
|
lyxerr << "minipages in a row" << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->params().pextraStartMinipage()) {
|
2001-03-22 15:45:15 +00:00
|
|
|
|
lyxerr << "start new minipage" << endl;
|
|
|
|
|
// minipages in a row
|
|
|
|
|
par->previous()->next(0);
|
|
|
|
|
par->previous(0);
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tmp = minipar;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
while (tmp) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
tmp->params().pextraType(0);
|
|
|
|
|
tmp->params().pextraWidth(string());
|
|
|
|
|
tmp->params().pextraWidthp(string());
|
|
|
|
|
tmp->params().pextraAlignment(0);
|
|
|
|
|
tmp->params().pextraHfill(false);
|
|
|
|
|
tmp->params().pextraStartMinipage(false);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
tmp = tmp->next();
|
|
|
|
|
}
|
|
|
|
|
// create a new paragraph to insert the
|
|
|
|
|
// minipages in the following case
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->params().pextraStartMinipage() &&
|
|
|
|
|
!par->params().pextraHfill())
|
2001-03-22 15:45:15 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * p = new Paragraph;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
p->layout = 0;
|
|
|
|
|
p->previous(parBeforeMinipage);
|
|
|
|
|
parBeforeMinipage->next(p);
|
|
|
|
|
p->next(0);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
p->params().depth(parBeforeMinipage->params().depth());
|
2001-03-22 15:45:15 +00:00
|
|
|
|
parBeforeMinipage = p;
|
|
|
|
|
}
|
|
|
|
|
InsetMinipage * mini = new InsetMinipage;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
mini->pos(static_cast<InsetMinipage::Position>(par->params().pextraAlignment()));
|
|
|
|
|
mini->width(par->params().pextraWidth());
|
|
|
|
|
if (!par->params().pextraWidthp().empty()) {
|
2001-03-29 15:00:20 +00:00
|
|
|
|
lyxerr << "WP:" << mini->width() << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
mini->width(tostr(par->params().pextraWidthp())+"%");
|
2001-03-29 15:00:20 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
mini->inset.paragraph(par);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
// Insert the minipage last in the
|
|
|
|
|
// previous paragraph.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->params().pextraHfill()) {
|
|
|
|
|
parBeforeMinipage->insertChar
|
|
|
|
|
(parBeforeMinipage->size(), Paragraph::META_HFILL);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
parBeforeMinipage->insertInset
|
2001-03-22 15:45:15 +00:00
|
|
|
|
(parBeforeMinipage->size(), mini);
|
|
|
|
|
|
|
|
|
|
minipar = par;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "new minipage par" << endl;
|
|
|
|
|
//nothing to do just continue reading
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if (minipar && (minipar != par)) {
|
|
|
|
|
lyxerr << "last minipage par read" << endl;
|
|
|
|
|
// The last paragraph read was not part of a
|
|
|
|
|
// minipage but the par linked list is...
|
|
|
|
|
// So we need to remove the last par from the
|
|
|
|
|
// rest
|
|
|
|
|
if (par->previous())
|
|
|
|
|
par->previous()->next(0);
|
|
|
|
|
par->previous(parBeforeMinipage);
|
|
|
|
|
parBeforeMinipage->next(par);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tmp = minipar;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
while (tmp) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
tmp->params().pextraType(0);
|
|
|
|
|
tmp->params().pextraWidth(string());
|
|
|
|
|
tmp->params().pextraWidthp(string());
|
|
|
|
|
tmp->params().pextraAlignment(0);
|
|
|
|
|
tmp->params().pextraHfill(false);
|
|
|
|
|
tmp->params().pextraStartMinipage(false);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
tmp = tmp->next();
|
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
depth = parBeforeMinipage->params().depth();
|
2001-03-22 15:45:15 +00:00
|
|
|
|
minipar = parBeforeMinipage = 0;
|
|
|
|
|
} else if (!minipar &&
|
2001-06-25 00:06:33 +00:00
|
|
|
|
(par->params().pextraType() == Paragraph::PEXTRA_MINIPAGE))
|
2001-03-22 15:45:15 +00:00
|
|
|
|
{
|
|
|
|
|
// par is the first paragraph in a minipage
|
|
|
|
|
lyxerr << "begin minipage" << endl;
|
|
|
|
|
// To minimize problems for
|
|
|
|
|
// the users we will insert
|
|
|
|
|
// the first minipage in
|
|
|
|
|
// a sequence of minipages
|
|
|
|
|
// in its own paragraph.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * p = new Paragraph;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
p->layout = 0;
|
|
|
|
|
p->previous(par->previous());
|
|
|
|
|
p->next(0);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
p->params().depth(depth);
|
|
|
|
|
par->params().depth(0);
|
2001-03-22 16:07:59 +00:00
|
|
|
|
depth = 0;
|
2001-03-22 15:45:15 +00:00
|
|
|
|
if (par->previous())
|
|
|
|
|
par->previous()->next(p);
|
|
|
|
|
par->previous(0);
|
|
|
|
|
parBeforeMinipage = p;
|
|
|
|
|
minipar = par;
|
|
|
|
|
if (!return_par || (return_par == par))
|
|
|
|
|
return_par = p;
|
|
|
|
|
|
|
|
|
|
InsetMinipage * mini = new InsetMinipage;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
mini->pos(static_cast<InsetMinipage::Position>(minipar->params().pextraAlignment()));
|
|
|
|
|
mini->width(minipar->params().pextraWidth());
|
|
|
|
|
if (!par->params().pextraWidthp().empty()) {
|
2001-03-29 15:00:20 +00:00
|
|
|
|
lyxerr << "WP:" << mini->width() << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
mini->width(tostr(par->params().pextraWidthp())+"%");
|
2001-03-29 15:00:20 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
mini->inset.paragraph(minipar);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
|
|
|
|
|
// Insert the minipage last in the
|
|
|
|
|
// previous paragraph.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (minipar->params().pextraHfill()) {
|
|
|
|
|
parBeforeMinipage->insertChar
|
|
|
|
|
(parBeforeMinipage->size(),Paragraph::META_HFILL);
|
2001-03-22 15:45:15 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
parBeforeMinipage->insertInset
|
2001-03-22 15:45:15 +00:00
|
|
|
|
(parBeforeMinipage->size(), mini);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// End of pextra_minipage compability
|
|
|
|
|
#endif
|
2001-03-14 14:54:30 +00:00
|
|
|
|
--call_depth;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return the_end_read;
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::readInset(LyXLex & lex, Paragraph *& par,
|
2000-07-24 21:49:58 +00:00
|
|
|
|
int & pos, LyXFont & font)
|
|
|
|
|
{
|
|
|
|
|
// consistency check
|
|
|
|
|
if (lex.GetString() != "\\begin_inset") {
|
|
|
|
|
lyxerr << "Buffer::readInset: Consistency check failed."
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
2000-09-27 05:40:29 +00:00
|
|
|
|
Inset * inset = 0;
|
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const tmptok = lex.GetString();
|
2000-07-24 21:49:58 +00:00
|
|
|
|
last_inset_read = tmptok;
|
2000-09-27 05:40:29 +00:00
|
|
|
|
|
2000-07-24 21:49:58 +00:00
|
|
|
|
// test the different insets
|
2000-09-27 05:40:29 +00:00
|
|
|
|
if (tmptok == "LatexCommand") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
InsetCommandParams inscmd;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inscmd.read(lex);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
|
string const cmdName = inscmd.getCmdName();
|
|
|
|
|
|
|
|
|
|
if (cmdName == "cite") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetCitation(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "bibitem") {
|
2000-07-24 21:49:58 +00:00
|
|
|
|
lex.printError("Wrong place for bibitem");
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetBibKey(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "BibTeX") {
|
2000-10-03 09:13:34 +00:00
|
|
|
|
inset = new InsetBibtex(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "index") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetIndex(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "include") {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetInclude(inscmd, *this);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "label") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetLabel(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "url"
|
|
|
|
|
|| cmdName == "htmlurl") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetUrl(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "ref"
|
|
|
|
|
|| cmdName == "pageref"
|
|
|
|
|
|| cmdName == "vref"
|
|
|
|
|
|| cmdName == "vpageref"
|
|
|
|
|
|| cmdName == "prettyref") {
|
2000-07-24 21:49:58 +00:00
|
|
|
|
if (!inscmd.getOptions().empty()
|
|
|
|
|
|| !inscmd.getContents().empty()) {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetRef(inscmd, *this);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "tableofcontents") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetTOC(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "listofalgorithms") {
|
|
|
|
|
inset = new InsetFloatList("algorithm");
|
|
|
|
|
} else if (cmdName == "listoffigures") {
|
|
|
|
|
inset = new InsetFloatList("figure");
|
|
|
|
|
} else if (cmdName == "listoftables") {
|
|
|
|
|
inset = new InsetFloatList("table");
|
|
|
|
|
} else if (cmdName == "printindex") {
|
2000-08-04 13:12:30 +00:00
|
|
|
|
inset = new InsetPrintIndex(inscmd);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (cmdName == "lyxparent") {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetParent(inscmd, *this);
|
2000-07-24 21:49:58 +00:00
|
|
|
|
}
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (tmptok == "Quotes") {
|
|
|
|
|
inset = new InsetQuotes;
|
|
|
|
|
} else if (tmptok == "External") {
|
|
|
|
|
inset = new InsetExternal;
|
|
|
|
|
} else if (tmptok == "FormulaMacro") {
|
|
|
|
|
inset = new InsetFormulaMacro;
|
|
|
|
|
} else if (tmptok == "Formula") {
|
|
|
|
|
inset = new InsetFormula;
|
|
|
|
|
} else if (tmptok == "Figure") {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetFig(100, 100, *this);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Info") {
|
|
|
|
|
inset = new InsetInfo;
|
|
|
|
|
} else if (tmptok == "Include") {
|
|
|
|
|
InsetCommandParams p( "Include" );
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetInclude(p, *this);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "ERT") {
|
|
|
|
|
inset = new InsetERT;
|
|
|
|
|
} else if (tmptok == "Tabular") {
|
2000-10-10 11:50:43 +00:00
|
|
|
|
inset = new InsetTabular(*this);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
} else if (tmptok == "Text") {
|
|
|
|
|
inset = new InsetText;
|
|
|
|
|
} else if (tmptok == "Foot") {
|
|
|
|
|
inset = new InsetFoot;
|
|
|
|
|
} else if (tmptok == "Marginal") {
|
|
|
|
|
inset = new InsetMarginal;
|
|
|
|
|
} else if (tmptok == "Minipage") {
|
|
|
|
|
inset = new InsetMinipage;
|
|
|
|
|
} else if (tmptok == "Float") {
|
|
|
|
|
lex.next();
|
|
|
|
|
string tmptok = lex.GetString();
|
|
|
|
|
inset = new InsetFloat(tmptok);
|
|
|
|
|
} else if (tmptok == "List") {
|
|
|
|
|
inset = new InsetList;
|
|
|
|
|
} else if (tmptok == "Theorem") {
|
|
|
|
|
inset = new InsetList;
|
|
|
|
|
} else if (tmptok == "Caption") {
|
|
|
|
|
inset = new InsetCaption;
|
|
|
|
|
} else if (tmptok == "GRAPHICS") {
|
|
|
|
|
inset = new InsetGraphics;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else if (tmptok == "FloatList") {
|
|
|
|
|
inset = new InsetFloatList;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
}
|
2000-09-27 05:40:29 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if (inset) inset->read(this, lex);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (inset) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, inset, font);
|
2000-09-27 05:40:29 +00:00
|
|
|
|
++pos;
|
2000-07-24 21:49:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
bool Buffer::readFile(LyXLex & lex, Paragraph * par)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
|
lex.next();
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const token(lex.GetString());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (token == "\\lyxformat") { // the first token _must_ be...
|
2000-09-26 13:10:34 +00:00
|
|
|
|
lex.EatLine();
|
2001-01-11 11:06:10 +00:00
|
|
|
|
string tmp_format = lex.GetString();
|
|
|
|
|
//lyxerr << "LyX Format: `" << tmp_format << "'" << endl;
|
|
|
|
|
// if present remove ".," from string.
|
|
|
|
|
string::size_type dot = tmp_format.find_first_of(".,");
|
|
|
|
|
//lyxerr << " dot found at " << dot << endl;
|
|
|
|
|
if (dot != string::npos)
|
|
|
|
|
tmp_format.erase(dot, 1);
|
|
|
|
|
file_format = strToInt(tmp_format);
|
|
|
|
|
if (file_format == LYX_FORMAT) {
|
|
|
|
|
// current format
|
|
|
|
|
} else if (file_format > LYX_FORMAT) {
|
|
|
|
|
// future format
|
|
|
|
|
WriteAlert(_("Warning!"),
|
|
|
|
|
_("LyX file format is newer that what"),
|
|
|
|
|
_("is supported in this LyX version. Expect some problems."));
|
|
|
|
|
|
|
|
|
|
} else if (file_format < LYX_FORMAT) {
|
|
|
|
|
// old formats
|
|
|
|
|
if (file_format < 200) {
|
|
|
|
|
WriteAlert(_("ERROR!"),
|
|
|
|
|
_("Old LyX file format found. "
|
|
|
|
|
"Use LyX 0.10.x to read this!"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
bool the_end = readLyXformat2(lex, par);
|
|
|
|
|
setPaperStuff();
|
|
|
|
|
// the_end was added in 213
|
|
|
|
|
if (file_format < 213)
|
|
|
|
|
the_end = true;
|
|
|
|
|
|
|
|
|
|
if (!the_end)
|
|
|
|
|
WriteAlert(_("Warning!"),
|
|
|
|
|
_("Reading of document is not complete"),
|
|
|
|
|
_("Maybe the document is truncated"));
|
|
|
|
|
return true;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else { // "\\lyxformat" not found
|
|
|
|
|
WriteAlert(_("ERROR!"), _("Not a LyX file!"));
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
WriteAlert(_("ERROR!"), _("Unable to read file!"));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Should probably be moved to somewhere else: BufferView? LyXView?
|
2000-03-20 14:49:54 +00:00
|
|
|
|
bool Buffer::save() const
|
2000-02-22 00:36:17 +00:00
|
|
|
|
{
|
|
|
|
|
// We don't need autosaves in the immediate future. (Asger)
|
|
|
|
|
resetAutosaveTimers();
|
|
|
|
|
|
|
|
|
|
// make a backup
|
2000-03-20 14:49:54 +00:00
|
|
|
|
string s;
|
|
|
|
|
if (lyxrc.make_backup) {
|
|
|
|
|
s = fileName() + '~';
|
|
|
|
|
if (!lyxrc.backupdir_path.empty())
|
|
|
|
|
s = AddName(lyxrc.backupdir_path,
|
2001-05-17 15:11:01 +00:00
|
|
|
|
subst(os::slashify_path(s),'/','!'));
|
2000-03-20 14:49:54 +00:00
|
|
|
|
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Rename is the wrong way of making a backup,
|
|
|
|
|
// this is the correct way.
|
|
|
|
|
/* truss cp fil fil2:
|
|
|
|
|
lstat("LyXVC3.lyx", 0xEFFFF898) Err#2 ENOENT
|
|
|
|
|
stat("LyXVC.lyx", 0xEFFFF688) = 0
|
|
|
|
|
open("LyXVC.lyx", O_RDONLY) = 3
|
|
|
|
|
open("LyXVC3.lyx", O_WRONLY|O_CREAT|O_TRUNC, 0600) = 4
|
|
|
|
|
fstat(4, 0xEFFFF508) = 0
|
|
|
|
|
fstat(3, 0xEFFFF508) = 0
|
|
|
|
|
read(3, " # T h i s f i l e w".., 8192) = 5579
|
|
|
|
|
write(4, " # T h i s f i l e w".., 5579) = 5579
|
|
|
|
|
read(3, 0xEFFFD4A0, 8192) = 0
|
|
|
|
|
close(4) = 0
|
|
|
|
|
close(3) = 0
|
|
|
|
|
chmod("LyXVC3.lyx", 0100644) = 0
|
|
|
|
|
lseek(0, 0, SEEK_CUR) = 46440
|
|
|
|
|
_exit(0)
|
|
|
|
|
*/
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
// Should probably have some more error checking here.
|
2000-02-22 00:36:17 +00:00
|
|
|
|
// Should be cleaned up in 0.13, at least a bit.
|
|
|
|
|
// Doing it this way, also makes the inodes stay the same.
|
|
|
|
|
// This is still not a very good solution, in particular we
|
|
|
|
|
// might loose the owner of the backup.
|
|
|
|
|
FileInfo finfo(fileName());
|
|
|
|
|
if (finfo.exist()) {
|
|
|
|
|
mode_t fmode = finfo.getMode();
|
2000-03-28 02:18:55 +00:00
|
|
|
|
struct utimbuf times = {
|
|
|
|
|
finfo.getAccessTime(),
|
|
|
|
|
finfo.getModificationTime() };
|
2000-02-22 00:36:17 +00:00
|
|
|
|
|
|
|
|
|
ifstream ifs(fileName().c_str());
|
|
|
|
|
ofstream ofs(s.c_str(), ios::out|ios::trunc);
|
|
|
|
|
if (ifs && ofs) {
|
|
|
|
|
ofs << ifs.rdbuf();
|
|
|
|
|
ifs.close();
|
|
|
|
|
ofs.close();
|
|
|
|
|
::chmod(s.c_str(), fmode);
|
|
|
|
|
|
2000-03-28 02:18:55 +00:00
|
|
|
|
if (::utime(s.c_str(), ×)) {
|
2000-02-22 00:36:17 +00:00
|
|
|
|
lyxerr << "utime error." << endl;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "LyX was not able to make "
|
2001-06-25 00:06:33 +00:00
|
|
|
|
"backup copy. Beware." << endl;
|
2000-02-22 00:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (writeFile(fileName(), false)) {
|
|
|
|
|
markLyxClean();
|
2000-08-08 15:36:25 +00:00
|
|
|
|
removeAutosaveFile(fileName());
|
2000-02-22 00:36:17 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Saving failed, so backup is not backup
|
2000-03-20 14:49:54 +00:00
|
|
|
|
if (lyxrc.make_backup) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
lyx::rename(s, fileName());
|
2000-02-22 00:36:17 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Returns false if unsuccesful
|
2000-02-22 00:36:17 +00:00
|
|
|
|
bool Buffer::writeFile(string const & fname, bool flag) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
// if flag is false writeFile will not create any GUI
|
1999-10-07 18:44:17 +00:00
|
|
|
|
// warnings, only cerr.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Needed for autosave in background or panic save (Matthias 120496)
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
if (read_only && (fname == filename)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Here we should come with a question if we should
|
|
|
|
|
// perform the write anyway.
|
|
|
|
|
if (flag)
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr << _("Error! Document is read-only: ")
|
1999-12-21 06:10:21 +00:00
|
|
|
|
<< fname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-15 12:01:38 +00:00
|
|
|
|
WriteAlert(_("Error! Document is read-only: "),
|
1999-12-21 06:10:21 +00:00
|
|
|
|
fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
FileInfo finfo(fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (finfo.exist() && !finfo.writable()) {
|
|
|
|
|
// Here we should come with a question if we should
|
|
|
|
|
// try to do the save anyway. (i.e. do a chmod first)
|
|
|
|
|
if (flag)
|
1999-10-07 18:44:17 +00:00
|
|
|
|
lyxerr << _("Error! Cannot write file: ")
|
1999-12-21 06:10:21 +00:00
|
|
|
|
<< fname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-15 12:01:38 +00:00
|
|
|
|
WriteFSAlert(_("Error! Cannot write file: "),
|
1999-12-21 06:10:21 +00:00
|
|
|
|
fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-21 06:10:21 +00:00
|
|
|
|
ofstream ofs(fname.c_str());
|
1999-12-07 00:44:53 +00:00
|
|
|
|
if (!ofs) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (flag)
|
1999-12-07 00:44:53 +00:00
|
|
|
|
lyxerr << _("Error! Cannot open file: ")
|
1999-12-21 06:10:21 +00:00
|
|
|
|
<< fname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-12-13 21:59:26 +00:00
|
|
|
|
WriteFSAlert(_("Error! Cannot open file: "),
|
1999-12-21 06:10:21 +00:00
|
|
|
|
fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
|
|
|
|
#ifdef HAVE_LOCALE
|
|
|
|
|
// Use the standard "C" locale for file output.
|
2000-09-15 10:24:15 +00:00
|
|
|
|
ofs.imbue(std::locale::classic());
|
2000-09-14 17:53:12 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// The top of the file should not be written by params.
|
|
|
|
|
|
|
|
|
|
// write out a comment in the top of the file
|
1999-12-15 17:42:22 +00:00
|
|
|
|
ofs << '#' << LYX_DOCVERSION
|
2001-02-14 19:22:41 +00:00
|
|
|
|
<< " created this file. For more info see http://www.lyx.org/\n"
|
|
|
|
|
<< "\\lyxformat " << LYX_FORMAT << "\n";
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
// now write out the buffer paramters.
|
|
|
|
|
params.writeFile(ofs);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// this will write out all the paragraphs
|
|
|
|
|
// using recursive descent.
|
2001-05-08 17:08:44 +00:00
|
|
|
|
paragraph->writeFile(this, ofs, params, depth);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Write marker that shows file is complete
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs << "\n\\the_end" << endl;
|
2000-10-13 12:20:38 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
2000-10-13 12:20:38 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
// how to check if close went ok?
|
2000-10-13 12:20:38 +00:00
|
|
|
|
// Following is an attempt... (BE 20001011)
|
|
|
|
|
|
|
|
|
|
// good() returns false if any error occured, including some
|
|
|
|
|
// formatting error.
|
|
|
|
|
// bad() returns true if something bad happened in the buffer,
|
|
|
|
|
// which should include file system full errors.
|
|
|
|
|
|
|
|
|
|
bool status = true;
|
|
|
|
|
if (!ofs.good()) {
|
|
|
|
|
status = false;
|
|
|
|
|
#if 0
|
|
|
|
|
if (ofs.bad()) {
|
|
|
|
|
lyxerr << "Buffer::writeFile: BAD ERROR!" << endl;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "Buffer::writeFile: NOT SO BAD ERROR!"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return status;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
string const Buffer::asciiParagraph(Paragraph const * par,
|
2000-09-27 17:07:33 +00:00
|
|
|
|
unsigned int linelen) const
|
2000-09-26 15:25:14 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream buffer;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
int ltype = 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type ltype_depth = 0;
|
2000-09-27 17:07:33 +00:00
|
|
|
|
unsigned int currlinelen = 0;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
bool ref_printed = false;
|
|
|
|
|
|
|
|
|
|
int noparbreak = 0;
|
|
|
|
|
int islatex = 0;
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if (!par->previous()) {
|
2001-05-16 07:53:23 +00:00
|
|
|
|
// begins or ends a deeper area ?
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth != par->params().depth()) {
|
|
|
|
|
if (par->params().depth() > depth) {
|
|
|
|
|
while (par->params().depth() > depth) {
|
2000-09-26 15:25:14 +00:00
|
|
|
|
++depth;
|
|
|
|
|
}
|
2001-03-06 14:07:14 +00:00
|
|
|
|
} else {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
while (par->params().depth() < depth) {
|
2000-09-26 15:25:14 +00:00
|
|
|
|
--depth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-16 07:53:23 +00:00
|
|
|
|
// First write the layout
|
2000-09-29 18:44:07 +00:00
|
|
|
|
string const tmp = textclasslist.NameOfLayout(params.textclass, par->layout);
|
2000-09-26 15:25:14 +00:00
|
|
|
|
if (tmp == "Itemize") {
|
|
|
|
|
ltype = 1;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
ltype_depth = depth + 1;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
} else if (tmp == "Enumerate") {
|
|
|
|
|
ltype = 2;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
ltype_depth = depth + 1;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
} else if (contains(tmp, "ection")) {
|
2000-09-26 15:25:14 +00:00
|
|
|
|
ltype = 3;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
ltype_depth = depth + 1;
|
2001-05-31 02:23:46 +00:00
|
|
|
|
} else if (contains(tmp, "aragraph")) {
|
2000-09-26 15:25:14 +00:00
|
|
|
|
ltype = 4;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
ltype_depth = depth + 1;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
} else if (tmp == "Description") {
|
|
|
|
|
ltype = 5;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
ltype_depth = depth + 1;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
} else if (tmp == "Abstract") {
|
|
|
|
|
ltype = 6;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
} else if (tmp == "Bibliography") {
|
|
|
|
|
ltype = 7;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
} else {
|
|
|
|
|
ltype = 0;
|
|
|
|
|
ltype_depth = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* maybe some vertical spaces */
|
|
|
|
|
|
|
|
|
|
/* the labelwidthstring used in lists */
|
|
|
|
|
|
|
|
|
|
/* some lines? */
|
|
|
|
|
|
|
|
|
|
/* some pagebreaks? */
|
|
|
|
|
|
|
|
|
|
/* noindent ? */
|
|
|
|
|
|
|
|
|
|
/* what about the alignment */
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "Should this ever happen?" << endl;
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
|
|
|
|
|
#ifndef NO_LATEX
|
2001-05-16 07:53:23 +00:00
|
|
|
|
LyXFont const font1 = LyXFont(LyXFont::ALL_INHERIT, params.language);
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#endif
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::size_type i = 0; i < par->size(); ++i) {
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if (!i && !noparbreak) {
|
2000-10-10 10:38:11 +00:00
|
|
|
|
if (linelen > 0)
|
|
|
|
|
buffer << "\n\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::depth_type j = 0; j < depth; ++j)
|
2000-09-26 15:25:14 +00:00
|
|
|
|
buffer << " ";
|
|
|
|
|
currlinelen = depth * 2;
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (ltype) {
|
2001-05-16 07:53:23 +00:00
|
|
|
|
case 0: // Standard
|
|
|
|
|
case 4: // (Sub)Paragraph
|
|
|
|
|
case 5: // Description
|
2000-09-26 15:25:14 +00:00
|
|
|
|
break;
|
2001-05-16 07:53:23 +00:00
|
|
|
|
case 6: // Abstract
|
2000-10-10 10:38:11 +00:00
|
|
|
|
if (linelen > 0)
|
|
|
|
|
buffer << "Abstract\n\n";
|
|
|
|
|
else
|
|
|
|
|
buffer << "Abstract: ";
|
2000-09-26 15:25:14 +00:00
|
|
|
|
break;
|
2001-05-16 07:53:23 +00:00
|
|
|
|
case 7: // Bibliography
|
2000-09-26 15:25:14 +00:00
|
|
|
|
if (!ref_printed) {
|
2000-10-10 10:38:11 +00:00
|
|
|
|
if (linelen > 0)
|
|
|
|
|
buffer << "References\n\n";
|
|
|
|
|
else
|
|
|
|
|
buffer << "References: ";
|
2000-09-26 15:25:14 +00:00
|
|
|
|
ref_printed = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
buffer << par->params().labelString() << " ";
|
2000-09-26 15:25:14 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (ltype_depth > depth) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::depth_type j = ltype_depth - 1;
|
|
|
|
|
j > depth; --j)
|
2000-09-26 15:25:14 +00:00
|
|
|
|
buffer << " ";
|
|
|
|
|
currlinelen += (ltype_depth-depth)*2;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#ifndef NO_LATEX
|
2001-06-25 00:06:33 +00:00
|
|
|
|
LyXFont const font2 = par->getFontSettings(params, i);
|
2000-09-26 15:25:14 +00:00
|
|
|
|
if (font1.latex() != font2.latex()) {
|
|
|
|
|
if (font2.latex() == LyXFont::OFF)
|
|
|
|
|
islatex = 0;
|
|
|
|
|
else
|
|
|
|
|
islatex = 1;
|
|
|
|
|
} else {
|
|
|
|
|
islatex = 0;
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#endif
|
2001-05-16 07:53:23 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
char c = par->getUChar(params, i);
|
2000-09-26 15:25:14 +00:00
|
|
|
|
if (islatex)
|
|
|
|
|
continue;
|
|
|
|
|
switch (c) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
case Paragraph::META_INSET:
|
2001-05-16 07:53:23 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Inset const * inset = par->getInset(i);
|
2001-05-16 07:53:23 +00:00
|
|
|
|
if (inset) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if (!inset->ascii(this, buffer)) {
|
2000-09-26 15:25:14 +00:00
|
|
|
|
string dummy;
|
2001-05-16 07:53:23 +00:00
|
|
|
|
string const s =
|
|
|
|
|
rsplit(buffer.str().c_str(),
|
|
|
|
|
dummy, '\n');
|
2000-09-26 15:25:14 +00:00
|
|
|
|
currlinelen += s.length();
|
|
|
|
|
} else {
|
|
|
|
|
// to be sure it breaks paragraph
|
|
|
|
|
currlinelen += linelen;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-05-16 07:53:23 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
case Paragraph::META_NEWLINE:
|
2000-10-10 10:38:11 +00:00
|
|
|
|
if (linelen > 0) {
|
|
|
|
|
buffer << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::depth_type j = 0;
|
|
|
|
|
j < depth; ++j)
|
2000-10-10 10:38:11 +00:00
|
|
|
|
buffer << " ";
|
|
|
|
|
}
|
2000-09-26 15:25:14 +00:00
|
|
|
|
currlinelen = depth * 2;
|
|
|
|
|
if (ltype_depth > depth) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::depth_type j = ltype_depth;
|
|
|
|
|
j > depth; --j)
|
2000-09-26 15:25:14 +00:00
|
|
|
|
buffer << " ";
|
|
|
|
|
currlinelen += (ltype_depth - depth) * 2;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-05-16 07:53:23 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
case Paragraph::META_HFILL:
|
2000-09-26 15:25:14 +00:00
|
|
|
|
buffer << "\t";
|
|
|
|
|
break;
|
2001-05-16 07:53:23 +00:00
|
|
|
|
|
2000-09-26 15:25:14 +00:00
|
|
|
|
case '\\':
|
|
|
|
|
buffer << "\\";
|
|
|
|
|
break;
|
2001-05-16 07:53:23 +00:00
|
|
|
|
|
2000-09-26 15:25:14 +00:00
|
|
|
|
default:
|
|
|
|
|
if ((linelen > 0) && (currlinelen > (linelen - 10)) &&
|
|
|
|
|
(c == ' ') && ((i + 2) < par->size()))
|
|
|
|
|
{
|
|
|
|
|
buffer << "\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::depth_type j = 0;
|
|
|
|
|
j < depth; ++j)
|
2000-09-26 15:25:14 +00:00
|
|
|
|
buffer << " ";
|
|
|
|
|
currlinelen = depth * 2;
|
|
|
|
|
if (ltype_depth > depth) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::depth_type j = ltype_depth;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
j > depth; --j)
|
|
|
|
|
buffer << " ";
|
|
|
|
|
currlinelen += (ltype_depth-depth)*2;
|
|
|
|
|
}
|
|
|
|
|
} else if (c != '\0')
|
|
|
|
|
buffer << c;
|
|
|
|
|
else if (c == '\0')
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "writeAsciiFile: NULL char in structure." << endl;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
++currlinelen;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-11-06 15:47:22 +00:00
|
|
|
|
return buffer.str().c_str();
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::writeFileAscii(string const & fname, int linelen)
|
|
|
|
|
{
|
|
|
|
|
ofstream ofs(fname.c_str());
|
|
|
|
|
if (!ofs) {
|
|
|
|
|
WriteFSAlert(_("Error: Cannot write file:"), fname);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
writeFileAscii(ofs, linelen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::writeFileAscii(ostream & ofs, int linelen)
|
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
2000-09-26 15:25:14 +00:00
|
|
|
|
while (par) {
|
|
|
|
|
ofs << asciiParagraph(par, linelen);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-09-26 15:25:14 +00:00
|
|
|
|
}
|
|
|
|
|
ofs << "\n";
|
|
|
|
|
}
|
2000-11-15 03:22:08 +00:00
|
|
|
|
|
2001-02-25 10:22:54 +00:00
|
|
|
|
bool use_babel;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
void Buffer::makeLaTeXFile(string const & fname,
|
|
|
|
|
string const & original_path,
|
|
|
|
|
bool nice, bool only_body)
|
|
|
|
|
{
|
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile..." << endl;
|
|
|
|
|
|
|
|
|
|
niceFile = nice; // this will be used by Insetincludes.
|
|
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
|
tex_code_break_column = lyxrc.ascii_linelen;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
LyXTextClass const & tclass =
|
|
|
|
|
textclasslist.TextClass(params.textclass);
|
|
|
|
|
|
|
|
|
|
ofstream ofs(fname.c_str());
|
|
|
|
|
if (!ofs) {
|
|
|
|
|
WriteFSAlert(_("Error: Cannot open file: "), fname);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// validate the buffer.
|
|
|
|
|
lyxerr[Debug::LATEX] << " Validating buffer..." << endl;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
LaTeXFeatures features(params, tclass.numLayouts());
|
2000-03-06 02:42:40 +00:00
|
|
|
|
validate(features);
|
|
|
|
|
lyxerr[Debug::LATEX] << " Buffer validation done." << endl;
|
|
|
|
|
|
|
|
|
|
texrow.reset();
|
|
|
|
|
// The starting paragraph of the coming rows is the
|
|
|
|
|
// first paragraph of the document. (Asger)
|
|
|
|
|
texrow.start(paragraph, 0);
|
|
|
|
|
|
|
|
|
|
if (!only_body && nice) {
|
|
|
|
|
ofs << "%% " LYX_DOCVERSION " created this file. "
|
|
|
|
|
"For more info, see http://www.lyx.org/.\n"
|
|
|
|
|
"%% Do not edit unless you really know what "
|
|
|
|
|
"you are doing.\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "lyx header finished" << endl;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// There are a few differences between nice LaTeX and usual files:
|
|
|
|
|
// usual is \batchmode and has a
|
|
|
|
|
// special input@path to allow the including of figures
|
|
|
|
|
// with either \input or \includegraphics (what figinsets do).
|
|
|
|
|
// batchmode is not set if there is a tex_code_break_column.
|
|
|
|
|
// In this case somebody is interested in the generated LaTeX,
|
|
|
|
|
// so this is OK. input@path is set when the actual parameter
|
|
|
|
|
// original_path is set. This is done for usual tex-file, but not
|
|
|
|
|
// for nice-latex-file. (Matthias 250696)
|
|
|
|
|
if (!only_body) {
|
|
|
|
|
if (!nice){
|
|
|
|
|
// code for usual, NOT nice-latex-file
|
|
|
|
|
ofs << "\\batchmode\n"; // changed
|
|
|
|
|
// from \nonstopmode
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
if (!original_path.empty()) {
|
|
|
|
|
ofs << "\\makeatletter\n"
|
|
|
|
|
<< "\\def\\input@path{{"
|
2001-05-17 15:11:01 +00:00
|
|
|
|
<< os::external_path(original_path) << "/}}\n"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "\\makeatother\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofs << "\\documentclass";
|
|
|
|
|
|
2001-05-08 17:08:44 +00:00
|
|
|
|
ostringstream options; // the document class options.
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
if (tokenPos(tclass.opt_fontsize(),
|
|
|
|
|
'|', params.fontsize) >= 0) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// only write if existing in list (and not default)
|
2001-05-09 09:14:50 +00:00
|
|
|
|
options << params.fontsize << "pt,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!params.use_geometry &&
|
|
|
|
|
(params.paperpackage == BufferParams::PACKAGE_NONE)) {
|
|
|
|
|
switch (params.papersize) {
|
|
|
|
|
case BufferParams::PAPER_A4PAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "a4paper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_USLETTER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "letterpaper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A5PAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "a5paper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_B5PAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "b5paper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_EXECUTIVEPAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "executivepaper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_LEGALPAPER:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "legalpaper,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if needed
|
|
|
|
|
if (params.sides != tclass.sides()) {
|
|
|
|
|
switch (params.sides) {
|
|
|
|
|
case LyXTextClass::OneSide:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "oneside,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
case LyXTextClass::TwoSides:
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "twoside,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if needed
|
|
|
|
|
if (params.columns != tclass.columns()) {
|
|
|
|
|
if (params.columns == 2)
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "twocolumn,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
else
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "onecolumn,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!params.use_geometry
|
|
|
|
|
&& params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << "landscape,";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2000-03-17 10:14:46 +00:00
|
|
|
|
// language should be a parameter to \documentclass
|
2001-02-25 10:22:54 +00:00
|
|
|
|
use_babel = false;
|
2001-05-10 15:53:10 +00:00
|
|
|
|
ostringstream language_options;
|
2001-01-20 14:16:01 +00:00
|
|
|
|
if (params.language->babel() == "hebrew"
|
|
|
|
|
&& default_language->babel() != "hebrew")
|
|
|
|
|
// This seems necessary
|
2000-05-12 13:11:20 +00:00
|
|
|
|
features.UsedLanguages.insert(default_language);
|
2001-02-25 10:22:54 +00:00
|
|
|
|
|
|
|
|
|
if (lyxrc.language_use_babel ||
|
|
|
|
|
params.language->lang() != lyxrc.default_language ||
|
|
|
|
|
!features.UsedLanguages.empty()) {
|
2000-03-17 10:14:46 +00:00
|
|
|
|
use_babel = true;
|
|
|
|
|
for (LaTeXFeatures::LanguageList::const_iterator cit =
|
|
|
|
|
features.UsedLanguages.begin();
|
2000-05-05 10:17:05 +00:00
|
|
|
|
cit != features.UsedLanguages.end(); ++cit)
|
2001-05-10 15:53:10 +00:00
|
|
|
|
language_options << (*cit)->babel() << ',';
|
|
|
|
|
language_options << params.language->babel();
|
2001-02-25 10:22:54 +00:00
|
|
|
|
if (lyxrc.language_global_options)
|
2001-05-10 15:53:10 +00:00
|
|
|
|
options << language_options.str() << ',';
|
2000-03-10 13:22:20 +00:00
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// the user-defined options
|
|
|
|
|
if (!params.options.empty()) {
|
2001-05-08 17:08:44 +00:00
|
|
|
|
options << params.options << ',';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
|
|
|
|
string strOptions(options.str().c_str());
|
|
|
|
|
if (!strOptions.empty()){
|
|
|
|
|
strOptions = strip(strOptions, ',');
|
|
|
|
|
ofs << '[' << strOptions << ']';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofs << '{'
|
|
|
|
|
<< textclasslist.LatexnameOfClass(params.textclass)
|
|
|
|
|
<< "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
// end of \documentclass defs
|
|
|
|
|
|
|
|
|
|
// font selection must be done before loading fontenc.sty
|
2001-01-23 12:53:05 +00:00
|
|
|
|
// The ae package is not needed when using OT1 font encoding.
|
|
|
|
|
if (params.fonts != "default" &&
|
|
|
|
|
(params.fonts != "ae" || lyxrc.fontenc != "default")) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
ofs << "\\usepackage{" << params.fonts << "}\n";
|
|
|
|
|
texrow.newline();
|
2001-01-23 12:53:05 +00:00
|
|
|
|
if (params.fonts == "ae") {
|
|
|
|
|
ofs << "\\usepackage{aecompl}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
// this one is not per buffer
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (lyxrc.fontenc != "default") {
|
|
|
|
|
ofs << "\\usepackage[" << lyxrc.fontenc
|
2000-03-06 02:42:40 +00:00
|
|
|
|
<< "]{fontenc}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
|
|
|
|
if (params.inputenc == "auto") {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const doc_encoding =
|
2000-10-10 12:36:36 +00:00
|
|
|
|
params.language->encoding()->LatexName();
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
|
|
|
|
// Create a list with all the input encodings used
|
|
|
|
|
// in the document
|
|
|
|
|
set<string> encodings;
|
|
|
|
|
for (LaTeXFeatures::LanguageList::const_iterator it =
|
|
|
|
|
features.UsedLanguages.begin();
|
|
|
|
|
it != features.UsedLanguages.end(); ++it)
|
|
|
|
|
if ((*it)->encoding()->LatexName() != doc_encoding)
|
|
|
|
|
encodings.insert((*it)->encoding()->LatexName());
|
|
|
|
|
|
|
|
|
|
ofs << "\\usepackage[";
|
2000-10-12 15:17:42 +00:00
|
|
|
|
std::copy(encodings.begin(), encodings.end(),
|
|
|
|
|
std::ostream_iterator<string>(ofs, ","));
|
2000-07-04 20:32:37 +00:00
|
|
|
|
ofs << doc_encoding << "]{inputenc}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
} else if (params.inputenc != "default") {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
ofs << "\\usepackage[" << params.inputenc
|
|
|
|
|
<< "]{inputenc}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2000-07-04 20:32:37 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// At the very beginning the text parameters.
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (params.paperpackage != BufferParams::PACKAGE_NONE) {
|
|
|
|
|
switch (params.paperpackage) {
|
|
|
|
|
case BufferParams::PACKAGE_A4:
|
|
|
|
|
ofs << "\\usepackage{a4}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PACKAGE_A4WIDE:
|
|
|
|
|
ofs << "\\usepackage{a4wide}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PACKAGE_WIDEMARGINSA4:
|
|
|
|
|
ofs << "\\usepackage[widemargins]{a4}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (params.use_geometry) {
|
|
|
|
|
ofs << "\\usepackage{geometry}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
ofs << "\\geometry{verbose";
|
|
|
|
|
if (params.orientation == BufferParams::ORIENTATION_LANDSCAPE)
|
|
|
|
|
ofs << ",landscape";
|
|
|
|
|
switch (params.papersize2) {
|
|
|
|
|
case BufferParams::VM_PAPER_CUSTOM:
|
|
|
|
|
if (!params.paperwidth.empty())
|
|
|
|
|
ofs << ",paperwidth="
|
|
|
|
|
<< params.paperwidth;
|
|
|
|
|
if (!params.paperheight.empty())
|
|
|
|
|
ofs << ",paperheight="
|
|
|
|
|
<< params.paperheight;
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_USLETTER:
|
|
|
|
|
ofs << ",letterpaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_USLEGAL:
|
|
|
|
|
ofs << ",legalpaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_USEXECUTIVE:
|
|
|
|
|
ofs << ",executivepaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_A3:
|
|
|
|
|
ofs << ",a3paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_A4:
|
|
|
|
|
ofs << ",a4paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_A5:
|
|
|
|
|
ofs << ",a5paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_B3:
|
|
|
|
|
ofs << ",b3paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_B4:
|
|
|
|
|
ofs << ",b4paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::VM_PAPER_B5:
|
|
|
|
|
ofs << ",b5paper";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
// default papersize ie BufferParams::VM_PAPER_DEFAULT
|
2000-03-12 10:35:05 +00:00
|
|
|
|
switch (lyxrc.default_papersize) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
case BufferParams::PAPER_DEFAULT: // keep compiler happy
|
|
|
|
|
case BufferParams::PAPER_USLETTER:
|
|
|
|
|
ofs << ",letterpaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_LEGALPAPER:
|
|
|
|
|
ofs << ",legalpaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_EXECUTIVEPAPER:
|
|
|
|
|
ofs << ",executivepaper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A3PAPER:
|
|
|
|
|
ofs << ",a3paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A4PAPER:
|
|
|
|
|
ofs << ",a4paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_A5PAPER:
|
|
|
|
|
ofs << ",a5paper";
|
|
|
|
|
break;
|
|
|
|
|
case BufferParams::PAPER_B5PAPER:
|
|
|
|
|
ofs << ",b5paper";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!params.topmargin.empty())
|
|
|
|
|
ofs << ",tmargin=" << params.topmargin;
|
|
|
|
|
if (!params.bottommargin.empty())
|
|
|
|
|
ofs << ",bmargin=" << params.bottommargin;
|
|
|
|
|
if (!params.leftmargin.empty())
|
|
|
|
|
ofs << ",lmargin=" << params.leftmargin;
|
|
|
|
|
if (!params.rightmargin.empty())
|
|
|
|
|
ofs << ",rmargin=" << params.rightmargin;
|
|
|
|
|
if (!params.headheight.empty())
|
|
|
|
|
ofs << ",headheight=" << params.headheight;
|
|
|
|
|
if (!params.headsep.empty())
|
|
|
|
|
ofs << ",headsep=" << params.headsep;
|
|
|
|
|
if (!params.footskip.empty())
|
|
|
|
|
ofs << ",footskip=" << params.footskip;
|
|
|
|
|
ofs << "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2001-02-03 21:02:22 +00:00
|
|
|
|
if (features.amsstyle
|
2000-05-05 10:17:05 +00:00
|
|
|
|
&& !tclass.provides(LyXTextClass::amsmath)) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
ofs << "\\usepackage{amsmath}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
if (tokenPos(tclass.opt_pagestyle(),
|
|
|
|
|
'|', params.pagestyle) >= 0) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (params.pagestyle == "fancy") {
|
|
|
|
|
ofs << "\\usepackage{fancyhdr}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
ofs << "\\pagestyle{" << params.pagestyle << "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We try to load babel late, in case it interferes
|
|
|
|
|
// with other packages.
|
2000-03-17 10:14:46 +00:00
|
|
|
|
if (use_babel) {
|
2001-02-25 10:22:54 +00:00
|
|
|
|
string tmp = lyxrc.language_package;
|
|
|
|
|
if (!lyxrc.language_global_options
|
|
|
|
|
&& tmp == "\\usepackage{babel}")
|
2001-05-10 15:53:10 +00:00
|
|
|
|
tmp = string("\\usepackage[") +
|
|
|
|
|
language_options.str().c_str() +
|
|
|
|
|
"]{babel}";
|
2001-02-25 10:22:54 +00:00
|
|
|
|
ofs << tmp << "\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (params.secnumdepth != tclass.secnumdepth()) {
|
|
|
|
|
ofs << "\\setcounter{secnumdepth}{"
|
|
|
|
|
<< params.secnumdepth
|
|
|
|
|
<< "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
if (params.tocdepth != tclass.tocdepth()) {
|
|
|
|
|
ofs << "\\setcounter{tocdepth}{"
|
|
|
|
|
<< params.tocdepth
|
|
|
|
|
<< "}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (params.paragraph_separation) {
|
|
|
|
|
switch (params.defskip.kind()) {
|
|
|
|
|
case VSpace::SMALLSKIP:
|
|
|
|
|
ofs << "\\setlength\\parskip{\\smallskipamount}\n";
|
|
|
|
|
break;
|
|
|
|
|
case VSpace::MEDSKIP:
|
|
|
|
|
ofs << "\\setlength\\parskip{\\medskipamount}\n";
|
|
|
|
|
break;
|
|
|
|
|
case VSpace::BIGSKIP:
|
|
|
|
|
ofs << "\\setlength\\parskip{\\bigskipamount}\n";
|
|
|
|
|
break;
|
|
|
|
|
case VSpace::LENGTH:
|
|
|
|
|
ofs << "\\setlength\\parskip{"
|
|
|
|
|
<< params.defskip.length().asLatexString()
|
|
|
|
|
<< "}\n";
|
|
|
|
|
break;
|
|
|
|
|
default: // should never happen // Then delete it.
|
|
|
|
|
ofs << "\\setlength\\parskip{\\medskipamount}\n";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
texrow.newline();
|
|
|
|
|
|
|
|
|
|
ofs << "\\setlength\\parindent{0pt}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Now insert the LyX specific LaTeX commands...
|
|
|
|
|
|
|
|
|
|
// The optional packages;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
string preamble(features.getPackages());
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// this might be useful...
|
2000-07-04 19:16:35 +00:00
|
|
|
|
preamble += "\n\\makeatletter\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// Some macros LyX will need
|
2000-07-04 19:16:35 +00:00
|
|
|
|
string tmppreamble(features.getMacros());
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
if (!tmppreamble.empty()) {
|
|
|
|
|
preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
|
|
|
|
|
"LyX specific LaTeX commands.\n"
|
|
|
|
|
+ tmppreamble + '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the text class specific preamble
|
2000-04-10 21:40:13 +00:00
|
|
|
|
tmppreamble = features.getTClassPreamble();
|
2000-03-06 02:42:40 +00:00
|
|
|
|
if (!tmppreamble.empty()) {
|
|
|
|
|
preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
|
|
|
|
|
"Textclass specific LaTeX commands.\n"
|
|
|
|
|
+ tmppreamble + '\n';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* the user-defined preamble */
|
|
|
|
|
if (!params.preamble.empty()) {
|
|
|
|
|
preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% "
|
|
|
|
|
"User specified LaTeX commands.\n"
|
|
|
|
|
+ params.preamble + '\n';
|
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
preamble += "\\makeatother\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// Itemize bullet settings need to be last in case the user
|
|
|
|
|
// defines their own bullets that use a package included
|
|
|
|
|
// in the user-defined preamble -- ARRae
|
|
|
|
|
// Actually it has to be done much later than that
|
|
|
|
|
// since some packages like frenchb make modifications
|
|
|
|
|
// at \begin{document} time -- JMarc
|
|
|
|
|
string bullets_def;
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
|
|
|
|
|
if (bullets_def.empty())
|
|
|
|
|
bullets_def="\\AtBeginDocument{\n";
|
|
|
|
|
bullets_def += " \\renewcommand{\\labelitemi";
|
|
|
|
|
switch (i) {
|
|
|
|
|
// `i' is one less than the item to modify
|
|
|
|
|
case 0:
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
bullets_def += 'i';
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
bullets_def += "ii";
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
bullets_def += 'v';
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
bullets_def += "}{" +
|
|
|
|
|
params.user_defined_bullets[i].getText()
|
|
|
|
|
+ "}\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!bullets_def.empty())
|
|
|
|
|
preamble += bullets_def + "}\n\n";
|
|
|
|
|
|
|
|
|
|
for (int j = countChar(preamble, '\n'); j-- ;) {
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ofs << preamble;
|
|
|
|
|
|
|
|
|
|
// make the body.
|
2000-07-04 19:16:35 +00:00
|
|
|
|
ofs << "\\begin{document}\n";
|
2000-03-06 02:42:40 +00:00
|
|
|
|
texrow.newline();
|
|
|
|
|
} // only_body
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "preamble finished, now the body." << endl;
|
2001-03-01 15:57:10 +00:00
|
|
|
|
|
2000-10-10 12:36:36 +00:00
|
|
|
|
if (!lyxrc.language_auto_begin) {
|
2000-03-17 10:14:46 +00:00
|
|
|
|
ofs << subst(lyxrc.language_command_begin, "$$lang",
|
2000-10-10 12:36:36 +00:00
|
|
|
|
params.language->babel())
|
2000-03-17 10:14:46 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
latexParagraphs(ofs, paragraph, 0, texrow);
|
|
|
|
|
|
|
|
|
|
// add this just in case after all the paragraphs
|
|
|
|
|
ofs << endl;
|
|
|
|
|
texrow.newline();
|
|
|
|
|
|
2001-03-01 15:57:10 +00:00
|
|
|
|
if (!lyxrc.language_auto_end) {
|
2000-05-04 08:14:34 +00:00
|
|
|
|
ofs << subst(lyxrc.language_command_end, "$$lang",
|
2000-10-10 12:36:36 +00:00
|
|
|
|
params.language->babel())
|
2000-05-04 08:14:34 +00:00
|
|
|
|
<< endl;
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!only_body) {
|
|
|
|
|
ofs << "\\end{document}\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::LATEX] << "makeLaTeXFile...done" << endl;
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr[Debug::LATEX] << "LaTeXFile for inclusion made."
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Just to be sure. (Asger)
|
|
|
|
|
texrow.newline();
|
|
|
|
|
|
|
|
|
|
// tex_code_break_column's value is used to decide
|
|
|
|
|
// if we are in batchmode or not (within mathed_write()
|
|
|
|
|
// in math_write.C) so we must set it to a non-zero
|
|
|
|
|
// value when we leave otherwise we save incorrect .lyx files.
|
|
|
|
|
tex_code_break_column = lyxrc.ascii_linelen;
|
|
|
|
|
|
|
|
|
|
ofs.close();
|
|
|
|
|
if (ofs.fail()) {
|
|
|
|
|
lyxerr << "File was not closed properly." << endl;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Finished making latex file." << endl;
|
2000-05-04 08:14:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
2000-05-04 08:14:34 +00:00
|
|
|
|
//
|
|
|
|
|
// LaTeX all paragraphs from par to endpar, if endpar == 0 then to the end
|
|
|
|
|
//
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::latexParagraphs(ostream & ofs, Paragraph * par,
|
|
|
|
|
Paragraph * endpar, TexRow & texrow) const
|
2000-05-04 08:14:34 +00:00
|
|
|
|
{
|
2000-03-06 02:42:40 +00:00
|
|
|
|
bool was_title = false;
|
|
|
|
|
bool already_title = false;
|
|
|
|
|
|
|
|
|
|
// if only_body
|
2000-05-04 08:14:34 +00:00
|
|
|
|
while (par != endpar) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
LyXLayout const & layout =
|
|
|
|
|
textclasslist.Style(params.textclass,
|
|
|
|
|
par->layout);
|
|
|
|
|
|
|
|
|
|
if (layout.intitle) {
|
|
|
|
|
if (already_title) {
|
2000-05-04 08:14:34 +00:00
|
|
|
|
lyxerr <<"Error in latexParagraphs: You"
|
2000-03-06 02:42:40 +00:00
|
|
|
|
" should not mix title layouts"
|
|
|
|
|
" with normal ones." << endl;
|
|
|
|
|
} else
|
|
|
|
|
was_title = true;
|
|
|
|
|
} else if (was_title && !already_title) {
|
|
|
|
|
ofs << "\\maketitle\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
already_title = true;
|
|
|
|
|
was_title = false;
|
|
|
|
|
}
|
2001-05-08 17:08:44 +00:00
|
|
|
|
|
2001-05-03 14:31:33 +00:00
|
|
|
|
if (layout.isEnvironment()) {
|
|
|
|
|
par = par->TeXEnvironment(this, params, ofs, texrow);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
} else {
|
2001-05-03 14:31:33 +00:00
|
|
|
|
par = par->TeXOnePar(this, params, ofs, texrow, false);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// It might be that we only have a title in this document
|
|
|
|
|
if (was_title && !already_title) {
|
|
|
|
|
ofs << "\\maketitle\n";
|
|
|
|
|
texrow.newline();
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLatex() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == LATEX;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLinuxDoc() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isLiterate() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == LITERATE;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isDocBook() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
bool Buffer::isSGML() const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return textclasslist.TextClass(params.textclass).outputType() == LINUXDOC ||
|
|
|
|
|
textclasslist.TextClass(params.textclass).outputType() == DOCBOOK;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth,
|
1999-12-07 00:44:53 +00:00
|
|
|
|
string const & latexname) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (!latexname.empty() && latexname != "!-- --")
|
2001-06-27 14:10:35 +00:00
|
|
|
|
os << "<!-- " << depth << " -->" << "<" << latexname << ">";
|
|
|
|
|
//os << string(depth, ' ') << "<" << latexname << ">\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth,
|
1999-11-15 12:01:38 +00:00
|
|
|
|
string const & latexname) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (!latexname.empty() && latexname != "!-- --")
|
2001-06-27 14:10:35 +00:00
|
|
|
|
os << "<!-- " << depth << " -->" << "</" << latexname << ">\n";
|
|
|
|
|
//os << string(depth, ' ') << "</" << latexname << ">\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-12-21 06:10:21 +00:00
|
|
|
|
ofstream ofs(fname.c_str());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
if (!ofs) {
|
1999-12-21 06:10:21 +00:00
|
|
|
|
WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
niceFile = nice; // this will be used by included files.
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
|
|
|
|
textclasslist.TextClass(params.textclass);
|
|
|
|
|
|
|
|
|
|
LaTeXFeatures features(params, tclass.numLayouts());
|
|
|
|
|
validate(features);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
texrow.reset();
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
string top_element = textclasslist.LatexnameOfClass(params.textclass);
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (!body_only) {
|
2000-11-13 15:43:36 +00:00
|
|
|
|
string sgml_includedfiles=features.getIncludedFiles(fname);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
|
|
|
|
if (params.preamble.empty() && sgml_includedfiles.empty()) {
|
|
|
|
|
ofs << "<!doctype linuxdoc system>\n\n";
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
2000-07-01 12:54:45 +00:00
|
|
|
|
ofs << "<!doctype linuxdoc system [ "
|
|
|
|
|
<< params.preamble << sgml_includedfiles << " \n]>\n\n";
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (params.options.empty())
|
2000-07-01 12:54:45 +00:00
|
|
|
|
sgmlOpenTag(ofs, 0, top_element);
|
|
|
|
|
else {
|
|
|
|
|
string top = top_element;
|
|
|
|
|
top += " ";
|
|
|
|
|
top += params.options;
|
|
|
|
|
sgmlOpenTag(ofs, 0, top);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-19 14:07:39 +00:00
|
|
|
|
ofs << "<!-- " << LYX_DOCVERSION
|
|
|
|
|
<< " created this file. For more info see http://www.lyx.org/"
|
|
|
|
|
<< " -->\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth = 0; // paragraph depth
|
|
|
|
|
Paragraph * par = paragraph;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
string item_name;
|
|
|
|
|
vector<string> environment_stack(5);
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (par) {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
LyXLayout const & style =
|
2000-07-01 12:54:45 +00:00
|
|
|
|
textclasslist.Style(params.textclass,
|
1999-11-15 12:01:38 +00:00
|
|
|
|
par->layout);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// treat <toc> as a special case for compatibility with old code
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->getChar(0) == Paragraph::META_INSET) {
|
|
|
|
|
Inset * inset = par->getInset(0);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
Inset::Code lyx_code = inset->lyxCode();
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (lyx_code == Inset::TOC_CODE){
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const temp = "toc";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, temp);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// environment tag closing
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (; depth > par->params().depth(); --depth) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth, environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// write opening SGML tags
|
2000-09-26 13:54:57 +00:00
|
|
|
|
switch (style.latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_PARAGRAPH:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth == par->params().depth()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& !environment_stack[depth].empty()) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth, environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (depth)
|
1999-12-07 00:44:53 +00:00
|
|
|
|
--depth;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs << "</p>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_COMMAND:
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (depth!= 0)
|
2001-06-28 10:25:20 +00:00
|
|
|
|
linuxDocError(par, 0,
|
2000-04-26 13:57:28 +00:00
|
|
|
|
_("Error : Wrong depth for"
|
|
|
|
|
" LatexType Command.\n"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
if (!environment_stack[depth].empty()){
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth,
|
|
|
|
|
environment_stack[depth]);
|
|
|
|
|
ofs << "</p>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth == par->params().depth()
|
2001-03-21 23:38:07 +00:00
|
|
|
|
&& environment_stack[depth] != style.latexname()) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth,
|
1999-11-15 12:01:38 +00:00
|
|
|
|
environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth < par->params().depth()) {
|
|
|
|
|
depth = par->params().depth();
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (environment_stack[depth] != style.latexname()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (depth == 0) {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, "p");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-21 23:38:07 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, style.latexname());
|
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (environment_stack.size() == depth + 1)
|
2001-03-21 23:38:07 +00:00
|
|
|
|
environment_stack.push_back("!-- --");
|
1999-11-04 01:40:20 +00:00
|
|
|
|
environment_stack[depth] = style.latexname();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (style.latexparam() == "CDATA")
|
|
|
|
|
ofs << "<![CDATA[";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (style.latextype == LATEX_ENVIRONMENT) break;
|
|
|
|
|
|
|
|
|
|
if (style.labeltype == LABEL_MANUAL)
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name = "tag";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name = "item";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1, item_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
simpleLinuxDocOnePar(ofs, par, depth);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs << "\n";
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// write closing SGML tags
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (style.latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_COMMAND:
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (style.latexparam() == "CDATA")
|
|
|
|
|
ofs << "]]>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// Close open tags
|
2001-03-21 23:38:07 +00:00
|
|
|
|
for (int i=depth; i >= 0; --i)
|
|
|
|
|
sgmlCloseTag(ofs, depth, environment_stack[i]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (!body_only) {
|
|
|
|
|
ofs << "\n\n";
|
|
|
|
|
sgmlCloseTag(ofs, 0, top_element);
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
|
|
|
|
// How to check for successful close
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::docBookHandleCaption(ostream & os, string & inner_tag,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type depth, int desc_on,
|
|
|
|
|
Paragraph * & par)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * tpar = par;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
while (tpar
|
|
|
|
|
&& (tpar->layout != textclasslist.NumberOfLayout(params.textclass,
|
|
|
|
|
"Caption").second))
|
|
|
|
|
tpar = tpar->next();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (tpar &&
|
1999-11-15 12:01:38 +00:00
|
|
|
|
tpar->layout == textclasslist.NumberOfLayout(params.textclass,
|
|
|
|
|
"Caption").second) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(os, depth + 1, inner_tag);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
string extra_par;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
simpleDocBookOnePar(os, extra_par, tpar,
|
2000-03-06 02:42:40 +00:00
|
|
|
|
desc_on, depth + 2);
|
2000-03-09 03:36:48 +00:00
|
|
|
|
sgmlCloseTag(os, depth+1, inner_tag);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!extra_par.empty())
|
2000-03-09 03:36:48 +00:00
|
|
|
|
os << extra_par;
|
1999-12-07 00:44:53 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// checks, if newcol chars should be put into this line
|
|
|
|
|
// writes newline, if necessary.
|
2001-03-20 01:22:46 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2000-09-27 17:07:33 +00:00
|
|
|
|
void linux_doc_line_break(ostream & os, string::size_type & colcount,
|
|
|
|
|
string::size_type newcol)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
colcount += newcol;
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (colcount > lyxrc.ascii_linelen) {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
colcount = newcol; // assume write after this call
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
enum PAR_TAG {
|
|
|
|
|
NONE=0,
|
|
|
|
|
TT = 1,
|
|
|
|
|
SF = 2,
|
|
|
|
|
BF = 4,
|
|
|
|
|
IT = 8,
|
|
|
|
|
SL = 16,
|
|
|
|
|
EM = 32
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string tag_name(PAR_TAG const & pt) {
|
|
|
|
|
switch (pt) {
|
2001-03-23 16:46:39 +00:00
|
|
|
|
case NONE: return "!-- --";
|
|
|
|
|
case TT: return "tt";
|
|
|
|
|
case SF: return "sf";
|
|
|
|
|
case BF: return "bf";
|
|
|
|
|
case IT: return "it";
|
|
|
|
|
case SL: return "sl";
|
|
|
|
|
case EM: return "em";
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
void operator|=(PAR_TAG & p1, PAR_TAG const & p2)
|
|
|
|
|
{
|
|
|
|
|
p1 = static_cast<PAR_TAG>(p1 | p2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
|
|
|
|
void reset(PAR_TAG & p1, PAR_TAG const & p2)
|
|
|
|
|
{
|
|
|
|
|
p1 = static_cast<PAR_TAG>( p1 & ~p2);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
// Handle internal paragraph parsing -- layout already processed.
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::simpleLinuxDocOnePar(ostream & os,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par,
|
|
|
|
|
Paragraph::depth_type /*depth*/)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
|
LyXLayout const & style = textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
2000-09-27 17:07:33 +00:00
|
|
|
|
string::size_type char_line_count = 5; // Heuristic choice ;-)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// gets paragraph main font
|
2001-03-21 23:38:07 +00:00
|
|
|
|
LyXFont font_old;
|
|
|
|
|
bool desc_on;
|
|
|
|
|
if (style.labeltype == LABEL_MANUAL) {
|
|
|
|
|
font_old = style.labelfont;
|
|
|
|
|
desc_on = true;
|
2001-03-22 19:36:21 +00:00
|
|
|
|
} else {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
font_old = style.font;
|
|
|
|
|
desc_on = false;
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
LyXFont::FONT_FAMILY family_type = LyXFont::ROMAN_FAMILY;
|
|
|
|
|
LyXFont::FONT_SERIES series_type = LyXFont::MEDIUM_SERIES;
|
|
|
|
|
LyXFont::FONT_SHAPE shape_type = LyXFont::UP_SHAPE;
|
|
|
|
|
bool is_em = false;
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
stack < PAR_TAG > tag_state;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// parsing main loop
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::size_type i = 0; i < par->size(); ++i) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
PAR_TAG tag_close = NONE;
|
|
|
|
|
list < PAR_TAG > tag_open;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
LyXFont const font = par->getFont(params, i);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.family() != font.family()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (family_type) {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::SANS_FAMILY:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= SF;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::TYPEWRITER_FAMILY:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= TT;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
family_type = font.family();
|
|
|
|
|
|
|
|
|
|
switch (family_type) {
|
|
|
|
|
case LyXFont::SANS_FAMILY:
|
|
|
|
|
tag_open.push_back(SF);
|
|
|
|
|
break;
|
|
|
|
|
case LyXFont::TYPEWRITER_FAMILY:
|
|
|
|
|
tag_open.push_back(TT);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.series() != font.series()) {
|
|
|
|
|
switch (series_type) {
|
|
|
|
|
case LyXFont::BOLD_SERIES:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= BF;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
series_type = font.series();
|
|
|
|
|
|
|
|
|
|
switch (series_type) {
|
|
|
|
|
case LyXFont::BOLD_SERIES:
|
|
|
|
|
tag_open.push_back(BF);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-03-21 23:38:07 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.shape() != font.shape()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (shape_type) {
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::ITALIC_SHAPE:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= IT;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
case LyXFont::SLANTED_SHAPE:
|
2001-03-23 08:37:44 +00:00
|
|
|
|
tag_close |= SL;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shape_type = font.shape();
|
|
|
|
|
|
|
|
|
|
switch (shape_type) {
|
|
|
|
|
case LyXFont::ITALIC_SHAPE:
|
|
|
|
|
tag_open.push_back(IT);
|
|
|
|
|
break;
|
|
|
|
|
case LyXFont::SLANTED_SHAPE:
|
|
|
|
|
tag_open.push_back(SL);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// handle <em> tag
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (font_old.emph() != font.emph()) {
|
|
|
|
|
if (font.emph() == LyXFont::ON) {
|
|
|
|
|
tag_open.push_back(EM);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
is_em = true;
|
2001-03-23 08:37:44 +00:00
|
|
|
|
}
|
|
|
|
|
else if (is_em) {
|
|
|
|
|
tag_close |= EM;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
is_em = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
list < PAR_TAG > temp;
|
|
|
|
|
while(!tag_state.empty() && tag_close ) {
|
|
|
|
|
PAR_TAG k = tag_state.top();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
tag_state.pop();
|
2001-03-23 08:37:44 +00:00
|
|
|
|
os << "</" << tag_name(k) << ">";
|
|
|
|
|
if (tag_close & k)
|
|
|
|
|
reset(tag_close,k);
|
2001-03-21 23:38:07 +00:00
|
|
|
|
else
|
|
|
|
|
temp.push_back(k);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
for(list< PAR_TAG >::const_iterator j = temp.begin();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
j != temp.end(); ++j) {
|
|
|
|
|
tag_state.push(*j);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
os << "<" << tag_name(*j) << ">";
|
2001-03-21 23:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
for(list< PAR_TAG >::const_iterator j = tag_open.begin();
|
2001-03-21 23:38:07 +00:00
|
|
|
|
j != tag_open.end(); ++j) {
|
|
|
|
|
tag_state.push(*j);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
os << "<" << tag_name(*j) << ">";
|
2001-03-21 23:38:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
char c = par->getChar(i);
|
2000-07-01 12:54:45 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (c == Paragraph::META_INSET) {
|
|
|
|
|
Inset * inset = par->getInset(i);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->linuxdoc(this, os);
|
2001-03-21 23:38:07 +00:00
|
|
|
|
font_old = font;
|
|
|
|
|
continue;
|
2000-07-01 12:54:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if (
|
|
|
|
|
#ifndef NO_LATEX
|
|
|
|
|
font.latex() == LyXFont::ON ||
|
|
|
|
|
#endif
|
|
|
|
|
style.latexparam() == "CDATA") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
// "TeX"-Mode on == > SGML-Mode on.
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (c != '\0')
|
2001-03-21 23:38:07 +00:00
|
|
|
|
os << c;
|
2000-01-24 18:34:46 +00:00
|
|
|
|
++char_line_count;
|
2000-03-09 23:58:55 +00:00
|
|
|
|
} else {
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string sgml_string;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (par->linuxDocConvertChar(c, sgml_string)
|
2001-03-21 23:38:07 +00:00
|
|
|
|
&& !style.free_spacing) {
|
|
|
|
|
// in freespacing mode, spaces are
|
|
|
|
|
// non-breaking characters
|
|
|
|
|
if (desc_on) {// if char is ' ' then...
|
|
|
|
|
|
2000-01-24 18:34:46 +00:00
|
|
|
|
++char_line_count;
|
1999-12-07 00:44:53 +00:00
|
|
|
|
linux_doc_line_break(os, char_line_count, 6);
|
|
|
|
|
os << "</tag>";
|
2001-03-21 23:38:07 +00:00
|
|
|
|
desc_on = false;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
linux_doc_line_break(os, char_line_count, 1);
|
|
|
|
|
os << c;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
1999-12-07 00:44:53 +00:00
|
|
|
|
os << sgml_string;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
char_line_count += sgml_string.length();
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-21 23:38:07 +00:00
|
|
|
|
font_old = font;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
}
|
1999-11-15 12:01:38 +00:00
|
|
|
|
|
2001-03-21 23:38:07 +00:00
|
|
|
|
while (!tag_state.empty()) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
os << "</" << tag_name(tag_state.top()) << ">";
|
2001-03-21 23:38:07 +00:00
|
|
|
|
tag_state.pop();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// resets description flag correctly
|
2001-03-21 23:38:07 +00:00
|
|
|
|
if (desc_on) {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// <tag> not closed...
|
1999-12-07 00:44:53 +00:00
|
|
|
|
linux_doc_line_break(os, char_line_count, 6);
|
|
|
|
|
os << "</tag>";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// Print an error message.
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::linuxDocError(Paragraph * par, int pos,
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const & message)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// insert an error marker in text
|
2000-06-28 13:35:52 +00:00
|
|
|
|
InsetError * new_inset = new InsetError(message);
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->insertInset(pos, new_inset);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-03-23 08:37:44 +00:00
|
|
|
|
ofstream ofs(fname.c_str());
|
|
|
|
|
if (!ofs) {
|
|
|
|
|
WriteAlert(_("LYX_ERROR:"), _("Cannot write file"), fname);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
niceFile = nice; // this will be used by Insetincludes.
|
|
|
|
|
|
|
|
|
|
LyXTextClass const & tclass =
|
|
|
|
|
textclasslist.TextClass(params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
LaTeXFeatures features(params, tclass.numLayouts());
|
|
|
|
|
validate(features);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
texrow.reset();
|
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
string top_element = textclasslist.LatexnameOfClass(params.textclass);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!only_body) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
string sgml_includedfiles = features.getIncludedFiles(fname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
ofs << "<!doctype " << top_element
|
|
|
|
|
<< " public \"-//OASIS//DTD DocBook V3.1//EN\"";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
if (params.preamble.empty() && sgml_includedfiles.empty())
|
|
|
|
|
ofs << ">\n\n";
|
|
|
|
|
else
|
|
|
|
|
ofs << "\n [ " << params.preamble
|
|
|
|
|
<< sgml_includedfiles << " \n]>\n\n";
|
2000-11-13 15:43:36 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-01-28 21:54:15 +00:00
|
|
|
|
string top = top_element;
|
|
|
|
|
top += " lang=\"";
|
|
|
|
|
top += params.language->code();
|
|
|
|
|
top += "\"";
|
|
|
|
|
|
|
|
|
|
if (!params.options.empty()) {
|
2000-11-13 15:43:36 +00:00
|
|
|
|
top += " ";
|
|
|
|
|
top += params.options;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-01-28 21:54:15 +00:00
|
|
|
|
sgmlOpenTag(ofs, 0, top);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-07-01 12:54:45 +00:00
|
|
|
|
ofs << "<!-- DocBook file was created by " << LYX_DOCVERSION
|
|
|
|
|
<< "\n See http://www.lyx.org/ for more information -->\n";
|
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
vector<string> environment_stack(10);
|
|
|
|
|
vector<string> environment_inner(10);
|
|
|
|
|
vector<string> command_stack(10);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
bool command_flag = false;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::depth_type command_depth = 0;
|
|
|
|
|
Paragraph::depth_type command_base = 0;
|
|
|
|
|
Paragraph::depth_type cmd_depth = 0;
|
|
|
|
|
Paragraph::depth_type depth = 0; // paragraph depth
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
string item_name;
|
|
|
|
|
string command_name;
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (par) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
string sgmlparam;
|
|
|
|
|
string c_depth;
|
|
|
|
|
string c_params;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
int desc_on = 0; // description mode
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
|
LyXLayout const & style =
|
2000-07-01 12:54:45 +00:00
|
|
|
|
textclasslist.Style(params.textclass,
|
2000-02-29 02:19:17 +00:00
|
|
|
|
par->layout);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// environment tag closing
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (; depth > par->params().depth(); --depth) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
item_name = "listitem";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, command_depth + depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth+command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_stack[depth]);
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
environment_inner[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth == par->params().depth()
|
1999-11-04 01:40:20 +00:00
|
|
|
|
&& environment_stack[depth] != style.latexname()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
&& !environment_stack[depth].empty()) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "listitem";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, command_depth+depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs,
|
|
|
|
|
depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_stack[depth]);
|
|
|
|
|
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
|
|
|
|
environment_inner[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Write opening SGML tags.
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (style.latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_PARAGRAPH:
|
2001-04-04 21:47:26 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth,
|
|
|
|
|
style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_COMMAND:
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (depth != 0)
|
2001-06-28 10:25:20 +00:00
|
|
|
|
linuxDocError(par, 0,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
_("Error : Wrong depth for "
|
|
|
|
|
"LatexType Command.\n"));
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
command_name = style.latexname();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
sgmlparam = style.latexparam();
|
|
|
|
|
c_params = split(sgmlparam, c_depth,'|');
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-04-04 21:47:26 +00:00
|
|
|
|
cmd_depth = lyx::atoi(c_depth);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (command_flag) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (cmd_depth < command_base) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::depth_type j = command_depth; j >= command_base; --j)
|
2001-03-23 08:37:44 +00:00
|
|
|
|
sgmlCloseTag(ofs, j, command_stack[j]);
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_depth = command_base = cmd_depth;
|
2000-11-04 10:00:12 +00:00
|
|
|
|
} else if (cmd_depth <= command_depth) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (int j = command_depth; j >= int(cmd_depth); --j)
|
2001-03-23 08:37:44 +00:00
|
|
|
|
sgmlCloseTag(ofs, j, command_stack[j]);
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_depth = cmd_depth;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_depth = cmd_depth;
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
command_depth = command_base = cmd_depth;
|
|
|
|
|
command_flag = true;
|
|
|
|
|
}
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if (command_stack.size() == command_depth + 1)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
command_stack.push_back(string());
|
2001-04-04 21:47:26 +00:00
|
|
|
|
command_stack[command_depth] = command_name;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// treat label as a special case for
|
|
|
|
|
// more WYSIWYM handling.
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (par->getChar(0) == Paragraph::META_INSET) {
|
|
|
|
|
Inset * inset = par->getInset(0);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
Inset::Code lyx_code = inset->lyxCode();
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (lyx_code == Inset::LABEL_CODE){
|
1999-12-07 00:44:53 +00:00
|
|
|
|
command_name += " id=\"";
|
|
|
|
|
command_name += (static_cast<InsetCommand *>(inset))->getContents();
|
|
|
|
|
command_name += "\"";
|
|
|
|
|
desc_on = 3;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-05-18 13:26:04 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth, command_name);
|
2001-02-11 21:25:34 +00:00
|
|
|
|
if (c_params.empty())
|
|
|
|
|
item_name = "title";
|
|
|
|
|
else
|
|
|
|
|
item_name = c_params;
|
2001-01-28 21:54:15 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1 + command_depth, item_name);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (depth < par->params().depth()) {
|
|
|
|
|
depth = par->params().depth();
|
2000-05-04 10:57:00 +00:00
|
|
|
|
environment_stack[depth].erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
if (environment_stack[depth] != style.latexname()) {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
if(environment_stack.size() == depth + 1) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
environment_stack.push_back("!-- --");
|
|
|
|
|
environment_inner.push_back("!-- --");
|
|
|
|
|
}
|
1999-12-07 00:44:53 +00:00
|
|
|
|
environment_stack[depth] = style.latexname();
|
|
|
|
|
environment_inner[depth] = "!-- --";
|
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_stack[depth]);
|
|
|
|
|
} else {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "listitem";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
command_depth + depth,
|
|
|
|
|
item_name);
|
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs,
|
|
|
|
|
depth + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (style.latextype == LATEX_ENVIRONMENT) {
|
2001-01-28 21:54:15 +00:00
|
|
|
|
if (!style.latexparam().empty()) {
|
|
|
|
|
if(style.latexparam() == "CDATA")
|
2001-03-21 23:38:07 +00:00
|
|
|
|
ofs << "<![CDATA[";
|
2001-01-28 21:54:15 +00:00
|
|
|
|
else
|
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth,
|
|
|
|
|
style.latexparam());
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
1999-11-15 12:01:38 +00:00
|
|
|
|
desc_on = (style.labeltype == LABEL_MANUAL);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (desc_on)
|
1999-11-15 12:01:38 +00:00
|
|
|
|
environment_inner[depth]= "varlistentry";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
else
|
1999-11-15 12:01:38 +00:00
|
|
|
|
environment_inner[depth]= "listitem";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1 + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (desc_on) {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "term";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1 + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
item_name);
|
2000-07-04 19:16:35 +00:00
|
|
|
|
} else {
|
1999-11-15 12:01:38 +00:00
|
|
|
|
item_name= "para";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + 1 + command_depth,
|
1999-09-27 18:44:28 +00:00
|
|
|
|
item_name);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlOpenTag(ofs, depth + command_depth,
|
1999-11-04 01:40:20 +00:00
|
|
|
|
style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
string extra_par;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
simpleDocBookOnePar(ofs, extra_par, par, desc_on,
|
2001-03-09 00:56:42 +00:00
|
|
|
|
depth + 1 + command_depth);
|
|
|
|
|
par = par->next();
|
2001-05-03 14:31:33 +00:00
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string end_tag;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// write closing SGML tags
|
2000-11-04 10:00:12 +00:00
|
|
|
|
switch (style.latextype) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
case LATEX_COMMAND:
|
2001-02-11 21:25:34 +00:00
|
|
|
|
if (c_params.empty())
|
|
|
|
|
end_tag = "title";
|
|
|
|
|
else
|
|
|
|
|
end_tag = c_params;
|
2001-01-28 21:54:15 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth, end_tag);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_ENVIRONMENT:
|
2001-01-28 21:54:15 +00:00
|
|
|
|
if (!style.latexparam().empty()) {
|
|
|
|
|
if(style.latexparam() == "CDATA")
|
|
|
|
|
ofs << "]]>";
|
|
|
|
|
else
|
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
|
|
|
|
style.latexparam());
|
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_ITEM_ENVIRONMENT:
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (desc_on == 1) break;
|
1999-11-15 12:01:38 +00:00
|
|
|
|
end_tag= "para";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
case LATEX_PARAGRAPH:
|
2000-11-13 15:43:36 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2000-11-13 15:43:36 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth, style.latexname());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close open tags
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (int d = depth; d >= 0; --d) {
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!environment_stack[depth].empty()) {
|
|
|
|
|
if (environment_inner[depth] != "!-- --") {
|
2001-04-04 21:47:26 +00:00
|
|
|
|
item_name = "listitem";
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, command_depth + depth,
|
1999-10-02 14:01:04 +00:00
|
|
|
|
item_name);
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (environment_inner[depth] == "varlistentry")
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
1999-10-02 14:01:04 +00:00
|
|
|
|
environment_inner[depth]);
|
|
|
|
|
}
|
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, depth + command_depth,
|
1999-10-02 14:01:04 +00:00
|
|
|
|
environment_stack[depth]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (int j = command_depth; j >= 0 ; --j)
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (!command_stack[j].empty())
|
1999-12-07 00:44:53 +00:00
|
|
|
|
sgmlCloseTag(ofs, j, command_stack[j]);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-11-13 15:43:36 +00:00
|
|
|
|
ofs << "\n\n";
|
|
|
|
|
sgmlCloseTag(ofs, 0, top_element);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-12-07 00:44:53 +00:00
|
|
|
|
ofs.close();
|
|
|
|
|
// How to check for successful close
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::simpleDocBookOnePar(ostream & os, string & extra,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par, int & desc_on,
|
|
|
|
|
Paragraph::depth_type depth) const
|
2000-03-06 02:42:40 +00:00
|
|
|
|
{
|
|
|
|
|
bool emph_flag = false;
|
|
|
|
|
|
|
|
|
|
LyXLayout const & style = textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout());
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2000-03-09 03:36:48 +00:00
|
|
|
|
int char_line_count = depth;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
//if (!style.free_spacing)
|
|
|
|
|
// os << string(depth,' ');
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// parsing main loop
|
2001-06-25 00:06:33 +00:00
|
|
|
|
for (Paragraph::size_type i = 0;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
i < par->size(); ++i) {
|
2001-03-23 08:37:44 +00:00
|
|
|
|
LyXFont font = par->getFont(params, i);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
|
|
// handle <emphasis> tag
|
2001-03-23 08:37:44 +00:00
|
|
|
|
if (font_old.emph() != font.emph()) {
|
|
|
|
|
if (font.emph() == LyXFont::ON) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "<emphasis>";
|
2000-03-09 03:36:48 +00:00
|
|
|
|
emph_flag = true;
|
2001-03-21 23:38:07 +00:00
|
|
|
|
}else if(i) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "</emphasis>";
|
2000-03-09 03:36:48 +00:00
|
|
|
|
emph_flag = false;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
char c = par->getChar(i);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
if (c == Paragraph::META_INSET) {
|
|
|
|
|
Inset * inset = par->getInset(i);
|
2000-04-04 00:19:15 +00:00
|
|
|
|
std::ostringstream ost;
|
2001-06-28 10:25:20 +00:00
|
|
|
|
inset->docBook(this, ost);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
string tmp_out = ost.str().c_str();
|
2000-09-18 17:39:21 +00:00
|
|
|
|
|
2000-03-06 02:42:40 +00:00
|
|
|
|
//
|
|
|
|
|
// This code needs some explanation:
|
|
|
|
|
// Two insets are treated specially
|
|
|
|
|
// label if it is the first element in a command paragraph
|
|
|
|
|
// desc_on == 3
|
|
|
|
|
// graphics inside tables or figure floats can't go on
|
|
|
|
|
// title (the equivalente in latex for this case is caption
|
|
|
|
|
// and title should come first
|
|
|
|
|
// desc_on == 4
|
|
|
|
|
//
|
2000-11-04 10:00:12 +00:00
|
|
|
|
if (desc_on!= 3 || i!= 0) {
|
|
|
|
|
if (!tmp_out.empty() && tmp_out[0] == '@') {
|
|
|
|
|
if (desc_on == 4)
|
2000-03-06 02:42:40 +00:00
|
|
|
|
extra += frontStrip(tmp_out, '@');
|
|
|
|
|
else
|
|
|
|
|
os << frontStrip(tmp_out, '@');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
os << tmp_out;
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#ifndef NO_LATEX
|
2001-03-23 08:37:44 +00:00
|
|
|
|
} else if (font.latex() == LyXFont::ON) {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
// "TeX"-Mode on ==> SGML-Mode on.
|
2000-03-09 03:36:48 +00:00
|
|
|
|
if (c != '\0')
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << c;
|
|
|
|
|
++char_line_count;
|
2001-06-27 14:10:35 +00:00
|
|
|
|
#endif
|
2000-04-26 13:57:28 +00:00
|
|
|
|
} else {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
string sgml_string;
|
|
|
|
|
if (par->linuxDocConvertChar(c, sgml_string)
|
|
|
|
|
&& !style.free_spacing) { // in freespacing
|
|
|
|
|
// mode, spaces are
|
|
|
|
|
// non-breaking characters
|
|
|
|
|
// char is ' '
|
|
|
|
|
if (desc_on == 1) {
|
|
|
|
|
++char_line_count;
|
|
|
|
|
os << "\n</term><listitem><para>";
|
|
|
|
|
desc_on = 2;
|
2000-04-26 13:57:28 +00:00
|
|
|
|
} else {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << c;
|
|
|
|
|
}
|
2000-04-26 13:57:28 +00:00
|
|
|
|
} else {
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << sgml_string;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-23 08:37:44 +00:00
|
|
|
|
font_old = font;
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (emph_flag) {
|
|
|
|
|
os << "</emphasis>";
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// resets description flag correctly
|
2001-03-23 08:37:44 +00:00
|
|
|
|
if (desc_on == 1) {
|
2000-04-26 13:57:28 +00:00
|
|
|
|
// <term> not closed...
|
2000-03-06 02:42:40 +00:00
|
|
|
|
os << "</term>";
|
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
if(style.free_spacing) os << '\n';
|
2000-03-06 02:42:40 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This should be enabled when the Chktex class is implemented. (Asger)
|
|
|
|
|
// chktex should be run with these flags disabled: 3, 22, 25, 30, 38(?)
|
|
|
|
|
// Other flags: -wall -v0 -x
|
|
|
|
|
int Buffer::runChktex()
|
|
|
|
|
{
|
1999-12-10 00:07:59 +00:00
|
|
|
|
if (!users->text) return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2001-07-03 15:19:04 +00:00
|
|
|
|
users->owner()->prohibitInput();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// get LaTeX-Filename
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const name = getLatexName();
|
1999-10-02 16:21:10 +00:00
|
|
|
|
string path = OnlyPath(filename);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string const org_path = path;
|
2000-03-12 10:35:05 +00:00
|
|
|
|
if (lyxrc.use_tempdir || (IsDirWriteable(path) < 1)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
path = tmppath;
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-13 17:32:46 +00:00
|
|
|
|
Path p(path); // path to LaTeX file
|
2001-04-24 17:33:01 +00:00
|
|
|
|
users->owner()->message(_("Running chktex..."));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Remove all error insets
|
2000-09-26 13:54:57 +00:00
|
|
|
|
bool const removedErrorInsets = users->removeAutoInsets();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Generate the LaTeX file if neccessary
|
2000-06-20 12:49:14 +00:00
|
|
|
|
makeLaTeXFile(name, org_path, false);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
TeXErrors terr;
|
2000-03-12 10:35:05 +00:00
|
|
|
|
Chktex chktex(lyxrc.chktex_command, name, filepath);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
int res = chktex.run(terr); // run chktex
|
|
|
|
|
|
|
|
|
|
if (res == -1) {
|
|
|
|
|
WriteAlert(_("chktex did not work!"),
|
|
|
|
|
_("Could not run with file:"), name);
|
|
|
|
|
} else if (res > 0) {
|
|
|
|
|
// Insert all errors as errors boxes
|
2000-01-08 21:02:58 +00:00
|
|
|
|
users->insertErrors(terr);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if we removed error insets before we ran chktex or if we inserted
|
|
|
|
|
// error insets after we ran chktex, this must be run:
|
2000-06-20 12:49:14 +00:00
|
|
|
|
if (removedErrorInsets || res){
|
1999-09-27 18:44:28 +00:00
|
|
|
|
users->redraw();
|
2000-09-28 14:05:24 +00:00
|
|
|
|
users->fitCursor(users->text);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-07-03 15:19:04 +00:00
|
|
|
|
users->owner()->allowInput();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
void Buffer::validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
1999-11-15 12:01:38 +00:00
|
|
|
|
LyXTextClass const & tclass =
|
1999-11-04 01:40:20 +00:00
|
|
|
|
textclasslist.TextClass(params.textclass);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// AMS Style is at document level
|
|
|
|
|
|
|
|
|
|
features.amsstyle = (params.use_amsmath ||
|
1999-11-04 01:40:20 +00:00
|
|
|
|
tclass.provides(LyXTextClass::amsmath));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
while (par) {
|
|
|
|
|
// We don't use "lyxerr.debug" because of speed. (Asger)
|
1999-10-07 18:44:17 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::LATEX))
|
|
|
|
|
lyxerr << "Paragraph: " << par << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
|
// Now just follow the list of paragraphs and run
|
|
|
|
|
// validate on each of them.
|
|
|
|
|
par->validate(features);
|
|
|
|
|
|
|
|
|
|
// and then the next paragraph
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// the bullet shapes are buffer level not paragraph level
|
|
|
|
|
// so they are tested here
|
|
|
|
|
for (int i = 0; i < 4; ++i) {
|
|
|
|
|
if (params.user_defined_bullets[i] != ITEMIZE_DEFAULTS[i]) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
int const font = params.user_defined_bullets[i].getFont();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (font == 0) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
int const c = params
|
1999-11-04 01:40:20 +00:00
|
|
|
|
.user_defined_bullets[i]
|
|
|
|
|
.getCharacter();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (c == 16
|
|
|
|
|
|| c == 17
|
|
|
|
|
|| c == 25
|
|
|
|
|
|| c == 26
|
|
|
|
|
|| c == 31) {
|
|
|
|
|
features.latexsym = true;
|
|
|
|
|
}
|
2000-09-26 13:54:57 +00:00
|
|
|
|
} else if (font == 1) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
features.amssymb = true;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
} else if ((font >= 2 && font <= 5)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
features.pifont = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
|
if (lyxerr.debugging(Debug::LATEX)) {
|
2000-04-10 21:40:13 +00:00
|
|
|
|
features.showStruct();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Buffer::setPaperStuff()
|
|
|
|
|
{
|
1999-11-15 12:01:38 +00:00
|
|
|
|
params.papersize = BufferParams::PAPER_DEFAULT;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
char const c1 = params.paperpackage;
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (c1 == BufferParams::PACKAGE_NONE) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
char const c2 = params.papersize2;
|
1999-11-15 12:01:38 +00:00
|
|
|
|
if (c2 == BufferParams::VM_PAPER_USLETTER)
|
|
|
|
|
params.papersize = BufferParams::PAPER_USLETTER;
|
|
|
|
|
else if (c2 == BufferParams::VM_PAPER_USLEGAL)
|
|
|
|
|
params.papersize = BufferParams::PAPER_LEGALPAPER;
|
|
|
|
|
else if (c2 == BufferParams::VM_PAPER_USEXECUTIVE)
|
|
|
|
|
params.papersize = BufferParams::PAPER_EXECUTIVEPAPER;
|
|
|
|
|
else if (c2 == BufferParams::VM_PAPER_A3)
|
|
|
|
|
params.papersize = BufferParams::PAPER_A3PAPER;
|
|
|
|
|
else if (c2 == BufferParams::VM_PAPER_A4)
|
|
|
|
|
params.papersize = BufferParams::PAPER_A4PAPER;
|
|
|
|
|
else if (c2 == BufferParams::VM_PAPER_A5)
|
|
|
|
|
params.papersize = BufferParams::PAPER_A5PAPER;
|
|
|
|
|
else if ((c2 == BufferParams::VM_PAPER_B3) || (c2 == BufferParams::VM_PAPER_B4) ||
|
|
|
|
|
(c2 == BufferParams::VM_PAPER_B5))
|
|
|
|
|
params.papersize = BufferParams::PAPER_B5PAPER;
|
|
|
|
|
} else if ((c1 == BufferParams::PACKAGE_A4) || (c1 == BufferParams::PACKAGE_A4WIDE) ||
|
|
|
|
|
(c1 == BufferParams::PACKAGE_WIDEMARGINSA4))
|
|
|
|
|
params.papersize = BufferParams::PAPER_A4PAPER;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// This function should be in Buffer because it's a buffer's property (ale)
|
2000-09-14 17:53:12 +00:00
|
|
|
|
string const Buffer::getIncludeonlyList(char delim)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
string lst;
|
2000-05-19 16:46:01 +00:00
|
|
|
|
for (inset_iterator it = inset_iterator_begin();
|
|
|
|
|
it != inset_iterator_end(); ++it) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
|
2000-05-19 16:46:01 +00:00
|
|
|
|
InsetInclude * insetinc =
|
|
|
|
|
static_cast<InsetInclude *>(*it);
|
2001-03-14 10:57:39 +00:00
|
|
|
|
if (insetinc->isIncludeOnly()) {
|
2000-05-19 16:46:01 +00:00
|
|
|
|
if (!lst.empty())
|
|
|
|
|
lst += delim;
|
2001-03-14 10:57:39 +00:00
|
|
|
|
lst += insetinc->getRelFileBaseName();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2001-06-27 14:10:35 +00:00
|
|
|
|
lyxerr[Debug::INFO] << "Includeonly(" << lst << ')' << endl;
|
1999-11-04 01:40:20 +00:00
|
|
|
|
return lst;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
vector<string> const Buffer::getLabelList()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
/// if this is a child document and the parent is already loaded
|
|
|
|
|
/// Use the parent's list instead [ale990407]
|
2000-01-25 12:35:27 +00:00
|
|
|
|
if (!params.parentname.empty()
|
|
|
|
|
&& bufferlist.exists(params.parentname)) {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
Buffer * tmp = bufferlist.getBuffer(params.parentname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (tmp)
|
2000-05-19 16:46:01 +00:00
|
|
|
|
return tmp->getLabelList();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-05-19 16:46:01 +00:00
|
|
|
|
vector<string> label_list;
|
|
|
|
|
for (inset_iterator it = inset_iterator_begin();
|
|
|
|
|
it != inset_iterator_end(); ++it) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
vector<string> const l = (*it)->getLabelList();
|
2000-05-19 16:46:01 +00:00
|
|
|
|
label_list.insert(label_list.end(), l.begin(), l.end());
|
|
|
|
|
}
|
|
|
|
|
return label_list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-12 01:43:12 +00:00
|
|
|
|
Buffer::Lists const Buffer::getLists() const
|
2000-05-19 16:46:01 +00:00
|
|
|
|
{
|
2001-03-12 01:43:12 +00:00
|
|
|
|
Lists l;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
2001-03-12 13:08:03 +00:00
|
|
|
|
bool found;
|
|
|
|
|
LyXTextClassList::size_type cap;
|
2001-03-15 16:04:46 +00:00
|
|
|
|
boost::tie(found, cap) = textclasslist
|
|
|
|
|
.NumberOfLayout(params.textclass, "Caption");
|
2001-03-12 13:08:03 +00:00
|
|
|
|
|
2000-01-25 12:35:27 +00:00
|
|
|
|
while (par) {
|
2001-05-04 10:36:36 +00:00
|
|
|
|
char const labeltype =
|
|
|
|
|
textclasslist.Style(params.textclass,
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->getLayout()).labeltype;
|
2001-05-04 10:36:36 +00:00
|
|
|
|
|
|
|
|
|
if (labeltype >= LABEL_COUNTER_CHAPTER
|
|
|
|
|
&& labeltype <= LABEL_COUNTER_CHAPTER + params.tocdepth) {
|
2000-05-19 16:46:01 +00:00
|
|
|
|
// insert this into the table of contents
|
2001-05-04 10:36:36 +00:00
|
|
|
|
SingleList & item = l["TOC"];
|
|
|
|
|
int depth = max(0,
|
|
|
|
|
labeltype -
|
|
|
|
|
textclasslist.TextClass(params.textclass).maxcounter());
|
2001-06-25 00:06:33 +00:00
|
|
|
|
item.push_back(TocItem(par, depth, par->asString(this, true)));
|
2001-05-04 10:36:36 +00:00
|
|
|
|
}
|
|
|
|
|
// For each paragrph, traverse its insets and look for
|
|
|
|
|
// FLOAT_CODE
|
|
|
|
|
|
|
|
|
|
if (found) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::inset_iterator it =
|
2001-05-04 10:36:36 +00:00
|
|
|
|
par->inset_iterator_begin();
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph::inset_iterator end =
|
2001-05-04 10:36:36 +00:00
|
|
|
|
par->inset_iterator_end();
|
2001-03-12 01:43:12 +00:00
|
|
|
|
|
2001-05-04 10:36:36 +00:00
|
|
|
|
for (; it != end; ++it) {
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if ((*it)->lyxCode() == Inset::FLOAT_CODE) {
|
2001-05-04 10:36:36 +00:00
|
|
|
|
InsetFloat * il =
|
|
|
|
|
static_cast<InsetFloat*>(*it);
|
|
|
|
|
|
|
|
|
|
string const type = il->type();
|
|
|
|
|
|
|
|
|
|
// Now find the caption in the float...
|
|
|
|
|
// We now tranverse the paragraphs of
|
|
|
|
|
// the inset...
|
2001-07-06 15:57:54 +00:00
|
|
|
|
Paragraph * tmp = il->inset.paragraph();
|
2001-05-04 10:36:36 +00:00
|
|
|
|
while (tmp) {
|
|
|
|
|
if (tmp->layout == cap) {
|
|
|
|
|
SingleList & item = l[type];
|
|
|
|
|
string const str =
|
2001-06-25 00:06:33 +00:00
|
|
|
|
tostr(item.size()+1) + ". " + tmp->asString(this, false);
|
2001-05-04 10:36:36 +00:00
|
|
|
|
item.push_back(TocItem(tmp, 0 , str));
|
2001-03-11 20:04:33 +00:00
|
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
|
tmp = tmp->next();
|
2001-03-11 20:04:33 +00:00
|
|
|
|
}
|
2001-03-11 18:39:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2001-05-04 10:36:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "caption not found" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
return l;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
// This is also a buffer property (ale)
|
2001-03-12 01:43:12 +00:00
|
|
|
|
vector<pair<string, string> > const Buffer::getBibkeyList()
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
/// if this is a child document and the parent is already loaded
|
|
|
|
|
/// Use the parent's list instead [ale990412]
|
|
|
|
|
if (!params.parentname.empty() && bufferlist.exists(params.parentname)) {
|
1999-12-10 00:07:59 +00:00
|
|
|
|
Buffer * tmp = bufferlist.getBuffer(params.parentname);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
if (tmp)
|
2000-06-07 08:53:40 +00:00
|
|
|
|
return tmp->getBibkeyList();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-08 23:16:16 +00:00
|
|
|
|
vector<pair<string, string> > keys;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (par) {
|
2000-06-07 08:53:40 +00:00
|
|
|
|
if (par->bibkey)
|
2000-07-19 17:16:27 +00:00
|
|
|
|
keys.push_back(pair<string, string>(par->bibkey->getContents(),
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->asString(this, false)));
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Might be either using bibtex or a child has bibliography
|
2000-06-07 08:53:40 +00:00
|
|
|
|
if (keys.empty()) {
|
2000-05-19 16:46:01 +00:00
|
|
|
|
for (inset_iterator it = inset_iterator_begin();
|
2000-06-07 08:53:40 +00:00
|
|
|
|
it != inset_iterator_end(); ++it) {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
// Search for Bibtex or Include inset
|
2001-06-28 10:25:20 +00:00
|
|
|
|
if ((*it)->lyxCode() == Inset::BIBTEX_CODE) {
|
2000-06-07 08:53:40 +00:00
|
|
|
|
vector<pair<string,string> > tmp =
|
2000-10-03 09:13:34 +00:00
|
|
|
|
static_cast<InsetBibtex*>(*it)->getKeys(this);
|
2000-06-07 08:53:40 +00:00
|
|
|
|
keys.insert(keys.end(), tmp.begin(), tmp.end());
|
2001-06-28 10:25:20 +00:00
|
|
|
|
} else if ((*it)->lyxCode() == Inset::INCLUDE_CODE) {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
vector<pair<string,string> > const tmp =
|
2000-06-07 08:53:40 +00:00
|
|
|
|
static_cast<InsetInclude*>(*it)->getKeys();
|
|
|
|
|
keys.insert(keys.end(), tmp.begin(), tmp.end());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-06-07 08:53:40 +00:00
|
|
|
|
return keys;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
bool Buffer::isDepClean(string const & name) const
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
1999-11-04 01:40:20 +00:00
|
|
|
|
DEPCLEAN * item = dep_clean;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (item && item->master != name)
|
|
|
|
|
item = item->next;
|
|
|
|
|
if (!item) return true;
|
|
|
|
|
return item->clean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
|
void Buffer::markDepClean(string const & name)
|
1999-09-27 18:44:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (!dep_clean) {
|
|
|
|
|
dep_clean = new DEPCLEAN;
|
|
|
|
|
dep_clean->clean = true;
|
|
|
|
|
dep_clean->master = name;
|
1999-10-02 16:21:10 +00:00
|
|
|
|
dep_clean->next = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
} else {
|
2000-09-26 13:54:57 +00:00
|
|
|
|
DEPCLEAN * item = dep_clean;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
while (item && item->master != name)
|
|
|
|
|
item = item->next;
|
|
|
|
|
if (item) {
|
|
|
|
|
item->clean = true;
|
|
|
|
|
} else {
|
|
|
|
|
item = new DEPCLEAN;
|
|
|
|
|
item->clean = true;
|
|
|
|
|
item->master = name;
|
2000-05-26 00:00:02 +00:00
|
|
|
|
item->next = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool Buffer::dispatch(string const & command)
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
|
|
|
|
// Split command string into command and argument
|
2000-09-26 13:54:57 +00:00
|
|
|
|
string cmd;
|
|
|
|
|
string line = frontStrip(command);
|
|
|
|
|
string const arg = strip(frontStrip(split(line, cmd, ' ')));
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
return dispatch(lyxaction.LookupFunc(cmd), arg);
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-01-08 21:02:58 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
bool Buffer::dispatch(int action, string const & argument)
|
1999-12-10 00:07:59 +00:00
|
|
|
|
{
|
2000-04-28 11:18:04 +00:00
|
|
|
|
bool dispatched = true;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
switch (action) {
|
1999-12-15 17:42:22 +00:00
|
|
|
|
case LFUN_EXPORT:
|
2000-08-30 03:40:51 +00:00
|
|
|
|
Exporter::Export(this, argument, false);
|
1999-12-15 17:42:22 +00:00
|
|
|
|
break;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
|
|
|
|
|
default:
|
2000-04-28 11:18:04 +00:00
|
|
|
|
dispatched = false;
|
|
|
|
|
}
|
|
|
|
|
return dispatched;
|
1999-12-10 00:07:59 +00:00
|
|
|
|
}
|
2000-04-10 21:40:13 +00:00
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2000-07-14 14:57:20 +00:00
|
|
|
|
void Buffer::resizeInsets(BufferView * bv)
|
|
|
|
|
{
|
2000-06-23 15:02:46 +00:00
|
|
|
|
/// then remove all LyXText in text-insets
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
for (; par; par = par->next()) {
|
2000-07-14 14:57:20 +00:00
|
|
|
|
par->resizeInsetsLyXText(bv);
|
2000-06-23 15:02:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-09 00:56:42 +00:00
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
void Buffer::redraw()
|
|
|
|
|
{
|
|
|
|
|
users->redraw();
|
|
|
|
|
users->fitCursor(users->text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::changeLanguage(Language const * from, Language const * to)
|
2000-04-10 21:40:13 +00:00
|
|
|
|
{
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
while (par) {
|
2001-06-25 00:06:33 +00:00
|
|
|
|
par->changeLanguage(params, from, to);
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-04-10 21:40:13 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2000-04-26 13:57:28 +00:00
|
|
|
|
|
2000-04-10 21:40:13 +00:00
|
|
|
|
bool Buffer::isMultiLingual()
|
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Paragraph * par = paragraph;
|
2000-04-10 21:40:13 +00:00
|
|
|
|
while (par) {
|
2000-06-08 23:16:16 +00:00
|
|
|
|
if (par->isMultiLingual(params))
|
2000-04-10 21:40:13 +00:00
|
|
|
|
return true;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-04-10 21:40:13 +00:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2000-05-19 16:46:01 +00:00
|
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
|
Buffer::inset_iterator::inset_iterator(Paragraph * paragraph,
|
|
|
|
|
Paragraph::size_type pos)
|
2000-09-26 13:54:57 +00:00
|
|
|
|
: par(paragraph)
|
|
|
|
|
{
|
2000-05-19 16:46:01 +00:00
|
|
|
|
it = par->InsetIterator(pos);
|
|
|
|
|
if (it == par->inset_iterator_end()) {
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2001-06-28 10:25:20 +00:00
|
|
|
|
setParagraph();
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void Buffer::inset_iterator::setParagraph()
|
2000-09-26 13:54:57 +00:00
|
|
|
|
{
|
2000-05-19 16:46:01 +00:00
|
|
|
|
while (par) {
|
|
|
|
|
it = par->inset_iterator_begin();
|
|
|
|
|
if (it != par->inset_iterator_end())
|
|
|
|
|
return;
|
2001-03-09 00:56:42 +00:00
|
|
|
|
par = par->next();
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
//it = 0;
|
2000-05-20 21:37:05 +00:00
|
|
|
|
// We maintain an invariant that whenever par = 0 then it = 0
|
2000-05-19 16:46:01 +00:00
|
|
|
|
}
|
2001-07-06 15:57:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inset * Buffer::getInsetFromID(int id_arg) const
|
|
|
|
|
{
|
|
|
|
|
for (inset_iterator it = inset_const_iterator_begin();
|
|
|
|
|
it != inset_const_iterator_end(); ++it)
|
|
|
|
|
{
|
|
|
|
|
if ((*it)->id() == id_arg)
|
|
|
|
|
return *it;
|
|
|
|
|
Inset * in = (*it)->getInsetFromID(id_arg);
|
|
|
|
|
if (in)
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2001-07-09 09:16:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Paragraph * Buffer::getParFromID(int id) const
|
|
|
|
|
{
|
|
|
|
|
if (id < 0) return 0;
|
|
|
|
|
Paragraph * par = paragraph;
|
|
|
|
|
while (par) {
|
|
|
|
|
if (par->id() == id) {
|
|
|
|
|
return par;
|
|
|
|
|
}
|
|
|
|
|
Paragraph * tmp = par->getParFromID(id);
|
|
|
|
|
if (tmp) {
|
|
|
|
|
return tmp;
|
|
|
|
|
}
|
|
|
|
|
par = par->next();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|