2003-08-22 09:44:59 +00:00
|
|
|
|
/**
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \file lyxtextclass.C
|
2003-08-22 09:44:59 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-22 09:44:59 +00:00
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author Jean-Marc Lasgouttes
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Angus Leeming
|
|
|
|
|
* \author John Levon
|
2003-08-22 09:44:59 +00:00
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2002-03-21 17:27:08 +00:00
|
|
|
|
*
|
2003-08-22 09:44:59 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2001-12-28 13:26:54 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "lyxtextclass.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "lyxlex.h"
|
2002-09-06 14:48:01 +00:00
|
|
|
|
#include "counters.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
|
#include "Floating.h"
|
2002-09-11 07:39:55 +00:00
|
|
|
|
#include "FloatList.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
#include "support/lstrings.h"
|
2005-10-21 16:11:36 +00:00
|
|
|
|
#include "support/lyxlib.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
#include "support/filetools.h"
|
|
|
|
|
|
2005-10-21 16:11:36 +00:00
|
|
|
|
#include <sstream>
|
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::LibFileSearch;
|
|
|
|
|
using lyx::support::MakeDisplayPath;
|
2005-10-21 16:11:36 +00:00
|
|
|
|
using lyx::support::QuoteName;
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::rtrim;
|
|
|
|
|
using lyx::support::subst;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
using std::endl;
|
2002-01-07 14:17:54 +00:00
|
|
|
|
using std::find_if;
|
|
|
|
|
using std::remove_if;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::ostream;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
|
2004-01-31 15:30:24 +00:00
|
|
|
|
namespace {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2004-01-31 15:30:24 +00:00
|
|
|
|
class LayoutNamesEqual : public std::unary_function<LyXLayout_ptr, bool> {
|
|
|
|
|
public:
|
|
|
|
|
LayoutNamesEqual(string const & name)
|
2003-03-14 11:57:12 +00:00
|
|
|
|
: name_(name)
|
|
|
|
|
{}
|
2004-01-31 15:30:24 +00:00
|
|
|
|
bool operator()(LyXLayout_ptr const & c) const
|
2003-03-14 11:57:12 +00:00
|
|
|
|
{
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return c->name() == name_;
|
|
|
|
|
}
|
2004-01-31 15:30:24 +00:00
|
|
|
|
private:
|
2002-06-24 20:28:12 +00:00
|
|
|
|
string name_;
|
|
|
|
|
};
|
|
|
|
|
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
|
|
|
|
int const FORMAT = 2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool layout2layout(string const & filename, string const & tempfile)
|
|
|
|
|
{
|
|
|
|
|
string const script = LibFileSearch("scripts", "layout2layout.py");
|
|
|
|
|
if (script.empty()) {
|
|
|
|
|
lyxerr << "Could not find layout conversion "
|
|
|
|
|
"script layout2layout.py." << endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::ostringstream command;
|
|
|
|
|
command << "python " << QuoteName(script)
|
|
|
|
|
<< ' ' << QuoteName(filename)
|
|
|
|
|
<< ' ' << QuoteName(tempfile);
|
|
|
|
|
string const command_str = command.str();
|
|
|
|
|
|
|
|
|
|
lyxerr[Debug::TCLASS] << "Running `" << command_str << '\'' << endl;
|
|
|
|
|
|
|
|
|
|
lyx::support::cmd_ret const ret =
|
|
|
|
|
lyx::support::RunCommand(command_str);
|
|
|
|
|
if (ret.first != 0) {
|
|
|
|
|
lyxerr << "Could not run layout conversion "
|
|
|
|
|
"script layout2layout.py." << endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-31 15:30:24 +00:00
|
|
|
|
} // namespace anon
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
LyXTextClass::LyXTextClass(string const & fn, string const & cln,
|
2003-05-03 19:24:36 +00:00
|
|
|
|
string const & desc, bool texClassAvail )
|
2002-09-11 07:39:55 +00:00
|
|
|
|
: name_(fn), latexname_(cln), description_(desc),
|
2004-01-31 15:30:24 +00:00
|
|
|
|
floatlist_(new FloatList), ctrs_(new Counters),
|
|
|
|
|
texClassAvail_(texClassAvail)
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
|
|
|
|
outputType_ = LATEX;
|
|
|
|
|
columns_ = 1;
|
|
|
|
|
sides_ = OneSide;
|
|
|
|
|
secnumdepth_ = 3;
|
|
|
|
|
tocdepth_ = 3;
|
|
|
|
|
pagestyle_ = "default";
|
|
|
|
|
defaultfont_ = LyXFont(LyXFont::ALL_SANE);
|
|
|
|
|
opt_fontsize_ = "10|11|12";
|
|
|
|
|
opt_pagestyle_ = "empty|plain|headings|fancy";
|
|
|
|
|
provides_ = nothing;
|
2003-02-13 17:49:09 +00:00
|
|
|
|
titletype_ = TITLE_COMMAND_AFTER;
|
|
|
|
|
titlename_ = "maketitle";
|
2004-03-30 16:19:50 +00:00
|
|
|
|
loaded_ = false;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-03 19:24:36 +00:00
|
|
|
|
bool LyXTextClass::isTeXClassAvailable() const
|
|
|
|
|
{
|
|
|
|
|
return texClassAvail_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
bool LyXTextClass::do_readStyle(LyXLex & lexrc, LyXLayout & lay)
|
|
|
|
|
{
|
|
|
|
|
lyxerr[Debug::TCLASS] << "Reading style " << lay.name() << endl;
|
|
|
|
|
if (!lay.Read(lexrc, *this)) {
|
2002-02-26 10:50:48 +00:00
|
|
|
|
// Resolve fonts
|
2001-12-28 13:26:54 +00:00
|
|
|
|
lay.resfont = lay.font;
|
|
|
|
|
lay.resfont.realize(defaultfont());
|
|
|
|
|
lay.reslabelfont = lay.labelfont;
|
|
|
|
|
lay.reslabelfont.realize(defaultfont());
|
|
|
|
|
return false; // no errors
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lyxerr << "Error parsing style `" << lay.name() << '\'' << endl;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum TextClassTags {
|
|
|
|
|
TC_OUTPUTTYPE = 1,
|
|
|
|
|
TC_INPUT,
|
|
|
|
|
TC_STYLE,
|
2002-03-02 16:39:54 +00:00
|
|
|
|
TC_DEFAULTSTYLE,
|
2003-11-12 14:38:26 +00:00
|
|
|
|
TC_CHARSTYLE,
|
2003-03-21 12:48:20 +00:00
|
|
|
|
TC_ENVIRONMENT,
|
2001-12-28 13:26:54 +00:00
|
|
|
|
TC_NOSTYLE,
|
|
|
|
|
TC_COLUMNS,
|
|
|
|
|
TC_SIDES,
|
|
|
|
|
TC_PAGESTYLE,
|
|
|
|
|
TC_DEFAULTFONT,
|
|
|
|
|
TC_SECNUMDEPTH,
|
|
|
|
|
TC_TOCDEPTH,
|
|
|
|
|
TC_CLASSOPTIONS,
|
|
|
|
|
TC_PREAMBLE,
|
|
|
|
|
TC_PROVIDESAMSMATH,
|
2002-04-23 22:34:24 +00:00
|
|
|
|
TC_PROVIDESNATBIB,
|
2001-12-28 13:26:54 +00:00
|
|
|
|
TC_PROVIDESMAKEIDX,
|
|
|
|
|
TC_PROVIDESURL,
|
|
|
|
|
TC_LEFTMARGIN,
|
2002-09-04 06:52:26 +00:00
|
|
|
|
TC_RIGHTMARGIN,
|
2002-09-06 14:48:01 +00:00
|
|
|
|
TC_FLOAT,
|
2002-09-11 07:39:55 +00:00
|
|
|
|
TC_COUNTER,
|
2003-02-13 17:49:09 +00:00
|
|
|
|
TC_NOFLOAT,
|
|
|
|
|
TC_TITLELATEXNAME,
|
2005-10-21 16:11:36 +00:00
|
|
|
|
TC_TITLELATEXTYPE,
|
|
|
|
|
TC_FORMAT
|
2001-12-28 13:26:54 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-10-21 16:11:36 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
// Reads a textclass structure from file.
|
|
|
|
|
bool LyXTextClass::Read(string const & filename, bool merge)
|
|
|
|
|
{
|
2005-10-21 16:11:36 +00:00
|
|
|
|
if (!lyx::support::IsFileReadable(filename)) {
|
|
|
|
|
lyxerr << "Cannot read layout file `" << filename << "'."
|
|
|
|
|
<< endl;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
keyword_item textClassTags[] = {
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{ "charstyle", TC_CHARSTYLE },
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{ "classoptions", TC_CLASSOPTIONS },
|
|
|
|
|
{ "columns", TC_COLUMNS },
|
2002-09-06 14:48:01 +00:00
|
|
|
|
{ "counter", TC_COUNTER },
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{ "defaultfont", TC_DEFAULTFONT },
|
2002-03-02 16:39:54 +00:00
|
|
|
|
{ "defaultstyle", TC_DEFAULTSTYLE },
|
2003-03-21 12:48:20 +00:00
|
|
|
|
{ "environment", TC_ENVIRONMENT },
|
2002-09-04 06:52:26 +00:00
|
|
|
|
{ "float", TC_FLOAT },
|
2005-10-21 16:11:36 +00:00
|
|
|
|
{ "format", TC_FORMAT },
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{ "input", TC_INPUT },
|
|
|
|
|
{ "leftmargin", TC_LEFTMARGIN },
|
2002-09-11 07:39:55 +00:00
|
|
|
|
{ "nofloat", TC_NOFLOAT },
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{ "nostyle", TC_NOSTYLE },
|
|
|
|
|
{ "outputtype", TC_OUTPUTTYPE },
|
|
|
|
|
{ "pagestyle", TC_PAGESTYLE },
|
|
|
|
|
{ "preamble", TC_PREAMBLE },
|
|
|
|
|
{ "providesamsmath", TC_PROVIDESAMSMATH },
|
|
|
|
|
{ "providesmakeidx", TC_PROVIDESMAKEIDX },
|
2002-04-23 22:34:24 +00:00
|
|
|
|
{ "providesnatbib", TC_PROVIDESNATBIB },
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{ "providesurl", TC_PROVIDESURL },
|
|
|
|
|
{ "rightmargin", TC_RIGHTMARGIN },
|
|
|
|
|
{ "secnumdepth", TC_SECNUMDEPTH },
|
|
|
|
|
{ "sides", TC_SIDES },
|
|
|
|
|
{ "style", TC_STYLE },
|
2003-02-13 17:49:09 +00:00
|
|
|
|
{ "titlelatexname", TC_TITLELATEXNAME },
|
|
|
|
|
{ "titlelatextype", TC_TITLELATEXTYPE },
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{ "tocdepth", TC_TOCDEPTH }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!merge)
|
|
|
|
|
lyxerr[Debug::TCLASS] << "Reading textclass "
|
|
|
|
|
<< MakeDisplayPath(filename)
|
|
|
|
|
<< endl;
|
|
|
|
|
else
|
|
|
|
|
lyxerr[Debug::TCLASS] << "Reading input file "
|
|
|
|
|
<< MakeDisplayPath(filename)
|
|
|
|
|
<< endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-03-21 12:48:20 +00:00
|
|
|
|
LyXLex lexrc(textClassTags,
|
|
|
|
|
sizeof(textClassTags) / sizeof(textClassTags[0]));
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
lexrc.setFile(filename);
|
2005-10-21 16:11:36 +00:00
|
|
|
|
bool error = !lexrc.isOK();
|
|
|
|
|
|
|
|
|
|
// Format of files before the 'Format' tag was introduced
|
|
|
|
|
int format = 1;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
// parsing
|
|
|
|
|
while (lexrc.isOK() && !error) {
|
|
|
|
|
int le = lexrc.lex();
|
2003-03-14 12:08:15 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
switch (le) {
|
|
|
|
|
case LyXLex::LEX_FEOF:
|
2002-03-21 17:27:08 +00:00
|
|
|
|
continue;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
case LyXLex::LEX_UNDEF:
|
2001-12-28 13:26:54 +00:00
|
|
|
|
lexrc.printError("Unknown TextClass tag `$$Token'");
|
|
|
|
|
error = true;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
continue;
|
2003-03-14 12:08:15 +00:00
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
2003-03-14 12:08:15 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
switch (static_cast<TextClassTags>(le)) {
|
2003-03-14 12:08:15 +00:00
|
|
|
|
|
2005-10-21 16:11:36 +00:00
|
|
|
|
case TC_FORMAT:
|
|
|
|
|
if (lexrc.next())
|
|
|
|
|
format = lexrc.getInteger();
|
|
|
|
|
break;
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
case TC_OUTPUTTYPE: // output type definition
|
|
|
|
|
readOutputType(lexrc);
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
case TC_INPUT: // Include file
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (lexrc.next()) {
|
|
|
|
|
string tmp = LibFileSearch("layouts",
|
|
|
|
|
lexrc.getString(),
|
2001-12-28 13:26:54 +00:00
|
|
|
|
"layout");
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
if (Read(tmp, true)) {
|
|
|
|
|
lexrc.printError("Error reading input"
|
|
|
|
|
"file: "+tmp);
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
case TC_DEFAULTSTYLE:
|
|
|
|
|
if (lexrc.next()) {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
string const name = subst(lexrc.getString(),
|
|
|
|
|
'_', ' ');
|
2002-03-02 16:39:54 +00:00
|
|
|
|
defaultlayout_ = name;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2003-05-19 07:12:09 +00:00
|
|
|
|
case TC_ENVIRONMENT:
|
2001-12-28 13:26:54 +00:00
|
|
|
|
case TC_STYLE:
|
|
|
|
|
if (lexrc.next()) {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
string const name = subst(lexrc.getString(),
|
2001-12-28 13:26:54 +00:00
|
|
|
|
'_', ' ');
|
|
|
|
|
if (hasLayout(name)) {
|
2003-03-14 11:57:12 +00:00
|
|
|
|
LyXLayout * lay = operator[](name).get();
|
2002-06-24 20:28:12 +00:00
|
|
|
|
error = do_readStyle(lexrc, *lay);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
} else {
|
|
|
|
|
LyXLayout lay;
|
|
|
|
|
lay.setName(name);
|
2003-05-19 07:12:09 +00:00
|
|
|
|
if (le == TC_ENVIRONMENT)
|
|
|
|
|
lay.is_environment = true;
|
2005-11-02 20:11:36 +00:00
|
|
|
|
error = do_readStyle(lexrc, lay);
|
|
|
|
|
if (!error)
|
2003-11-03 17:47:28 +00:00
|
|
|
|
layoutlist_.push_back(
|
|
|
|
|
boost::shared_ptr<LyXLayout>(new LyXLayout(lay))
|
|
|
|
|
);
|
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
if (defaultlayout_.empty()) {
|
|
|
|
|
// We do not have a default
|
|
|
|
|
// layout yet, so we choose
|
|
|
|
|
// the first layout we
|
|
|
|
|
// encounter.
|
|
|
|
|
defaultlayout_ = name;
|
|
|
|
|
}
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
lexrc.printError("No name given for style: `$$Token'.");
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TC_NOSTYLE:
|
|
|
|
|
if (lexrc.next()) {
|
2002-03-03 20:25:07 +00:00
|
|
|
|
string const style = subst(lexrc.getString(),
|
2001-12-28 13:26:54 +00:00
|
|
|
|
'_', ' ');
|
|
|
|
|
if (!delete_layout(style))
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lyxerr << "Cannot delete style `"
|
|
|
|
|
<< style << '\'' << endl;
|
2002-03-02 16:39:54 +00:00
|
|
|
|
// lexrc.printError("Cannot delete style"
|
|
|
|
|
// " `$$Token'");
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TC_COLUMNS:
|
|
|
|
|
if (lexrc.next())
|
|
|
|
|
columns_ = lexrc.getInteger();
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
case TC_SIDES:
|
|
|
|
|
if (lexrc.next()) {
|
|
|
|
|
switch (lexrc.getInteger()) {
|
|
|
|
|
case 1: sides_ = OneSide; break;
|
|
|
|
|
case 2: sides_ = TwoSides; break;
|
|
|
|
|
default:
|
|
|
|
|
lyxerr << "Impossible number of page"
|
|
|
|
|
" sides, setting to one."
|
|
|
|
|
<< endl;
|
|
|
|
|
sides_ = OneSide;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
case TC_PAGESTYLE:
|
2002-03-21 17:27:08 +00:00
|
|
|
|
lexrc.next();
|
2002-07-28 22:50:13 +00:00
|
|
|
|
pagestyle_ = rtrim(lexrc.getString());
|
2001-12-28 13:26:54 +00:00
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
case TC_DEFAULTFONT:
|
|
|
|
|
defaultfont_.lyxRead(lexrc);
|
|
|
|
|
if (!defaultfont_.resolved()) {
|
|
|
|
|
lexrc.printError("Warning: defaultfont should "
|
|
|
|
|
"be fully instantiated!");
|
|
|
|
|
defaultfont_.realize(LyXFont(LyXFont::ALL_SANE));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TC_SECNUMDEPTH:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
secnumdepth_ = lexrc.getInteger();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TC_TOCDEPTH:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
tocdepth_ = lexrc.getInteger();
|
|
|
|
|
break;
|
|
|
|
|
|
2002-03-21 17:27:08 +00:00
|
|
|
|
// First step to support options
|
|
|
|
|
case TC_CLASSOPTIONS:
|
2001-12-28 13:26:54 +00:00
|
|
|
|
readClassOptions(lexrc);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
break;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
case TC_PREAMBLE:
|
|
|
|
|
preamble_ = lexrc.getLongString("EndPreamble");
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TC_PROVIDESAMSMATH:
|
|
|
|
|
if (lexrc.next() && lexrc.getInteger())
|
|
|
|
|
provides_ |= amsmath;
|
|
|
|
|
break;
|
|
|
|
|
|
2002-04-23 22:34:24 +00:00
|
|
|
|
case TC_PROVIDESNATBIB:
|
|
|
|
|
if (lexrc.next() && lexrc.getInteger())
|
|
|
|
|
provides_ |= natbib;
|
|
|
|
|
break;
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
case TC_PROVIDESMAKEIDX:
|
|
|
|
|
if (lexrc.next() && lexrc.getInteger())
|
|
|
|
|
provides_ |= makeidx;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TC_PROVIDESURL:
|
|
|
|
|
if (lexrc.next() && lexrc.getInteger())
|
2002-04-17 21:05:37 +00:00
|
|
|
|
provides_ |= url;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TC_LEFTMARGIN: // left margin type
|
2002-03-21 17:27:08 +00:00
|
|
|
|
if (lexrc.next())
|
2001-12-28 13:26:54 +00:00
|
|
|
|
leftmargin_ = lexrc.getString();
|
2002-03-21 17:27:08 +00:00
|
|
|
|
break;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
case TC_RIGHTMARGIN: // right margin type
|
|
|
|
|
if (lexrc.next())
|
|
|
|
|
rightmargin_ = lexrc.getString();
|
|
|
|
|
break;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
case TC_CHARSTYLE:
|
|
|
|
|
if (lexrc.next()) {
|
|
|
|
|
string const name = subst(lexrc.getString(), '_', ' ');
|
|
|
|
|
readCharStyle(lexrc, name);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2002-09-04 06:52:26 +00:00
|
|
|
|
case TC_FLOAT:
|
|
|
|
|
readFloat(lexrc);
|
|
|
|
|
break;
|
2002-09-06 14:48:01 +00:00
|
|
|
|
case TC_COUNTER:
|
|
|
|
|
readCounter(lexrc);
|
|
|
|
|
break;
|
2003-02-13 17:49:09 +00:00
|
|
|
|
case TC_TITLELATEXTYPE:
|
|
|
|
|
readTitleType(lexrc);
|
|
|
|
|
break;
|
|
|
|
|
case TC_TITLELATEXNAME:
|
|
|
|
|
if (lexrc.next())
|
|
|
|
|
titlename_ = lexrc.getString();
|
|
|
|
|
break;
|
2002-09-11 07:39:55 +00:00
|
|
|
|
case TC_NOFLOAT:
|
|
|
|
|
if (lexrc.next()) {
|
|
|
|
|
string const nofloat = lexrc.getString();
|
|
|
|
|
floatlist_->erase(nofloat);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
2005-10-21 16:11:36 +00:00
|
|
|
|
if (format != FORMAT)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (format != FORMAT) {
|
|
|
|
|
lyxerr[Debug::TCLASS] << "Converting layout file from format "
|
|
|
|
|
<< format << " to " << FORMAT << endl;
|
|
|
|
|
string const tempfile = lyx::support::tempName();
|
|
|
|
|
error = !layout2layout(filename, tempfile);
|
|
|
|
|
if (!error)
|
|
|
|
|
error = Read(tempfile, merge);
|
|
|
|
|
lyx::support::unlink(tempfile);
|
|
|
|
|
return error;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
}
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
if (!merge) { // we are at top level here.
|
2002-03-21 17:27:08 +00:00
|
|
|
|
lyxerr[Debug::TCLASS] << "Finished reading textclass "
|
2001-12-28 13:26:54 +00:00
|
|
|
|
<< MakeDisplayPath(filename)
|
|
|
|
|
<< endl;
|
2002-03-02 16:39:54 +00:00
|
|
|
|
if (defaultlayout_.empty()) {
|
|
|
|
|
lyxerr << "Error: Textclass '" << name_
|
|
|
|
|
<< "' is missing a defaultstyle." << endl;
|
|
|
|
|
error = true;
|
|
|
|
|
}
|
2005-05-12 10:16:04 +00:00
|
|
|
|
|
|
|
|
|
min_toclevel_ = LyXLayout::NOT_IN_TOC;
|
|
|
|
|
max_toclevel_ = LyXLayout::NOT_IN_TOC;
|
|
|
|
|
const_iterator cit = begin();
|
|
|
|
|
const_iterator the_end = end();
|
|
|
|
|
for ( ; cit != the_end ; ++cit) {
|
|
|
|
|
int const toclevel = (*cit)->toclevel;
|
|
|
|
|
if (toclevel != LyXLayout::NOT_IN_TOC) {
|
|
|
|
|
if (min_toclevel_ == LyXLayout::NOT_IN_TOC)
|
|
|
|
|
min_toclevel_ = toclevel;
|
|
|
|
|
else
|
2005-06-09 09:58:08 +00:00
|
|
|
|
min_toclevel_ = std::min(min_toclevel_,
|
2005-05-12 10:16:04 +00:00
|
|
|
|
toclevel);
|
2005-06-09 09:58:08 +00:00
|
|
|
|
max_toclevel_ = std::max(max_toclevel_,
|
2005-05-12 10:16:04 +00:00
|
|
|
|
toclevel);
|
|
|
|
|
}
|
|
|
|
|
}
|
2005-06-09 09:58:08 +00:00
|
|
|
|
lyxerr[Debug::TCLASS]
|
2005-05-12 10:16:04 +00:00
|
|
|
|
<< "Minimum TocLevel is " << min_toclevel_
|
|
|
|
|
<< ", maximum is " << max_toclevel_ <<endl;
|
2005-06-09 09:58:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
} else
|
2002-03-21 17:27:08 +00:00
|
|
|
|
lyxerr[Debug::TCLASS] << "Finished reading input file "
|
2001-12-28 13:26:54 +00:00
|
|
|
|
<< MakeDisplayPath(filename)
|
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-13 17:49:09 +00:00
|
|
|
|
void LyXTextClass::readTitleType(LyXLex & lexrc)
|
|
|
|
|
{
|
|
|
|
|
keyword_item titleTypeTags[] = {
|
|
|
|
|
{ "commandafter", TITLE_COMMAND_AFTER },
|
|
|
|
|
{ "environment", TITLE_ENVIRONMENT }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pushpophelper pph(lexrc, titleTypeTags, TITLE_ENVIRONMENT);
|
|
|
|
|
|
|
|
|
|
int le = lexrc.lex();
|
|
|
|
|
switch (le) {
|
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
|
lexrc.printError("Unknown output type `$$Token'");
|
|
|
|
|
return;
|
|
|
|
|
case TITLE_COMMAND_AFTER:
|
|
|
|
|
case TITLE_ENVIRONMENT:
|
|
|
|
|
titletype_ = static_cast<LYX_TITLE_LATEX_TYPES>(le);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
lyxerr << "Unhandled value " << le
|
|
|
|
|
<< " in LyXTextClass::readTitleType." << endl;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
void LyXTextClass::readOutputType(LyXLex & lexrc)
|
|
|
|
|
{
|
|
|
|
|
keyword_item outputTypeTags[] = {
|
|
|
|
|
{ "docbook", DOCBOOK },
|
|
|
|
|
{ "latex", LATEX },
|
|
|
|
|
{ "linuxdoc", LINUXDOC },
|
|
|
|
|
{ "literate", LITERATE }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pushpophelper pph(lexrc, outputTypeTags, LITERATE);
|
|
|
|
|
|
|
|
|
|
int le = lexrc.lex();
|
|
|
|
|
switch (le) {
|
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
|
lexrc.printError("Unknown output type `$$Token'");
|
|
|
|
|
return;
|
|
|
|
|
case LATEX:
|
|
|
|
|
case LINUXDOC:
|
|
|
|
|
case DOCBOOK:
|
|
|
|
|
case LITERATE:
|
|
|
|
|
outputType_ = static_cast<OutputType>(le);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
lyxerr << "Unhandled value " << le
|
|
|
|
|
<< " in LyXTextClass::readOutputType." << endl;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum ClassOptionsTags {
|
|
|
|
|
CO_FONTSIZE = 1,
|
|
|
|
|
CO_PAGESTYLE,
|
|
|
|
|
CO_OTHER,
|
2003-11-27 16:57:12 +00:00
|
|
|
|
CO_HEADER,
|
2001-12-28 13:26:54 +00:00
|
|
|
|
CO_END
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXTextClass::readClassOptions(LyXLex & lexrc)
|
|
|
|
|
{
|
|
|
|
|
keyword_item classOptionsTags[] = {
|
|
|
|
|
{"end", CO_END },
|
|
|
|
|
{"fontsize", CO_FONTSIZE },
|
2003-11-27 16:57:12 +00:00
|
|
|
|
{"header", CO_HEADER },
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{"other", CO_OTHER },
|
|
|
|
|
{"pagestyle", CO_PAGESTYLE }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
lexrc.pushTable(classOptionsTags, CO_END);
|
|
|
|
|
bool getout = false;
|
|
|
|
|
while (!getout && lexrc.isOK()) {
|
|
|
|
|
int le = lexrc.lex();
|
|
|
|
|
switch (le) {
|
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
|
lexrc.printError("Unknown ClassOption tag `$$Token'");
|
2002-03-21 17:27:08 +00:00
|
|
|
|
continue;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
switch (static_cast<ClassOptionsTags>(le)) {
|
|
|
|
|
case CO_FONTSIZE:
|
|
|
|
|
lexrc.next();
|
2002-07-28 22:50:13 +00:00
|
|
|
|
opt_fontsize_ = rtrim(lexrc.getString());
|
2001-12-28 13:26:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case CO_PAGESTYLE:
|
|
|
|
|
lexrc.next();
|
2002-07-28 22:50:13 +00:00
|
|
|
|
opt_pagestyle_ = rtrim(lexrc.getString());
|
2001-12-28 13:26:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case CO_OTHER:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
options_ = lexrc.getString();
|
|
|
|
|
break;
|
2003-11-27 16:57:12 +00:00
|
|
|
|
case CO_HEADER:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
class_header_ = subst(lexrc.getString(), """, "\"");
|
|
|
|
|
break;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
case CO_END:
|
|
|
|
|
getout = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
lexrc.popTable();
|
|
|
|
|
}
|
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
enum CharStyleTags {
|
|
|
|
|
CS_FONT = 1,
|
|
|
|
|
CS_LABELFONT,
|
|
|
|
|
CS_LATEXTYPE,
|
|
|
|
|
CS_LATEXNAME,
|
2003-12-01 16:01:50 +00:00
|
|
|
|
CS_LATEXPARAM,
|
2003-11-12 14:38:26 +00:00
|
|
|
|
CS_PREAMBLE,
|
|
|
|
|
CS_END
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void LyXTextClass::readCharStyle(LyXLex & lexrc, string const & name)
|
|
|
|
|
{
|
|
|
|
|
keyword_item elementTags[] = {
|
|
|
|
|
{ "end", CS_END },
|
|
|
|
|
{ "font", CS_FONT },
|
|
|
|
|
{ "labelfont", CS_LABELFONT },
|
|
|
|
|
{ "latexname", CS_LATEXNAME },
|
2003-12-01 16:01:50 +00:00
|
|
|
|
{ "latexparam", CS_LATEXPARAM },
|
2003-11-12 14:38:26 +00:00
|
|
|
|
{ "latextype", CS_LATEXTYPE },
|
|
|
|
|
{ "preamble", CS_PREAMBLE}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
lexrc.pushTable(elementTags, CS_END);
|
|
|
|
|
|
|
|
|
|
string latextype;
|
|
|
|
|
string latexname;
|
2003-12-01 16:01:50 +00:00
|
|
|
|
string latexparam;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_INHERIT);
|
|
|
|
|
LyXFont labelfont(LyXFont::ALL_INHERIT);
|
|
|
|
|
string preamble;
|
2004-01-31 15:30:24 +00:00
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
bool getout = false;
|
|
|
|
|
while (!getout && lexrc.isOK()) {
|
|
|
|
|
int le = lexrc.lex();
|
|
|
|
|
switch (le) {
|
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
|
lexrc.printError("Unknown ClassOption tag `$$Token'");
|
|
|
|
|
continue;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
switch (static_cast<CharStyleTags>(le)) {
|
|
|
|
|
case CS_LATEXTYPE:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
latextype = lexrc.getString();
|
|
|
|
|
break;
|
|
|
|
|
case CS_LATEXNAME:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
latexname = lexrc.getString();
|
|
|
|
|
break;
|
2003-12-01 16:01:50 +00:00
|
|
|
|
case CS_LATEXPARAM:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
latexparam = subst(lexrc.getString(), """, "\"");
|
|
|
|
|
break;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
case CS_LABELFONT:
|
|
|
|
|
labelfont.lyxRead(lexrc);
|
|
|
|
|
break;
|
|
|
|
|
case CS_FONT:
|
|
|
|
|
font.lyxRead(lexrc);
|
|
|
|
|
labelfont = font;
|
|
|
|
|
break;
|
|
|
|
|
case CS_PREAMBLE:
|
|
|
|
|
preamble = lexrc.getLongString("EndPreamble");
|
|
|
|
|
break;
|
|
|
|
|
case CS_END:
|
|
|
|
|
getout = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Here add element to list if getout == true
|
|
|
|
|
if (getout) {
|
|
|
|
|
CharStyle cs;
|
|
|
|
|
cs.name = name;
|
|
|
|
|
cs.latextype = latextype;
|
|
|
|
|
cs.latexname = latexname;
|
2003-12-01 16:01:50 +00:00
|
|
|
|
cs.latexparam = latexparam;
|
2003-11-12 14:38:26 +00:00
|
|
|
|
cs.font = font;
|
|
|
|
|
cs.labelfont = labelfont;
|
|
|
|
|
cs.preamble = preamble;
|
|
|
|
|
charstyles().push_back(cs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lexrc.popTable();
|
|
|
|
|
}
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2002-09-04 06:52:26 +00:00
|
|
|
|
enum FloatTags {
|
|
|
|
|
FT_TYPE = 1,
|
|
|
|
|
FT_NAME,
|
|
|
|
|
FT_PLACEMENT,
|
|
|
|
|
FT_EXT,
|
|
|
|
|
FT_WITHIN,
|
|
|
|
|
FT_STYLE,
|
|
|
|
|
FT_LISTNAME,
|
|
|
|
|
FT_BUILTIN,
|
|
|
|
|
FT_END
|
|
|
|
|
};
|
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
|
2002-09-04 06:52:26 +00:00
|
|
|
|
void LyXTextClass::readFloat(LyXLex & lexrc)
|
|
|
|
|
{
|
|
|
|
|
keyword_item floatTags[] = {
|
|
|
|
|
{ "end", FT_END },
|
|
|
|
|
{ "extension", FT_EXT },
|
|
|
|
|
{ "guiname", FT_NAME },
|
|
|
|
|
{ "latexbuiltin", FT_BUILTIN },
|
|
|
|
|
{ "listname", FT_LISTNAME },
|
|
|
|
|
{ "numberwithin", FT_WITHIN },
|
|
|
|
|
{ "placement", FT_PLACEMENT },
|
|
|
|
|
{ "style", FT_STYLE },
|
|
|
|
|
{ "type", FT_TYPE }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
lexrc.pushTable(floatTags, FT_END);
|
|
|
|
|
|
|
|
|
|
string type;
|
|
|
|
|
string placement;
|
|
|
|
|
string ext;
|
|
|
|
|
string within;
|
|
|
|
|
string style;
|
|
|
|
|
string name;
|
|
|
|
|
string listname;
|
|
|
|
|
bool builtin = false;
|
|
|
|
|
|
|
|
|
|
bool getout = false;
|
|
|
|
|
while (!getout && lexrc.isOK()) {
|
|
|
|
|
int le = lexrc.lex();
|
|
|
|
|
switch (le) {
|
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
|
lexrc.printError("Unknown ClassOption tag `$$Token'");
|
|
|
|
|
continue;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
switch (static_cast<FloatTags>(le)) {
|
|
|
|
|
case FT_TYPE:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
type = lexrc.getString();
|
|
|
|
|
// Here we could check if this type is already defined
|
|
|
|
|
// and modify it with the rest of the vars instead.
|
|
|
|
|
break;
|
|
|
|
|
case FT_NAME:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
name = lexrc.getString();
|
|
|
|
|
break;
|
|
|
|
|
case FT_PLACEMENT:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
placement = lexrc.getString();
|
|
|
|
|
break;
|
|
|
|
|
case FT_EXT:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
ext = lexrc.getString();
|
|
|
|
|
break;
|
|
|
|
|
case FT_WITHIN:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
within = lexrc.getString();
|
|
|
|
|
if (within == "none")
|
|
|
|
|
within.erase();
|
|
|
|
|
break;
|
|
|
|
|
case FT_STYLE:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
style = lexrc.getString();
|
|
|
|
|
break;
|
|
|
|
|
case FT_LISTNAME:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
listname = lexrc.getString();
|
|
|
|
|
break;
|
|
|
|
|
case FT_BUILTIN:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
builtin = lexrc.getBool();
|
|
|
|
|
break;
|
|
|
|
|
case FT_END:
|
|
|
|
|
getout = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Here if have a full float if getout == true
|
|
|
|
|
if (getout) {
|
|
|
|
|
Floating newfloat(type, placement, ext, within,
|
|
|
|
|
style, name, listname, builtin);
|
2002-09-11 07:39:55 +00:00
|
|
|
|
floatlist_->newFloat(newfloat);
|
2002-09-04 06:52:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lexrc.popTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
enum CounterTags {
|
|
|
|
|
CT_NAME = 1,
|
|
|
|
|
CT_WITHIN,
|
|
|
|
|
CT_END
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void LyXTextClass::readCounter(LyXLex & lexrc)
|
|
|
|
|
{
|
|
|
|
|
keyword_item counterTags[] = {
|
|
|
|
|
{ "end", CT_END },
|
|
|
|
|
{ "name", CT_NAME },
|
|
|
|
|
{ "within", CT_WITHIN }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
lexrc.pushTable(counterTags, CT_END);
|
|
|
|
|
|
|
|
|
|
string name;
|
|
|
|
|
string within;
|
|
|
|
|
|
|
|
|
|
bool getout = false;
|
|
|
|
|
while (!getout && lexrc.isOK()) {
|
|
|
|
|
int le = lexrc.lex();
|
|
|
|
|
switch (le) {
|
|
|
|
|
case LyXLex::LEX_UNDEF:
|
|
|
|
|
lexrc.printError("Unknown ClassOption tag `$$Token'");
|
|
|
|
|
continue;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
switch (static_cast<CounterTags>(le)) {
|
|
|
|
|
case CT_NAME:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
name = lexrc.getString();
|
|
|
|
|
break;
|
|
|
|
|
case CT_WITHIN:
|
|
|
|
|
lexrc.next();
|
|
|
|
|
within = lexrc.getString();
|
|
|
|
|
if (within == "none")
|
|
|
|
|
within.erase();
|
|
|
|
|
break;
|
|
|
|
|
case CT_END:
|
|
|
|
|
getout = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-09-12 17:13:22 +00:00
|
|
|
|
// Here if have a full counter if getout == true
|
2002-09-06 14:48:01 +00:00
|
|
|
|
if (getout) {
|
|
|
|
|
if (within.empty()) {
|
|
|
|
|
ctrs_->newCounter(name);
|
|
|
|
|
} else {
|
|
|
|
|
ctrs_->newCounter(name, within);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lexrc.popTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
LyXFont const & LyXTextClass::defaultfont() const
|
|
|
|
|
{
|
|
|
|
|
return defaultfont_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::leftmargin() const
|
|
|
|
|
{
|
|
|
|
|
return leftmargin_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::rightmargin() const
|
|
|
|
|
{
|
|
|
|
|
return rightmargin_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
bool LyXTextClass::hasLayout(string const & n) const
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2002-03-03 20:25:07 +00:00
|
|
|
|
string const name = (n.empty() ? defaultLayoutName() : n);
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
return find_if(layoutlist_.begin(), layoutlist_.end(),
|
2004-01-31 15:30:24 +00:00
|
|
|
|
LayoutNamesEqual(name))
|
2002-08-27 15:51:19 +00:00
|
|
|
|
!= layoutlist_.end();
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-19 07:12:09 +00:00
|
|
|
|
|
2003-05-28 09:54:27 +00:00
|
|
|
|
LyXLayout_ptr const & LyXTextClass::operator[](string const & name) const
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(!name.empty());
|
2002-03-12 18:11:49 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
LayoutList::const_iterator cit =
|
2002-08-27 15:51:19 +00:00
|
|
|
|
find_if(layoutlist_.begin(),
|
|
|
|
|
layoutlist_.end(),
|
2004-01-31 15:30:24 +00:00
|
|
|
|
LayoutNamesEqual(name));
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
if (cit == layoutlist_.end()) {
|
2002-03-02 16:39:54 +00:00
|
|
|
|
lyxerr << "We failed to find the layout '" << name
|
|
|
|
|
<< "' in the layout list. You MUST investigate!"
|
|
|
|
|
<< endl;
|
2003-05-19 07:12:09 +00:00
|
|
|
|
for (LayoutList::const_iterator it = layoutlist_.begin();
|
|
|
|
|
it != layoutlist_.end(); ++it)
|
|
|
|
|
lyxerr << " " << it->get()->name() << endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
// we require the name to exist
|
2003-09-09 17:25:35 +00:00
|
|
|
|
BOOST_ASSERT(false);
|
2002-03-02 16:39:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
return (*cit);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-14 11:57:12 +00:00
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
bool LyXTextClass::delete_layout(string const & name)
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2002-03-02 16:39:54 +00:00
|
|
|
|
if (name == defaultLayoutName())
|
|
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
LayoutList::iterator it =
|
2002-08-27 15:51:19 +00:00
|
|
|
|
remove_if(layoutlist_.begin(), layoutlist_.end(),
|
2004-01-31 15:30:24 +00:00
|
|
|
|
LayoutNamesEqual(name));
|
2002-06-24 20:28:12 +00:00
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
LayoutList::iterator end = layoutlist_.end();
|
2001-12-28 13:26:54 +00:00
|
|
|
|
bool const ret = (it != end);
|
2002-08-27 15:51:19 +00:00
|
|
|
|
layoutlist_.erase(it, end);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Load textclass info if not loaded yet
|
2002-03-02 16:39:54 +00:00
|
|
|
|
bool LyXTextClass::load() const
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
2004-03-30 16:19:50 +00:00
|
|
|
|
if (loaded_)
|
2002-03-02 16:39:54 +00:00
|
|
|
|
return true;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
|
|
// Read style-file
|
|
|
|
|
string const real_file = LibFileSearch("layouts", name_, "layout");
|
2004-03-31 09:44:40 +00:00
|
|
|
|
loaded_ = const_cast<LyXTextClass*>(this)->Read(real_file) == 0;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
2004-03-31 09:44:40 +00:00
|
|
|
|
if (!loaded_) {
|
2001-12-28 13:26:54 +00:00
|
|
|
|
lyxerr << "Error reading `"
|
|
|
|
|
<< MakeDisplayPath(real_file)
|
|
|
|
|
<< "'\n(Check `" << name_
|
|
|
|
|
<< "')\nCheck your installation and "
|
|
|
|
|
"try Options/Reconfigure..." << endl;
|
|
|
|
|
}
|
2004-03-31 09:44:40 +00:00
|
|
|
|
|
2004-03-30 16:19:50 +00:00
|
|
|
|
return loaded_;
|
2002-03-02 16:39:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
FloatList & LyXTextClass::floats()
|
|
|
|
|
{
|
2002-09-11 07:39:55 +00:00
|
|
|
|
return *floatlist_.get();
|
2002-08-27 15:51:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FloatList const & LyXTextClass::floats() const
|
|
|
|
|
{
|
2002-09-11 07:39:55 +00:00
|
|
|
|
return *floatlist_.get();
|
2002-08-27 15:51:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
Counters & LyXTextClass::counters() const
|
|
|
|
|
{
|
|
|
|
|
return *ctrs_.get();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
CharStyles::iterator LyXTextClass::charstyle(string const & s) const
|
|
|
|
|
{
|
|
|
|
|
CharStyles::iterator cs = charstyles().begin();
|
|
|
|
|
CharStyles::iterator csend = charstyles().end();
|
|
|
|
|
for (; cs != csend; ++cs) {
|
|
|
|
|
if (cs->name == s)
|
|
|
|
|
return cs;
|
|
|
|
|
}
|
|
|
|
|
return csend;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
string const & LyXTextClass::defaultLayoutName() const
|
2002-03-02 16:39:54 +00:00
|
|
|
|
{
|
|
|
|
|
// This really should come from the actual layout... (Lgb)
|
|
|
|
|
return defaultlayout_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-24 20:28:12 +00:00
|
|
|
|
LyXLayout_ptr const & LyXTextClass::defaultLayout() const
|
2002-03-02 16:39:54 +00:00
|
|
|
|
{
|
|
|
|
|
return operator[](defaultLayoutName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::name() const
|
|
|
|
|
{
|
|
|
|
|
return name_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::latexname() const
|
|
|
|
|
{
|
|
|
|
|
const_cast<LyXTextClass*>(this)->load();
|
|
|
|
|
return latexname_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::description() const
|
|
|
|
|
{
|
|
|
|
|
return description_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::opt_fontsize() const
|
|
|
|
|
{
|
|
|
|
|
return opt_fontsize_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::opt_pagestyle() const
|
|
|
|
|
{
|
|
|
|
|
return opt_pagestyle_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::options() const
|
|
|
|
|
{
|
|
|
|
|
return options_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-27 16:57:12 +00:00
|
|
|
|
string const & LyXTextClass::class_header() const
|
|
|
|
|
{
|
|
|
|
|
return class_header_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
string const & LyXTextClass::pagestyle() const
|
|
|
|
|
{
|
|
|
|
|
return pagestyle_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::preamble() const
|
|
|
|
|
{
|
|
|
|
|
return preamble_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LyXTextClass::PageSides LyXTextClass::sides() const
|
|
|
|
|
{
|
|
|
|
|
return sides_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXTextClass::secnumdepth() const
|
|
|
|
|
{
|
|
|
|
|
return secnumdepth_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXTextClass::tocdepth() const
|
|
|
|
|
{
|
|
|
|
|
return tocdepth_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutputType LyXTextClass::outputType() const
|
|
|
|
|
{
|
|
|
|
|
return outputType_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool LyXTextClass::provides(LyXTextClass::Provides p) const
|
|
|
|
|
{
|
|
|
|
|
return provides_ & p;
|
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
|
|
|
|
|
unsigned int LyXTextClass::columns() const
|
|
|
|
|
{
|
|
|
|
|
return columns_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-13 17:49:09 +00:00
|
|
|
|
LYX_TITLE_LATEX_TYPES LyXTextClass::titletype() const
|
|
|
|
|
{
|
|
|
|
|
return titletype_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & LyXTextClass::titlename() const
|
|
|
|
|
{
|
|
|
|
|
return titlename_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
|
int LyXTextClass::size() const
|
|
|
|
|
{
|
2002-08-27 15:51:19 +00:00
|
|
|
|
return layoutlist_.size();
|
2001-12-28 13:26:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-05-12 10:16:04 +00:00
|
|
|
|
int LyXTextClass::min_toclevel() const
|
|
|
|
|
{
|
|
|
|
|
return min_toclevel_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int LyXTextClass::max_toclevel() const
|
|
|
|
|
{
|
|
|
|
|
return max_toclevel_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-24 11:59:09 +00:00
|
|
|
|
bool LyXTextClass::hasTocLevels() const
|
|
|
|
|
{
|
|
|
|
|
return min_toclevel_ != LyXLayout::NOT_IN_TOC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
ostream & operator<<(ostream & os, LyXTextClass::PageSides p)
|
2001-12-28 13:26:54 +00:00
|
|
|
|
{
|
|
|
|
|
switch (p) {
|
|
|
|
|
case LyXTextClass::OneSide:
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '1';
|
2001-12-28 13:26:54 +00:00
|
|
|
|
break;
|
|
|
|
|
case LyXTextClass::TwoSides:
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '2';
|
2001-12-28 13:26:54 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return os;
|
|
|
|
|
}
|