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/branches/BRANCH_1_6_X@31361 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2009-09-10 12:10:18 +00:00
parent fb8a55bedc
commit bd5d83a578
6 changed files with 54 additions and 12 deletions

View File

@ -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
@ -1097,7 +1102,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", ""] + \
@ -2177,7 +2182,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

View File

@ -24,7 +24,8 @@ OutputParams::OutputParams(Encoding const * enc)
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)
{

View File

@ -147,6 +147,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.
*/

View File

@ -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"
@ -75,9 +76,33 @@ int InsetERT::latex(odocstream & os, OutputParams const & op) 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;
}

View File

@ -48,8 +48,10 @@ InsetIndex::InsetIndex(Buffer const & buf)
int InsetIndex::latex(odocstream & os,
OutputParams const & runparams) const
OutputParams const & runparams_in) const
{
OutputParams runparams(runparams_in);
runparams.inIndexEntry = true;
os << "\\index";
os << '{';
int i = 0;

View File

@ -69,8 +69,12 @@ What's new
- Do not unnecessarily enquote brackets in the LaTeX output (bug 5988).
- Remove the last '//' in the output of multiline equations. This caused
- Remove the last '\\' in the output of multiline equations. This caused
labels to appear double (bug 2969).
- Put "|" characters in index entries in ERT when converting old documents
to LyX 1.6.x format, to assure the character is treated verbatim
(bug 6179).
* USER INTERFACE