2003-08-22 09:44:59 +00:00
|
|
|
/**
|
2007-04-29 19:53:54 +00:00
|
|
|
* \file TextClass.cpp
|
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
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-22 09:44:59 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Angus Leeming
|
|
|
|
* \author John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pö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>
|
|
|
|
|
2007-04-29 19:53:54 +00:00
|
|
|
#include "TextClass.h"
|
2007-10-25 12:41:02 +00:00
|
|
|
|
2016-12-30 15:22:08 +00:00
|
|
|
#include "CiteEnginesList.h"
|
2007-04-26 04:41:58 +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"
|
2007-10-25 12:41:02 +00:00
|
|
|
#include "Layout.h"
|
2020-10-20 08:36:59 +00:00
|
|
|
#include "LayoutFile.h"
|
2009-02-11 23:22:10 +00:00
|
|
|
#include "ModuleList.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2007-07-11 13:39:08 +00:00
|
|
|
#include "frontends/alert.h"
|
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-12-17 16:04:46 +00:00
|
|
|
#include "support/FileName.h"
|
2001-12-28 13:26:54 +00:00
|
|
|
#include "support/filetools.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/gettext.h"
|
2024-04-27 22:24:46 +00:00
|
|
|
#include "support/Lexer.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/lstrings.h"
|
2006-06-30 13:54:01 +00:00
|
|
|
#include "support/os.h"
|
2014-06-09 11:05:50 +00:00
|
|
|
#include "support/TempFile.h"
|
2006-06-30 13:54:01 +00:00
|
|
|
|
2008-03-07 19:43:17 +00:00
|
|
|
#include <algorithm>
|
2008-03-24 12:31:07 +00:00
|
|
|
#include <fstream>
|
2005-10-21 16:11:36 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
2009-10-11 10:30:00 +00:00
|
|
|
#ifdef ERROR
|
|
|
|
#undef ERROR
|
|
|
|
#endif
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2007-10-28 18:51:54 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
// Keep the changes documented in the Customization manual.
|
2010-07-18 11:58:38 +00:00
|
|
|
//
|
|
|
|
// If you change this format, then you MUST also make sure that
|
2011-12-03 22:15:11 +00:00
|
|
|
// your changes do not invalidate the hardcoded layout file in
|
2010-07-18 11:58:38 +00:00
|
|
|
// LayoutFile.cpp. Additions will never do so, but syntax changes
|
|
|
|
// could. See LayoutFileList::addEmptyClass() and, especially, the
|
2011-12-03 22:15:11 +00:00
|
|
|
// definition of the layoutpost string.
|
2014-11-16 11:43:52 +00:00
|
|
|
// You should also run the development/tools/updatelayouts.py script,
|
|
|
|
// to update the format of all of our layout files.
|
2010-07-18 11:58:38 +00:00
|
|
|
//
|
2024-08-12 10:25:31 +00:00
|
|
|
int const LAYOUT_FORMAT = 107; // spitz: EscapeChars
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2016-07-23 14:29:40 +00:00
|
|
|
|
|
|
|
// Layout format for the current lyx file format. Controls which format is
|
|
|
|
// targeted by Local Layout > Convert. In master, equal to LAYOUT_FORMAT.
|
|
|
|
int const LYXFILE_LAYOUT_FORMAT = LAYOUT_FORMAT;
|
|
|
|
|
|
|
|
|
2004-01-31 15:30:24 +00:00
|
|
|
namespace {
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2016-07-23 14:29:40 +00:00
|
|
|
bool layout2layout(FileName const & filename, FileName const & tempfile,
|
|
|
|
int const format = LAYOUT_FORMAT)
|
2005-10-21 16:11:36 +00:00
|
|
|
{
|
2006-11-26 21:30:39 +00:00
|
|
|
FileName const script = libFileSearch("scripts", "layout2layout.py");
|
2005-10-21 16:11:36 +00:00
|
|
|
if (script.empty()) {
|
2008-04-03 21:36:57 +00:00
|
|
|
LYXERR0("Could not find layout conversion "
|
2016-07-23 14:29:40 +00:00
|
|
|
"script layout2layout.py.");
|
2005-10-21 16:11:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
ostringstream command;
|
2007-12-12 19:57:42 +00:00
|
|
|
command << os::python() << ' ' << quoteName(script.toFilesystemEncoding())
|
2016-07-23 14:29:40 +00:00
|
|
|
<< " -t " << format
|
|
|
|
<< ' ' << quoteName(filename.toFilesystemEncoding())
|
|
|
|
<< ' ' << quoteName(tempfile.toFilesystemEncoding());
|
2005-10-21 16:11:36 +00:00
|
|
|
string const command_str = command.str();
|
|
|
|
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::TCLASS, "Running `" << command_str << '\'');
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2008-04-03 21:36:57 +00:00
|
|
|
cmd_ret const ret = runCommand(command_str);
|
2020-09-10 21:22:55 +00:00
|
|
|
if (!ret.valid) {
|
2016-07-23 14:29:40 +00:00
|
|
|
if (format == LAYOUT_FORMAT)
|
|
|
|
LYXERR0("Conversion of layout with layout2layout.py has failed.");
|
2005-10-21 16:11:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-02-05 16:20:18 +00:00
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
string translateReadType(TextClass::ReadType rt)
|
2008-02-05 16:20:18 +00:00
|
|
|
{
|
|
|
|
switch (rt) {
|
|
|
|
case TextClass::BASECLASS:
|
|
|
|
return "textclass";
|
|
|
|
case TextClass::MERGE:
|
|
|
|
return "input file";
|
|
|
|
case TextClass::MODULE:
|
|
|
|
return "module file";
|
2016-12-30 15:22:08 +00:00
|
|
|
case TextClass::CITE_ENGINE:
|
|
|
|
return "cite engine";
|
2008-03-24 12:31:07 +00:00
|
|
|
case TextClass::VALIDATION:
|
|
|
|
return "validation";
|
2008-02-05 16:20:18 +00:00
|
|
|
}
|
2008-02-06 09:37:37 +00:00
|
|
|
// shutup warning
|
|
|
|
return string();
|
2008-02-05 16:20:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
// This string should not be translated here,
|
2008-04-15 15:32:46 +00:00
|
|
|
// because it is a layout identifier.
|
2015-04-17 13:58:14 +00:00
|
|
|
docstring const TextClass::plain_layout_ = from_ascii(N_("Plain Layout"));
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
|
|
|
|
|
2008-04-16 21:23:45 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// TextClass
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
TextClass::TextClass()
|
2015-09-12 21:11:35 +00:00
|
|
|
: loaded_(false), tex_class_avail_(false),
|
|
|
|
opt_enginetype_("authoryear|numerical"), opt_fontsize_("10|11|12"),
|
2019-08-07 14:44:11 +00:00
|
|
|
opt_pagesize_("default|a4|a5|b5|letter|legal|executive"),
|
2019-08-06 17:27:49 +00:00
|
|
|
opt_pagestyle_("empty|plain|headings|fancy"), fontsize_format_("$$spt"), pagesize_("default"),
|
2024-06-02 09:41:54 +00:00
|
|
|
pagesize_format_("$$spaper"), pagestyle_("default"), parskip_full_(""), parskip_half_(""),
|
|
|
|
tablestyle_("default"), docbookroot_("article"), docbookforceabstract_(false),
|
2019-08-07 14:44:11 +00:00
|
|
|
columns_(1), sides_(OneSide), secnumdepth_(3), tocdepth_(3), outputType_(LATEX),
|
|
|
|
outputFormat_("latex"), has_output_format_(false), defaultfont_(sane_font),
|
2015-09-12 21:11:35 +00:00
|
|
|
titletype_(TITLE_COMMAND_AFTER), titlename_("maketitle"),
|
2017-01-07 15:44:27 +00:00
|
|
|
min_toclevel_(0), max_toclevel_(0), maxcitenames_(2),
|
2020-07-08 11:34:45 +00:00
|
|
|
cite_full_author_list_(true), bibintoc_(false) {
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-09-29 02:07:08 +00:00
|
|
|
bool TextClass::readStyle(Lexer & lexrc, Layout & lay, ReadType rt) const
|
2001-12-28 13:26:54 +00:00
|
|
|
{
|
2007-11-15 20:04:51 +00:00
|
|
|
LYXERR(Debug::TCLASS, "Reading style " << to_utf8(lay.name()));
|
2020-09-29 02:07:08 +00:00
|
|
|
if (!lay.read(lexrc, *this, rt == VALIDATION)) {
|
2008-04-03 21:36:57 +00:00
|
|
|
LYXERR0("Error parsing style `" << to_utf8(lay.name()) << '\'');
|
2008-02-13 14:39:16 +00:00
|
|
|
return false;
|
2002-03-21 17:27:08 +00:00
|
|
|
}
|
2008-02-13 14:39:16 +00:00
|
|
|
// Resolve fonts
|
|
|
|
lay.resfont = lay.font;
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
lay.resfont.realize(defaultfont_);
|
2008-02-13 14:39:16 +00:00
|
|
|
lay.reslabelfont = lay.labelfont;
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
lay.reslabelfont.realize(defaultfont_);
|
2008-02-13 14:39:16 +00:00
|
|
|
return true; // no errors
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum TextClassTags {
|
|
|
|
TC_OUTPUTTYPE = 1,
|
2009-05-28 08:59:25 +00:00
|
|
|
TC_OUTPUTFORMAT,
|
2001-12-28 13:26:54 +00:00
|
|
|
TC_INPUT,
|
2021-01-26 07:42:39 +00:00
|
|
|
TC_INPUT_GLOBAL,
|
2001-12-28 13:26:54 +00:00
|
|
|
TC_STYLE,
|
2015-12-04 02:06:28 +00:00
|
|
|
TC_MODIFYSTYLE,
|
|
|
|
TC_PROVIDESTYLE,
|
2002-03-02 16:39:54 +00:00
|
|
|
TC_DEFAULTSTYLE,
|
2007-08-13 12:13:17 +00:00
|
|
|
TC_INSETLAYOUT,
|
2021-01-30 14:56:31 +00:00
|
|
|
TC_MODIFYINSETLAYOUT,
|
|
|
|
TC_PROVIDEINSETLAYOUT,
|
2013-02-09 19:31:26 +00:00
|
|
|
TC_NOINSETLAYOUT,
|
2001-12-28 13:26:54 +00:00
|
|
|
TC_NOSTYLE,
|
|
|
|
TC_COLUMNS,
|
|
|
|
TC_SIDES,
|
|
|
|
TC_PAGESTYLE,
|
2019-08-06 15:34:16 +00:00
|
|
|
TC_PAGESIZE,
|
2001-12-28 13:26:54 +00:00
|
|
|
TC_DEFAULTFONT,
|
|
|
|
TC_SECNUMDEPTH,
|
|
|
|
TC_TOCDEPTH,
|
|
|
|
TC_CLASSOPTIONS,
|
|
|
|
TC_PREAMBLE,
|
2009-06-05 17:26:30 +00:00
|
|
|
TC_HTMLPREAMBLE,
|
2011-12-06 22:38:46 +00:00
|
|
|
TC_HTMLSTYLES,
|
2007-04-06 09:02:23 +00:00
|
|
|
TC_PROVIDES,
|
2008-01-07 16:59:10 +00:00
|
|
|
TC_REQUIRES,
|
2013-05-23 13:25:40 +00:00
|
|
|
TC_PKGOPTS,
|
2001-12-28 13:26:54 +00:00
|
|
|
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,
|
2011-01-12 22:53:41 +00:00
|
|
|
TC_NOCOUNTER,
|
2009-08-12 14:50:01 +00:00
|
|
|
TC_IFCOUNTER,
|
2003-02-13 17:49:09 +00:00
|
|
|
TC_NOFLOAT,
|
|
|
|
TC_TITLELATEXNAME,
|
2005-10-21 16:11:36 +00:00
|
|
|
TC_TITLELATEXTYPE,
|
2008-03-24 13:11:16 +00:00
|
|
|
TC_FORMAT,
|
2008-07-25 15:51:27 +00:00
|
|
|
TC_ADDTOPREAMBLE,
|
2009-06-19 12:49:08 +00:00
|
|
|
TC_ADDTOHTMLPREAMBLE,
|
2011-12-06 22:38:46 +00:00
|
|
|
TC_ADDTOHTMLSTYLES,
|
2008-10-23 00:27:03 +00:00
|
|
|
TC_DEFAULTMODULE,
|
|
|
|
TC_PROVIDESMODULE,
|
2010-01-12 19:38:31 +00:00
|
|
|
TC_EXCLUDESMODULE,
|
2010-03-29 18:37:25 +00:00
|
|
|
TC_HTMLTOCSECTION,
|
2012-03-01 00:41:30 +00:00
|
|
|
TC_CITEENGINE,
|
2018-05-21 10:46:53 +00:00
|
|
|
TC_ADDTOCITEENGINE,
|
2012-03-01 00:41:30 +00:00
|
|
|
TC_CITEENGINETYPE,
|
|
|
|
TC_CITEFORMAT,
|
2016-12-31 18:44:32 +00:00
|
|
|
TC_CITEFRAMEWORK,
|
2017-01-07 15:44:27 +00:00
|
|
|
TC_MAXCITENAMES,
|
2012-03-01 00:41:30 +00:00
|
|
|
TC_DEFAULTBIBLIO,
|
2015-11-03 16:47:25 +00:00
|
|
|
TC_FULLAUTHORLIST,
|
2019-03-26 16:42:56 +00:00
|
|
|
TC_OUTLINERNAME,
|
2019-07-08 13:40:17 +00:00
|
|
|
TC_TABLESTYLE,
|
2020-06-08 21:27:49 +00:00
|
|
|
TC_BIBINTOC,
|
|
|
|
TC_DOCBOOKROOT,
|
|
|
|
TC_DOCBOOKFORCEABSTRACT
|
2001-12-28 13:26:54 +00:00
|
|
|
};
|
|
|
|
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2008-03-24 12:31:07 +00:00
|
|
|
namespace {
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
LexerKeyword textClassTags[] = {
|
2018-05-21 10:46:53 +00:00
|
|
|
{ "addtociteengine", TC_ADDTOCITEENGINE },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "addtohtmlpreamble", TC_ADDTOHTMLPREAMBLE },
|
|
|
|
{ "addtohtmlstyles", TC_ADDTOHTMLSTYLES },
|
|
|
|
{ "addtopreamble", TC_ADDTOPREAMBLE },
|
2019-07-08 13:40:17 +00:00
|
|
|
{ "bibintoc", TC_BIBINTOC },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "citeengine", TC_CITEENGINE },
|
|
|
|
{ "citeenginetype", TC_CITEENGINETYPE },
|
|
|
|
{ "citeformat", TC_CITEFORMAT },
|
2016-12-31 18:44:32 +00:00
|
|
|
{ "citeframework", TC_CITEFRAMEWORK },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "classoptions", TC_CLASSOPTIONS },
|
|
|
|
{ "columns", TC_COLUMNS },
|
|
|
|
{ "counter", TC_COUNTER },
|
|
|
|
{ "defaultbiblio", TC_DEFAULTBIBLIO },
|
|
|
|
{ "defaultfont", TC_DEFAULTFONT },
|
|
|
|
{ "defaultmodule", TC_DEFAULTMODULE },
|
|
|
|
{ "defaultstyle", TC_DEFAULTSTYLE },
|
2020-06-08 21:27:49 +00:00
|
|
|
{ "docbookforceabstract", TC_DOCBOOKFORCEABSTRACT },
|
|
|
|
{ "docbookroot", TC_DOCBOOKROOT },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "excludesmodule", TC_EXCLUDESMODULE },
|
|
|
|
{ "float", TC_FLOAT },
|
|
|
|
{ "format", TC_FORMAT },
|
|
|
|
{ "fullauthorlist", TC_FULLAUTHORLIST },
|
|
|
|
{ "htmlpreamble", TC_HTMLPREAMBLE },
|
|
|
|
{ "htmlstyles", TC_HTMLSTYLES },
|
|
|
|
{ "htmltocsection", TC_HTMLTOCSECTION },
|
|
|
|
{ "ifcounter", TC_IFCOUNTER },
|
|
|
|
{ "input", TC_INPUT },
|
2021-01-26 07:42:39 +00:00
|
|
|
{ "inputglobal", TC_INPUT_GLOBAL },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "insetlayout", TC_INSETLAYOUT },
|
|
|
|
{ "leftmargin", TC_LEFTMARGIN },
|
2017-01-07 15:44:27 +00:00
|
|
|
{ "maxcitenames", TC_MAXCITENAMES },
|
2021-01-30 14:56:31 +00:00
|
|
|
{ "modifyinsetlayout", TC_MODIFYINSETLAYOUT },
|
2015-12-04 02:06:28 +00:00
|
|
|
{ "modifystyle", TC_MODIFYSTYLE },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "nocounter", TC_NOCOUNTER },
|
|
|
|
{ "nofloat", TC_NOFLOAT },
|
2013-02-09 19:31:26 +00:00
|
|
|
{ "noinsetlayout", TC_NOINSETLAYOUT },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "nostyle", TC_NOSTYLE },
|
2015-11-03 16:47:25 +00:00
|
|
|
{ "outlinername", TC_OUTLINERNAME },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "outputformat", TC_OUTPUTFORMAT },
|
|
|
|
{ "outputtype", TC_OUTPUTTYPE },
|
2015-05-22 08:37:14 +00:00
|
|
|
{ "packageoptions", TC_PKGOPTS },
|
2019-08-06 15:34:16 +00:00
|
|
|
{ "pagesize", TC_PAGESIZE },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "pagestyle", TC_PAGESTYLE },
|
|
|
|
{ "preamble", TC_PREAMBLE },
|
2021-01-30 14:56:31 +00:00
|
|
|
{ "provideinsetlayout", TC_PROVIDEINSETLAYOUT },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "provides", TC_PROVIDES },
|
|
|
|
{ "providesmodule", TC_PROVIDESMODULE },
|
2015-12-04 02:06:28 +00:00
|
|
|
{ "providestyle", TC_PROVIDESTYLE },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "requires", TC_REQUIRES },
|
|
|
|
{ "rightmargin", TC_RIGHTMARGIN },
|
|
|
|
{ "secnumdepth", TC_SECNUMDEPTH },
|
|
|
|
{ "sides", TC_SIDES },
|
|
|
|
{ "style", TC_STYLE },
|
2019-03-26 16:42:56 +00:00
|
|
|
{ "tablestyle", TC_TABLESTYLE },
|
2012-10-27 13:45:27 +00:00
|
|
|
{ "titlelatexname", TC_TITLELATEXNAME },
|
|
|
|
{ "titlelatextype", TC_TITLELATEXTYPE },
|
|
|
|
{ "tocdepth", TC_TOCDEPTH }
|
|
|
|
};
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2008-03-24 12:31:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool TextClass::convertLayoutFormat(support::FileName const & filename, ReadType rt)
|
|
|
|
{
|
2010-07-18 11:52:12 +00:00
|
|
|
LYXERR(Debug::TCLASS, "Converting layout file to " << LAYOUT_FORMAT);
|
2014-06-09 11:05:50 +00:00
|
|
|
TempFile tmp("convertXXXXXX.layout");
|
|
|
|
FileName const tempfile = tmp.name();
|
2008-10-06 12:16:17 +00:00
|
|
|
bool success = layout2layout(filename, tempfile);
|
|
|
|
if (success)
|
2009-02-17 20:25:56 +00:00
|
|
|
success = readWithoutConv(tempfile, rt) == OK;
|
2008-10-06 12:16:17 +00:00
|
|
|
return success;
|
2008-03-24 12:31:07 +00:00
|
|
|
}
|
|
|
|
|
2009-02-17 20:25:56 +00:00
|
|
|
|
2011-05-08 00:54:17 +00:00
|
|
|
std::string TextClass::convert(std::string const & str)
|
|
|
|
{
|
2014-06-09 11:05:50 +00:00
|
|
|
TempFile tmp1("localXXXXXX.layout");
|
|
|
|
FileName const fn = tmp1.name();
|
2011-05-08 00:54:17 +00:00
|
|
|
ofstream os(fn.toFilesystemEncoding().c_str());
|
|
|
|
os << str;
|
|
|
|
os.close();
|
2014-06-09 11:05:50 +00:00
|
|
|
TempFile tmp2("convert_localXXXXXX.layout");
|
|
|
|
FileName const tempfile = tmp2.name();
|
2016-07-23 14:29:40 +00:00
|
|
|
bool success = layout2layout(fn, tempfile, LYXFILE_LAYOUT_FORMAT);
|
2011-05-08 00:54:17 +00:00
|
|
|
if (!success)
|
|
|
|
return "";
|
|
|
|
ifstream is(tempfile.toFilesystemEncoding().c_str());
|
|
|
|
string ret;
|
|
|
|
string tmp;
|
|
|
|
while (!is.eof()) {
|
|
|
|
getline(is, tmp);
|
|
|
|
ret += tmp + '\n';
|
|
|
|
}
|
|
|
|
is.close();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-17 20:25:56 +00:00
|
|
|
TextClass::ReturnValues TextClass::readWithoutConv(FileName const & filename, ReadType rt)
|
2008-03-24 12:31:07 +00:00
|
|
|
{
|
|
|
|
if (!filename.isReadableFile()) {
|
|
|
|
lyxerr << "Cannot read layout file `" << filename << "'."
|
|
|
|
<< endl;
|
2009-02-17 20:25:56 +00:00
|
|
|
return ERROR;
|
2008-03-24 12:31:07 +00:00
|
|
|
}
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2010-08-05 20:25:04 +00:00
|
|
|
LYXERR(Debug::TCLASS, "Reading " + translateReadType(rt) + ": " +
|
2010-04-21 01:19:09 +00:00
|
|
|
to_utf8(makeDisplayPath(filename.absFileName())));
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
// Define the plain layout used in table cells, ert, etc. Note that
|
|
|
|
// we do this before loading any layout file, so that classes can
|
Fix bug 4037 and related problems. The patch has been cleaned up a bit
from the one posted to the list.
The basic idea has two parts. First, we hard code an "empty layout"
(called PlainLayout, for want of a better name) in TextClass and read it
before doing anything else. It can therefore be customized by classes,
if they want---say, to make it left-aligned. Second, InsetText's are
divided into three types: (i) normal ones, that use the "default" layout
defined by the text class; (ii) highly restrictive ones, such as ERT and
(not quite an inset) table cells, which demand the empty layout; (iii)
middling ones, which default to an empty layout and use the empty layout
in place of the default. (This is so we don't get the same problem we
had with ERT in e.g. footnotes.) The type of inset is signaled by new
methods InsetText::forceEmptyLayout() and InsetText::useEmptyLayout().
(The latter might better be called: useEmptyLayoutInsteadOfDefault(),
but that's silly.) The old InsetText::forceDefaultParagraphs() has been
split into these, plus a new method InsetText::allowParagraphCustomization().
A lot of the changes just adapt to this change.
The other big change is in GuiToolbar: We want to show LyXDefault and
the "default" layout only when they're active.
There are a handful of places where I'm not entirely sure whether we
should be using forceEmptyLayout or !allowParagraphCustomization() or
both. The InsetCaption is one of these. These places, and some others,
are marked with FIXMEs, so I'd appreciate it if people would search
through the patch and let me know whether these need changing. If they
don't, the FIXMEs can be deleted.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22966 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-12 17:31:07 +00:00
|
|
|
// override features of this layout if they should choose to do so.
|
2008-08-01 21:03:45 +00:00
|
|
|
if (rt == BASECLASS && !hasLayout(plain_layout_))
|
2008-08-01 21:13:03 +00:00
|
|
|
layoutlist_.push_back(createBasicLayout(plain_layout_));
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lexrc(textClassTags);
|
2002-03-21 17:27:08 +00:00
|
|
|
lexrc.setFile(filename);
|
2008-03-24 12:31:07 +00:00
|
|
|
ReturnValues retval = read(lexrc, rt);
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2010-08-05 20:25:04 +00:00
|
|
|
LYXERR(Debug::TCLASS, "Finished reading " + translateReadType(rt) + ": " +
|
2010-04-21 01:19:09 +00:00
|
|
|
to_utf8(makeDisplayPath(filename.absFileName())));
|
2009-02-17 20:25:56 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TextClass::read(FileName const & filename, ReadType rt)
|
|
|
|
{
|
|
|
|
ReturnValues const retval = readWithoutConv(filename, rt);
|
|
|
|
if (retval != FORMAT_MISMATCH)
|
2008-03-24 12:31:07 +00:00
|
|
|
return retval == OK;
|
2009-02-17 20:25:56 +00:00
|
|
|
|
2008-03-24 12:31:07 +00:00
|
|
|
bool const worx = convertLayoutFormat(filename, rt);
|
2011-05-08 00:54:17 +00:00
|
|
|
if (!worx)
|
2011-12-03 22:15:11 +00:00
|
|
|
LYXERR0 ("Unable to convert " << filename <<
|
2010-07-18 11:52:12 +00:00
|
|
|
" to format " << LAYOUT_FORMAT);
|
2011-05-08 00:54:17 +00:00
|
|
|
return worx;
|
2008-03-24 12:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-08 00:54:17 +00:00
|
|
|
TextClass::ReturnValues TextClass::validate(std::string const & str)
|
2008-03-24 12:31:07 +00:00
|
|
|
{
|
|
|
|
TextClass tc;
|
|
|
|
return tc.read(str, VALIDATION);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-08 00:54:17 +00:00
|
|
|
TextClass::ReturnValues TextClass::read(std::string const & str, ReadType rt)
|
2008-03-24 12:31:07 +00:00
|
|
|
{
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lexrc(textClassTags);
|
2008-03-24 12:31:07 +00:00
|
|
|
istringstream is(str);
|
|
|
|
lexrc.setStream(is);
|
|
|
|
ReturnValues retval = read(lexrc, rt);
|
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
if (retval != FORMAT_MISMATCH)
|
2011-05-08 00:54:17 +00:00
|
|
|
return retval;
|
2008-03-24 12:31:07 +00:00
|
|
|
|
|
|
|
// write the layout string to a temporary file
|
2014-06-09 11:05:50 +00:00
|
|
|
TempFile tmp("TextClass_read");
|
|
|
|
FileName const tempfile = tmp.name();
|
2008-03-24 12:31:07 +00:00
|
|
|
ofstream os(tempfile.toFilesystemEncoding().c_str());
|
|
|
|
if (!os) {
|
2008-07-23 09:41:26 +00:00
|
|
|
LYXERR0("Unable to create temporary file");
|
2011-05-08 00:54:17 +00:00
|
|
|
return ERROR;
|
2008-03-24 12:31:07 +00:00
|
|
|
}
|
|
|
|
os << str;
|
|
|
|
os.close();
|
|
|
|
|
2016-07-23 14:29:40 +00:00
|
|
|
// now try to convert it to LAYOUT_FORMAT
|
|
|
|
if (!convertLayoutFormat(tempfile, rt)) {
|
2011-12-03 22:15:11 +00:00
|
|
|
LYXERR0("Unable to convert internal layout information to format "
|
2010-07-18 11:52:12 +00:00
|
|
|
<< LAYOUT_FORMAT);
|
2011-05-08 00:54:17 +00:00
|
|
|
return ERROR;
|
2008-03-24 12:31:07 +00:00
|
|
|
}
|
2016-07-23 14:29:40 +00:00
|
|
|
|
2011-05-08 00:54:17 +00:00
|
|
|
return OK_OLDFORMAT;
|
2008-03-24 12:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Reads a textclass structure from file.
|
2011-12-03 22:15:11 +00:00
|
|
|
TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
|
2008-03-24 12:31:07 +00:00
|
|
|
{
|
2010-04-18 20:37:07 +00:00
|
|
|
if (!lexrc.isOK())
|
|
|
|
return ERROR;
|
2005-10-21 16:11:36 +00:00
|
|
|
|
2017-07-13 17:03:06 +00:00
|
|
|
// The first usable line should be
|
|
|
|
// Format LAYOUT_FORMAT
|
|
|
|
if (lexrc.lex() != TC_FORMAT || !lexrc.next()
|
|
|
|
|| lexrc.getInteger() != LAYOUT_FORMAT)
|
|
|
|
return FORMAT_MISMATCH;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
// parsing
|
2017-07-13 17:03:06 +00:00
|
|
|
bool error = false;
|
2001-12-28 13:26:54 +00:00
|
|
|
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) {
|
2007-04-26 11:30:54 +00:00
|
|
|
case Lexer::LEX_FEOF:
|
2002-03-21 17:27:08 +00:00
|
|
|
continue;
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
case Lexer::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
|
|
|
|
2009-08-12 14:50:01 +00:00
|
|
|
// used below to track whether we are in an IfStyle or IfCounter tag.
|
2021-01-30 14:56:31 +00:00
|
|
|
bool modify = false;
|
|
|
|
bool provide = false;
|
2015-12-04 02:06:28 +00:00
|
|
|
bool ifcounter = false;
|
2021-01-26 07:42:39 +00:00
|
|
|
bool only_global = false;
|
2009-08-12 14:50:01 +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:
|
2017-07-13 17:03:06 +00:00
|
|
|
lexrc.next();
|
|
|
|
lexrc.printError("Duplicate Format directive");
|
2005-10-21 16:11:36 +00:00
|
|
|
break;
|
|
|
|
|
2009-05-28 08:59:25 +00:00
|
|
|
case TC_OUTPUTFORMAT:
|
2017-09-01 08:27:12 +00:00
|
|
|
if (lexrc.next()) {
|
2009-05-28 08:59:25 +00:00
|
|
|
outputFormat_ = lexrc.getString();
|
2017-09-01 08:27:12 +00:00
|
|
|
has_output_format_ = true;
|
|
|
|
}
|
2009-05-28 08:59:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TC_OUTPUTTYPE:
|
2001-12-28 13:26:54 +00:00
|
|
|
readOutputType(lexrc);
|
2009-05-28 08:59:25 +00:00
|
|
|
switch(outputType_) {
|
|
|
|
case LATEX:
|
|
|
|
outputFormat_ = "latex";
|
|
|
|
break;
|
|
|
|
case LITERATE:
|
|
|
|
outputFormat_ = "literate";
|
|
|
|
break;
|
|
|
|
}
|
2001-12-28 13:26:54 +00:00
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2021-01-26 07:42:39 +00:00
|
|
|
case TC_INPUT_GLOBAL:
|
|
|
|
only_global = true;
|
|
|
|
// fall through
|
2001-12-28 13:26:54 +00:00
|
|
|
case TC_INPUT: // Include file
|
2002-03-21 17:27:08 +00:00
|
|
|
if (lexrc.next()) {
|
Allow Input of local includes from local layout files
When including files, LyX always searches the user and the system
directory, in that order. This means that when using local layout
files broken down into multiple includes, the various includes should
be specified with a path relative to the user layouts directory
(typically ~/.lyx/layouts), making this very impractical.
This commit allows including local files by specifying their path
as explicitly relative to the main layout file position, i.e., by
specifying their path with either "./" or "../". If the main layout
is not loaded from a local file, the usual search order is used,
even if the path are explicitly relative. So, for system layouts,
both "Input ./name.inc" and "Input name.inc" are equivalent.
2017-03-01 08:19:18 +00:00
|
|
|
FileName tmp;
|
2006-10-04 16:22:38 +00:00
|
|
|
string const inc = lexrc.getString();
|
Allow Input of local includes from local layout files
When including files, LyX always searches the user and the system
directory, in that order. This means that when using local layout
files broken down into multiple includes, the various includes should
be specified with a path relative to the user layouts directory
(typically ~/.lyx/layouts), making this very impractical.
This commit allows including local files by specifying their path
as explicitly relative to the main layout file position, i.e., by
specifying their path with either "./" or "../". If the main layout
is not loaded from a local file, the usual search order is used,
even if the path are explicitly relative. So, for system layouts,
both "Input ./name.inc" and "Input name.inc" are equivalent.
2017-03-01 08:19:18 +00:00
|
|
|
if (!path().empty() && (prefixIs(inc, "./") ||
|
|
|
|
prefixIs(inc, "../")))
|
|
|
|
tmp = fileSearch(path(), inc, "layout");
|
2021-01-26 07:42:39 +00:00
|
|
|
else {
|
|
|
|
// InputGlobal only searches in the system and
|
|
|
|
// build directories. This allows to reuse and
|
|
|
|
// modify files in the user directory.
|
Allow Input of local includes from local layout files
When including files, LyX always searches the user and the system
directory, in that order. This means that when using local layout
files broken down into multiple includes, the various includes should
be specified with a path relative to the user layouts directory
(typically ~/.lyx/layouts), making this very impractical.
This commit allows including local files by specifying their path
as explicitly relative to the main layout file position, i.e., by
specifying their path with either "./" or "../". If the main layout
is not loaded from a local file, the usual search order is used,
even if the path are explicitly relative. So, for system layouts,
both "Input ./name.inc" and "Input name.inc" are equivalent.
2017-03-01 08:19:18 +00:00
|
|
|
tmp = libFileSearch("layouts", inc,
|
2021-01-26 07:42:39 +00:00
|
|
|
"layout", must_exist, only_global);
|
|
|
|
}
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2006-10-04 16:22:38 +00:00
|
|
|
if (tmp.empty()) {
|
2008-02-03 00:32:02 +00:00
|
|
|
lexrc.printError("Could not find input file: " + inc);
|
2006-10-04 16:22:38 +00:00
|
|
|
error = true;
|
2008-02-14 03:38:08 +00:00
|
|
|
} else if (!read(tmp, MERGE)) {
|
2010-04-21 01:19:09 +00:00
|
|
|
lexrc.printError("Error reading input file: " + tmp.absFileName());
|
2001-12-28 13:26:54 +00:00
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2002-03-02 16:39:54 +00:00
|
|
|
case TC_DEFAULTSTYLE:
|
|
|
|
if (lexrc.next()) {
|
2007-07-11 13:39:08 +00:00
|
|
|
docstring const name = from_utf8(subst(lexrc.getString(),
|
|
|
|
'_', ' '));
|
2002-03-02 16:39:54 +00:00
|
|
|
defaultlayout_ = name;
|
|
|
|
}
|
|
|
|
break;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2015-12-04 02:06:28 +00:00
|
|
|
case TC_MODIFYSTYLE:
|
2021-01-30 14:56:31 +00:00
|
|
|
modify = true;
|
2015-12-04 02:06:28 +00:00
|
|
|
// fall through
|
|
|
|
case TC_PROVIDESTYLE:
|
|
|
|
// if modifystyle is true, then we got here by falling through
|
|
|
|
// so we are not in an ProvideStyle block
|
2021-01-30 14:56:31 +00:00
|
|
|
if (!modify)
|
|
|
|
provide = true;
|
2015-12-04 02:06:28 +00:00
|
|
|
// fall through
|
2008-12-16 16:01:32 +00:00
|
|
|
case TC_STYLE: {
|
|
|
|
if (!lexrc.next()) {
|
2001-12-28 13:26:54 +00:00
|
|
|
lexrc.printError("No name given for style: `$$Token'.");
|
|
|
|
error = true;
|
2008-12-16 16:01:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
docstring const name = from_utf8(subst(lexrc.getString(),
|
|
|
|
'_', ' '));
|
|
|
|
if (name.empty()) {
|
|
|
|
string s = "Could not read name for style: `$$Token' "
|
|
|
|
+ lexrc.getString() + " is probably not valid UTF-8!";
|
2010-04-18 21:06:38 +00:00
|
|
|
lexrc.printError(s);
|
2008-12-16 16:01:32 +00:00
|
|
|
Layout lay;
|
|
|
|
// Since we couldn't read the name, we just scan the rest
|
|
|
|
// of the style and discard it.
|
2020-09-29 02:07:08 +00:00
|
|
|
error = !readStyle(lexrc, lay, rt);
|
2015-12-04 02:06:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2015-12-04 02:06:28 +00:00
|
|
|
bool const have_layout = hasLayout(name);
|
2017-07-03 17:53:14 +00:00
|
|
|
|
2015-12-04 02:06:28 +00:00
|
|
|
// If the layout already exists, then we want to add it to
|
|
|
|
// the existing layout, as long as we are not in an ProvideStyle
|
|
|
|
// block.
|
2021-01-30 14:56:31 +00:00
|
|
|
if (have_layout && !provide) {
|
2008-12-16 16:01:32 +00:00
|
|
|
Layout & lay = operator[](name);
|
2020-09-29 02:07:08 +00:00
|
|
|
error = !readStyle(lexrc, lay, rt);
|
2015-12-04 02:06:28 +00:00
|
|
|
}
|
|
|
|
// If the layout does not exist, then we want to create a new
|
|
|
|
// one, but not if we are in a ModifyStyle block.
|
2021-01-30 14:56:31 +00:00
|
|
|
else if (!have_layout && !modify) {
|
2008-12-16 16:01:32 +00:00
|
|
|
Layout layout;
|
|
|
|
layout.setName(name);
|
2020-09-29 02:07:08 +00:00
|
|
|
error = !readStyle(lexrc, layout, rt);
|
2008-12-16 16:01:32 +00:00
|
|
|
if (!error)
|
|
|
|
layoutlist_.push_back(layout);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2015-12-04 02:06:28 +00:00
|
|
|
// There are two ways to get here:
|
|
|
|
// (i) The layout exists but we are in an ProvideStyle block
|
|
|
|
// (ii) The layout doesn't exist, but we are in an ModifyStyle
|
|
|
|
// block.
|
|
|
|
// Either way, we just scan the rest and discard it
|
2009-08-12 14:50:01 +00:00
|
|
|
else {
|
|
|
|
Layout lay;
|
2017-03-28 08:52:59 +00:00
|
|
|
// signal to coverity that we do not care about the result
|
2020-09-29 02:07:08 +00:00
|
|
|
(void)readStyle(lexrc, lay, rt);
|
2009-08-12 14:50:01 +00:00
|
|
|
}
|
2001-12-28 13:26:54 +00:00
|
|
|
break;
|
2008-12-16 16:01:32 +00:00
|
|
|
}
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
case TC_NOSTYLE:
|
|
|
|
if (lexrc.next()) {
|
2007-07-11 13:39:08 +00:00
|
|
|
docstring const style = from_utf8(subst(lexrc.getString(),
|
|
|
|
'_', ' '));
|
2007-11-04 09:51:26 +00:00
|
|
|
if (!deleteLayout(style))
|
2002-11-27 10:30:28 +00:00
|
|
|
lyxerr << "Cannot delete style `"
|
2007-07-11 13:39:08 +00:00
|
|
|
<< to_utf8(style) << '\'' << endl;
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-02-09 19:31:26 +00:00
|
|
|
case TC_NOINSETLAYOUT:
|
|
|
|
if (lexrc.next()) {
|
|
|
|
docstring const style = from_utf8(subst(lexrc.getString(),
|
|
|
|
'_', ' '));
|
|
|
|
if (!deleteInsetLayout(style))
|
|
|
|
LYXERR0("Style `" << style << "' cannot be removed\n"
|
|
|
|
"because it was not found!");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
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
|
|
|
|
2019-08-06 15:34:16 +00:00
|
|
|
case TC_PAGESIZE:
|
|
|
|
lexrc.next();
|
|
|
|
pagesize_ = rtrim(lexrc.getString());
|
|
|
|
break;
|
|
|
|
|
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:
|
2007-11-01 09:57:38 +00:00
|
|
|
defaultfont_ = lyxRead(lexrc);
|
2001-12-28 13:26:54 +00:00
|
|
|
if (!defaultfont_.resolved()) {
|
|
|
|
lexrc.printError("Warning: defaultfont should "
|
|
|
|
"be fully instantiated!");
|
2007-10-28 18:51:54 +00:00
|
|
|
defaultfont_.realize(sane_font);
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TC_SECNUMDEPTH:
|
|
|
|
lexrc.next();
|
|
|
|
secnumdepth_ = lexrc.getInteger();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TC_TOCDEPTH:
|
|
|
|
lexrc.next();
|
|
|
|
tocdepth_ = lexrc.getInteger();
|
|
|
|
break;
|
|
|
|
|
2008-02-14 03:38:08 +00:00
|
|
|
// First step to support options
|
2002-03-21 17:27:08 +00:00
|
|
|
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:
|
2016-09-25 10:37:40 +00:00
|
|
|
preamble_ = lexrc.getLongString(from_ascii("EndPreamble"));
|
2001-12-28 13:26:54 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-05 17:26:30 +00:00
|
|
|
case TC_HTMLPREAMBLE:
|
2016-09-25 10:37:40 +00:00
|
|
|
htmlpreamble_ = lexrc.getLongString(from_ascii("EndPreamble"));
|
2009-06-05 17:26:30 +00:00
|
|
|
break;
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2011-12-06 22:38:46 +00:00
|
|
|
case TC_HTMLSTYLES:
|
2016-09-25 10:37:40 +00:00
|
|
|
htmlstyles_ = lexrc.getLongString(from_ascii("EndStyles"));
|
2011-12-06 22:38:46 +00:00
|
|
|
break;
|
|
|
|
|
2010-01-12 19:38:31 +00:00
|
|
|
case TC_HTMLTOCSECTION:
|
|
|
|
html_toc_section_ = from_utf8(trim(lexrc.getString()));
|
|
|
|
break;
|
2009-06-05 17:26:30 +00:00
|
|
|
|
2008-03-24 13:11:16 +00:00
|
|
|
case TC_ADDTOPREAMBLE:
|
2016-09-25 10:37:40 +00:00
|
|
|
preamble_ += lexrc.getLongString(from_ascii("EndPreamble"));
|
2008-03-24 13:11:16 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-19 12:49:08 +00:00
|
|
|
case TC_ADDTOHTMLPREAMBLE:
|
2016-09-25 10:37:40 +00:00
|
|
|
htmlpreamble_ += lexrc.getLongString(from_ascii("EndPreamble"));
|
2009-06-19 12:49:08 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-06 22:38:46 +00:00
|
|
|
case TC_ADDTOHTMLSTYLES:
|
2016-09-25 10:37:40 +00:00
|
|
|
htmlstyles_ += lexrc.getLongString(from_ascii("EndStyles"));
|
2011-12-06 22:38:46 +00:00
|
|
|
break;
|
|
|
|
|
2007-04-06 09:02:23 +00:00
|
|
|
case TC_PROVIDES: {
|
|
|
|
lexrc.next();
|
|
|
|
string const feature = lexrc.getString();
|
|
|
|
lexrc.next();
|
|
|
|
if (lexrc.getInteger())
|
|
|
|
provides_.insert(feature);
|
|
|
|
else
|
|
|
|
provides_.erase(feature);
|
2001-12-28 13:26:54 +00:00
|
|
|
break;
|
2007-04-06 09:02:23 +00:00
|
|
|
}
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2008-01-07 16:59:10 +00:00
|
|
|
case TC_REQUIRES: {
|
|
|
|
lexrc.eatLine();
|
2011-12-03 22:15:11 +00:00
|
|
|
vector<string> const req
|
2008-02-01 15:12:04 +00:00
|
|
|
= getVectorFromString(lexrc.getString());
|
2020-05-04 18:05:44 +00:00
|
|
|
required_.insert(req.begin(), req.end());
|
2008-01-07 16:59:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-05-23 13:39:16 +00:00
|
|
|
|
2013-05-23 13:25:40 +00:00
|
|
|
case TC_PKGOPTS : {
|
|
|
|
lexrc.next();
|
|
|
|
string const pkg = lexrc.getString();
|
2022-05-19 08:31:37 +00:00
|
|
|
lexrc.eatLine();
|
2013-05-23 13:25:40 +00:00
|
|
|
string const options = lexrc.getString();
|
2024-06-06 04:58:33 +00:00
|
|
|
package_options_[pkg] = trim(options, "\"");
|
2013-05-23 13:25:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-01-07 16:59:10 +00:00
|
|
|
|
2008-10-23 00:27:03 +00:00
|
|
|
case TC_DEFAULTMODULE: {
|
2008-07-25 15:51:27 +00:00
|
|
|
lexrc.next();
|
|
|
|
string const module = lexrc.getString();
|
2008-10-23 00:27:03 +00:00
|
|
|
if (find(default_modules_.begin(), default_modules_.end(), module) == default_modules_.end())
|
|
|
|
default_modules_.push_back(module);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TC_PROVIDESMODULE: {
|
|
|
|
lexrc.next();
|
|
|
|
string const module = lexrc.getString();
|
|
|
|
if (find(provided_modules_.begin(), provided_modules_.end(), module) == provided_modules_.end())
|
|
|
|
provided_modules_.push_back(module);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case TC_EXCLUDESMODULE: {
|
|
|
|
lexrc.next();
|
|
|
|
string const module = lexrc.getString();
|
|
|
|
// modules already have their own way to exclude other modules
|
|
|
|
if (rt == MODULE) {
|
|
|
|
LYXERR0("ExcludesModule tag cannot be used in a module!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (find(excluded_modules_.begin(), excluded_modules_.end(), module) == excluded_modules_.end())
|
|
|
|
excluded_modules_.push_back(module);
|
2008-07-25 15:51:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
case TC_LEFTMARGIN: // left margin type
|
2002-03-21 17:27:08 +00:00
|
|
|
if (lexrc.next())
|
2007-08-18 13:21:12 +00:00
|
|
|
leftmargin_ = lexrc.getDocString();
|
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())
|
2007-08-18 13:21:12 +00:00
|
|
|
rightmargin_ = lexrc.getDocString();
|
2001-12-28 13:26:54 +00:00
|
|
|
break;
|
2008-02-14 03:38:08 +00:00
|
|
|
|
2021-01-30 14:56:31 +00:00
|
|
|
case TC_MODIFYINSETLAYOUT:
|
|
|
|
modify = true;
|
|
|
|
// fall through
|
|
|
|
case TC_PROVIDEINSETLAYOUT:
|
|
|
|
// if modifyinsetlayout is true, then we got here by falling through
|
|
|
|
// so we are not in an ProvideInsetLayout block
|
|
|
|
if (!modify)
|
|
|
|
provide = true;
|
|
|
|
// fall through
|
2008-12-16 16:11:15 +00:00
|
|
|
case TC_INSETLAYOUT: {
|
|
|
|
if (!lexrc.next()) {
|
|
|
|
lexrc.printError("No name given for InsetLayout: `$$Token'.");
|
|
|
|
error = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
docstring const name = subst(lexrc.getDocString(), '_', ' ');
|
2020-02-27 03:18:58 +00:00
|
|
|
bool const validating = (rt == VALIDATION);
|
2021-01-30 14:56:31 +00:00
|
|
|
bool const have_layout = name.empty() ? false : hasInsetLayout(name);
|
2008-12-16 16:11:15 +00:00
|
|
|
if (name.empty()) {
|
|
|
|
string s = "Could not read name for InsetLayout: `$$Token' "
|
|
|
|
+ lexrc.getString() + " is probably not valid UTF-8!";
|
2010-04-18 21:06:38 +00:00
|
|
|
lexrc.printError(s);
|
2008-02-22 03:27:42 +00:00
|
|
|
InsetLayout il;
|
2008-12-16 16:11:15 +00:00
|
|
|
// Since we couldn't read the name, we just scan the rest
|
|
|
|
// of the style and discard it.
|
|
|
|
il.read(lexrc, *this);
|
2020-02-27 03:18:58 +00:00
|
|
|
// Let's try to continue rather than abort, unless we're validating
|
|
|
|
// in which case we want to report the error
|
|
|
|
if (validating)
|
|
|
|
error = true;
|
2021-01-30 14:56:31 +00:00
|
|
|
} else if (have_layout && !provide) {
|
2008-12-16 16:11:15 +00:00
|
|
|
InsetLayout & il = insetlayoutlist_[name];
|
2020-02-27 03:18:58 +00:00
|
|
|
error = !il.read(lexrc, *this, validating);
|
2021-01-30 14:56:31 +00:00
|
|
|
} else if (!modify && !have_layout) {
|
2010-01-14 23:45:53 +00:00
|
|
|
InsetLayout il;
|
|
|
|
il.setName(name);
|
2020-02-27 03:18:58 +00:00
|
|
|
error = !il.read(lexrc, *this, validating);
|
2008-12-16 16:11:15 +00:00
|
|
|
if (!error)
|
|
|
|
insetlayoutlist_[name] = il;
|
2021-01-30 14:56:31 +00:00
|
|
|
} else {
|
|
|
|
InsetLayout il;
|
|
|
|
// We just scan the rest of the style and discard it.
|
|
|
|
il.read(lexrc, *this);
|
2007-08-13 12:13:17 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-12-16 16:11:15 +00:00
|
|
|
}
|
2008-02-14 03:38:08 +00:00
|
|
|
|
2002-09-04 06:52:26 +00:00
|
|
|
case TC_FLOAT:
|
2010-04-18 22:21:21 +00:00
|
|
|
error = !readFloat(lexrc);
|
2002-09-04 06:52:26 +00:00
|
|
|
break;
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
case TC_CITEENGINE:
|
2018-05-21 10:46:53 +00:00
|
|
|
error = !readCiteEngine(lexrc, rt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TC_ADDTOCITEENGINE:
|
|
|
|
error = !readCiteEngine(lexrc, rt, true);
|
2012-03-01 00:41:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TC_CITEENGINETYPE:
|
|
|
|
if (lexrc.next())
|
|
|
|
opt_enginetype_ = rtrim(lexrc.getString());
|
|
|
|
break;
|
|
|
|
|
2010-03-29 18:37:25 +00:00
|
|
|
case TC_CITEFORMAT:
|
2018-05-21 10:46:53 +00:00
|
|
|
error = !readCiteFormat(lexrc, rt);
|
2012-03-01 00:41:30 +00:00
|
|
|
break;
|
|
|
|
|
2016-12-31 18:44:32 +00:00
|
|
|
case TC_CITEFRAMEWORK:
|
|
|
|
lexrc.next();
|
|
|
|
citeframework_ = rtrim(lexrc.getString());
|
|
|
|
break;
|
|
|
|
|
2017-01-07 15:44:27 +00:00
|
|
|
case TC_MAXCITENAMES:
|
|
|
|
lexrc.next();
|
|
|
|
maxcitenames_ = size_t(lexrc.getInteger());
|
|
|
|
break;
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
case TC_DEFAULTBIBLIO:
|
2016-12-31 13:57:09 +00:00
|
|
|
if (lexrc.next()) {
|
|
|
|
vector<string> const dbs =
|
|
|
|
getVectorFromString(rtrim(lexrc.getString()), "|");
|
2020-03-16 05:08:03 +00:00
|
|
|
for (auto const & dbase : dbs) {
|
|
|
|
if (!contains(dbase, ':')) {
|
2017-01-04 16:11:25 +00:00
|
|
|
vector<string> const enginetypes =
|
|
|
|
getVectorFromString(opt_enginetype_, "|");
|
2020-03-16 05:08:03 +00:00
|
|
|
for (string const & s: enginetypes)
|
|
|
|
cite_default_biblio_style_[s] = dbase;
|
2017-01-04 16:11:25 +00:00
|
|
|
} else {
|
2016-12-31 13:57:09 +00:00
|
|
|
string eng;
|
2020-03-16 05:08:03 +00:00
|
|
|
string const db = split(dbase, eng, ':');
|
2016-12-31 13:57:09 +00:00
|
|
|
cite_default_biblio_style_[eng] = db;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-03-01 00:41:30 +00:00
|
|
|
break;
|
|
|
|
|
2019-07-08 13:40:17 +00:00
|
|
|
case TC_BIBINTOC:
|
|
|
|
if (lexrc.next())
|
|
|
|
bibintoc_ = lexrc.getBool();
|
|
|
|
break;
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
case TC_FULLAUTHORLIST:
|
|
|
|
if (lexrc.next())
|
|
|
|
cite_full_author_list_ &= lexrc.getBool();
|
2010-03-29 18:37:25 +00:00
|
|
|
break;
|
2008-02-14 03:38:08 +00:00
|
|
|
|
2011-01-12 22:53:41 +00:00
|
|
|
case TC_NOCOUNTER:
|
|
|
|
if (lexrc.next()) {
|
|
|
|
docstring const cnt = lexrc.getDocString();
|
|
|
|
if (!counters_.remove(cnt))
|
|
|
|
LYXERR0("Unable to remove counter: " + to_utf8(cnt));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2009-08-12 14:50:01 +00:00
|
|
|
case TC_IFCOUNTER:
|
|
|
|
ifcounter = true;
|
2015-09-12 20:19:59 +00:00
|
|
|
// fall through
|
2002-09-06 14:48:01 +00:00
|
|
|
case TC_COUNTER:
|
2008-10-06 14:37:28 +00:00
|
|
|
if (lexrc.next()) {
|
|
|
|
docstring const name = lexrc.getDocString();
|
|
|
|
if (name.empty()) {
|
|
|
|
string s = "Could not read name for counter: `$$Token' "
|
|
|
|
+ lexrc.getString() + " is probably not valid UTF-8!";
|
|
|
|
lexrc.printError(s.c_str());
|
|
|
|
Counter c;
|
|
|
|
// Since we couldn't read the name, we just scan the rest
|
|
|
|
// and discard it.
|
|
|
|
c.read(lexrc);
|
|
|
|
} else
|
2009-08-12 14:50:01 +00:00
|
|
|
error = !counters_.read(lexrc, name, !ifcounter);
|
2008-10-06 14:37:28 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
lexrc.printError("No name given for style: `$$Token'.");
|
|
|
|
error = true;
|
|
|
|
}
|
2002-09-06 14:48:01 +00:00
|
|
|
break;
|
2008-02-14 03:38:08 +00:00
|
|
|
|
2003-02-13 17:49:09 +00:00
|
|
|
case TC_TITLELATEXTYPE:
|
|
|
|
readTitleType(lexrc);
|
|
|
|
break;
|
2008-02-14 03:38:08 +00:00
|
|
|
|
2003-02-13 17:49:09 +00:00
|
|
|
case TC_TITLELATEXNAME:
|
|
|
|
if (lexrc.next())
|
|
|
|
titlename_ = lexrc.getString();
|
|
|
|
break;
|
2008-02-14 03:38:08 +00:00
|
|
|
|
2002-09-11 07:39:55 +00:00
|
|
|
case TC_NOFLOAT:
|
|
|
|
if (lexrc.next()) {
|
|
|
|
string const nofloat = lexrc.getString();
|
2008-03-07 03:41:12 +00:00
|
|
|
floatlist_.erase(nofloat);
|
2002-09-11 07:39:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-11-03 16:47:25 +00:00
|
|
|
|
|
|
|
case TC_OUTLINERNAME:
|
|
|
|
error = !readOutlinerName(lexrc);
|
|
|
|
break;
|
2019-03-26 16:42:56 +00:00
|
|
|
|
2023-05-22 14:32:49 +00:00
|
|
|
case TC_TABLESTYLE:
|
2019-03-26 16:42:56 +00:00
|
|
|
lexrc.next();
|
|
|
|
tablestyle_ = rtrim(lexrc.getString());
|
|
|
|
break;
|
2020-06-08 21:27:49 +00:00
|
|
|
|
|
|
|
case TC_DOCBOOKROOT:
|
|
|
|
if (lexrc.next())
|
|
|
|
docbookroot_ = lexrc.getString();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TC_DOCBOOKFORCEABSTRACT:
|
|
|
|
if (lexrc.next())
|
|
|
|
docbookforceabstract_ = lexrc.getBool();
|
|
|
|
break;
|
2008-10-06 12:16:17 +00:00
|
|
|
} // end of switch
|
2005-10-21 16:11:36 +00:00
|
|
|
}
|
|
|
|
|
2010-04-18 20:42:04 +00:00
|
|
|
// at present, we abort if we encounter an error,
|
|
|
|
// so there is no point continuing.
|
|
|
|
if (error)
|
|
|
|
return ERROR;
|
2008-02-05 16:20:18 +00:00
|
|
|
|
2010-04-18 20:42:04 +00:00
|
|
|
if (rt != BASECLASS)
|
2015-09-12 16:14:28 +00:00
|
|
|
return OK;
|
2008-02-05 22:57:33 +00:00
|
|
|
|
|
|
|
if (defaultlayout_.empty()) {
|
2008-04-03 21:36:57 +00:00
|
|
|
LYXERR0("Error: Textclass '" << name_
|
|
|
|
<< "' is missing a defaultstyle.");
|
2010-04-18 20:37:07 +00:00
|
|
|
return ERROR;
|
2008-02-05 22:57:33 +00:00
|
|
|
}
|
2011-12-03 22:15:11 +00:00
|
|
|
|
|
|
|
// Try to erase "stdinsets" from the provides_ set.
|
2008-04-03 21:36:57 +00:00
|
|
|
// The
|
|
|
|
// Provides stdinsets 1
|
|
|
|
// declaration simply tells us that the standard insets have been
|
|
|
|
// defined. (It's found in stdinsets.inc but could also be used in
|
|
|
|
// user-defined files.) There isn't really any such package. So we
|
|
|
|
// might as well go ahead and erase it.
|
|
|
|
// If we do not succeed, then it was not there, which means that
|
|
|
|
// the textclass did not provide the definitions of the standard
|
|
|
|
// insets. So we need to try to load them.
|
2020-05-03 03:11:53 +00:00
|
|
|
size_type const erased = provides_.erase("stdinsets");
|
2008-02-05 22:57:33 +00:00
|
|
|
if (!erased) {
|
|
|
|
FileName tmp = libFileSearch("layouts", "stdinsets.inc");
|
|
|
|
|
|
|
|
if (tmp.empty()) {
|
2010-04-17 22:49:38 +00:00
|
|
|
frontend::Alert::warning(_("Missing File"),
|
2008-02-06 09:46:48 +00:00
|
|
|
_("Could not find stdinsets.inc! This may lead to data loss!"));
|
2008-02-05 22:57:33 +00:00
|
|
|
error = true;
|
2008-02-14 03:38:08 +00:00
|
|
|
} else if (!read(tmp, MERGE)) {
|
2010-04-17 22:49:38 +00:00
|
|
|
frontend::Alert::warning(_("Corrupt File"),
|
2008-02-14 03:38:08 +00:00
|
|
|
_("Could not read stdinsets.inc! This may lead to data loss!"));
|
2002-03-02 16:39:54 +00:00
|
|
|
error = true;
|
|
|
|
}
|
2008-02-05 22:57:33 +00:00
|
|
|
}
|
2005-05-12 10:16:04 +00:00
|
|
|
|
2008-02-05 22:57:33 +00:00
|
|
|
min_toclevel_ = Layout::NOT_IN_TOC;
|
|
|
|
max_toclevel_ = Layout::NOT_IN_TOC;
|
2020-03-16 05:08:03 +00:00
|
|
|
for (auto const & lay : *this) {
|
|
|
|
int const toclevel = lay.toclevel;
|
2008-02-05 22:57:33 +00:00
|
|
|
if (toclevel != Layout::NOT_IN_TOC) {
|
|
|
|
if (min_toclevel_ == Layout::NOT_IN_TOC)
|
|
|
|
min_toclevel_ = toclevel;
|
|
|
|
else
|
2008-02-23 16:45:38 +00:00
|
|
|
min_toclevel_ = min(min_toclevel_, toclevel);
|
|
|
|
max_toclevel_ = max(max_toclevel_, toclevel);
|
2005-05-12 10:16:04 +00:00
|
|
|
}
|
This is one of a series of patches that will merge the layout modules development in personal/branches/rgheck back into the tree.
Design goal: Allow the use of layout "modules", which are to LaTeX packages as layout files are to LaTeX document classes. Thus, one could have a module that defined certain character styles, environments, commands, or what have you, and include it in various documents, each of which uses a different document class, without having to modify the layout files themselves. For example, a theorems.module could be used with article.layout to provide support for theorem-type environments, without having to modify article.layout itself, and the same module could be used with book.layout, etc.
This patch adds the backend. The ModuleList class holds a list of the available modules, which are retrieved from lyxmodules.lst, itself generated by configure.py. There are two LFUNs available: modules-clear and module-add, which do the obvious thing; you can test by typing these into the minibuffer, along with the name of one of the available modules: URL (a CharStyle), Endnote (a Custom Inset), and---with the spaces---End To Foot (View>LaTeX and look at the user preamble), which are themselves in lib/layouts. There are some others, too, that allow theorems to be added to classes like article and book.
The GUI will come next.
Issues: (i) The configure.py script could be improved. It'd be nice, for example, if it tested for the presence of the LaTeX packages a particular module needs. But this would mean re-working the LaTeX script, and I don't know how to do that. Note that at present, the packages are ignored. This will change shortly. (ii) I've used std::string in LyXModule, following what seemed to be a precedent in TextClass. If some of these should be docstrings, please let me know, and I'll change them. (iii) There is at present no distinction between LaTeX and DocBook modules. Should there be? That is: Should there be modules that are available when the document class is a LaTeX class and others that are available only when it is DocBook? Or should there just be one set of modules? Each module can of course indicate for what it is suitable in its description.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19893 a592a061-630c-0410-9148-cb99ea01b6c8
2007-08-29 17:59:49 +00:00
|
|
|
}
|
2008-02-05 22:57:33 +00:00
|
|
|
LYXERR(Debug::TCLASS, "Minimum TocLevel is " << min_toclevel_
|
|
|
|
<< ", maximum is " << max_toclevel_);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
2008-03-24 12:31:07 +00:00
|
|
|
return (error ? ERROR : OK);
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 19:53:54 +00:00
|
|
|
void TextClass::readTitleType(Lexer & lexrc)
|
2003-02-13 17:49:09 +00:00
|
|
|
{
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword titleTypeTags[] = {
|
2003-02-13 17:49:09 +00:00
|
|
|
{ "commandafter", TITLE_COMMAND_AFTER },
|
2008-04-03 20:55:09 +00:00
|
|
|
{ "environment", TITLE_ENVIRONMENT }
|
2003-02-13 17:49:09 +00:00
|
|
|
};
|
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
PushPopHelper pph(lexrc, titleTypeTags);
|
2003-02-13 17:49:09 +00:00
|
|
|
|
|
|
|
int le = lexrc.lex();
|
|
|
|
switch (le) {
|
2007-04-26 11:30:54 +00:00
|
|
|
case Lexer::LEX_UNDEF:
|
2003-02-13 17:49:09 +00:00
|
|
|
lexrc.printError("Unknown output type `$$Token'");
|
2008-04-03 21:36:57 +00:00
|
|
|
break;
|
2003-02-13 17:49:09 +00:00
|
|
|
case TITLE_COMMAND_AFTER:
|
|
|
|
case TITLE_ENVIRONMENT:
|
2007-09-29 20:02:32 +00:00
|
|
|
titletype_ = static_cast<TitleLatexType>(le);
|
2003-02-13 17:49:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-04-03 21:36:57 +00:00
|
|
|
LYXERR0("Unhandled value " << le << " in TextClass::readTitleType.");
|
2003-02-13 17:49:09 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 19:53:54 +00:00
|
|
|
void TextClass::readOutputType(Lexer & lexrc)
|
2001-12-28 13:26:54 +00:00
|
|
|
{
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword outputTypeTags[] = {
|
2008-04-03 20:55:09 +00:00
|
|
|
{ "latex", LATEX },
|
2001-12-28 13:26:54 +00:00
|
|
|
{ "literate", LITERATE }
|
|
|
|
};
|
|
|
|
|
2008-04-03 20:55:09 +00:00
|
|
|
PushPopHelper pph(lexrc, outputTypeTags);
|
2001-12-28 13:26:54 +00:00
|
|
|
|
|
|
|
int le = lexrc.lex();
|
|
|
|
switch (le) {
|
2007-04-26 11:30:54 +00:00
|
|
|
case Lexer::LEX_UNDEF:
|
2001-12-28 13:26:54 +00:00
|
|
|
lexrc.printError("Unknown output type `$$Token'");
|
|
|
|
return;
|
|
|
|
case LATEX:
|
|
|
|
case LITERATE:
|
|
|
|
outputType_ = static_cast<OutputType>(le);
|
|
|
|
break;
|
|
|
|
default:
|
2008-04-03 21:36:57 +00:00
|
|
|
LYXERR0("Unhandled value " << le);
|
2001-12-28 13:26:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-29 19:53:54 +00:00
|
|
|
void TextClass::readClassOptions(Lexer & lexrc)
|
2001-12-28 13:26:54 +00:00
|
|
|
{
|
2008-04-03 20:55:09 +00:00
|
|
|
enum {
|
|
|
|
CO_FONTSIZE = 1,
|
2019-08-06 17:27:49 +00:00
|
|
|
CO_FONTSIZE_FORMAT,
|
2019-08-06 15:34:16 +00:00
|
|
|
CO_PAGESIZE,
|
2019-08-07 14:44:11 +00:00
|
|
|
CO_PAGESIZE_FORMAT,
|
2008-04-03 20:55:09 +00:00
|
|
|
CO_PAGESTYLE,
|
2024-06-02 09:41:54 +00:00
|
|
|
CO_PARSKIP_FULL,
|
|
|
|
CO_PARSKIP_HALF,
|
2008-04-03 20:55:09 +00:00
|
|
|
CO_OTHER,
|
|
|
|
CO_END
|
|
|
|
};
|
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword classOptionsTags[] = {
|
2008-04-03 20:55:09 +00:00
|
|
|
{"end", CO_END },
|
|
|
|
{"fontsize", CO_FONTSIZE },
|
2019-08-06 17:27:49 +00:00
|
|
|
{"fontsizeformat", CO_FONTSIZE_FORMAT },
|
2008-04-03 20:55:09 +00:00
|
|
|
{"other", CO_OTHER },
|
2019-08-06 15:34:16 +00:00
|
|
|
{"pagesize", CO_PAGESIZE },
|
2019-08-07 14:44:11 +00:00
|
|
|
{"pagesizeformat", CO_PAGESIZE_FORMAT },
|
2024-06-02 09:41:54 +00:00
|
|
|
{"pagestyle", CO_PAGESTYLE },
|
|
|
|
{"parskipfull", CO_PARSKIP_FULL },
|
|
|
|
{"parskiphalf", CO_PARSKIP_HALF }
|
2001-12-28 13:26:54 +00:00
|
|
|
};
|
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
lexrc.pushTable(classOptionsTags);
|
2001-12-28 13:26:54 +00:00
|
|
|
bool getout = false;
|
|
|
|
while (!getout && lexrc.isOK()) {
|
|
|
|
int le = lexrc.lex();
|
|
|
|
switch (le) {
|
2007-04-26 11:30:54 +00:00
|
|
|
case Lexer::LEX_UNDEF:
|
2001-12-28 13:26:54 +00:00
|
|
|
lexrc.printError("Unknown ClassOption tag `$$Token'");
|
2002-03-21 17:27:08 +00:00
|
|
|
continue;
|
2010-04-18 21:06:38 +00:00
|
|
|
default:
|
|
|
|
break;
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
2008-04-03 20:55:09 +00:00
|
|
|
switch (le) {
|
2001-12-28 13:26:54 +00:00
|
|
|
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;
|
2019-08-06 17:27:49 +00:00
|
|
|
case CO_FONTSIZE_FORMAT:
|
|
|
|
lexrc.next();
|
|
|
|
fontsize_format_ = rtrim(lexrc.getString());
|
|
|
|
break;
|
2019-08-06 15:34:16 +00:00
|
|
|
case CO_PAGESIZE:
|
|
|
|
lexrc.next();
|
|
|
|
opt_pagesize_ = rtrim(lexrc.getString());
|
|
|
|
break;
|
2019-08-07 14:44:11 +00:00
|
|
|
case CO_PAGESIZE_FORMAT:
|
|
|
|
lexrc.next();
|
|
|
|
pagesize_format_ = rtrim(lexrc.getString());
|
|
|
|
break;
|
2001-12-28 13:26:54 +00:00
|
|
|
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;
|
2024-06-02 09:41:54 +00:00
|
|
|
case CO_PARSKIP_FULL:
|
|
|
|
lexrc.next();
|
|
|
|
parskip_full_ = rtrim(lexrc.getString());
|
|
|
|
break;
|
|
|
|
case CO_PARSKIP_HALF:
|
|
|
|
lexrc.next();
|
|
|
|
parskip_half_ = rtrim(lexrc.getString());
|
|
|
|
break;
|
2001-12-28 13:26:54 +00:00
|
|
|
case CO_OTHER:
|
|
|
|
lexrc.next();
|
2010-04-01 21:34:22 +00:00
|
|
|
if (options_.empty())
|
|
|
|
options_ = lexrc.getString();
|
|
|
|
else
|
|
|
|
options_ += ',' + lexrc.getString();
|
2001-12-28 13:26:54 +00:00
|
|
|
break;
|
|
|
|
case CO_END:
|
|
|
|
getout = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lexrc.popTable();
|
|
|
|
}
|
|
|
|
|
2003-11-12 14:38:26 +00:00
|
|
|
|
2018-05-27 07:56:45 +00:00
|
|
|
vector<CitationStyle> const & TextClass::getCiteStyles(
|
2018-05-21 10:46:53 +00:00
|
|
|
CiteEngineType const & type) const
|
|
|
|
{
|
|
|
|
static vector<CitationStyle> empty;
|
|
|
|
map<CiteEngineType, vector<CitationStyle> >::const_iterator it = cite_styles_.find(type);
|
|
|
|
if (it == cite_styles_.end())
|
|
|
|
return empty;
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TextClass::readCiteEngine(Lexer & lexrc, ReadType rt, bool const add)
|
2012-03-01 00:41:30 +00:00
|
|
|
{
|
|
|
|
int const type = readCiteEngineType(lexrc);
|
2018-05-27 09:49:10 +00:00
|
|
|
bool authoryear = (type & ENGINE_TYPE_AUTHORYEAR);
|
|
|
|
bool numerical = (type & ENGINE_TYPE_NUMERICAL);
|
2024-07-07 13:14:05 +00:00
|
|
|
bool notes = (type & ENGINE_TYPE_NOTES);
|
2018-05-27 09:49:10 +00:00
|
|
|
bool defce = (type & ENGINE_TYPE_DEFAULT);
|
2018-05-21 10:46:53 +00:00
|
|
|
|
2018-05-27 09:49:10 +00:00
|
|
|
if (rt == CITE_ENGINE) {
|
2018-05-21 10:46:53 +00:00
|
|
|
// The cite engines are not supposed to overwrite
|
|
|
|
// CiteStyle defined by the class or a module.
|
2018-05-27 09:49:10 +00:00
|
|
|
if (authoryear)
|
|
|
|
authoryear = getCiteStyles(ENGINE_TYPE_AUTHORYEAR).empty();
|
|
|
|
if (numerical)
|
|
|
|
numerical = getCiteStyles(ENGINE_TYPE_NUMERICAL).empty();
|
2024-07-07 13:14:05 +00:00
|
|
|
if (notes)
|
|
|
|
numerical = getCiteStyles(ENGINE_TYPE_NOTES).empty();
|
2018-05-27 09:49:10 +00:00
|
|
|
if (defce)
|
|
|
|
defce = getCiteStyles(ENGINE_TYPE_DEFAULT).empty();
|
|
|
|
}
|
2018-05-21 10:46:53 +00:00
|
|
|
|
2018-05-27 09:49:10 +00:00
|
|
|
if (rt != CITE_ENGINE && !add) {
|
2018-05-21 10:46:53 +00:00
|
|
|
// Reset if we defined CiteStyle
|
|
|
|
// from the class or a module
|
2018-05-27 09:49:10 +00:00
|
|
|
if (authoryear)
|
|
|
|
cite_styles_[ENGINE_TYPE_AUTHORYEAR].clear();
|
|
|
|
if (numerical)
|
|
|
|
cite_styles_[ENGINE_TYPE_NUMERICAL].clear();
|
2024-07-07 13:14:05 +00:00
|
|
|
if (notes)
|
|
|
|
cite_styles_[ENGINE_TYPE_NOTES].clear();
|
2018-05-27 09:49:10 +00:00
|
|
|
if (defce)
|
|
|
|
cite_styles_[ENGINE_TYPE_DEFAULT].clear();
|
|
|
|
}
|
2018-05-21 10:46:53 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
string def;
|
|
|
|
bool getout = false;
|
|
|
|
while (!getout && lexrc.isOK()) {
|
|
|
|
lexrc.eatLine();
|
|
|
|
def = lexrc.getString();
|
|
|
|
def = subst(def, " ", "");
|
|
|
|
def = subst(def, "\t", "");
|
|
|
|
if (compare_ascii_no_case(def, "end") == 0) {
|
|
|
|
getout = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CitationStyle cs;
|
|
|
|
char ichar = def[0];
|
|
|
|
if (ichar == '#')
|
|
|
|
continue;
|
|
|
|
|
2017-01-03 12:11:11 +00:00
|
|
|
/** For portability reasons (between different
|
|
|
|
* cite engines such as natbib and biblatex),
|
|
|
|
* we distinguish between:
|
2024-07-10 14:58:34 +00:00
|
|
|
* 1. The style that features this command
|
|
|
|
* 2. The LyX name as output in the LyX file
|
|
|
|
* 3. Possible aliases that might fall back to
|
2017-01-03 12:11:11 +00:00
|
|
|
* the given LyX name in the current engine
|
2024-07-10 14:58:34 +00:00
|
|
|
* 4. The actual LaTeX command that is output
|
|
|
|
* (1), (3) and (4) are optional.
|
2017-01-03 16:25:41 +00:00
|
|
|
* Also, the GUI string for the starred version can
|
|
|
|
* be changed
|
2017-01-03 12:11:11 +00:00
|
|
|
* The syntax is:
|
2024-07-10 14:58:34 +00:00
|
|
|
* style@LyXName|alias,nextalias*<!stardesc!stardesctooltip>[][]=latexcmd
|
2017-01-03 12:11:11 +00:00
|
|
|
*/
|
|
|
|
enum ScanMode {
|
|
|
|
LyXName,
|
|
|
|
Alias,
|
2017-01-03 16:25:41 +00:00
|
|
|
LaTeXCmd,
|
|
|
|
StarDesc
|
2017-01-03 12:11:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ScanMode mode = LyXName;
|
2017-01-03 16:25:41 +00:00
|
|
|
ScanMode oldmode = LyXName;
|
2017-01-03 12:11:11 +00:00
|
|
|
string lyx_cmd;
|
|
|
|
string alias;
|
|
|
|
string latex_cmd;
|
2017-01-03 16:25:41 +00:00
|
|
|
string stardesc;
|
2024-07-10 14:58:34 +00:00
|
|
|
string style;
|
2012-03-01 00:41:30 +00:00
|
|
|
size_t const n = def.size();
|
|
|
|
for (size_t i = 0; i != n; ++i) {
|
|
|
|
ichar = def[i];
|
2017-01-03 12:11:11 +00:00
|
|
|
if (ichar == '|')
|
|
|
|
mode = Alias;
|
|
|
|
else if (ichar == '=')
|
|
|
|
mode = LaTeXCmd;
|
2017-01-03 16:25:41 +00:00
|
|
|
else if (ichar == '<') {
|
|
|
|
oldmode = mode;
|
|
|
|
mode = StarDesc;
|
|
|
|
} else if (ichar == '>')
|
|
|
|
mode = oldmode;
|
2017-01-03 12:11:11 +00:00
|
|
|
else if (mode == LaTeXCmd)
|
|
|
|
latex_cmd += ichar;
|
2017-01-03 16:25:41 +00:00
|
|
|
else if (mode == StarDesc)
|
|
|
|
stardesc += ichar;
|
Support for "qualified citation lists"
These are biblatex-specific multicite commands that allow for multiple
pre- and postnotes, as in:
\cites(pre)(post)[pre1][post1]{key1}[pre2][post2]{key2}...
with an optional general pre- and postnote, which applies to the whole
list (like [][] in normal cite commands) and an optional pre- and
postnotes for each item, so that pagination can actually be specified in
multi-cite references, as in:
(cf. Miller 2015, 2; furthermore Smith 2013, 23-23; Jenkins 2012, 103,
also refer to chapter 6 in this book)
See the biblatex manual, sec. 3.8.3., for details.
File format change.
2017-01-21 13:25:17 +00:00
|
|
|
else if (ichar == '$')
|
|
|
|
cs.hasQualifiedList = true;
|
2017-01-03 12:11:11 +00:00
|
|
|
else if (ichar == '*')
|
2017-01-03 16:25:41 +00:00
|
|
|
cs.hasStarredVersion = true;
|
2012-03-01 00:41:30 +00:00
|
|
|
else if (ichar == '[' && cs.textAfter)
|
|
|
|
cs.textBefore = true;
|
|
|
|
else if (ichar == '[')
|
|
|
|
cs.textAfter = true;
|
2017-01-03 12:11:11 +00:00
|
|
|
else if (ichar != ']') {
|
|
|
|
if (mode == Alias)
|
|
|
|
alias += ichar;
|
|
|
|
else
|
|
|
|
lyx_cmd += ichar;
|
|
|
|
}
|
|
|
|
}
|
2024-07-10 14:58:34 +00:00
|
|
|
// split off style prefix if there
|
|
|
|
if (contains(lyx_cmd, '@')) {
|
|
|
|
lyx_cmd = split(lyx_cmd, style, '@');
|
2024-07-13 15:20:29 +00:00
|
|
|
// a '!' prefix indicates nostyle
|
|
|
|
if (prefixIs(style, "!")) {
|
|
|
|
style = style.substr(1);
|
|
|
|
cs.nostyles = getVectorFromString(style);
|
|
|
|
} else
|
|
|
|
cs.styles = getVectorFromString(style);
|
2024-07-10 14:58:34 +00:00
|
|
|
}
|
2024-07-13 15:16:34 +00:00
|
|
|
char fchar = lyx_cmd[0];
|
|
|
|
if (isUpperCase(fchar)) {
|
|
|
|
cs.forceUpperCase = true;
|
|
|
|
lyx_cmd[0] = lowercase(fchar);
|
|
|
|
}
|
2017-01-03 12:11:11 +00:00
|
|
|
cs.name = lyx_cmd;
|
|
|
|
cs.cmd = latex_cmd.empty() ? lyx_cmd : latex_cmd;
|
|
|
|
if (!alias.empty()) {
|
|
|
|
vector<string> const aliases = getVectorFromString(alias);
|
2020-03-16 05:08:03 +00:00
|
|
|
for (string const & s: aliases)
|
2017-01-03 12:11:11 +00:00
|
|
|
cite_command_aliases_[s] = lyx_cmd;
|
2012-03-01 00:41:30 +00:00
|
|
|
}
|
2017-01-03 16:25:41 +00:00
|
|
|
vector<string> const stardescs = getVectorFromString(stardesc, "!");
|
2019-04-19 07:03:47 +00:00
|
|
|
int size = int(stardesc.size());
|
2017-01-03 16:25:41 +00:00
|
|
|
if (size > 0)
|
|
|
|
cs.stardesc = stardescs[0];
|
|
|
|
if (size > 1)
|
|
|
|
cs.startooltip = stardescs[1];
|
2018-05-27 09:49:10 +00:00
|
|
|
if (add) {
|
|
|
|
if (authoryear)
|
|
|
|
class_cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(cs);
|
|
|
|
if (numerical)
|
|
|
|
class_cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(cs);
|
2024-07-07 13:14:05 +00:00
|
|
|
if (notes)
|
|
|
|
class_cite_styles_[ENGINE_TYPE_NOTES].push_back(cs);
|
2018-05-27 09:49:10 +00:00
|
|
|
if (defce)
|
|
|
|
class_cite_styles_[ENGINE_TYPE_DEFAULT].push_back(cs);
|
|
|
|
} else {
|
|
|
|
if (authoryear)
|
|
|
|
cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(cs);
|
|
|
|
if (numerical)
|
|
|
|
cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(cs);
|
2024-07-07 13:14:05 +00:00
|
|
|
if (notes)
|
|
|
|
cite_styles_[ENGINE_TYPE_NOTES].push_back(cs);
|
2018-05-27 09:49:10 +00:00
|
|
|
if (defce)
|
|
|
|
cite_styles_[ENGINE_TYPE_DEFAULT].push_back(cs);
|
|
|
|
}
|
2018-05-21 10:46:53 +00:00
|
|
|
}
|
2018-05-27 09:49:10 +00:00
|
|
|
// If we do AddToCiteEngine, do not apply yet,
|
2018-05-21 10:46:53 +00:00
|
|
|
// except if we have already a style to add something to
|
2018-05-27 09:49:10 +00:00
|
|
|
bool apply_ay = !add;
|
|
|
|
bool apply_num = !add;
|
2024-07-07 13:14:05 +00:00
|
|
|
bool apply_notes = !add;
|
2018-05-27 09:49:10 +00:00
|
|
|
bool apply_def = !add;
|
|
|
|
if (add) {
|
|
|
|
if (type & ENGINE_TYPE_AUTHORYEAR)
|
|
|
|
apply_ay = !getCiteStyles(ENGINE_TYPE_AUTHORYEAR).empty();
|
|
|
|
if (type & ENGINE_TYPE_NUMERICAL)
|
|
|
|
apply_num = !getCiteStyles(ENGINE_TYPE_NUMERICAL).empty();
|
2024-07-07 13:14:05 +00:00
|
|
|
if (type & ENGINE_TYPE_NOTES)
|
|
|
|
apply_num = !getCiteStyles(ENGINE_TYPE_NOTES).empty();
|
2018-05-27 09:49:10 +00:00
|
|
|
if (type & ENGINE_TYPE_DEFAULT)
|
|
|
|
apply_def = !getCiteStyles(ENGINE_TYPE_DEFAULT).empty();
|
|
|
|
}
|
2018-05-21 10:46:53 +00:00
|
|
|
|
|
|
|
// Add the styles from AddToCiteEngine to the class' styles
|
|
|
|
// (but only if they are not yet defined)
|
2019-04-19 07:03:47 +00:00
|
|
|
for (auto const & cis : class_cite_styles_) {
|
2018-05-21 10:46:53 +00:00
|
|
|
// Only consider the current CiteEngineType
|
2018-05-27 09:49:10 +00:00
|
|
|
if (!(type & cis.first))
|
2018-05-21 10:46:53 +00:00
|
|
|
continue;
|
2019-04-19 07:03:47 +00:00
|
|
|
for (auto const & ciss : cis.second) {
|
2018-05-21 10:46:53 +00:00
|
|
|
bool defined = false;
|
|
|
|
// Check if the style "name" is already def'ed
|
2019-04-19 07:03:47 +00:00
|
|
|
for (auto const & av : getCiteStyles(cis.first))
|
2018-05-21 10:46:53 +00:00
|
|
|
if (av.name == ciss.name)
|
|
|
|
defined = true;
|
2018-05-27 09:49:10 +00:00
|
|
|
if (!defined) {
|
|
|
|
if (cis.first == ENGINE_TYPE_AUTHORYEAR && apply_ay)
|
|
|
|
cite_styles_[ENGINE_TYPE_AUTHORYEAR].push_back(ciss);
|
|
|
|
else if (cis.first == ENGINE_TYPE_NUMERICAL && apply_num)
|
|
|
|
cite_styles_[ENGINE_TYPE_NUMERICAL].push_back(ciss);
|
2024-07-07 13:14:05 +00:00
|
|
|
else if (cis.first == ENGINE_TYPE_NOTES && apply_notes)
|
|
|
|
cite_styles_[ENGINE_TYPE_NOTES].push_back(ciss);
|
2018-05-27 09:49:10 +00:00
|
|
|
else if (cis.first == ENGINE_TYPE_DEFAULT && apply_def)
|
|
|
|
cite_styles_[ENGINE_TYPE_DEFAULT].push_back(ciss);
|
|
|
|
}
|
2018-05-21 10:46:53 +00:00
|
|
|
}
|
2012-03-01 00:41:30 +00:00
|
|
|
}
|
2018-05-27 09:49:10 +00:00
|
|
|
if (type & ENGINE_TYPE_AUTHORYEAR && apply_ay)
|
|
|
|
class_cite_styles_[ENGINE_TYPE_AUTHORYEAR].clear();
|
|
|
|
if (type & ENGINE_TYPE_NUMERICAL && apply_num)
|
|
|
|
class_cite_styles_[ENGINE_TYPE_NUMERICAL].clear();
|
2024-07-07 13:14:05 +00:00
|
|
|
if (type & ENGINE_TYPE_NOTES && apply_notes)
|
|
|
|
class_cite_styles_[ENGINE_TYPE_NOTES].clear();
|
2018-05-27 09:49:10 +00:00
|
|
|
if (type & ENGINE_TYPE_DEFAULT && apply_def)
|
|
|
|
class_cite_styles_[ENGINE_TYPE_DEFAULT].clear();
|
2012-03-01 00:41:30 +00:00
|
|
|
return getout;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TextClass::readCiteEngineType(Lexer & lexrc) const
|
|
|
|
{
|
2017-12-14 15:22:46 +00:00
|
|
|
static_assert(ENGINE_TYPE_DEFAULT ==
|
2024-07-07 13:14:05 +00:00
|
|
|
(ENGINE_TYPE_AUTHORYEAR | ENGINE_TYPE_NUMERICAL | ENGINE_TYPE_NOTES),
|
2017-12-14 15:22:46 +00:00
|
|
|
"Incorrect default engine type");
|
2012-03-01 00:41:30 +00:00
|
|
|
if (!lexrc.next()) {
|
|
|
|
lexrc.printError("No cite engine type given for token: `$$Token'.");
|
|
|
|
return ENGINE_TYPE_DEFAULT;
|
|
|
|
}
|
|
|
|
string const type = rtrim(lexrc.getString());
|
|
|
|
if (compare_ascii_no_case(type, "authoryear") == 0)
|
|
|
|
return ENGINE_TYPE_AUTHORYEAR;
|
|
|
|
else if (compare_ascii_no_case(type, "numerical") == 0)
|
|
|
|
return ENGINE_TYPE_NUMERICAL;
|
2024-07-07 13:14:05 +00:00
|
|
|
else if (compare_ascii_no_case(type, "notes") == 0)
|
|
|
|
return ENGINE_TYPE_NOTES;
|
2012-03-01 00:41:30 +00:00
|
|
|
else if (compare_ascii_no_case(type, "default") != 0) {
|
|
|
|
string const s = "Unknown cite engine type `" + type
|
|
|
|
+ "' given for token: `$$Token',";
|
|
|
|
lexrc.printError(s);
|
|
|
|
}
|
|
|
|
return ENGINE_TYPE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-21 10:46:53 +00:00
|
|
|
bool TextClass::readCiteFormat(Lexer & lexrc, ReadType rt)
|
2010-03-29 18:37:25 +00:00
|
|
|
{
|
2012-03-01 00:41:30 +00:00
|
|
|
int const type = readCiteEngineType(lexrc);
|
2010-03-29 18:37:25 +00:00
|
|
|
string etype;
|
|
|
|
string definition;
|
2018-05-21 10:46:53 +00:00
|
|
|
// Cite engine definitions do not overwrite existing
|
|
|
|
// definitions from the class or a module
|
|
|
|
bool const overwrite = rt != CITE_ENGINE;
|
2010-03-29 18:37:25 +00:00
|
|
|
while (lexrc.isOK()) {
|
|
|
|
lexrc.next();
|
|
|
|
etype = lexrc.getString();
|
2012-03-01 00:41:30 +00:00
|
|
|
if (compare_ascii_no_case(etype, "end") == 0)
|
2010-03-29 18:37:25 +00:00
|
|
|
break;
|
2012-03-01 00:41:30 +00:00
|
|
|
if (!lexrc.isOK())
|
|
|
|
return false;
|
2010-03-29 18:37:25 +00:00
|
|
|
lexrc.eatLine();
|
|
|
|
definition = lexrc.getString();
|
2010-03-29 20:01:28 +00:00
|
|
|
char initchar = etype[0];
|
|
|
|
if (initchar == '#')
|
|
|
|
continue;
|
2018-01-27 13:26:36 +00:00
|
|
|
if (initchar == '!' || initchar == '_' || prefixIs(etype, "B_")) {
|
2018-05-21 10:46:53 +00:00
|
|
|
bool defined = false;
|
2019-04-19 07:04:23 +00:00
|
|
|
bool aydefined = false;
|
|
|
|
bool numdefined = false;
|
2024-07-07 13:14:05 +00:00
|
|
|
bool notesdefined = false;
|
2018-05-21 10:46:53 +00:00
|
|
|
// Check if the macro is already def'ed
|
2019-04-19 07:03:47 +00:00
|
|
|
for (auto const & cm : cite_macros_) {
|
2018-05-27 09:49:10 +00:00
|
|
|
if (!(type & cm.first))
|
2018-05-21 10:46:53 +00:00
|
|
|
continue;
|
2019-04-19 07:04:23 +00:00
|
|
|
if (cm.second.find(etype) != cm.second.end()) {
|
|
|
|
if (type == cm.first)
|
|
|
|
// defined as default or specific type
|
|
|
|
defined = true;
|
|
|
|
if (cm.first == ENGINE_TYPE_AUTHORYEAR)
|
|
|
|
// defined for author-year
|
|
|
|
aydefined = true;
|
|
|
|
else if (cm.first == ENGINE_TYPE_NUMERICAL)
|
|
|
|
// defined for numerical
|
|
|
|
numdefined = true;
|
2024-07-07 13:14:05 +00:00
|
|
|
else if (cm.first == ENGINE_TYPE_NOTES)
|
|
|
|
// defined for notes
|
|
|
|
notesdefined = true;
|
2019-04-19 07:04:23 +00:00
|
|
|
}
|
2018-05-21 10:46:53 +00:00
|
|
|
}
|
2018-05-27 09:49:10 +00:00
|
|
|
if (!defined || overwrite) {
|
2019-04-19 07:04:23 +00:00
|
|
|
if (type & ENGINE_TYPE_AUTHORYEAR && (type != ENGINE_TYPE_DEFAULT || !aydefined))
|
2018-05-27 09:49:10 +00:00
|
|
|
cite_macros_[ENGINE_TYPE_AUTHORYEAR][etype] = definition;
|
2019-04-19 07:04:23 +00:00
|
|
|
if (type & ENGINE_TYPE_NUMERICAL && (type != ENGINE_TYPE_DEFAULT || !numdefined))
|
2018-05-27 09:49:10 +00:00
|
|
|
cite_macros_[ENGINE_TYPE_NUMERICAL][etype] = definition;
|
2024-07-07 13:14:05 +00:00
|
|
|
if (type & ENGINE_TYPE_NOTES && (type != ENGINE_TYPE_DEFAULT || !notesdefined))
|
|
|
|
cite_macros_[ENGINE_TYPE_NOTES][etype] = definition;
|
2019-04-19 07:04:23 +00:00
|
|
|
if (type == ENGINE_TYPE_DEFAULT)
|
2018-05-27 09:49:10 +00:00
|
|
|
cite_macros_[ENGINE_TYPE_DEFAULT][etype] = definition;
|
|
|
|
}
|
2012-03-01 00:41:30 +00:00
|
|
|
} else {
|
2018-05-21 10:46:53 +00:00
|
|
|
bool defined = false;
|
2019-04-19 07:04:23 +00:00
|
|
|
bool aydefined = false;
|
|
|
|
bool numdefined = false;
|
2024-07-07 13:14:05 +00:00
|
|
|
bool notesdefined = false;
|
2018-05-21 10:46:53 +00:00
|
|
|
// Check if the format is already def'ed
|
2019-04-19 07:03:47 +00:00
|
|
|
for (auto const & cm : cite_formats_) {
|
2018-05-27 09:49:10 +00:00
|
|
|
if (!(type & cm.first))
|
2018-05-21 10:46:53 +00:00
|
|
|
continue;
|
2019-04-19 07:04:23 +00:00
|
|
|
if (cm.second.find(etype) != cm.second.end()) {
|
|
|
|
if (type == cm.first)
|
|
|
|
// defined as default or specific type
|
|
|
|
defined = true;
|
|
|
|
if (cm.first == ENGINE_TYPE_AUTHORYEAR)
|
|
|
|
// defined for author-year
|
|
|
|
aydefined = true;
|
|
|
|
else if (cm.first == ENGINE_TYPE_NUMERICAL)
|
|
|
|
// defined for numerical
|
|
|
|
numdefined = true;
|
2024-07-07 13:14:05 +00:00
|
|
|
else if (cm.first == ENGINE_TYPE_NOTES)
|
|
|
|
// defined for notes
|
|
|
|
notesdefined = true;
|
2019-04-19 07:04:23 +00:00
|
|
|
}
|
2018-05-21 10:46:53 +00:00
|
|
|
}
|
2018-05-27 09:49:10 +00:00
|
|
|
if (!defined || overwrite){
|
2019-04-19 07:04:23 +00:00
|
|
|
if (type & ENGINE_TYPE_AUTHORYEAR && (type != ENGINE_TYPE_DEFAULT || !aydefined))
|
2018-05-27 09:49:10 +00:00
|
|
|
cite_formats_[ENGINE_TYPE_AUTHORYEAR][etype] = definition;
|
2019-04-19 07:04:23 +00:00
|
|
|
if (type & ENGINE_TYPE_NUMERICAL && (type != ENGINE_TYPE_DEFAULT || !numdefined))
|
2018-05-27 09:49:10 +00:00
|
|
|
cite_formats_[ENGINE_TYPE_NUMERICAL][etype] = definition;
|
2024-07-07 13:14:05 +00:00
|
|
|
if (type & ENGINE_TYPE_NOTES && (type != ENGINE_TYPE_DEFAULT || !notesdefined))
|
|
|
|
cite_formats_[ENGINE_TYPE_NOTES][etype] = definition;
|
2019-04-19 07:04:23 +00:00
|
|
|
if (type == ENGINE_TYPE_DEFAULT)
|
2018-05-27 09:49:10 +00:00
|
|
|
cite_formats_[ENGINE_TYPE_DEFAULT][etype] = definition;
|
|
|
|
}
|
2012-03-01 00:41:30 +00:00
|
|
|
}
|
2010-03-29 18:37:25 +00:00
|
|
|
}
|
2012-03-01 00:41:30 +00:00
|
|
|
return true;
|
2010-03-29 18:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-04-18 21:06:38 +00:00
|
|
|
bool TextClass::readFloat(Lexer & lexrc)
|
2002-09-04 06:52:26 +00:00
|
|
|
{
|
2008-04-03 20:55:09 +00:00
|
|
|
enum {
|
|
|
|
FT_TYPE = 1,
|
|
|
|
FT_NAME,
|
|
|
|
FT_PLACEMENT,
|
|
|
|
FT_EXT,
|
|
|
|
FT_WITHIN,
|
|
|
|
FT_STYLE,
|
|
|
|
FT_LISTNAME,
|
2011-02-02 22:28:47 +00:00
|
|
|
FT_USESFLOAT,
|
|
|
|
FT_PREDEFINED,
|
2009-06-19 12:49:08 +00:00
|
|
|
FT_HTMLSTYLE,
|
2010-01-07 17:32:04 +00:00
|
|
|
FT_HTMLATTR,
|
2009-11-30 17:08:56 +00:00
|
|
|
FT_HTMLTAG,
|
2020-06-08 21:27:49 +00:00
|
|
|
FT_DOCBOOKATTR,
|
2021-09-19 22:06:20 +00:00
|
|
|
FT_DOCBOOKFLOATTYPE,
|
2020-06-08 21:27:49 +00:00
|
|
|
FT_DOCBOOKTAG,
|
2020-08-17 21:06:26 +00:00
|
|
|
FT_DOCBOOKTAGTYPE,
|
2021-09-19 22:06:20 +00:00
|
|
|
FT_DOCBOOKCAPTION,
|
2010-03-05 22:58:29 +00:00
|
|
|
FT_LISTCOMMAND,
|
2010-03-17 12:23:24 +00:00
|
|
|
FT_REFPREFIX,
|
2015-05-22 08:37:14 +00:00
|
|
|
FT_ALLOWED_PLACEMENT,
|
2015-05-22 16:59:17 +00:00
|
|
|
FT_ALLOWS_SIDEWAYS,
|
2019-08-12 10:18:28 +00:00
|
|
|
FT_ALLOWS_WIDE,
|
|
|
|
FT_REQUIRES,
|
2023-07-28 21:37:13 +00:00
|
|
|
FT_PRETTYFORMAT,
|
2008-04-03 20:55:09 +00:00
|
|
|
FT_END
|
|
|
|
};
|
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
LexerKeyword floatTags[] = {
|
2015-05-22 08:37:14 +00:00
|
|
|
{ "allowedplacement", FT_ALLOWED_PLACEMENT },
|
2015-05-22 16:59:17 +00:00
|
|
|
{ "allowssideways", FT_ALLOWS_SIDEWAYS },
|
|
|
|
{ "allowswide", FT_ALLOWS_WIDE },
|
2020-06-08 21:27:49 +00:00
|
|
|
{ "docbookattr", FT_DOCBOOKATTR },
|
2021-09-19 22:06:20 +00:00
|
|
|
{ "docbookcaption", FT_DOCBOOKCAPTION },
|
|
|
|
{ "docbookfloattype", FT_DOCBOOKFLOATTYPE },
|
2020-06-08 21:27:49 +00:00
|
|
|
{ "docbooktag", FT_DOCBOOKTAG },
|
2020-08-17 21:06:26 +00:00
|
|
|
{ "docbooktagtype", FT_DOCBOOKTAGTYPE },
|
2002-09-04 06:52:26 +00:00
|
|
|
{ "end", FT_END },
|
|
|
|
{ "extension", FT_EXT },
|
|
|
|
{ "guiname", FT_NAME },
|
2010-01-07 17:32:04 +00:00
|
|
|
{ "htmlattr", FT_HTMLATTR },
|
2009-06-19 12:49:08 +00:00
|
|
|
{ "htmlstyle", FT_HTMLSTYLE },
|
2009-11-30 17:08:56 +00:00
|
|
|
{ "htmltag", FT_HTMLTAG },
|
2011-02-02 22:28:47 +00:00
|
|
|
{ "ispredefined", FT_PREDEFINED },
|
2010-03-05 22:58:29 +00:00
|
|
|
{ "listcommand", FT_LISTCOMMAND },
|
2002-09-04 06:52:26 +00:00
|
|
|
{ "listname", FT_LISTNAME },
|
|
|
|
{ "numberwithin", FT_WITHIN },
|
|
|
|
{ "placement", FT_PLACEMENT },
|
2023-07-28 21:37:13 +00:00
|
|
|
{ "prettyformat", FT_PRETTYFORMAT },
|
2010-03-17 12:23:24 +00:00
|
|
|
{ "refprefix", FT_REFPREFIX },
|
2019-08-12 10:18:28 +00:00
|
|
|
{ "requires", FT_REQUIRES },
|
2002-09-04 06:52:26 +00:00
|
|
|
{ "style", FT_STYLE },
|
2011-02-02 22:28:47 +00:00
|
|
|
{ "type", FT_TYPE },
|
|
|
|
{ "usesfloatpkg", FT_USESFLOAT }
|
2002-09-04 06:52:26 +00:00
|
|
|
};
|
|
|
|
|
2008-04-02 23:06:22 +00:00
|
|
|
lexrc.pushTable(floatTags);
|
2002-09-04 06:52:26 +00:00
|
|
|
|
|
|
|
string ext;
|
2010-01-07 17:32:04 +00:00
|
|
|
string htmlattr;
|
2016-09-25 10:37:40 +00:00
|
|
|
docstring htmlstyle;
|
2009-11-30 17:08:56 +00:00
|
|
|
string htmltag;
|
2020-06-08 21:27:49 +00:00
|
|
|
string docbookattr;
|
2021-09-19 22:06:20 +00:00
|
|
|
string docbookcaption;
|
2020-06-08 21:27:49 +00:00
|
|
|
string docbooktag;
|
2020-08-17 21:06:26 +00:00
|
|
|
string docbooktagtype;
|
2021-09-19 22:06:20 +00:00
|
|
|
string docbookfloattype;
|
2010-03-17 12:23:24 +00:00
|
|
|
string listname;
|
|
|
|
string listcommand;
|
2009-06-19 12:49:08 +00:00
|
|
|
string name;
|
|
|
|
string placement;
|
2015-05-22 08:37:14 +00:00
|
|
|
string allowed_placement = "!htbpH";
|
2010-03-17 12:23:24 +00:00
|
|
|
string refprefix;
|
2009-06-19 12:49:08 +00:00
|
|
|
string style;
|
|
|
|
string type;
|
|
|
|
string within;
|
2020-03-16 05:31:09 +00:00
|
|
|
string required;
|
2023-07-28 21:37:13 +00:00
|
|
|
docstring prettyformat;
|
2011-02-02 22:15:52 +00:00
|
|
|
bool usesfloat = true;
|
2011-02-02 22:28:47 +00:00
|
|
|
bool ispredefined = false;
|
2015-05-22 16:59:17 +00:00
|
|
|
bool allowswide = true;
|
|
|
|
bool allowssideways = true;
|
2002-09-04 06:52:26 +00:00
|
|
|
|
|
|
|
bool getout = false;
|
|
|
|
while (!getout && lexrc.isOK()) {
|
|
|
|
int le = lexrc.lex();
|
|
|
|
switch (le) {
|
2007-04-26 11:30:54 +00:00
|
|
|
case Lexer::LEX_UNDEF:
|
2008-01-07 16:59:10 +00:00
|
|
|
lexrc.printError("Unknown float tag `$$Token'");
|
2002-09-04 06:52:26 +00:00
|
|
|
continue;
|
2010-04-18 21:06:38 +00:00
|
|
|
default:
|
|
|
|
break;
|
2002-09-04 06:52:26 +00:00
|
|
|
}
|
2008-04-03 20:55:09 +00:00
|
|
|
switch (le) {
|
2002-09-04 06:52:26 +00:00
|
|
|
case FT_TYPE:
|
|
|
|
lexrc.next();
|
|
|
|
type = lexrc.getString();
|
2008-03-07 03:41:12 +00:00
|
|
|
if (floatlist_.typeExist(type)) {
|
|
|
|
Floating const & fl = floatlist_.getType(type);
|
2007-08-16 11:07:00 +00:00
|
|
|
placement = fl.placement();
|
|
|
|
ext = fl.ext();
|
|
|
|
within = fl.within();
|
|
|
|
style = fl.style();
|
|
|
|
name = fl.name();
|
2010-03-17 12:23:24 +00:00
|
|
|
listname = fl.listName();
|
2011-02-02 22:15:52 +00:00
|
|
|
usesfloat = fl.usesFloatPkg();
|
2011-02-02 22:34:23 +00:00
|
|
|
ispredefined = fl.isPredefined();
|
2010-03-17 12:23:24 +00:00
|
|
|
listcommand = fl.listCommand();
|
|
|
|
refprefix = fl.refPrefix();
|
2011-12-03 22:15:11 +00:00
|
|
|
}
|
2002-09-04 06:52:26 +00:00
|
|
|
break;
|
|
|
|
case FT_NAME:
|
|
|
|
lexrc.next();
|
|
|
|
name = lexrc.getString();
|
|
|
|
break;
|
|
|
|
case FT_PLACEMENT:
|
|
|
|
lexrc.next();
|
|
|
|
placement = lexrc.getString();
|
|
|
|
break;
|
2015-05-22 08:37:14 +00:00
|
|
|
case FT_ALLOWED_PLACEMENT:
|
|
|
|
lexrc.next();
|
|
|
|
allowed_placement = lexrc.getString();
|
|
|
|
break;
|
2002-09-04 06:52:26 +00:00
|
|
|
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;
|
2010-03-05 22:58:29 +00:00
|
|
|
case FT_LISTCOMMAND:
|
|
|
|
lexrc.next();
|
2010-03-17 12:23:24 +00:00
|
|
|
listcommand = lexrc.getString();
|
|
|
|
break;
|
|
|
|
case FT_REFPREFIX:
|
|
|
|
lexrc.next();
|
|
|
|
refprefix = lexrc.getString();
|
2010-03-05 22:58:29 +00:00
|
|
|
break;
|
2002-09-04 06:52:26 +00:00
|
|
|
case FT_LISTNAME:
|
|
|
|
lexrc.next();
|
2010-03-17 12:23:24 +00:00
|
|
|
listname = lexrc.getString();
|
2002-09-04 06:52:26 +00:00
|
|
|
break;
|
2011-02-02 22:28:47 +00:00
|
|
|
case FT_USESFLOAT:
|
2002-09-04 06:52:26 +00:00
|
|
|
lexrc.next();
|
2011-02-02 22:15:52 +00:00
|
|
|
usesfloat = lexrc.getBool();
|
2002-09-04 06:52:26 +00:00
|
|
|
break;
|
2019-08-12 10:18:28 +00:00
|
|
|
case FT_REQUIRES:
|
|
|
|
lexrc.next();
|
2020-03-16 05:31:09 +00:00
|
|
|
required = lexrc.getString();
|
2019-08-12 10:18:28 +00:00
|
|
|
break;
|
2011-02-02 22:28:47 +00:00
|
|
|
case FT_PREDEFINED:
|
|
|
|
lexrc.next();
|
|
|
|
ispredefined = lexrc.getBool();
|
|
|
|
break;
|
2015-05-22 16:59:17 +00:00
|
|
|
case FT_ALLOWS_SIDEWAYS:
|
|
|
|
lexrc.next();
|
|
|
|
allowssideways = lexrc.getBool();
|
|
|
|
break;
|
|
|
|
case FT_ALLOWS_WIDE:
|
|
|
|
lexrc.next();
|
|
|
|
allowswide = lexrc.getBool();
|
|
|
|
break;
|
2010-01-07 17:32:04 +00:00
|
|
|
case FT_HTMLATTR:
|
2009-06-19 12:49:08 +00:00
|
|
|
lexrc.next();
|
2010-01-07 17:32:04 +00:00
|
|
|
htmlattr = lexrc.getString();
|
2009-06-19 12:49:08 +00:00
|
|
|
break;
|
|
|
|
case FT_HTMLSTYLE:
|
|
|
|
lexrc.next();
|
2016-09-25 10:37:40 +00:00
|
|
|
htmlstyle = lexrc.getLongString(from_ascii("EndHTMLStyle"));
|
2009-06-19 12:49:08 +00:00
|
|
|
break;
|
2009-11-30 17:08:56 +00:00
|
|
|
case FT_HTMLTAG:
|
2009-06-19 12:49:08 +00:00
|
|
|
lexrc.next();
|
2009-11-30 17:08:56 +00:00
|
|
|
htmltag = lexrc.getString();
|
2009-06-19 12:49:08 +00:00
|
|
|
break;
|
2023-07-28 21:37:13 +00:00
|
|
|
case FT_PRETTYFORMAT:
|
|
|
|
lexrc.next();
|
|
|
|
prettyformat = lexrc.getDocString();
|
|
|
|
break;
|
2020-06-08 21:27:49 +00:00
|
|
|
case FT_DOCBOOKATTR:
|
|
|
|
lexrc.next();
|
|
|
|
docbookattr = lexrc.getString();
|
|
|
|
break;
|
2021-09-19 22:06:20 +00:00
|
|
|
case FT_DOCBOOKCAPTION:
|
|
|
|
lexrc.next();
|
|
|
|
docbookcaption = lexrc.getString();
|
|
|
|
break;
|
2020-06-08 21:27:49 +00:00
|
|
|
case FT_DOCBOOKTAG:
|
|
|
|
lexrc.next();
|
|
|
|
docbooktag = lexrc.getString();
|
|
|
|
break;
|
2020-08-17 21:06:26 +00:00
|
|
|
case FT_DOCBOOKTAGTYPE:
|
|
|
|
lexrc.next();
|
|
|
|
docbooktagtype = lexrc.getString();
|
|
|
|
break;
|
2021-09-19 22:06:20 +00:00
|
|
|
case FT_DOCBOOKFLOATTYPE:
|
|
|
|
lexrc.next();
|
|
|
|
docbookfloattype = lexrc.getString();
|
|
|
|
break;
|
2002-09-04 06:52:26 +00:00
|
|
|
case FT_END:
|
|
|
|
getout = true;
|
|
|
|
break;
|
2021-09-19 18:10:51 +00:00
|
|
|
default:
|
|
|
|
LYXERR0("Unhandled value " << le << " in TextClass::readFloat.");
|
|
|
|
break;
|
2002-09-04 06:52:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-18 21:06:38 +00:00
|
|
|
lexrc.popTable();
|
|
|
|
|
2010-03-05 22:58:29 +00:00
|
|
|
// Here we have a full float if getout == true
|
2002-09-04 06:52:26 +00:00
|
|
|
if (getout) {
|
2011-02-02 22:15:52 +00:00
|
|
|
if (!usesfloat && listcommand.empty()) {
|
2011-02-02 17:32:59 +00:00
|
|
|
// if this float uses the same auxfile as an existing one,
|
|
|
|
// there is no need for it to provide a list command.
|
|
|
|
bool found_ext = false;
|
2020-03-16 05:08:03 +00:00
|
|
|
for (auto const & f : floatlist_) {
|
|
|
|
if (f.second.ext() == ext) {
|
2011-02-02 17:32:59 +00:00
|
|
|
found_ext = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found_ext)
|
|
|
|
LYXERR0("The layout does not provide a list command " <<
|
2011-02-02 22:15:52 +00:00
|
|
|
"for the float `" << type << "'. LyX will " <<
|
2011-02-02 17:32:59 +00:00
|
|
|
"not be able to produce a float list.");
|
|
|
|
}
|
2011-12-03 22:15:11 +00:00
|
|
|
Floating fl(type, placement, ext, within, style, name,
|
2020-03-16 05:31:09 +00:00
|
|
|
listname, listcommand, refprefix, allowed_placement,
|
2021-09-19 22:06:20 +00:00
|
|
|
htmltag, htmlattr, htmlstyle, docbooktag, docbookattr,
|
|
|
|
docbooktagtype, docbookfloattype, docbookcaption,
|
|
|
|
required, usesfloat, ispredefined,
|
2020-08-17 21:06:26 +00:00
|
|
|
allowswide, allowssideways);
|
2008-03-07 03:41:12 +00:00
|
|
|
floatlist_.newFloat(fl);
|
2007-08-16 11:07:00 +00:00
|
|
|
// each float has its own counter
|
2008-03-07 03:41:12 +00:00
|
|
|
counters_.newCounter(from_ascii(type), from_ascii(within),
|
2020-05-03 03:11:53 +00:00
|
|
|
docstring(), docstring(),
|
2023-07-28 21:37:13 +00:00
|
|
|
prettyformat.empty() ? bformat(_("%1$s ##"), _(name)) : prettyformat,
|
2020-05-03 11:36:34 +00:00
|
|
|
bformat(_("%1$s (Float)"), _(name)));
|
2008-03-02 11:30:50 +00:00
|
|
|
// also define sub-float counters
|
|
|
|
docstring const subtype = "sub-" + from_ascii(type);
|
2008-03-07 03:41:12 +00:00
|
|
|
counters_.newCounter(subtype, from_ascii(type),
|
2020-05-03 03:11:53 +00:00
|
|
|
"\\alph{" + subtype + "}", docstring(),
|
2023-07-28 21:37:13 +00:00
|
|
|
prettyformat.empty() ? bformat(_("Sub-%1$s ##"), _(name)) : prettyformat,
|
2023-07-26 17:35:42 +00:00
|
|
|
bformat(_("Sub-%1$s (Float)"), _(name)));
|
2002-09-04 06:52:26 +00:00
|
|
|
}
|
2010-04-18 21:06:38 +00:00
|
|
|
return getout;
|
2002-09-04 06:52:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-03 16:47:25 +00:00
|
|
|
bool TextClass::readOutlinerName(Lexer & lexrc)
|
|
|
|
{
|
|
|
|
std::string type;
|
|
|
|
docstring name;
|
|
|
|
if (lexrc.next())
|
|
|
|
type = lexrc.getString();
|
|
|
|
else {
|
|
|
|
lexrc.printError("No type given for OutlinerName: `$$Token'.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (lexrc.next())
|
|
|
|
name = lexrc.getDocString();
|
|
|
|
else {
|
|
|
|
lexrc.printError("No name given for OutlinerName: `$$Token'.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
outliner_names_[type] = name;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-09 05:17:36 +00:00
|
|
|
string const & TextClass::prerequisites(string const & sep) const
|
2011-12-03 22:15:11 +00:00
|
|
|
{
|
2010-03-25 00:44:15 +00:00
|
|
|
if (contains(prerequisites_, ',')) {
|
|
|
|
vector<string> const pres = getVectorFromString(prerequisites_);
|
2012-10-09 05:17:36 +00:00
|
|
|
prerequisites_ = getStringFromVector(pres, sep);
|
2010-03-25 00:44:15 +00:00
|
|
|
}
|
2011-12-03 22:15:11 +00:00
|
|
|
return prerequisites_;
|
2010-03-25 00:44:15 +00:00
|
|
|
}
|
|
|
|
|
2012-10-27 13:45:27 +00:00
|
|
|
|
2007-07-11 13:39:08 +00:00
|
|
|
bool TextClass::hasLayout(docstring const & n) const
|
2001-12-28 13:26:54 +00:00
|
|
|
{
|
2007-07-11 13:39:08 +00:00
|
|
|
docstring const name = n.empty() ? defaultLayoutName() : n;
|
2020-05-04 23:41:18 +00:00
|
|
|
return getLayout(name) != nullptr;
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-12-16 16:11:15 +00:00
|
|
|
bool TextClass::hasInsetLayout(docstring const & n) const
|
|
|
|
{
|
2011-12-03 22:15:11 +00:00
|
|
|
if (n.empty())
|
2008-12-16 16:11:15 +00:00
|
|
|
return false;
|
2013-02-09 19:37:42 +00:00
|
|
|
InsetLayouts::const_iterator it = insetlayoutlist_.find(n);
|
|
|
|
return it != insetlayoutlist_.end();
|
2008-12-16 16:11:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 20:01:30 +00:00
|
|
|
Layout const & TextClass::operator[](docstring const & name) const
|
2001-12-28 13:26:54 +00:00
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(!name.empty());
|
2002-03-12 18:11:49 +00:00
|
|
|
|
2020-05-04 23:41:18 +00:00
|
|
|
Layout const * c = getLayout(name);
|
|
|
|
if (!c) {
|
2013-04-25 21:27:10 +00:00
|
|
|
LYXERR0("We failed to find the layout '" << name
|
|
|
|
<< "' in the layout list. You MUST investigate!");
|
2020-03-16 05:08:03 +00:00
|
|
|
for (auto const & lay : *this)
|
|
|
|
lyxerr << " " << to_utf8(lay.name()) << endl;
|
2002-03-21 17:27:08 +00:00
|
|
|
|
2013-04-25 21:27:10 +00:00
|
|
|
// We require the name to exist
|
|
|
|
static const Layout dummy;
|
|
|
|
LASSERT(false, return dummy);
|
2002-03-02 16:39:54 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 23:41:18 +00:00
|
|
|
return *c;
|
2008-03-06 20:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Layout & TextClass::operator[](docstring const & name)
|
|
|
|
{
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(!name.empty());
|
|
|
|
// Safe to continue, given what we do below.
|
2008-03-06 20:01:30 +00:00
|
|
|
|
2020-05-04 23:41:18 +00:00
|
|
|
Layout * c = getLayout(name);
|
|
|
|
if (!c) {
|
2008-04-03 21:36:57 +00:00
|
|
|
LYXERR0("We failed to find the layout '" << to_utf8(name)
|
|
|
|
<< "' in the layout list. You MUST investigate!");
|
2020-03-16 05:08:03 +00:00
|
|
|
for (auto const & lay : *this)
|
|
|
|
LYXERR0(" " << to_utf8(lay.name()));
|
2008-03-06 20:01:30 +00:00
|
|
|
|
|
|
|
// we require the name to exist
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(false);
|
|
|
|
// we are here only in release mode
|
|
|
|
layoutlist_.push_back(createBasicLayout(name, true));
|
2020-05-04 23:41:18 +00:00
|
|
|
c = getLayout(name);
|
2008-03-06 20:01:30 +00:00
|
|
|
}
|
|
|
|
|
2020-05-04 23:41:18 +00:00
|
|
|
return *c;
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-04 09:51:26 +00:00
|
|
|
bool TextClass::deleteLayout(docstring const & name)
|
2001-12-28 13:26:54 +00:00
|
|
|
{
|
2008-08-01 20:57:27 +00:00
|
|
|
if (name == defaultLayoutName() || name == plainLayoutName())
|
2002-03-02 16:39:54 +00:00
|
|
|
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(),
|
2020-05-04 23:41:18 +00:00
|
|
|
[name](const Layout &c) { return c.name() == name; });
|
2002-06-24 20:28:12 +00:00
|
|
|
|
2020-05-04 23:41:18 +00:00
|
|
|
LayoutList::iterator const 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-09 19:31:26 +00:00
|
|
|
bool TextClass::deleteInsetLayout(docstring const & name)
|
|
|
|
{
|
|
|
|
return insetlayoutlist_.erase(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-28 13:26:54 +00:00
|
|
|
// Load textclass info if not loaded yet
|
2007-04-29 19:53:54 +00:00
|
|
|
bool TextClass::load(string const & path) 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
|
|
|
|
2006-05-04 02:38:11 +00:00
|
|
|
// Read style-file, provided path is searched before the system ones
|
2008-07-11 02:43:02 +00:00
|
|
|
// If path is a file, it is loaded directly.
|
|
|
|
FileName layout_file(path);
|
|
|
|
if (!path.empty() && !layout_file.isReadableFile())
|
2006-11-26 21:30:39 +00:00
|
|
|
layout_file = FileName(addName(path, name_ + ".layout"));
|
2007-10-18 19:29:32 +00:00
|
|
|
if (layout_file.empty() || !layout_file.exists())
|
2006-05-04 02:38:11 +00:00
|
|
|
layout_file = libFileSearch("layouts", name_, "layout");
|
2008-02-14 03:38:08 +00:00
|
|
|
loaded_ = const_cast<TextClass*>(this)->read(layout_file);
|
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 `"
|
2010-04-21 01:19:09 +00:00
|
|
|
<< to_utf8(makeDisplayPath(layout_file.absFileName()))
|
2001-12-28 13:26:54 +00:00
|
|
|
<< "'\n(Check `" << name_
|
|
|
|
<< "')\nCheck your installation and "
|
2021-01-28 04:04:39 +00:00
|
|
|
"try Tools/Reconfigure..."
|
2010-04-07 13:25:44 +00:00
|
|
|
<< endl;
|
2001-12-28 13:26:54 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-04 23:41:18 +00:00
|
|
|
Layout const * TextClass::getLayout(docstring const & name) const
|
|
|
|
{
|
|
|
|
LayoutList::const_iterator cit =
|
|
|
|
find_if(begin(), end(),
|
|
|
|
[name](const Layout &c) { return c.name() == name; });
|
|
|
|
if (cit == layoutlist_.end())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &(*cit);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Layout * TextClass::getLayout(docstring const & name)
|
|
|
|
{
|
|
|
|
LayoutList::iterator it =
|
|
|
|
find_if(layoutlist_.begin(), layoutlist_.end(),
|
|
|
|
[name](const Layout &c) { return c.name() == name; });
|
|
|
|
if (it == layoutlist_.end())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &(*it);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-08 00:12:57 +00:00
|
|
|
bool DocumentClass::addLayoutIfNeeded(docstring const & n) const
|
2008-07-15 17:51:57 +00:00
|
|
|
{
|
2011-06-08 00:12:57 +00:00
|
|
|
if (hasLayout(n))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
layoutlist_.push_back(createBasicLayout(n, true));
|
|
|
|
return true;
|
2008-07-15 17:51:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-15 05:19:49 +00:00
|
|
|
string DocumentClass::forcedLayouts() const
|
|
|
|
{
|
|
|
|
ostringstream os;
|
|
|
|
bool first = true;
|
2020-03-16 05:08:03 +00:00
|
|
|
for (auto const & lay : *this) {
|
|
|
|
if (lay.forcelocal > 0) {
|
2013-05-15 05:19:49 +00:00
|
|
|
if (first) {
|
|
|
|
os << "Format " << LAYOUT_FORMAT << '\n';
|
|
|
|
first = false;
|
|
|
|
}
|
2020-03-16 05:08:03 +00:00
|
|
|
lay.write(os);
|
2013-05-15 05:19:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return os.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
InsetLayout const & DocumentClass::insetLayout(docstring const & name) const
|
2007-08-13 12:13:17 +00:00
|
|
|
{
|
2008-07-15 18:09:44 +00:00
|
|
|
// FIXME The fix for the InsetLayout part of 4812 would be here:
|
|
|
|
// Add the InsetLayout to the document class if it is not found.
|
2007-08-17 15:38:58 +00:00
|
|
|
docstring n = name;
|
2008-03-07 03:41:12 +00:00
|
|
|
InsetLayouts::const_iterator cen = insetlayoutlist_.end();
|
2007-08-17 15:38:58 +00:00
|
|
|
while (!n.empty()) {
|
2008-03-07 03:41:12 +00:00
|
|
|
InsetLayouts::const_iterator cit = insetlayoutlist_.lower_bound(n);
|
2014-12-08 08:06:41 +00:00
|
|
|
if (cit != cen && cit->first == n) {
|
|
|
|
if (cit->second.obsoleted_by().empty())
|
|
|
|
return cit->second;
|
|
|
|
n = cit->second.obsoleted_by();
|
|
|
|
return insetLayout(n);
|
|
|
|
}
|
|
|
|
// If we have a generic prefix (e.g., "Note:"),
|
|
|
|
// try if this one alone is found.
|
2008-02-23 16:45:38 +00:00
|
|
|
size_t i = n.find(':');
|
2007-08-17 15:38:58 +00:00
|
|
|
if (i == string::npos)
|
|
|
|
break;
|
2008-09-08 01:18:33 +00:00
|
|
|
n = n.substr(0, i);
|
2007-08-17 15:38:58 +00:00
|
|
|
}
|
2014-12-08 08:06:41 +00:00
|
|
|
// Layout "name" not found.
|
2024-06-20 16:26:50 +00:00
|
|
|
return InsetLayout::undefined();
|
2007-08-13 12:13:17 +00:00
|
|
|
}
|
|
|
|
|
2002-09-06 14:48:01 +00:00
|
|
|
|
2007-07-11 13:39:08 +00:00
|
|
|
docstring const & TextClass::defaultLayoutName() const
|
2002-03-02 16:39:54 +00:00
|
|
|
{
|
|
|
|
return defaultlayout_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-06 20:01:30 +00:00
|
|
|
Layout const & TextClass::defaultLayout() const
|
2002-03-02 16:39:54 +00:00
|
|
|
{
|
|
|
|
return operator[](defaultLayoutName());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
bool TextClass::isDefaultLayout(Layout const & layout) const
|
2008-03-06 20:01:30 +00:00
|
|
|
{
|
2008-04-16 21:23:45 +00:00
|
|
|
return layout.name() == defaultLayoutName();
|
2008-03-06 20:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
bool TextClass::isPlainLayout(Layout const & layout) const
|
2008-03-06 20:01:30 +00:00
|
|
|
{
|
2008-08-01 20:57:27 +00:00
|
|
|
return layout.name() == plainLayoutName();
|
2008-03-06 20:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-01 21:13:03 +00:00
|
|
|
Layout TextClass::createBasicLayout(docstring const & name, bool unknown) const
|
2008-07-11 02:43:02 +00:00
|
|
|
{
|
2020-03-16 05:08:03 +00:00
|
|
|
static Layout * defaultLayout = nullptr;
|
2008-07-11 02:43:02 +00:00
|
|
|
|
|
|
|
if (defaultLayout) {
|
|
|
|
defaultLayout->setUnknown(unknown);
|
|
|
|
defaultLayout->setName(name);
|
|
|
|
return *defaultLayout;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char const * s = "Margin Static\n"
|
|
|
|
"LatexType Paragraph\n"
|
|
|
|
"LatexName dummy\n"
|
|
|
|
"Align Block\n"
|
|
|
|
"AlignPossible Left, Right, Center\n"
|
|
|
|
"LabelType No_Label\n"
|
|
|
|
"End";
|
|
|
|
istringstream ss(s);
|
|
|
|
Lexer lex(textClassTags);
|
|
|
|
lex.setStream(ss);
|
|
|
|
defaultLayout = new Layout;
|
|
|
|
defaultLayout->setUnknown(unknown);
|
|
|
|
defaultLayout->setName(name);
|
2020-09-29 02:07:08 +00:00
|
|
|
if (!readStyle(lex, *defaultLayout, BASECLASS)) {
|
2008-07-11 02:43:02 +00:00
|
|
|
// The only way this happens is because the hardcoded layout above
|
|
|
|
// is wrong.
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(false);
|
2008-07-11 02:43:02 +00:00
|
|
|
};
|
|
|
|
return *defaultLayout;
|
|
|
|
}
|
|
|
|
|
2010-01-12 19:38:31 +00:00
|
|
|
|
2021-01-14 06:15:19 +00:00
|
|
|
DocumentClassPtr getDocumentClass(LayoutFile const & baseClass, LayoutModuleList const & modlist,
|
|
|
|
string const & cengine, bool clone, bool internal)
|
2009-02-11 23:22:10 +00:00
|
|
|
{
|
2021-01-14 06:15:19 +00:00
|
|
|
bool const show_warnings = !clone && !internal;
|
2012-03-13 16:13:31 +00:00
|
|
|
DocumentClassPtr doc_class =
|
|
|
|
DocumentClassPtr(new DocumentClass(baseClass));
|
2020-03-16 05:08:03 +00:00
|
|
|
for (auto const & mod : modlist) {
|
|
|
|
LyXModule * lm = theModuleList[mod];
|
2009-02-11 23:22:10 +00:00
|
|
|
if (!lm) {
|
2021-01-14 06:15:19 +00:00
|
|
|
if (show_warnings) {
|
|
|
|
docstring const msg =
|
2021-01-14 06:28:42 +00:00
|
|
|
bformat(_("The module %1$s has been requested by\n"
|
|
|
|
"this document but has not been found in the list of\n"
|
|
|
|
"available modules. If you recently installed it, you\n"
|
|
|
|
"probably need to reconfigure LyX.\n"), from_utf8(mod));
|
2014-02-09 10:15:57 +00:00
|
|
|
frontend::Alert::warning(_("Module not available"), msg);
|
2021-01-14 06:15:19 +00:00
|
|
|
}
|
2009-02-11 23:22:10 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-01-14 06:15:19 +00:00
|
|
|
if (!lm->isAvailable() && show_warnings) {
|
2011-01-13 21:19:14 +00:00
|
|
|
docstring const prereqs = from_utf8(getStringFromVector(lm->prerequisites(), "\n\t"));
|
2009-02-11 23:22:10 +00:00
|
|
|
docstring const msg =
|
2011-01-13 21:19:14 +00:00
|
|
|
bformat(_("The module %1$s requires a package that is not\n"
|
|
|
|
"available in your LaTeX installation, or a converter that\n"
|
|
|
|
"you have not installed. LaTeX output may not be possible.\n"
|
|
|
|
"Missing prerequisites:\n"
|
|
|
|
"\t%2$s\n"
|
2011-01-21 13:08:21 +00:00
|
|
|
"See section 3.1.2.3 (Modules) of the User's Guide for more information."),
|
2020-03-16 05:08:03 +00:00
|
|
|
from_utf8(mod), prereqs);
|
2011-01-13 21:31:14 +00:00
|
|
|
frontend::Alert::warning(_("Package not available"), msg, true);
|
2009-02-11 23:22:10 +00:00
|
|
|
}
|
|
|
|
FileName layout_file = libFileSearch("layouts", lm->getFilename());
|
2012-03-13 16:13:31 +00:00
|
|
|
if (!doc_class->read(layout_file, TextClass::MODULE)) {
|
2009-02-11 23:22:10 +00:00
|
|
|
docstring const msg =
|
2021-01-14 06:28:42 +00:00
|
|
|
bformat(_("Error reading module %1$s\n"), from_utf8(mod));
|
2010-04-17 22:36:31 +00:00
|
|
|
frontend::Alert::warning(_("Read Error"), msg);
|
2009-02-11 23:22:10 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-30 15:22:08 +00:00
|
|
|
|
2018-05-21 11:45:31 +00:00
|
|
|
if (cengine.empty())
|
|
|
|
return doc_class;
|
|
|
|
|
2018-05-20 10:27:03 +00:00
|
|
|
LyXCiteEngine * ce = theCiteEnginesList[cengine];
|
|
|
|
if (!ce) {
|
2021-01-14 06:15:19 +00:00
|
|
|
if (show_warnings) {
|
|
|
|
docstring const msg =
|
2021-01-14 06:28:42 +00:00
|
|
|
bformat(_("The cite engine %1$s has been requested by\n"
|
|
|
|
"this document but has not been found in the list of\n"
|
|
|
|
"available engines. If you recently installed it, you\n"
|
|
|
|
"probably need to reconfigure LyX.\n"), from_utf8(cengine));
|
2018-05-20 10:27:03 +00:00
|
|
|
frontend::Alert::warning(_("Cite Engine not available"), msg);
|
2021-01-14 06:15:19 +00:00
|
|
|
}
|
|
|
|
} else if (!ce->isAvailable() && show_warnings) {
|
2018-05-20 10:27:03 +00:00
|
|
|
docstring const prereqs = from_utf8(getStringFromVector(ce->prerequisites(), "\n\t"));
|
|
|
|
docstring const msg =
|
|
|
|
bformat(_("The cite engine %1$s requires a package that is not\n"
|
|
|
|
"available in your LaTeX installation, or a converter that\n"
|
|
|
|
"you have not installed. LaTeX output may not be possible.\n"
|
|
|
|
"Missing prerequisites:\n"
|
|
|
|
"\t%2$s\n"
|
|
|
|
"See section 3.1.2.3 (Modules) of the User's Guide for more information."),
|
|
|
|
from_utf8(cengine), prereqs);
|
|
|
|
frontend::Alert::warning(_("Package not available"), msg, true);
|
|
|
|
} else {
|
2016-12-30 15:22:08 +00:00
|
|
|
FileName layout_file = libFileSearch("citeengines", ce->getFilename());
|
|
|
|
if (!doc_class->read(layout_file, TextClass::CITE_ENGINE)) {
|
|
|
|
docstring const msg =
|
2021-01-14 06:28:42 +00:00
|
|
|
bformat(_("Error reading cite engine %1$s\n"), from_utf8(cengine));
|
2016-12-30 15:22:08 +00:00
|
|
|
frontend::Alert::warning(_("Read Error"), msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-11 23:22:10 +00:00
|
|
|
return doc_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-16 21:23:45 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// DocumentClass
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
DocumentClass::DocumentClass(LayoutFile const & tc)
|
2008-02-28 01:42:02 +00:00
|
|
|
: TextClass(tc)
|
|
|
|
{}
|
2008-02-25 19:31:31 +00:00
|
|
|
|
|
|
|
|
2008-02-28 21:25:57 +00:00
|
|
|
bool DocumentClass::hasLaTeXLayout(std::string const & lay) const
|
|
|
|
{
|
2020-03-16 05:08:03 +00:00
|
|
|
for (auto const & l : layoutlist_)
|
|
|
|
if (l.latexname() == lay)
|
2008-02-28 21:25:57 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
This is the last of the commits that hopes to enforce the distinction between "layout files" and "document classes" that was introduced by the modules code. For the most part, these changes just refactor code from TextClass between: (a) a TextClass base class; (b) a LayoutFile subclass, which represents the information in a .layout file; and (c) a DocumentClass subclass, which represents the layout information associated with a Buffer---a LayoutFile plus Modules. Methods from TextClass have been apportioned between the three classes depending upon what is needed where, and signatures have been changed where necessary so that the right kind of class is required.
At this point, there are no simple TextClass objects in the main LyX code, and it is impossible to create them, since the TextClass constructor is protected. Only LayoutFile and DocumentClass objects can be constructed, and for the most part these are constructed only by their respective containers: BaseClassList and DocumentClassBundle. There is an exception: LayoutFile does have a public default constructor, but if anyone knows how to make it go away, please do.
There will be one or two more commits along these lines, but these will be simple renamings. For example, BaseClassList should be LayoutFileList.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23343 a592a061-630c-0410-9148-cb99ea01b6c8
2008-02-29 02:45:33 +00:00
|
|
|
bool DocumentClass::provides(string const & p) const
|
|
|
|
{
|
|
|
|
return provides_.find(p) != provides_.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DocumentClass::hasTocLevels() const
|
|
|
|
{
|
|
|
|
return min_toclevel_ != Layout::NOT_IN_TOC;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-21 18:14:12 +00:00
|
|
|
Layout const & DocumentClass::getTOCLayout() const
|
|
|
|
{
|
|
|
|
// we're going to look for the layout with the minimum toclevel
|
|
|
|
int minlevel = 1000;
|
2020-03-16 05:08:03 +00:00
|
|
|
Layout const * lay = nullptr;
|
|
|
|
for (auto const & l : *this) {
|
|
|
|
int const level = l.toclevel;
|
2013-05-03 21:48:48 +00:00
|
|
|
// we don't want Part or unnumbered sections
|
2017-07-03 17:53:14 +00:00
|
|
|
if (level == Layout::NOT_IN_TOC || level < 0
|
2020-03-16 05:08:03 +00:00
|
|
|
|| level >= minlevel || l.counter.empty())
|
2012-07-21 18:14:12 +00:00
|
|
|
continue;
|
2020-03-16 05:08:03 +00:00
|
|
|
lay = &l;
|
2012-07-21 18:14:12 +00:00
|
|
|
minlevel = level;
|
|
|
|
}
|
|
|
|
if (lay)
|
|
|
|
return *lay;
|
|
|
|
// hmm. that is very odd, so we'll do our best.
|
|
|
|
return operator[](defaultLayoutName());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-12 19:38:31 +00:00
|
|
|
Layout const & DocumentClass::htmlTOCLayout() const
|
|
|
|
{
|
2012-10-27 13:45:27 +00:00
|
|
|
if (html_toc_section_.empty())
|
2012-07-21 18:14:12 +00:00
|
|
|
html_toc_section_ = getTOCLayout().name();
|
2010-01-12 19:38:31 +00:00
|
|
|
return operator[](html_toc_section_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-07 16:55:38 +00:00
|
|
|
string const DocumentClass::getCiteFormat(CiteEngineType const & type,
|
|
|
|
string const & entry, bool const punct, string const & fallback) const
|
2010-03-29 18:37:25 +00:00
|
|
|
{
|
2019-04-19 07:04:11 +00:00
|
|
|
string default_format = "{%fullnames:author%[[%fullnames:author%, ]][[{%fullnames:editor%[[%fullnames:editor%, ed., ]]}]]}"
|
|
|
|
"\"%title%\"{%journal%[[, {!<i>!}%journal%{!</i>!}]][[{%publisher%[[, %publisher%]]"
|
|
|
|
"[[{%institution%[[, %institution%]]}]]}]]}{%year%[[ (%year%)]]}{%pages%[[, %pages%]]}";
|
2017-01-07 16:55:38 +00:00
|
|
|
if (punct)
|
|
|
|
default_format += ".";
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
map<CiteEngineType, map<string, string> >::const_iterator itype = cite_formats_.find(type);
|
|
|
|
if (itype == cite_formats_.end())
|
|
|
|
return default_format;
|
|
|
|
map<string, string>::const_iterator it = itype->second.find(entry);
|
|
|
|
if (it == itype->second.end() && !fallback.empty())
|
|
|
|
it = itype->second.find(fallback);
|
|
|
|
if (it == itype->second.end())
|
|
|
|
return default_format;
|
2017-01-07 16:55:38 +00:00
|
|
|
if (punct)
|
|
|
|
return it->second + ".";
|
2012-03-01 00:41:30 +00:00
|
|
|
return it->second;
|
2010-03-29 18:37:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
string const & DocumentClass::getCiteMacro(CiteEngineType const & type,
|
|
|
|
string const & macro) const
|
2010-03-29 20:01:28 +00:00
|
|
|
{
|
|
|
|
static string empty;
|
2012-03-01 00:41:30 +00:00
|
|
|
map<CiteEngineType, map<string, string> >::const_iterator itype = cite_macros_.find(type);
|
|
|
|
if (itype == cite_macros_.end())
|
|
|
|
return empty;
|
|
|
|
map<string, string>::const_iterator it = itype->second.find(macro);
|
|
|
|
if (it == itype->second.end())
|
|
|
|
return empty;
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vector<string> const DocumentClass::citeCommands(
|
|
|
|
CiteEngineType const & type) const
|
|
|
|
{
|
|
|
|
vector<CitationStyle> const styles = citeStyles(type);
|
|
|
|
vector<string> cmds;
|
2020-10-31 13:09:46 +00:00
|
|
|
cmds.reserve(styles.size());
|
2020-03-16 05:08:03 +00:00
|
|
|
for (auto const & cs : styles)
|
|
|
|
cmds.push_back(cs.name);
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
return cmds;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
vector<CitationStyle> const & DocumentClass::citeStyles(
|
|
|
|
CiteEngineType const & type) const
|
|
|
|
{
|
|
|
|
static vector<CitationStyle> empty;
|
|
|
|
map<CiteEngineType, vector<CitationStyle> >::const_iterator it = cite_styles_.find(type);
|
|
|
|
if (it == cite_styles_.end())
|
|
|
|
return empty;
|
|
|
|
return it->second;
|
2010-03-29 20:01:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-16 21:23:45 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// PageSides
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2007-11-07 23:25:08 +00:00
|
|
|
ostream & operator<<(ostream & os, PageSides p)
|
2001-12-28 13:26:54 +00:00
|
|
|
{
|
|
|
|
switch (p) {
|
2007-11-07 23:25:08 +00:00
|
|
|
case OneSide:
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '1';
|
2001-12-28 13:26:54 +00:00
|
|
|
break;
|
2007-11-07 23:25:08 +00:00
|
|
|
case TwoSides:
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '2';
|
2001-12-28 13:26:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return os;
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|