diff --git a/lib/lyx2lyx/lyx_1_6.py b/lib/lyx2lyx/lyx_1_6.py index 520ea6184a..224ceebf84 100644 --- a/lib/lyx2lyx/lyx_1_6.py +++ b/lib/lyx2lyx/lyx_1_6.py @@ -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 diff --git a/src/OutputParams.cpp b/src/OutputParams.cpp index 498c65148c..a4d60c698f 100644 --- a/src/OutputParams.cpp +++ b/src/OutputParams.cpp @@ -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) { diff --git a/src/OutputParams.h b/src/OutputParams.h index 00a1e11030..bce61bcc28 100644 --- a/src/OutputParams.h +++ b/src/OutputParams.h @@ -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. */ diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index 6fc51e11d8..fba6c1ecc7 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -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; } diff --git a/src/insets/InsetIndex.cpp b/src/insets/InsetIndex.cpp index 398281d2a2..54254c5b3b 100644 --- a/src/insets/InsetIndex.cpp +++ b/src/insets/InsetIndex.cpp @@ -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; diff --git a/status.16x b/status.16x index 7bddf7292c..0508940471 100644 --- a/status.16x +++ b/status.16x @@ -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