2003-08-04 10:26:10 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-19 10:04:35 +00:00
|
|
|
/**
|
|
|
|
* \file tex2lyx.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 10:04:35 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-08-19 10:04:35 +00:00
|
|
|
*/
|
|
|
|
|
2003-04-17 15:05:17 +00:00
|
|
|
#ifndef TEX2LYX_H
|
|
|
|
#define TEX2LYX_H
|
|
|
|
|
2007-04-26 04:53:06 +00:00
|
|
|
#include "Parser.h"
|
2007-04-29 19:53:54 +00:00
|
|
|
#include "TextClass.h"
|
2003-04-17 15:05:17 +00:00
|
|
|
|
|
|
|
#include <iosfwd>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2003-11-19 10:35:50 +00:00
|
|
|
#include <map>
|
2003-04-17 15:05:17 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2006-11-26 21:30:39 +00:00
|
|
|
namespace support { class FileName; }
|
|
|
|
|
2010-04-17 22:36:31 +00:00
|
|
|
/// Simple support for frontend::Alert::warning().
|
|
|
|
namespace frontend {
|
|
|
|
namespace Alert {
|
|
|
|
void warning(docstring const & title, docstring const & message,
|
|
|
|
bool const &);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-04 10:26:10 +00:00
|
|
|
class Context;
|
2003-04-17 15:05:17 +00:00
|
|
|
|
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
|
|
|
/// A trivial subclass, just to give us a public default constructor
|
|
|
|
class TeX2LyXDocClass : public DocumentClass
|
2011-01-23 21:10:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void setName(std::string const & name) { name_ = name; }
|
|
|
|
};
|
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
|
|
|
|
2011-01-12 21:04:39 +00:00
|
|
|
/// Translate babel language name to LyX language name
|
|
|
|
extern std::string babel2lyx(std::string const & language);
|
2013-02-17 16:53:04 +00:00
|
|
|
/// Translate LyX language name to babel language name
|
|
|
|
extern std::string lyx2babel(std::string const & language);
|
2012-06-23 02:28:52 +00:00
|
|
|
/// Translate polyglossia language name to LyX language name
|
|
|
|
extern std::string polyglossia2lyx(std::string const & language);
|
2011-10-30 18:12:49 +00:00
|
|
|
/// Translate basic color name or RGB color in LaTeX syntax to LyX color code
|
|
|
|
extern std::string rgbcolor2code(std::string const & name);
|
2003-04-17 15:05:17 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
/// in text.cpp
|
2006-03-16 15:37:35 +00:00
|
|
|
std::string translate_len(std::string const &);
|
|
|
|
|
2003-07-28 21:58:09 +00:00
|
|
|
void parse_text(Parser & p, std::ostream & os, unsigned flags, bool outer,
|
2003-08-04 10:26:10 +00:00
|
|
|
Context & context);
|
|
|
|
|
2005-07-26 11:58:43 +00:00
|
|
|
/*!
|
|
|
|
* Parses a subdocument, usually useful in insets (whence the name).
|
|
|
|
*
|
|
|
|
* It ignores \c context.need_layout and \c context.need_end_layout and
|
|
|
|
* starts and ends always a new layout.
|
|
|
|
* Therefore this may only be used to parse text in insets or table cells.
|
|
|
|
*/
|
2003-09-09 18:27:24 +00:00
|
|
|
void parse_text_in_inset(Parser & p, std::ostream & os, unsigned flags,
|
2011-01-22 12:00:33 +00:00
|
|
|
bool outer, Context const & context,
|
|
|
|
InsetLayout const * layout = 0);
|
2003-04-17 15:05:17 +00:00
|
|
|
|
2012-10-06 07:38:14 +00:00
|
|
|
/// Guess document language from \p p if CJK is used.
|
|
|
|
/// \p lang is used for all non-CJK contents.
|
|
|
|
std::string guessLanguage(Parser & p, std::string const & lang);
|
|
|
|
|
2003-04-17 15:05:17 +00:00
|
|
|
|
2007-04-26 04:53:06 +00:00
|
|
|
/// in math.cpp
|
2003-04-17 15:05:17 +00:00
|
|
|
void parse_math(Parser & p, std::ostream & os, unsigned flags, mode_type mode);
|
|
|
|
|
|
|
|
|
2007-04-26 04:53:06 +00:00
|
|
|
/// in table.cpp
|
2011-11-12 17:54:50 +00:00
|
|
|
void handle_tabular(Parser & p, std::ostream & os, std::string const & name,
|
|
|
|
std::string const & width, Context & context);
|
2003-08-04 10:26:10 +00:00
|
|
|
|
2003-04-17 15:05:17 +00:00
|
|
|
|
2007-04-26 04:53:06 +00:00
|
|
|
/// in tex2lyx.cpp
|
2011-10-16 08:22:20 +00:00
|
|
|
std::string const trimSpaceAndEol(std::string const & a);
|
2003-04-17 15:05:17 +00:00
|
|
|
|
2003-06-30 11:36:08 +00:00
|
|
|
void split(std::string const & s, std::vector<std::string> & result,
|
|
|
|
char delim = ',');
|
|
|
|
std::string join(std::vector<std::string> const & input,
|
|
|
|
char const * delim);
|
2003-04-17 15:05:17 +00:00
|
|
|
|
|
|
|
bool is_math_env(std::string const & name);
|
2011-11-13 11:29:48 +00:00
|
|
|
bool is_display_math_env(std::string const & name);
|
2004-06-28 06:53:12 +00:00
|
|
|
char const * const * is_known(std::string const &, char const * const *);
|
2003-04-17 15:05:17 +00:00
|
|
|
|
2005-01-06 13:22:20 +00:00
|
|
|
/*!
|
|
|
|
* Adds the command \p command to the list of known commands.
|
2011-01-23 21:10:20 +00:00
|
|
|
* \param o1 first optional parameter to the latex command \\newcommand
|
2008-04-29 18:11:46 +00:00
|
|
|
* (with brackets), or the empty string if there were no optional arguments.
|
2011-01-23 21:10:20 +00:00
|
|
|
* \param o2 wether \\newcommand had a second optional parameter.
|
|
|
|
* If \p definition is not empty the command is assumed to be from the LyX
|
|
|
|
* preamble and added to possible_textclass_commands.
|
2005-01-06 13:22:20 +00:00
|
|
|
*/
|
|
|
|
void add_known_command(std::string const & command, std::string const & o1,
|
2011-01-23 21:10:20 +00:00
|
|
|
bool o2, docstring const & definition = docstring());
|
|
|
|
extern void add_known_environment(std::string const & environment,
|
|
|
|
std::string const & o1, bool o2, docstring const & beg,
|
|
|
|
docstring const & end);
|
2012-10-26 20:23:16 +00:00
|
|
|
extern void add_known_theorem(std::string const & theorem,
|
|
|
|
std::string const & o1, bool o2, docstring const & definition);
|
2011-01-23 21:10:20 +00:00
|
|
|
extern Layout const * findLayoutWithoutModule(TextClass const & textclass,
|
|
|
|
std::string const & name, bool command);
|
|
|
|
extern InsetLayout const * findInsetLayoutWithoutModule(
|
|
|
|
TextClass const & textclass, std::string const & name, bool command);
|
|
|
|
/*!
|
|
|
|
* Check whether a module provides command (if \p command is true) or
|
|
|
|
* environment (if \p command is false) \p name, and add the module to the
|
|
|
|
* list of used modules if yes.
|
|
|
|
*/
|
|
|
|
extern bool checkModule(std::string const & name, bool command);
|
2012-12-28 13:29:46 +00:00
|
|
|
/// Is this feature already provided e.g. by the document class?
|
|
|
|
extern bool isProvided(std::string const & name);
|
2003-04-17 15:05:17 +00:00
|
|
|
// Access to environment stack
|
2003-04-23 15:14:43 +00:00
|
|
|
extern std::vector<std::string> active_environments;
|
|
|
|
std::string active_environment();
|
2003-04-17 15:05:17 +00:00
|
|
|
|
2003-11-19 10:35:50 +00:00
|
|
|
enum ArgumentType {
|
|
|
|
required,
|
2011-11-13 16:11:45 +00:00
|
|
|
req_group,
|
2003-11-19 10:35:50 +00:00
|
|
|
verbatim,
|
2010-12-27 20:15:24 +00:00
|
|
|
item,
|
2011-11-13 11:29:48 +00:00
|
|
|
optional,
|
2011-11-13 16:11:45 +00:00
|
|
|
opt_group,
|
2011-11-13 11:29:48 +00:00
|
|
|
displaymath,
|
2003-11-19 10:35:50 +00:00
|
|
|
};
|
|
|
|
|
2011-01-23 21:10:20 +00:00
|
|
|
class FullCommand {
|
|
|
|
public:
|
|
|
|
FullCommand() {}
|
|
|
|
FullCommand(std::vector<ArgumentType> const & a, docstring const & d)
|
|
|
|
: args(a), def(d) {}
|
|
|
|
std::vector<ArgumentType> args;
|
|
|
|
docstring def;
|
|
|
|
};
|
|
|
|
|
|
|
|
class FullEnvironment {
|
|
|
|
public:
|
|
|
|
FullEnvironment() {}
|
|
|
|
FullEnvironment(std::vector<ArgumentType> const & a,
|
|
|
|
docstring const & b, docstring const & e)
|
|
|
|
: args(a), beg(b), end(e) {}
|
|
|
|
std::vector<ArgumentType> args;
|
|
|
|
docstring beg;
|
|
|
|
docstring end;
|
|
|
|
};
|
|
|
|
|
2005-07-14 15:19:01 +00:00
|
|
|
typedef std::map<std::string, std::vector<ArgumentType> > CommandMap;
|
2011-01-23 21:10:20 +00:00
|
|
|
typedef std::map<std::string, FullCommand> FullCommandMap;
|
|
|
|
typedef std::map<std::string, FullEnvironment> FullEnvironmentMap;
|
2003-11-19 10:35:50 +00:00
|
|
|
|
2005-07-14 15:19:01 +00:00
|
|
|
/// Known TeX commands with arguments that get parsed into ERT.
|
|
|
|
extern CommandMap known_commands;
|
|
|
|
/// Known TeX environments with arguments that get parsed into ERT.
|
|
|
|
extern CommandMap known_environments;
|
|
|
|
/// Known TeX math environments with arguments that get parsed into LyX mathed.
|
|
|
|
extern CommandMap known_math_environments;
|
2011-01-23 21:10:20 +00:00
|
|
|
/// Commands that might be defined by the document class or modules
|
|
|
|
extern FullCommandMap possible_textclass_commands;
|
|
|
|
/// Environments that might be defined by the document class or modules
|
|
|
|
extern FullEnvironmentMap possible_textclass_environments;
|
2012-10-26 20:23:16 +00:00
|
|
|
/// Theorems that might be defined by the document class or modules
|
|
|
|
extern FullCommandMap possible_textclass_theorems;
|
2006-08-13 09:46:28 +00:00
|
|
|
///
|
|
|
|
extern bool noweb_mode;
|
2010-12-30 20:29:33 +00:00
|
|
|
/// Did we recognize any pdflatex-only construct?
|
|
|
|
extern bool pdflatex;
|
2011-11-06 17:03:59 +00:00
|
|
|
/// Did we recognize any xetex-only construct?
|
|
|
|
extern bool xetex;
|
2012-06-24 16:10:36 +00:00
|
|
|
/// Do we have non-CJK Japanese?
|
|
|
|
extern bool is_nonCJKJapanese;
|
2010-12-12 11:45:09 +00:00
|
|
|
/// LyX format that is created by tex2lyx
|
2011-10-23 10:29:21 +00:00
|
|
|
extern int const LYX_FORMAT;
|
2004-07-29 17:03:37 +00:00
|
|
|
|
2012-10-03 11:23:27 +00:00
|
|
|
/// Absolute path of the master .lyx or .tex file
|
|
|
|
extern std::string getMasterFilePath(bool input);
|
|
|
|
/// Absolute path of the currently processed .lyx or .tex file
|
|
|
|
extern std::string getParentFilePath(bool input);
|
|
|
|
/// Is it allowed to overwrite existing files?
|
|
|
|
extern bool overwriteFiles();
|
|
|
|
/// Do we need to copy included files to the output directory?
|
|
|
|
extern bool copyFiles();
|
2012-10-18 20:01:32 +00:00
|
|
|
/// Shall we skip child documents and keep them as TeX?
|
|
|
|
extern bool skipChildren();
|
2013-05-26 14:06:11 +00:00
|
|
|
/// Does tex2lyx run in roundtrip mode?
|
|
|
|
extern bool roundtripMode();
|
2004-07-29 17:03:37 +00:00
|
|
|
|
|
|
|
|
2005-05-25 16:01:19 +00:00
|
|
|
/*!
|
|
|
|
* Reads tex input from \a infilename and writes lyx output to \a outfilename.
|
2013-01-19 18:47:15 +00:00
|
|
|
* The iconv name of the encoding can be provided as \a encoding.
|
2003-10-23 11:46:33 +00:00
|
|
|
* Uses some common settings for the preamble, so this should only
|
|
|
|
* be used more than once for included documents.
|
|
|
|
* Caution: Overwrites the existing preamble settings if the new document
|
2005-05-25 16:01:19 +00:00
|
|
|
* contains a preamble.
|
|
|
|
* \return true if the conversion was successful, else false.
|
|
|
|
*/
|
2009-01-30 14:47:06 +00:00
|
|
|
bool tex2lyx(std::string const & infilename,
|
|
|
|
support::FileName const & outfilename,
|
|
|
|
std::string const & encoding);
|
2003-10-23 11:46:33 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
2003-04-17 15:05:17 +00:00
|
|
|
#endif
|