mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Fix bug 6179 ("|" in index entries not embraced in ERT by lyx2lyx).
* OutputParams.{cpp,h}: - new param inIndexEntry * InsetIndex.cpp (latex): - set param. * InsetErt.cpp (plainText): - output active chars in IndexInsets * lib/lyx2lyx/lyx_1_6.py: - embrace "|" in ERT when converting old index entries to collapsables. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31360 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
3be8389d61
commit
71001a8087
@ -209,7 +209,7 @@ def extract_argument(line):
|
||||
return (line[:pos + 1], line[pos + 1:])
|
||||
|
||||
|
||||
def latex2ert(line):
|
||||
def latex2ert(line, isindex):
|
||||
'''Converts LaTeX commands into ERT. line may well be a multi-line
|
||||
string when it is returned.'''
|
||||
if not line:
|
||||
@ -246,6 +246,9 @@ def latex2ert(line):
|
||||
# put all remaining braces in ERT
|
||||
line = wrap_into_ert(line, '}', '}')
|
||||
line = wrap_into_ert(line, '{', '{')
|
||||
if isindex:
|
||||
# active character that is not available in all font encodings
|
||||
line = wrap_into_ert(line, '|', '|')
|
||||
retval += line
|
||||
return retval
|
||||
|
||||
@ -257,10 +260,12 @@ unicode_reps = read_unicodesymbols()
|
||||
#end up inside ERT. That routine could be modified so that it returned
|
||||
#a list of lines, and we could then skip ERT bits and only deal with
|
||||
#the other bits.
|
||||
def latex2lyx(data):
|
||||
def latex2lyx(data, isindex):
|
||||
'''Takes a string, possibly multi-line, and returns the result of
|
||||
converting LaTeX constructs into LyX constructs. Returns a list of
|
||||
lines, suitable for insertion into document.body.'''
|
||||
lines, suitable for insertion into document.body.
|
||||
The bool isindex specifies whether we are in an index macro (which
|
||||
has some specific active characters that need to be ERTed).'''
|
||||
|
||||
if not data:
|
||||
return [""]
|
||||
@ -309,14 +314,14 @@ def latex2lyx(data):
|
||||
g = m.group(3)
|
||||
if s:
|
||||
# this is non-math!
|
||||
s = latex2ert(s)
|
||||
s = latex2ert(s, isindex)
|
||||
subst = s.split('\n')
|
||||
retval += subst
|
||||
retval.append("\\begin_inset Formula " + f)
|
||||
retval.append("\\end_inset")
|
||||
m = mathre.match(g)
|
||||
# Handle whatever is left, which is just text
|
||||
g = latex2ert(g)
|
||||
g = latex2ert(g, isindex)
|
||||
subst = g.split('\n')
|
||||
retval += subst
|
||||
return retval
|
||||
@ -1096,7 +1101,7 @@ def convert_latexcommand_index(document):
|
||||
linelist = [""]
|
||||
else:
|
||||
fullcontent = m.group(1)
|
||||
linelist = latex2lyx(fullcontent)
|
||||
linelist = latex2lyx(fullcontent, True)
|
||||
#document.warning(fullcontent)
|
||||
|
||||
linelist = ["\\begin_inset Index", "status collapsed", "\\begin_layout Standard", ""] + \
|
||||
@ -2176,7 +2181,7 @@ def convert_subfig(document):
|
||||
addedLines -= 1
|
||||
subst = ['\\begin_inset Float figure', 'wide false', 'sideways false',
|
||||
'status open', '', '\\begin_layout Plain Layout', '\\begin_inset Caption',
|
||||
'', '\\begin_layout Plain Layout'] + latex2lyx(caption) + \
|
||||
'', '\\begin_layout Plain Layout'] + latex2lyx(caption, False) + \
|
||||
[ '\\end_layout', '', '\\end_inset', '',
|
||||
'\\end_layout', '', '\\begin_layout Plain Layout']
|
||||
document.body[i : i] = subst
|
||||
|
@ -24,7 +24,8 @@ OutputParams::OutputParams(Encoding const * enc)
|
||||
use_indices(false), use_japanese(false), linelen(0), depth(0),
|
||||
exportdata(new ExportData),
|
||||
inComment(false), inTableCell(NO), inFloat(NONFLOAT),
|
||||
inDeletedInset(0), changeOfDeletedInset(Change::UNCHANGED),
|
||||
inIndexEntry(false), inDeletedInset(0),
|
||||
changeOfDeletedInset(Change::UNCHANGED),
|
||||
par_begin(0), par_end(0), isLastPar(false),
|
||||
dryrun(false), verbatim(false), disable_captions(false)
|
||||
{
|
||||
|
@ -168,6 +168,11 @@ public:
|
||||
*/
|
||||
Float inFloat;
|
||||
|
||||
/** Whether we are inside an index inset.
|
||||
* ERT needs to know this, due to the active chars.
|
||||
*/
|
||||
bool inIndexEntry;
|
||||
|
||||
/** Whether we are inside an inset that is logically deleted.
|
||||
* A value > 0 indicates a deleted inset.
|
||||
*/
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "Lexer.h"
|
||||
#include "LyXAction.h"
|
||||
#include "MetricsInfo.h"
|
||||
#include "OutputParams.h"
|
||||
#include "ParagraphParameters.h"
|
||||
#include "Paragraph.h"
|
||||
#include "TextClass.h"
|
||||
@ -63,9 +64,33 @@ void InsetERT::write(ostream & os) const
|
||||
}
|
||||
|
||||
|
||||
int InsetERT::plaintext(odocstream &, OutputParams const &) const
|
||||
int InsetERT::plaintext(odocstream & os, OutputParams const & rp) const
|
||||
{
|
||||
return 0; // do not output TeX code
|
||||
if (!rp.inIndexEntry)
|
||||
// do not output TeX code
|
||||
return 0;
|
||||
|
||||
ParagraphList::const_iterator par = paragraphs().begin();
|
||||
ParagraphList::const_iterator end = paragraphs().end();
|
||||
|
||||
while (par != end) {
|
||||
pos_type siz = par->size();
|
||||
for (pos_type i = 0; i < siz; ++i) {
|
||||
char_type const c = par->getChar(i);
|
||||
// output the active characters
|
||||
switch (c) {
|
||||
case '|':
|
||||
case '!':
|
||||
case '@':
|
||||
os.put(c);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
++par;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,8 +54,11 @@ InsetIndex::InsetIndex(Buffer const & buf, InsetIndexParams const & params)
|
||||
|
||||
|
||||
int InsetIndex::latex(odocstream & os,
|
||||
OutputParams const & runparams) const
|
||||
OutputParams const & runparams_in) const
|
||||
{
|
||||
OutputParams runparams(runparams_in);
|
||||
runparams.inIndexEntry = true;
|
||||
|
||||
if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
|
||||
&& params_.index != "idx") {
|
||||
os << "\\sindex[";
|
||||
@ -88,9 +91,6 @@ int InsetIndex::latex(odocstream & os,
|
||||
// ...and erase that stuff from latexstr
|
||||
latexstr = latexstr.erase(pos);
|
||||
// ...and similarly from plainstr
|
||||
// FIXME This utterly fails if the "|" is in ERT
|
||||
// which is necessary with font encodings other
|
||||
// than T1.
|
||||
size_t ppos = plainstr.find(from_ascii("|"));
|
||||
if (ppos < plainstr.size())
|
||||
plainstr.erase(ppos);
|
||||
@ -100,7 +100,6 @@ int InsetIndex::latex(odocstream & os,
|
||||
|
||||
// Separate the entires and subentries, i.e., split on "!"
|
||||
// FIXME This would do the wrong thing with escaped ! characters
|
||||
// and with "!" in ERT.
|
||||
std::vector<docstring> const levels =
|
||||
getVectorFromString(latexstr, from_ascii("!"), true);
|
||||
std::vector<docstring> const levels_plain =
|
||||
|
Loading…
Reference in New Issue
Block a user