Merge: Remove tex2lyx defines to allow for newer automake

Automake version 1.14 warns that subdir-objects needs to be
enabled to avoid future incompatibilities. However, this causes problems
for objects that are compiled twice (for LyX and tex2lyx) with different
defines (e.g., TEX2LYX and NO_LAYOUT_CSS). Therefore, we need to properly
fix the code without using these defines.

See also:
 - commit 16cdf70d (Jul 26, 2013),
 - commit 3698fde0 (Aug 19, 2013), and
 - http://marc.info/?l=lyx-devel&m=137673178123427&w=2.
This commit is contained in:
Vincent van Ravesteijn 2013-09-29 16:46:35 +02:00
commit c6c07d28ae
18 changed files with 470 additions and 304 deletions

View File

@ -27,7 +27,7 @@ fi
AM_MAINTAINER_MODE
save_PACKAGE=$PACKAGE
AM_INIT_AUTOMAKE([foreign dist-bzip2 no-define 1.8])
AM_INIT_AUTOMAKE([foreign dist-bzip2 no-define 1.8 subdir-objects])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
PACKAGE=$save_PACKAGE

View File

@ -28,7 +28,7 @@
#include "CutAndPaste.h"
#include "DispatchResult.h"
#include "DocIterator.h"
#include "Encoding.h"
#include "BufferEncodings.h"
#include "ErrorList.h"
#include "Exporter.h"
#include "Format.h"
@ -1558,7 +1558,7 @@ void Buffer::writeLaTeXSource(otexstream & os,
d->ignore_parent = true;
// Classify the unicode characters appearing in math insets
Encodings::initUnicodeMath(*this);
BufferEncodings::initUnicodeMath(*this);
// validate the buffer.
LYXERR(Debug::LATEX, " Validating buffer...");

109
src/BufferEncodings.cpp Normal file
View File

@ -0,0 +1,109 @@
/**
* \file BufferEncodings.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
* \author Dekel Tsur
* \author Stephan Witt
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "BufferEncodings.h"
#include "Buffer.h"
#include "InsetIterator.h"
#include "LaTeXFeatures.h"
#include "support/lstrings.h"
using namespace std;
using namespace lyx::support;
namespace lyx {
void BufferEncodings::initUnicodeMath(Buffer const & buffer, bool for_master)
{
if (for_master) {
mathcmd.clear();
textcmd.clear();
mathsym.clear();
}
// Check this buffer
Inset & inset = buffer.inset();
InsetIterator it = inset_iterator_begin(inset);
InsetIterator const end = inset_iterator_end(inset);
for (; it != end; ++it)
it->initUnicodeMath();
if (!for_master)
return;
// Check children
ListOfBuffers blist = buffer.getDescendents();
ListOfBuffers::const_iterator bit = blist.begin();
ListOfBuffers::const_iterator const bend = blist.end();
for (; bit != bend; ++bit)
initUnicodeMath(**bit, false);
}
void BufferEncodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed)
{
CharInfo const & ci = Encodings::unicodeCharInfo(c);
if (ci.isUnicodeSymbol()) {
// In mathed, c could be used both in textmode and mathmode
docstring const textcommand = ci.textcommand();
bool const math_mode = for_mathed && isMathCmd(c);
bool const use_math = math_mode ||
(!for_mathed && textcommand.empty());
bool const use_text = (for_mathed && isTextCmd(c)) ||
(!for_mathed && !textcommand.empty());
bool const plain_utf8 = (features.runparams().encoding->name() == "utf8-plain");
bool const unicode_math = (features.isRequired("unicode-math")
&& features.isAvailable("unicode-math"));
// with utf8-plain, we only load packages when in mathed (see #7766)
// and if we do not use unicode-math
if ((math_mode && !unicode_math)
|| (use_math && !plain_utf8)) {
string const mathpreamble = ci.mathpreamble();
if (!mathpreamble.empty()) {
if (ci.mathfeature()) {
string feats = mathpreamble;
while (!feats.empty()) {
string feat;
feats = split(feats, feat, ',');
features.require(feat);
}
} else
features.addPreambleSnippet(mathpreamble);
}
}
// with utf8-plain, we do not load packages (see #7766)
if (use_text && !plain_utf8) {
string const textpreamble = ci.textpreamble();
if (!textpreamble.empty()) {
if (ci.textfeature()) {
string feats = textpreamble;
while (!feats.empty()) {
string feat;
feats = split(feats, feat, ',');
features.require(feat);
}
} else
features.addPreambleSnippet(textpreamble);
}
}
}
if (for_mathed && isMathSym(c)) {
features.require("amstext");
features.require("lyxmathsym");
}
}
} // namespace lyx

44
src/BufferEncodings.h Normal file
View File

@ -0,0 +1,44 @@
// -*- C++ -*-
/**
* \file BufferEncodings.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
* \author Stephan Witt
*
* Full author contact details are available in file CREDITS.
*/
#ifndef BUFFER_ENCODINGS_H
#define BUFFER_ENCODINGS_H
#include "Encoding.h"
#include "support/docstring.h"
#include "support/types.h"
namespace lyx {
class Buffer;
class LaTeXFeatures;
class BufferEncodings : public Encodings {
public:
/**
* Initialize mathcmd, textcmd, and mathsym sets.
*/
static void initUnicodeMath(Buffer const & buffer, bool for_master = true);
/**
* If \p c cannot be encoded in the given \p encoding, convert
* it to something that LaTeX can understand in mathmode.
* \p needsTermination indicates whether the command needs to be
* terminated by {} or a space.
* \return whether \p command is a mathmode command
*/
static void validate(char_type c, LaTeXFeatures & features, bool for_mathed = false);
};
} // namespace lyx
#endif // BUFFER_ENCODINGS_H

View File

@ -14,16 +14,10 @@
#include "Encoding.h"
#include "Buffer.h"
#include "BufferList.h"
#include "InsetIterator.h"
#include "LaTeXFeatures.h"
#include "Lexer.h"
#include "LyXRC.h"
#include "support/debug.h"
#include "support/gettext.h"
#include "support/FileName.h"
#include "support/lstrings.h"
#include "support/textutils.h"
#include "support/unicode.h"
@ -231,57 +225,6 @@ char_type const arabic_start = 0x0621;
char_type const arabic_end = 0x06cc;
enum CharInfoFlags {
///
CharInfoCombining = 1,
///
CharInfoTextFeature = 2,
///
CharInfoMathFeature = 4,
///
CharInfoForce = 8,
///
CharInfoTextNoTermination = 16,
///
CharInfoMathNoTermination = 32,
///
CharInfoForceSelected = 64,
};
/// Information about a single UCS4 character
struct CharInfo {
/// LaTeX command (text mode) for this character
docstring textcommand;
/// LaTeX command (math mode) for this character
docstring mathcommand;
/// Needed LaTeX preamble (or feature) for text mode
string textpreamble;
/// Needed LaTeX preamble (or feature) for math mode
string mathpreamble;
/// Is this a combining character?
bool combining() const { return flags & CharInfoCombining ? true : false; }
/// Is \c textpreamble a feature known by LaTeXFeatures, or a raw LaTeX
/// command?
bool textfeature() const { return flags & CharInfoTextFeature ? true : false; }
/// Is \c mathpreamble a feature known by LaTeXFeatures, or a raw LaTeX
/// command?
bool mathfeature() const { return flags & CharInfoMathFeature ? true : false; }
/// Always force the LaTeX command, even if the encoding contains
/// this character?
bool force() const { return flags & CharInfoForce ? true : false; }
/// Force the LaTeX command for some encodings?
bool forceselected() const { return flags & CharInfoForceSelected ? true : false; }
/// TIPA shortcut
string tipashortcut;
/// \c textcommand needs no termination (such as {} or space).
bool textnotermination() const { return flags & CharInfoTextNoTermination ? true : false; }
/// \c mathcommand needs no termination (such as {} or space).
bool mathnotermination() const { return flags & CharInfoMathNoTermination ? true : false; }
///
unsigned int flags;
};
typedef map<char_type, CharInfo> CharInfoMap;
CharInfoMap unicodesymbols;
@ -312,6 +255,16 @@ const char * EncodingException::what() const throw()
}
CharInfo::CharInfo(
docstring const textcommand, docstring const mathcommand,
std::string const textpreamble, std::string const mathpreamble,
std::string const tipashortcut, unsigned int flags)
: textcommand_(textcommand), mathcommand_(mathcommand),
textpreamble_(textpreamble), mathpreamble_(mathpreamble),
tipashortcut_(tipashortcut), flags_(flags)
{
}
Encoding::Encoding(string const & n, string const & l, string const & g,
string const & i, bool f, bool u, Encoding::Package p)
: name_(n), latexName_(l), guiName_(g), iconvName_(i), fixedwidth_(f),
@ -419,10 +372,10 @@ pair<docstring, bool> Encoding::latexChar(char_type c) const
if (it == unicodesymbols.end())
throw EncodingException(c);
// at least one of mathcommand and textcommand is nonempty
if (it->second.textcommand.empty())
if (it->second.textcommand().empty())
return make_pair(
"\\ensuremath{" + it->second.mathcommand + '}', false);
return make_pair(it->second.textcommand, !it->second.textnotermination());
"\\ensuremath{" + it->second.mathcommand() + '}', false);
return make_pair(it->second.textcommand(), !it->second.textnotermination());
}
@ -502,15 +455,15 @@ bool Encodings::latexMathChar(char_type c, bool mathmode,
return false;
}
// at least one of mathcommand and textcommand is nonempty
bool use_math = (mathmode && !it->second.mathcommand.empty()) ||
(!mathmode && it->second.textcommand.empty());
bool use_math = (mathmode && !it->second.mathcommand().empty()) ||
(!mathmode && it->second.textcommand().empty());
if (use_math) {
command = it->second.mathcommand;
command = it->second.mathcommand();
needsTermination = !it->second.mathnotermination();
addMathCmd(c);
} else {
if (!encoding || command.empty()) {
command = it->second.textcommand;
command = it->second.textcommand();
needsTermination = !it->second.textnotermination();
addTextCmd(c);
}
@ -527,22 +480,22 @@ char_type Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
CharInfoMap::const_iterator const end = unicodesymbols.end();
CharInfoMap::const_iterator it = unicodesymbols.begin();
for (combining = false; it != end; ++it) {
docstring const math = it->second.mathcommand;
docstring const text = it->second.textcommand;
docstring const math = it->second.mathcommand();
docstring const text = it->second.textcommand();
if ((cmdtype & MATH_CMD) && math == cmd) {
combining = it->second.combining();
needsTermination = !it->second.mathnotermination();
if (req && it->second.mathfeature() &&
!it->second.mathpreamble.empty())
req->insert(it->second.mathpreamble);
!it->second.mathpreamble().empty())
req->insert(it->second.mathpreamble());
return it->first;
}
if ((cmdtype & TEXT_CMD) && text == cmd) {
combining = it->second.combining();
needsTermination = !it->second.textnotermination();
if (req && it->second.textfeature() &&
!it->second.textpreamble.empty())
req->insert(it->second.textpreamble);
!it->second.textpreamble().empty())
req->insert(it->second.textpreamble());
return it->first;
}
}
@ -609,9 +562,9 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
size_t unicmd_size = 0;
char_type c = 0;
for (; it != uniend; ++it) {
docstring const math = mathmode ? it->second.mathcommand
docstring const math = mathmode ? it->second.mathcommand()
: docstring();
docstring const text = textmode ? it->second.textcommand
docstring const text = textmode ? it->second.textcommand()
: docstring();
if (!combcmd.empty() && it->second.combining() &&
(math == combcmd || text == combcmd))
@ -689,11 +642,11 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
needsTermination = !it->second.textnotermination();
if (req) {
if (math == tmp && it->second.mathfeature() &&
!it->second.mathpreamble.empty())
req->insert(it->second.mathpreamble);
!it->second.mathpreamble().empty())
req->insert(it->second.mathpreamble());
if (text == tmp && it->second.textfeature() &&
!it->second.textpreamble.empty())
req->insert(it->second.textpreamble);
!it->second.textpreamble().empty())
req->insert(it->second.textpreamble());
}
}
}
@ -751,97 +704,6 @@ docstring Encodings::fromLaTeXCommand(docstring const & cmd, int cmdtype,
}
void Encodings::initUnicodeMath(Buffer const & buffer, bool for_master)
{
#ifdef TEX2LYX
// The code below is not needed in tex2lyx and requires additional stuff
(void)buffer;
(void)for_master;
#else
if (for_master) {
mathcmd.clear();
textcmd.clear();
mathsym.clear();
}
// Check this buffer
Inset & inset = buffer.inset();
InsetIterator it = inset_iterator_begin(inset);
InsetIterator const end = inset_iterator_end(inset);
for (; it != end; ++it)
it->initUnicodeMath();
if (!for_master)
return;
// Check children
ListOfBuffers blist = buffer.getDescendents();
ListOfBuffers::const_iterator bit = blist.begin();
ListOfBuffers::const_iterator const bend = blist.end();
for (; bit != bend; ++bit)
initUnicodeMath(**bit, false);
#endif
}
void Encodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed)
{
#ifdef TEX2LYX
// The code below is not needed in tex2lyx and requires additional stuff
(void)c;
(void)features;
(void)for_mathed;
#else
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
if (it != unicodesymbols.end()) {
// In mathed, c could be used both in textmode and mathmode
bool const math_mode = for_mathed && isMathCmd(c);
bool const use_math = math_mode ||
(!for_mathed && it->second.textcommand.empty());
bool const use_text = (for_mathed && isTextCmd(c)) ||
(!for_mathed && !it->second.textcommand.empty());
bool const plain_utf8 = (features.runparams().encoding->name() == "utf8-plain");
bool const unicode_math = (features.isRequired("unicode-math")
&& features.isAvailable("unicode-math"));
// with utf8-plain, we only load packages when in mathed (see #7766)
// and if we do not use unicode-math
if ((math_mode && !unicode_math)
|| (use_math && !plain_utf8)) {
if (!it->second.mathpreamble.empty()) {
if (it->second.mathfeature()) {
string feats = it->second.mathpreamble;
while (!feats.empty()) {
string feat;
feats = split(feats, feat, ',');
features.require(feat);
}
} else
features.addPreambleSnippet(it->second.mathpreamble);
}
}
// with utf8-plain, we do not load packages (see #7766)
if (use_text && !plain_utf8) {
if (!it->second.textpreamble.empty()) {
if (it->second.textfeature()) {
string feats = it->second.textpreamble;
while (!feats.empty()) {
string feat;
feats = split(feats, feat, ',');
features.require(feat);
}
} else
features.addPreambleSnippet(it->second.textpreamble);
}
}
}
if (for_mathed && isMathSym(c)) {
features.require("amstext");
features.require("lyxmathsym");
}
#endif
}
bool Encodings::isHebrewComposeChar(char_type c)
{
return c <= 0x05c2 && c >= 0x05b0 && c != 0x05be && c != 0x05c0;
@ -873,6 +735,14 @@ bool Encodings::isArabicChar(char_type c)
}
CharInfo const & Encodings::unicodeCharInfo(char_type c)
{
static CharInfo empty;
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
return it != unicodesymbols.end() ? it->second : empty;
}
char_type Encodings::transformChar(char_type c, Encodings::LetterForm form)
{
return isArabicChar(c) ? arabic_table[c-arabic_start][form] : c;
@ -892,7 +762,7 @@ string const Encodings::TIPAShortcut(char_type c)
{
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
if (it != unicodesymbols.end())
return it->second.tipashortcut;
return it->second.tipashortcut();
return string();
}
@ -904,14 +774,14 @@ bool Encodings::isKnownScriptChar(char_type const c, string & preamble)
if (it == unicodesymbols.end())
return false;
if (it->second.textpreamble != "textgreek" && it->second.textpreamble != "textcyr")
if (it->second.textpreamble() != "textgreek" && it->second.textpreamble() != "textcyr")
return false;
if (preamble.empty()) {
preamble = it->second.textpreamble;
preamble = it->second.textpreamble();
return true;
}
return it->second.textpreamble == preamble;
return it->second.textpreamble() == preamble;
}
@ -980,8 +850,6 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
bool getNextToken = true;
while (symbolslex.isOK()) {
char_type symbol;
CharInfo info;
string flags;
if (getNextToken) {
if (!symbolslex.next(true))
@ -999,53 +867,53 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
if (!symbolslex.next(true))
break;
info.textcommand = symbolslex.getDocString();
docstring textcommand = symbolslex.getDocString();
if (!symbolslex.next(true))
break;
info.textpreamble = symbolslex.getString();
string textpreamble = symbolslex.getString();
if (!symbolslex.next(true))
break;
flags = symbolslex.getString();
string sflags = symbolslex.getString();
string tipashortcut;
int flags = 0;
info.flags = 0;
if (suffixIs(info.textcommand, '}'))
info.flags |= CharInfoTextNoTermination;
if (suffixIs(info.mathcommand, '}'))
info.flags |= CharInfoMathNoTermination;
while (!flags.empty()) {
if (suffixIs(textcommand, '}'))
flags |= CharInfoTextNoTermination;
while (!sflags.empty()) {
string flag;
flags = split(flags, flag, ',');
sflags = split(sflags, flag, ',');
if (flag == "combining") {
info.flags |= CharInfoCombining;
flags |= CharInfoCombining;
} else if (flag == "force") {
info.flags |= CharInfoForce;
flags |= CharInfoForce;
forced.insert(symbol);
} else if (prefixIs(flag, "force=")) {
vector<string> encodings =
getVectorFromString(flag.substr(6), ";");
for (size_t i = 0; i < encodings.size(); ++i)
forcedselected[encodings[i]].insert(symbol);
info.flags |= CharInfoForceSelected;
flags |= CharInfoForceSelected;
} else if (prefixIs(flag, "force!=")) {
vector<string> encodings =
getVectorFromString(flag.substr(7), ";");
for (size_t i = 0; i < encodings.size(); ++i)
forcednotselected[encodings[i]].insert(symbol);
info.flags |= CharInfoForceSelected;
flags |= CharInfoForceSelected;
} else if (flag == "mathalpha") {
mathalpha.insert(symbol);
} else if (flag == "notermination=text") {
info.flags |= CharInfoTextNoTermination;
flags |= CharInfoTextNoTermination;
} else if (flag == "notermination=math") {
info.flags |= CharInfoMathNoTermination;
flags |= CharInfoMathNoTermination;
} else if (flag == "notermination=both") {
info.flags |= CharInfoTextNoTermination;
info.flags |= CharInfoMathNoTermination;
flags |= CharInfoTextNoTermination;
flags |= CharInfoMathNoTermination;
} else if (flag == "notermination=none") {
info.flags &= ~CharInfoTextNoTermination;
info.flags &= ~CharInfoMathNoTermination;
flags &= ~CharInfoTextNoTermination;
flags &= ~CharInfoMathNoTermination;
} else if (contains(flag, "tipashortcut=")) {
info.tipashortcut = split(flag, '=');
tipashortcut = split(flag, '=');
} else {
lyxerr << "Ignoring unknown flag `" << flag
<< "' for symbol `0x"
@ -1057,19 +925,23 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
// make them optional so that old files still work.
int const lineno = symbolslex.lineNumber();
bool breakout = false;
docstring mathcommand;
string mathpreamble;
if (symbolslex.next(true)) {
if (symbolslex.lineNumber() != lineno) {
// line in old format without mathcommand and mathpreamble
getNextToken = false;
} else {
info.mathcommand = symbolslex.getDocString();
mathcommand = symbolslex.getDocString();
if (suffixIs(mathcommand, '}'))
flags |= CharInfoMathNoTermination;
if (symbolslex.next(true)) {
if (symbolslex.lineNumber() != lineno) {
// line in new format with mathcommand only
getNextToken = false;
} else {
// line in new format with mathcommand and mathpreamble
info.mathpreamble = symbolslex.getString();
mathpreamble = symbolslex.getString();
}
} else
breakout = true;
@ -1079,27 +951,32 @@ void Encodings::read(FileName const & encfile, FileName const & symbolsfile)
}
// backward compatibility
if (info.mathpreamble == "esintoramsmath")
info.mathpreamble = "esint|amsmath";
if (mathpreamble == "esintoramsmath")
mathpreamble = "esint|amsmath";
if (!info.textpreamble.empty())
if (info.textpreamble[0] != '\\')
info.flags |= CharInfoTextFeature;
if (!info.mathpreamble.empty())
if (info.mathpreamble[0] != '\\')
info.flags |= CharInfoMathFeature;
if (!textpreamble.empty())
if (textpreamble[0] != '\\')
flags |= CharInfoTextFeature;
if (!mathpreamble.empty())
if (mathpreamble[0] != '\\')
flags |= CharInfoMathFeature;
CharInfo info = CharInfo(
textcommand, mathcommand,
textpreamble, mathpreamble,
tipashortcut, flags);
LYXERR(Debug::INFO, "Read unicode symbol " << symbol << " '"
<< to_utf8(info.textcommand) << "' '" << info.textpreamble
<< " '" << info.textfeature() << ' ' << info.textnotermination()
<< ' ' << to_utf8(info.mathcommand) << "' '" << info.mathpreamble
<< "' " << info.mathfeature() << ' ' << info.mathnotermination()
<< ' ' << info.combining() << ' ' << info.force()
<< ' ' << info.forceselected());
<< to_utf8(info.textcommand()) << "' '" << info.textpreamble()
<< " '" << info.textfeature() << ' ' << info.textnotermination()
<< ' ' << to_utf8(info.mathcommand()) << "' '" << info.mathpreamble()
<< "' " << info.mathfeature() << ' ' << info.mathnotermination()
<< ' ' << info.combining() << ' ' << info.force()
<< ' ' << info.forceselected());
// we assume that at least one command is nonempty when using unicodesymbols
if (!info.textcommand.empty() || !info.mathcommand.empty())
if (info.isUnicodeSymbol()) {
unicodesymbols[symbol] = info;
}
if (breakout)
break;

View File

@ -24,9 +24,6 @@ namespace lyx {
namespace support { class FileName; }
class Buffer;
class LaTeXFeatures;
class EncodingException : public std::exception {
public:
EncodingException(char_type c);
@ -39,6 +36,78 @@ public:
};
enum CharInfoFlags {
///
CharInfoCombining = 1,
///
CharInfoTextFeature = 2,
///
CharInfoMathFeature = 4,
///
CharInfoForce = 8,
///
CharInfoTextNoTermination = 16,
///
CharInfoMathNoTermination = 32,
///
CharInfoForceSelected = 64,
};
/// Information about a single UCS4 character
class CharInfo {
public:
CharInfo() {}
CharInfo(
docstring const textcommand, docstring const mathcommand,
std::string const textpreamble, std::string const mathpreamble,
std::string const tipashortcut, unsigned int flags);
// we assume that at least one command is nonempty when using unicodesymbols
bool isUnicodeSymbol() const { return !textcommand_.empty() || !mathcommand_.empty(); }
/// LaTeX command (text mode) for this character
docstring const textcommand() const { return textcommand_; }
/// LaTeX command (math mode) for this character
docstring mathcommand() const { return mathcommand_; }
/// Needed LaTeX preamble (or feature) for text mode
std::string textpreamble() const { return textpreamble_; }
/// Needed LaTeX preamble (or feature) for math mode
std::string mathpreamble() const { return mathpreamble_; }
/// Is this a combining character?
bool combining() const { return flags_ & CharInfoCombining ? true : false; }
/// Is \c textpreamble a feature known by LaTeXFeatures, or a raw LaTeX
/// command?
bool textfeature() const { return flags_ & CharInfoTextFeature ? true : false; }
/// Is \c mathpreamble a feature known by LaTeXFeatures, or a raw LaTeX
/// command?
bool mathfeature() const { return flags_ & CharInfoMathFeature ? true : false; }
/// Always force the LaTeX command, even if the encoding contains
/// this character?
bool force() const { return flags_ & CharInfoForce ? true : false; }
/// Force the LaTeX command for some encodings?
bool forceselected() const { return flags_ & CharInfoForceSelected ? true : false; }
/// TIPA shortcut
std::string const tipashortcut() const { return tipashortcut_; }
/// \c textcommand needs no termination (such as {} or space).
bool textnotermination() const { return flags_ & CharInfoTextNoTermination ? true : false; }
/// \c mathcommand needs no termination (such as {} or space).
bool mathnotermination() const { return flags_ & CharInfoMathNoTermination ? true : false; }
///
private:
/// LaTeX command (text mode) for this character
docstring textcommand_;
/// LaTeX command (math mode) for this character
docstring mathcommand_;
/// Needed LaTeX preamble (or feature) for text mode
std::string textpreamble_;
/// Needed LaTeX preamble (or feature) for math mode
std::string mathpreamble_;
/// TIPA shortcut
std::string tipashortcut_;
/// feature flags
unsigned int flags_;
};
///
class Encoding {
public:
@ -205,6 +274,8 @@ public:
static bool isArabicSpecialChar(char_type c);
///
static bool isArabicChar(char_type c);
/// Accessor for the unicode information table.
static CharInfo const & unicodeCharInfo(char_type c);
///
static char_type transformChar(char_type c, LetterForm form);
/// Is this a combining char?
@ -250,10 +321,6 @@ public:
* Tell whether \p c is registered as a mathmode symbol.
*/
static bool isMathSym(char_type c) { return mathsym.count(c); }
/**
* Initialize mathcmd, textcmd, and mathsym sets.
*/
static void initUnicodeMath(Buffer const & buffer, bool for_master = true);
/**
* If \p c cannot be encoded in the given \p encoding, convert
* it to something that LaTeX can understand in mathmode.
@ -293,16 +360,8 @@ public:
static docstring fromLaTeXCommand(docstring const & cmd, int cmdtype,
bool & needsTermination, docstring & rem,
std::set<std::string> * req = 0);
/**
* Add the preamble snippet needed for the output of \p c to
* \p features.
* This does not depend on the used encoding, since the inputenc
* package only maps the code point \p c to a command, it does not
* make this command available.
*/
static void validate(char_type c, LaTeXFeatures & features, bool for_mathed = false);
private:
protected:
///
EncodingList encodinglist;
///

View File

@ -1505,14 +1505,11 @@ void Layout::makeDefaultCSS() const
htmldefaultstyle_ += from_ascii(tmp);
}
// tex2lyx does not see output_xhtml.cpp
#ifndef NO_LAYOUT_CSS
// alignment
string where = alignmentToCSS(align);
if (!where.empty()) {
htmldefaultstyle_ += from_ascii("text-align: " + where + ";\n");
}
#endif
// wrap up what we have, if anything
if (!htmldefaultstyle_.empty())

View File

@ -238,14 +238,8 @@ void Lexer::Pimpl::popTable()
bool Lexer::Pimpl::setFile(FileName const & filename)
{
#ifdef TEX2LYX
// tex2lyx does not read lyxrc and therefore can't really check for
// zipped formats.
if (false) {
#else
// Check the format of the file.
if (formats.isZippedFile(filename)) {
#endif
LYXERR(Debug::LYXLEX, "lyxlex: compressed");
// The check only outputs a debug message, because it triggers
// a bug in compaq cxx 6.2, where is_open() returns 'true' for

View File

@ -119,6 +119,7 @@ SOURCEFILESCORE = \
DepTable.cpp \
DocIterator.cpp \
Encoding.cpp \
BufferEncodings.cpp \
ErrorList.cpp \
Exporter.cpp \
factory.cpp \
@ -194,6 +195,7 @@ HEADERFILESCORE = \
BranchList.h \
buffer_funcs.h \
Buffer.h \
BufferEncodings.h \
BufferList.h \
BufferParams.h \
BufferView.h \
@ -689,7 +691,7 @@ if INSTALL_MACOSX
ADD_FRAMEWORKS = -framework QtGui -framework QtCore -framework AppKit -framework ApplicationServices
endif
check_layout_CPPFLAGS = $(AM_CPPFLAGS) -DNO_LAYOUT_CSS
check_layout_CPPFLAGS = $(AM_CPPFLAGS)
check_layout_LDADD = support/liblyxsupport.a $(LIBICONV) $(BOOST_LIBS) @LIBS@ $(QT4_CORE_LIBS) $(LIBSHLWAPI)
check_layout_LDFLAGS = $(QT4_CORE_LDFLAGS) $(ADD_FRAMEWORKS)
check_layout_SOURCES = \

View File

@ -48,21 +48,14 @@ LyXModule::LyXModule(string const & n, string const & i,
vector<string> LyXModule::prerequisites() const
{
#ifdef TEX2LYX
return vector<string>();
#else
if (!checked_)
isAvailable();
return prerequisites_;
#endif
}
bool LyXModule::isAvailable() const
{
#ifdef TEX2LYX
return true;
#else
if (package_list_.empty())
return true;
if (checked_)
@ -79,7 +72,6 @@ bool LyXModule::isAvailable() const
}
}
return available_;
#endif
}

View File

@ -25,7 +25,7 @@
#include "BufferParams.h"
#include "Changes.h"
#include "Counters.h"
#include "Encoding.h"
#include "BufferEncodings.h"
#include "InsetList.h"
#include "Language.h"
#include "LaTeXFeatures.h"
@ -1528,7 +1528,7 @@ void Paragraph::Private::validate(LaTeXFeatures & features) const
break;
}
}
Encodings::validate(text_[i], features);
BufferEncodings::validate(text_[i], features);
}
}

View File

@ -18,7 +18,7 @@
#include "MetricsInfo.h"
#include "Dimension.h"
#include "Encoding.h"
#include "BufferEncodings.h"
#include "LaTeXFeatures.h"
#include "TextPainter.h"
@ -141,7 +141,7 @@ void InsetMathChar::write(WriteStream & os) const
void InsetMathChar::validate(LaTeXFeatures & features) const
{
if (!isASCII(char_))
encodings.validate(char_, features, true);
BufferEncodings::validate(char_, features, true);
}

View File

@ -8,6 +8,11 @@ namespace lyx {
// Dummy LyXRC support
class LyXRC { string icon_set; } lyxrc;
// Dummy LyXAlignment support
enum LyXAlignment {
DUMMY
};
// Keep the linker happy on Windows
void lyx_exit(int) {}
@ -24,4 +29,10 @@ namespace lyx {
return lyx_messages;
}
string alignmentToCSS(LyXAlignment)
{
return string();
}
}

View File

@ -12,7 +12,6 @@ foreach(_f insets/InsetLayout.cpp Color.cpp Counters.cpp Floating.cpp
list(APPEND check_layout_SOURCES "${TOP_SRC_DIR}/src/${_f}")
endforeach()
add_definitions(-DNO_LAYOUT_CSS)
add_executable(check_layout ${check_layout_SOURCES})
target_link_libraries(check_layout support

View File

@ -29,9 +29,6 @@ include_directories(BEFORE
${TOP_SRC_DIR}/src/support/minizip
${ZLIB_INCLUDE_DIR})
add_definitions(-DTEX2LYX)
add_definitions(-DNO_LAYOUT_CSS)
if(WIN32)
set(FILE_RC ${TOP_CMAKE_PATH}/lyx.rc)
message(STATUS "Using icon defined in resource file: ${FILE_RC}")

View File

@ -16,7 +16,7 @@ bin_PROGRAMS = tex2lyx
DEFAULT_INCLUDES =
AM_CPPFLAGS += -DTEX2LYX -DNO_LAYOUT_CSS $(PCH_FLAGS) -I$(top_srcdir)/src/tex2lyx \
AM_CPPFLAGS += $(PCH_FLAGS) -I$(top_srcdir)/src/tex2lyx \
-I$(top_srcdir)/src -I$(top_builddir) $(BOOST_INCLUDES)
TEST_FILES = \
@ -97,6 +97,7 @@ tex2lyx_SOURCES = \
boost.cpp \
Context.cpp \
Context.h \
dummy_impl.cpp \
math.cpp \
Parser.cpp \
Parser.h \

131
src/tex2lyx/dummy_impl.cpp Normal file
View File

@ -0,0 +1,131 @@
/**
* \file dummy_impl.cpp
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS.
*/
/**
* This file contains dummy implementation of some methods that are
* needed byclasses used by tex2lyx. This allows to reduce the number
* of classes we have to link against.
*/
// {[(
#include <config.h>
#include "Format.h"
#include "LaTeXFeatures.h"
#include "LyXRC.h"
#include "output_xhtml.h"
#include "support/Messages.h"
#include <iostream>
using namespace std;
namespace lyx {
//
// Dummy Alert support (needed by TextClass)
//
namespace frontend {
namespace Alert {
void warning(docstring const & title, docstring const & message,
bool const &)
{
cerr << to_utf8(title) << "\n" << to_utf8(message) << endl;
}
}
}
//
// Dummy TexRow support (needed by docstream)
//
void TexRow::newline()
{}
void TexRow::newlines(int)
{}
//
// Dummy LyXRC support
//
LyXRC lyxrc;
/** Note that some variables are not initialized correctly. Hopefully
* they are not used in our code (currently valgrind does not complain).
* Linking against the full LyXRC.cpp forces us to pull too much
* stuff.
*/
LyXRC::LyXRC()
{}
//
// Dummy translation support (needed at many places)
//
Messages messages_;
Messages const & getMessages(string const &)
{
return messages_;
}
Messages const & getGuiMessages()
{
return messages_;
}
//
// Dummy formats support (needed by Lexer)
//
Formats formats;
bool Formats::isZippedFile(support::FileName const&) const
{
return false;
}
//
// Dummy features support (needed by ModuleList)
//
bool LaTeXFeatures::isAvailable(string const &)
{
return true;
}
string alignmentToCSS(LyXAlignment)
{
return string();
}
//
// Keep the linker happy on Windows
//
void lyx_exit(int)
{}
}

View File

@ -29,7 +29,6 @@
#include "support/filetools.h"
#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/Messages.h"
#include "support/os.h"
#include "support/Package.h"
#include "support/Systemcall.h"
@ -48,52 +47,6 @@ using namespace lyx::support::os;
namespace lyx {
namespace frontend {
namespace Alert {
void warning(docstring const & title, docstring const & message,
bool const &)
{
cerr << to_utf8(title) << "\n" << to_utf8(message) << endl;
}
}
}
// Dummy texrow support
void TexRow::newline()
{}
void TexRow::newlines(int)
{}
// Dummy LyXRC support
class LyXRC {
public:
string icon_set;
} lyxrc;
// Dummy translation support
Messages messages_;
Messages const & getMessages(std::string const &)
{
return messages_;
}
Messages const & getGuiMessages()
{
return messages_;
}
// Keep the linker happy on Windows
void lyx_exit(int)
{}
string const trimSpaceAndEol(string const & a)
{
return trim(a, " \t\n\r");