From 89a479f60dfef4dd04db3cce077d0ab2eac3acfb Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Thu, 27 Jul 2023 19:31:11 -0400 Subject: [PATCH] Fix bug #12797. Use plaintext to give some display of equations in TOC. --- src/mathed/InsetMathHull.cpp | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/mathed/InsetMathHull.cpp b/src/mathed/InsetMathHull.cpp index 9c641807f8..0004d1e17d 100644 --- a/src/mathed/InsetMathHull.cpp +++ b/src/mathed/InsetMathHull.cpp @@ -310,6 +310,13 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool output_active, if (first != last) b.argumentItem(bformat(from_ascii("(%1$s-%2$s)"), numbers_[first], numbers_[last])); + + odocstringstream ods; + Encoding const * enc = encodings.fromLyXName("utf8"); + OutputParams ops(enc); + ops.for_toc = true; + int const max_length = 30; + for (row_type row = 0; row != nrows(); ++row) { if (!numbered(row)) continue; @@ -319,12 +326,26 @@ void InsetMathHull::addToToc(DocIterator const & pit, bool output_active, label_[row]->addToToc(pit, output_active, utype, backend); } docstring label = nicelabel(row); - if (first == last) + if (first == last) { // this is the only equation - b.argumentItem(label); - else { + plaintext(ods, ops, max_length); + b.argumentItem(label + " " + ods.str()); + } else { // insert as sub-items - b.pushItem(pit, label, output_active); + otexrowstream ots(ods); + TeXMathStream wi(ots, false, false, TeXMathStream::wsDefault, enc); + docstring d; + for (col_type c = 0; c < ncols(); ++c) { + wi << cell(index(row, c)); + d = ods.str(); + if (d.size() > max_length) { + d = d.substr(0, max_length - 1); + break; + } + } + b.pushItem(pit, label+ " " + d, output_active); + // clear the stringstream + odocstringstream().swap(ods); b.pop(); } } -- 2.39.5