+static docstring buffer_to_latex(Buffer & buffer)
+{
+ OutputParams runparams(&buffer.params().encoding());
+ TexRow texrow;
+ odocstringstream ods;
+ otexstream os(ods, texrow);
+ runparams.nice = true;
+ runparams.flavor = OutputParams::LATEX;
+ runparams.linelen = 80; //lyxrc.plaintext_linelen;
+ // No side effect of file copying and image conversion
+ runparams.dryrun = true;
+ pit_type const endpit = buffer.paragraphs().size();
+ for (pit_type pit = 0; pit != endpit; ++pit) {
+ TeXOnePar(buffer, buffer.text(), pit, os, runparams);
+ LYXERR(Debug::FIND, "searchString up to here: " << ods.str());
+ }
+ return ods.str();
+}
+
+
+static docstring stringifySearchBuffer(Buffer & buffer, FindAndReplaceOptions const & opt) {
+ docstring str;
+ if (!opt.ignoreformat) {
+ str = buffer_to_latex(buffer);
+ } else {
+ ParIterator it = buffer.par_iterator_begin();
+ ParIterator end = buffer.par_iterator_end();
+ OutputParams runparams(&buffer.params().encoding());
+ odocstringstream os;
+ runparams.nice = true;
+ runparams.flavor = OutputParams::LATEX;
+ runparams.linelen = 100000; //lyxrc.plaintext_linelen;
+ runparams.dryrun = true;
+ for (; it != end; ++it) {
+ LYXERR(Debug::FIND, "Adding to search string: '"
+ << it->asString(false)
+ << "'");
+ str +=
+ it->stringify(pos_type(0), it->size(),
+ AS_STR_INSETS, runparams);
+ }
+ }
+ return str;
+}
+
+
+/// Return separation pos between the leading material and the rest
+static size_t identifyLeading(string const & s) {
+ string t = s;
+ // @TODO Support \item[text]
+ while (regex_replace(t, t, "\\\\(emph|textbf|subsubsection|subsection|section|subparagraph|paragraph|part)\\{", "")
+ || regex_replace(t, t, "^\\$", "")
+ || regex_replace(t, t, "^\\\\\\[ ", "")
+ || regex_replace(t, t, "^\\\\item ", ""))
+ LYXERR(Debug::FIND, " after removing leading $, \\[ , \\emph{, \\textbf{, etc.: " << t);
+ return s.find(t);
+}
+
+