mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 13:18:28 +00:00
When in mathmode, always use the mathcommand replacement from the
unicodesymbols file. Also take into account that a unicode symbol may appear in both mathmode and textmode and thus both the mathmode and textmode features may be required. As a side effect, the problem that the \lyxmathsym definition is added to the preamble even when a unicode symbol appears only in textmode is solved. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26548 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
4e142856d7
commit
b5dcdbc960
@ -34,6 +34,10 @@ namespace lyx {
|
||||
|
||||
Encodings encodings;
|
||||
|
||||
Encodings::MathCommandSet Encodings::mathcmd;
|
||||
Encodings::TextCommandSet Encodings::textcmd;
|
||||
Encodings::MathSymbolSet Encodings::mathsym;
|
||||
|
||||
namespace {
|
||||
|
||||
char_type arabic_table[172][4] = {
|
||||
@ -377,25 +381,34 @@ vector<char_type> Encoding::symbolsList() const
|
||||
}
|
||||
|
||||
|
||||
bool Encodings::latexMathChar(char_type c, Encoding const * encoding,
|
||||
docstring & command)
|
||||
bool Encodings::latexMathChar(char_type c, bool mathmode,
|
||||
Encoding const * encoding, docstring & command)
|
||||
{
|
||||
if (encoding) {
|
||||
if (encoding)
|
||||
command = encoding->latexChar(c, true);
|
||||
if (!command.empty())
|
||||
return false;
|
||||
}
|
||||
|
||||
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
|
||||
if (it == unicodesymbols.end())
|
||||
throw EncodingException(c);
|
||||
if (it->second.mathcommand.empty()) {
|
||||
if (it->second.textcommand.empty())
|
||||
if (it == unicodesymbols.end()) {
|
||||
if (!encoding || command.empty())
|
||||
throw EncodingException(c);
|
||||
command = it->second.textcommand;
|
||||
if (mathmode)
|
||||
addMathSym(c);
|
||||
return false;
|
||||
}
|
||||
command = it->second.mathcommand;
|
||||
return true;
|
||||
// at least one of mathcommand and textcommand is nonempty
|
||||
bool use_math = (mathmode && !it->second.mathcommand.empty()) ||
|
||||
(!mathmode && it->second.textcommand.empty());
|
||||
if (use_math) {
|
||||
command = it->second.mathcommand;
|
||||
addMathCmd(c);
|
||||
} else {
|
||||
if (!encoding || command.empty()) {
|
||||
command = it->second.textcommand;
|
||||
addTextCmd(c);
|
||||
} else if (mathmode)
|
||||
addMathSym(c);
|
||||
}
|
||||
return use_math;
|
||||
}
|
||||
|
||||
|
||||
@ -496,9 +509,11 @@ void Encodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed)
|
||||
{
|
||||
CharInfoMap::const_iterator const it = unicodesymbols.find(c);
|
||||
if (it != unicodesymbols.end()) {
|
||||
// at least one of mathcommand and textcommand is nonempty
|
||||
bool const use_math = (for_mathed && !it->second.mathcommand.empty()) ||
|
||||
// In mathed, c could be used both in textmode and mathmode
|
||||
bool const use_math = (for_mathed && isMathCmd(c)) ||
|
||||
(!for_mathed && it->second.textcommand.empty());
|
||||
bool const use_text = (for_mathed && isTextCmd(c)) ||
|
||||
(!for_mathed && !it->second.textcommand.empty());
|
||||
if (use_math) {
|
||||
if (!it->second.mathpreamble.empty()) {
|
||||
if (it->second.mathfeature)
|
||||
@ -506,19 +521,20 @@ void Encodings::validate(char_type c, LaTeXFeatures & features, bool for_mathed)
|
||||
else
|
||||
features.addPreambleSnippet(it->second.mathpreamble);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
if (use_text) {
|
||||
if (!it->second.textpreamble.empty()) {
|
||||
if (it->second.textfeature)
|
||||
features.require(it->second.textpreamble);
|
||||
else
|
||||
features.addPreambleSnippet(it->second.textpreamble);
|
||||
}
|
||||
if (for_mathed) {
|
||||
features.require("relsize");
|
||||
features.require("lyxmathsym");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (for_mathed && isMathSym(c)) {
|
||||
features.require("relsize");
|
||||
features.require("lyxmathsym");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -113,6 +113,12 @@ private:
|
||||
|
||||
class Encodings {
|
||||
public:
|
||||
///
|
||||
typedef std::set<char_type> MathCommandSet;
|
||||
///
|
||||
typedef std::set<char_type> TextCommandSet;
|
||||
///
|
||||
typedef std::set<char_type> MathSymbolSet;
|
||||
///
|
||||
typedef std::map<std::string, Encoding> EncodingList;
|
||||
/// iterator to iterate over all encodings.
|
||||
@ -181,12 +187,40 @@ public:
|
||||
*/
|
||||
static bool isForced(char_type c);
|
||||
/**
|
||||
* If \p c cannot be encoded in the given \p encoding, convert
|
||||
* it to something that LaTeX can understand in math mode.
|
||||
* \return whether \p command is a math mode command
|
||||
* Register \p c as a mathmode command.
|
||||
*/
|
||||
static bool latexMathChar(char_type c, Encoding const * encoding, docstring & command);
|
||||
|
||||
static void addMathCmd(char_type c) { mathcmd.insert(c); }
|
||||
/**
|
||||
* Register \p c as a textmode command.
|
||||
*/
|
||||
static void addTextCmd(char_type c) { textcmd.insert(c); }
|
||||
/**
|
||||
* Register \p c as a mathmode symbol.
|
||||
*/
|
||||
static void addMathSym(char_type c) { mathsym.insert(c); }
|
||||
/**
|
||||
* Tell whether \p c is registered as a mathmode command.
|
||||
*/
|
||||
static bool isMathCmd(char_type c) { return mathcmd.count(c); }
|
||||
/**
|
||||
* Tell whether \p c is registered as a textmode command.
|
||||
*/
|
||||
static bool isTextCmd(char_type c) { return textcmd.count(c); }
|
||||
/**
|
||||
* 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 initMathAndTextSets() { mathcmd.clear(); textcmd.clear(); mathsym.clear(); }
|
||||
/**
|
||||
* If \p c cannot be encoded in the given \p encoding, convert
|
||||
* it to something that LaTeX can understand in mathmode.
|
||||
* \return whether \p command is a mathmode command
|
||||
*/
|
||||
static bool latexMathChar(char_type c, bool mathmode,
|
||||
Encoding const * encoding, docstring & command);
|
||||
/**
|
||||
* Convert the LaTeX command in \p cmd to the corresponding unicode
|
||||
* point and set \p combining to true if it is a combining symbol
|
||||
@ -211,6 +245,12 @@ public:
|
||||
private:
|
||||
///
|
||||
EncodingList encodinglist;
|
||||
///
|
||||
static MathCommandSet mathcmd;
|
||||
///
|
||||
static TextCommandSet textcmd;
|
||||
///
|
||||
static MathSymbolSet mathsym;
|
||||
};
|
||||
|
||||
extern Encodings encodings;
|
||||
|
@ -118,10 +118,11 @@ void InsetMathString::write(WriteStream & os) const
|
||||
os.pendingBrace(false);
|
||||
|
||||
while (cit != end) {
|
||||
bool mathmode = in_forced_mode ? os.textMode() : !os.textMode();
|
||||
char_type const c = *cit;
|
||||
docstring command(1, c);
|
||||
try {
|
||||
docstring command(1, c);
|
||||
if (c < 0x80 || Encodings::latexMathChar(c, os.encoding(), command)) {
|
||||
if (c < 0x80 || Encodings::latexMathChar(c, mathmode, os.encoding(), command)) {
|
||||
if (os.textMode()) {
|
||||
if (in_forced_mode) {
|
||||
// we were inside \lyxmathsym
|
||||
@ -129,7 +130,7 @@ void InsetMathString::write(WriteStream & os) const
|
||||
os.textMode(false);
|
||||
in_forced_mode = false;
|
||||
}
|
||||
if (c >= 0x80) {
|
||||
if (c >= 0x80 && os.textMode()) {
|
||||
os << "\\ensuremath{";
|
||||
os.textMode(false);
|
||||
in_forced_mode = true;
|
||||
|
@ -749,6 +749,8 @@ void latexParagraphs(Buffer const & buf,
|
||||
ParagraphList::const_iterator par = paragraphs.begin();
|
||||
ParagraphList::const_iterator endpar = paragraphs.end();
|
||||
|
||||
Encodings::initMathAndTextSets();
|
||||
|
||||
LASSERT(runparams.par_begin <= runparams.par_end, /**/);
|
||||
// if only part of the paragraphs will be outputed
|
||||
if (runparams.par_begin != runparams.par_end) {
|
||||
|
Loading…
Reference in New Issue
Block a user