+2003-09-04 Angus Leeming <leeming@lyx.org>
+
+ * external_templates: add a new PreambleDef section and use it in the
+ XFig template.
+
2003-09-04 Johnathan Burchill <jkerrb@shaw.ca>
* external_templates: add some clever LaTeX to the XFIG template so that
# Basic External Templates for LyX
+PreambleDef XFigInput
+ %% This inputs the file if it exists, else prints a warning
+ %% encased in an fbox.
+ \def\stripprefix#1>{}
+ \newcommand*{\xfiginput}[1]{%
+ \edef\tempfilename{#1}%
+ \InputIfFileExists{#1}{}{%
+ \fbox{Could not find
+ \ttfamily\expandafter\stripprefix\meaning\tempfilename
+ !}}}
+PreambleDefEnd
+
Template XFig
GuiName "[XFig: $$Basename]"
HelpText
UpdateFormat pstex
UpdateResult "$$Basename.pstex_t"
Requirement "graphicx"
- Preamble
- %% This inputs the file if it exists, else prints a warning
- %% encased in an fbox.
- \def\stripprefix#1>{}
- \newcommand*{\xfiginput}[1]{%
- \edef\tempfilename{#1}%
- \InputIfFileExists{#1}{}{%
- \fbox{Could not find
- \ttfamily\expandafter\stripprefix\meaning\tempfilename
- !}}}
- PreambleEnd
+ Preamble XFigInput
FormatEnd
Format PDFLaTeX
Product "\\xfiginput{$$Basename.pdftex_t}"
UpdateFormat pdftex
UpdateResult "$$Basename.pdftex_t"
Requirement "graphicx"
- Preamble
- %% This inputs the file if it exists, else prints a warning
- %% encased in an fbox.
- \def\stripprefix#1>{}
- \newcommand*{\xfiginput}[1]{%
- \edef\tempfilename{#1}%
- \InputIfFileExists{#1}{}{%
- \fbox{Could not find
- \ttfamily\expandafter\stripprefix\meaning\tempfilename
- !}}}
- PreambleEnd
+ Preamble XFigInput
FormatEnd
Format Ascii
Product "$$Contents(\"$$Basename.asc\")"
+2003-09-04 Angus Leeming <leeming@lyx.org>
+
+ * LaTeXFeatures.C (getMacros): move the output of the preamble_snippets
+ here (from getPackages).
+
+ * debug.[Ch]: add a new EXTERNAL tag.
+
2003-09-04 Lars Gullik Bjønnes <larsbj@lyx.org>
* text2.C (cursorEnd): simplify
packages << "]{natbib}\n";
}
- FeaturesList::const_iterator pit = preamble_snippets.begin();
- FeaturesList::const_iterator pend = preamble_snippets.end();
- for (; pit != pend; ++pit) {
- packages << *pit << '\n';
- }
-
return STRCONV(packages.str());
}
{
ostringstream macros;
+ if (!preamble_snippets.empty())
+ macros << '\n';
+ FeaturesList::const_iterator pit = preamble_snippets.begin();
+ FeaturesList::const_iterator pend = preamble_snippets.end();
+ for (; pit != pend; ++pit) {
+ macros << *pit << '\n';
+ }
+
if (isRequired("LyX"))
macros << lyx_def << '\n';
using std::ostream;
+Box::Box()
+ : x1(0), x2(0), y1(0), y2(0)
+{}
+
+
Box::Box(int x1_, int x2_, int y1_, int y2_)
: x1(x1_), x2(x2_), y1(y1_), y2(y2_)
{}
-Box::Box()
- : x1(0), x2(0), y1(0), y2(0)
-{}
bool Box::contains(int x, int y)
{
{ Debug::INSETTEXT, "insettext", N_("Insettext/tabular messages")},
{ Debug::GRAPHICS, "graphics", N_("Graphics conversion and loading")},
{ Debug::CHANGES, "changes", N_("Change tracking")},
+ { Debug::EXTERNAL, "external", N_("External template/inset messages")},
{ Debug::ANY, "any", N_("All debugging messages")}
};
Debug::MATHED | Debug::FONT | Debug::TCLASS | Debug::LYXVC |
Debug::LYXSERVER | Debug::ROFF | Debug::ACTION | Debug::LYXLEX |
Debug::DEPEND | Debug::INSETS | Debug::FILES | Debug::WORKAREA |
- Debug::INSETTEXT | Debug::GRAPHICS | Debug::CHANGES);
+ Debug::INSETTEXT | Debug::GRAPHICS | Debug::CHANGES | Debug::EXTERNAL);
Debug::type Debug::value(string const & val)
///
GRAPHICS = (1 << 21),
/// change tracking
- CHANGES = (1 << 22)
+ CHANGES = (1 << 22),
+ ///
+ EXTERNAL = (1 << 23)
};
///
static type const ANY;
up the dialogs. Cursor has to be in front of the inset (i.e.
start of row) for this to function.
+2003-09-04 Angus Leeming <leeming@lyx.org>
+
+ * ExternalTemplate.[Ch]: store the preamble snippets in a separate
+ structure outside of the Format struct. Format::preambleName refers to
+ an item in the map of all preamble snippets.
+ Make use of the new Debug::EXTERNAL flag.
+
+ * insetexternal.C: make use of the new Debug::EXTERNAL flag.
+ (validate): Small change due to the changed storage of preamble snippets.
+
2003-09-04 Angus Leeming <leeming@lyx.org>
* insetgraphics.C: #include "support/os.h"
#include "support/path.h"
#include "support/LAssert.h"
#include "support/filetools.h"
+#include "support/lstrings.h"
#include "support/path_defines.h"
#include <algorithm>
-using namespace lyx::support;
+namespace support = lyx::support;
using std::endl;
using std::ostream;
ExternalTemplateManager::ExternalTemplateManager()
{
// gimp gnuchess gnuplot ical netscape tetris xpaint
- readTemplates(user_lyxdir());
- if (lyxerr.debugging())
- dumpTemplates();
+ readTemplates(support::user_lyxdir());
+ if (lyxerr.debugging(Debug::EXTERNAL)) {
+ dumpPreambleDefs(lyxerr);
+ lyxerr << '\n';
+ dumpTemplates(lyxerr);
+ }
}
+class dumpPreambleDef {
+public:
+ typedef ExternalTemplateManager::PreambleDefs::value_type value_type;
+
+ dumpPreambleDef(ostream & o) : ost(o) {}
+
+ void operator()(value_type const & vt) {
+ ost << "PreambleDef " << vt.first << '\n'
+ << vt.second
+ << "PreambleDefEnd" << endl;
+ }
+
+private:
+ ostream & ost;
+};
+
+
class dumpTemplate {
public:
- dumpTemplate(ostream & o)
- : ost(o) {}
- void operator()(ExternalTemplateManager::Templates::value_type const & vt) {
+ typedef ExternalTemplateManager::Templates::value_type value_type;
+
+ dumpTemplate(ostream & o) : ost(o) {}
+
+ void operator()(value_type const & vt) {
ExternalTemplate const & et = vt.second;
- ost << "Template " << et.lyxName << "\n"
- << "\tGuiName " << et.guiName << "\n"
+ ost << "Template " << et.lyxName << '\n'
+ << "\tGuiName " << et.guiName << '\n'
<< "\tHelpText\n"
<< et.helpText
<< "\tHelpTextEnd\n"
- << "\tInputFormat " << et.inputFormat << "\n"
- << "\tFileFilter " << et.fileRegExp << "\n"
- << "\tEditCommand " << et.editCommand << "\n"
- << "\tAutomaticProduction " << et.automaticProduction << "\n";
+ << "\tInputFormat " << et.inputFormat << '\n'
+ << "\tFileFilter " << et.fileRegExp << '\n'
+ << "\tEditCommand " << et.editCommand << '\n'
+ << "\tAutomaticProduction " << et.automaticProduction << '\n';
et.dumpFormats(ost);
ost << "TemplateEnd" << endl;
class dumpFormat {
public:
- dumpFormat(ostream & o)
- : ost(o) {}
- void operator()(ExternalTemplate::Formats::value_type const & vt) const{
+ typedef ExternalTemplate::Formats::value_type value_type;
+
+ dumpFormat(ostream & o) : ost(o) {}
+
+ void operator()(value_type const & vt) const{
ExternalTemplate::FormatTemplate const & ft = vt.second;
- ost << "\tFormat " << vt.first << "\n"
- << "\t\tProduct " << ft.product << "\n"
- << "\t\tUpdateFormat " << ft.updateFormat << "\n"
- << "\t\tUpdateResult " << ft.updateResult << "\n"
- << "\t\tRequirement " << ft.requirement << "\n"
- << "\t\tPreamble\n"
- << ft.preamble
- << "\t\tPreambleEnd\n"
+ ost << "\tFormat " << vt.first << '\n'
+ << "\t\tProduct " << ft.product << '\n'
+ << "\t\tUpdateFormat " << ft.updateFormat << '\n'
+ << "\t\tUpdateResult " << ft.updateResult << '\n'
+ << "\t\tRequirement " << ft.requirement << '\n'
+ << "\t\tPreamble " << ft.preambleName << '\n'
<< "\tFormatEnd\n";
}
private:
}
-void ExternalTemplateManager::dumpTemplates() const
+void ExternalTemplateManager::dumpPreambleDefs(ostream & os) const
{
- for_each(templates.begin(), templates.end(), dumpTemplate(lyxerr));
+ for_each(preambledefs.begin(), preambledefs.end(), dumpPreambleDef(os));
+}
+
+
+void ExternalTemplateManager::dumpTemplates(ostream & os) const
+{
+ for_each(templates.begin(), templates.end(), dumpTemplate(os));
}
}
+string const
+ExternalTemplateManager::getPreambleDefByName(string const & name) const
+{
+ string const trimmed_name = support::trim(name);
+ if (trimmed_name.empty())
+ return string();
+
+ PreambleDefs::const_iterator it = preambledefs.find(trimmed_name);
+ if (it == preambledefs.end())
+ return string();
+
+ return it->second;
+}
+
+
void ExternalTemplateManager::readTemplates(string const & path)
{
- Path p(path);
+ support::Path p(path);
enum TemplateTags {
- TM_TEMPLATE = 1,
- TM_END
+ TM_PREAMBLEDEF = 1,
+ TM_PREAMBLEDEF_END,
+ TM_TEMPLATE,
+ TM_TEMPLATE_END
};
keyword_item templatetags[] = {
+ { "preambledef", TM_PREAMBLEDEF },
+ { "preambledefend", TM_PREAMBLEDEF_END },
{ "template", TM_TEMPLATE },
- { "templateend", TM_END }
+ { "templateend", TM_TEMPLATE_END }
};
- string filename = LibFileSearch("", "external_templates");
- if (filename.empty()) {
- lyxerr << "ExternalTemplateManager::readTemplates: "
- "No template file" << endl;
- return;
- }
+ LyXLex lex(templatetags, TM_TEMPLATE_END);
- LyXLex lex(templatetags, TM_END);
- if (!lex.setFile(filename)) {
- lyxerr << "ExternalTemplateManager::readTemplates: "
- "No template file" << endl;
+ string filename = support::LibFileSearch("", "external_templates");
+ if (filename.empty() || !lex.setFile(filename)) {
+ lex.printError("ExternalTemplateManager::readTemplates: "
+ "No template file");
return;
}
+ char const * const preamble_end_tag =
+ templatetags[TM_PREAMBLEDEF_END-1].tag;
+
while (lex.isOK()) {
switch (lex.lex()) {
+ case TM_PREAMBLEDEF: {
+ lex.next();
+ string const name = lex.getString();
+ preambledefs[name] = lex.getLongString(preamble_end_tag);
+ }
+ break;
+
case TM_TEMPLATE: {
lex.next();
- string const temp = lex.getString();
- ExternalTemplate & tmp = templates[temp];
- tmp.lyxName = temp;
+ string const name = lex.getString();
+ ExternalTemplate & tmp = templates[name];
+ tmp.lyxName = name;
tmp.readTemplate(lex);
}
break;
- case TM_END:
+ case TM_TEMPLATE_END:
lex.printError("Warning: End outside Template.");
break;
+
+ case TM_PREAMBLEDEF_END:
+ lex.printError("Warning: End outside PreambleDef.");
+ break;
}
}
}
default:
lex.printError("ExternalTemplate::readTemplate: "
"Wrong tag: $$Token");
- Assert(false);
+ support::Assert(false);
break;
}
}
break;
case FO_PREAMBLE:
- preamble = lex.getLongString("preambleend");
+ lex.next(true);
+ preambleName = lex.getString();
break;
case FO_END:
- if (lyxerr.debugging())
- lex.printError("FormatEnd");
return;
}
}
string updateFormat;
/// What features does this external inset require?
string requirement;
- /// What should be inserted into the preamble
- string preamble;
+ /// Identify the preamble snippet using \c preambleName.
+ string preambleName;
///
void readFormat(LyXLex &);
/// This constructor has to default a command for safety reasons!
public:
/// Map from the LyX name of the template to the template structure
typedef std::map<string, ExternalTemplate> Templates;
+ /** Map from the LyX name of the preamble definition to the preamble
+ * definition itself.
+ */
+ typedef std::map<string, string> PreambleDefs;
static ExternalTemplateManager & get();
Templates & getTemplates();
Templates const & getTemplates() const;
/// return the template by LyX name
ExternalTemplate const & getTemplateByName(string const & name);
+ string const getPreambleDefByName(string const & name) const;
private:
ExternalTemplateManager();
void readTemplates(string const & path);
- void dumpTemplates() const;
+ void dumpTemplates(std::ostream &) const;
+ void dumpPreambleDefs(std::ostream &) const;
+
Templates templates;
+ PreambleDefs preambledefs;
};
#endif
// Replace the inset's store
setParams(params, buffer);
- lyxerr[Debug::INFO] << "InsetExternal::Read: "
- << "template: '" << params_.templatename
- << "' filename: '" << params_.filename.absFilename()
- << "' display: '" << params_.display
- << "' scale: '" << params_.lyxscale
- << '\'' << endl;
+ lyxerr[Debug::EXTERNAL]
+ << "InsetExternal::Read: "
+ << "template: '" << params_.templatename
+ << "' filename: '" << params_.filename.absFilename()
+ << "' display: '" << params_.display
+ << "' scale: '" << params_.lyxscale
+ << '\'' << endl;
}
ExternalTemplate::Formats::const_iterator cit =
et.formats.find(format);
if (cit == et.formats.end()) {
- lyxerr << "External template format '" << format
- << "' not specified in template "
- << params_.templatename << endl;
+ lyxerr[Debug::EXTERNAL]
+ << "External template format '" << format
+ << "' not specified in template "
+ << params_.templatename << endl;
return 0;
}
return;
ExternalTemplate const & et = *et_ptr;
- ExternalTemplate::Formats::const_iterator cit =
- et.formats.find("LaTeX");
-
+ ExternalTemplate::Formats::const_iterator cit = et.formats.find("LaTeX");
if (cit == et.formats.end())
return;
- if (!cit->second.requirement.empty()) {
+ if (!cit->second.requirement.empty())
features.require(cit->second.requirement);
- }
- if (!cit->second.preamble.empty()) {
- features.addExternalPreamble(cit->second.preamble);
- }
+
+ ExternalTemplateManager & etm = ExternalTemplateManager::get();
+ string const preamble = etm.getPreambleDefByName(cit->second.preambleName);
+ if (!preamble.empty())
+ features.addExternalPreamble(preamble);
}
return;
if (!converters.isReachable(from_format, to_format)) {
- lyxerr << "InsetExternal::updateExternal. "
- "Unable to convert from "
- << from_format << " to " << to_format << endl;
+ lyxerr[Debug::EXTERNAL]
+ << "InsetExternal::updateExternal. "
+ << "Unable to convert from "
+ << from_format << " to " << to_format << endl;
return;
}
support::Path p(buffer.filePath());
support::Forkedcall call;
- if (lyxerr.debugging()) {
+ if (lyxerr.debugging(Debug::EXTERNAL)) {
lyxerr << "Executing '" << command << "' in '"
<< buffer.filePath() << '\'' << endl;
}