master_language(0), encoding(enc), free_spacing(false),
use_babel(false), use_polyglossia(false), use_CJK(false),
use_indices(false), use_japanese(false), linelen(0), depth(0),
- exportdata(new ExportData), inDisplayMath(false), wasDisplayMath(false),
- inComment(false), openbtUnit(false), only_childbibs(false),
+ exportdata(new ExportData), postpone_fragile_stuff(false), inDisplayMath(false),
+ wasDisplayMath(false), inComment(false), openbtUnit(false), only_childbibs(false),
inTableCell(NO), inFloat(NONFLOAT),
inIndexEntry(false), inIPA(false), inDeletedInset(0),
changeOfDeletedInset(Change::UNCHANGED),
*/
std::shared_ptr<ExportData> exportdata;
+ /** Store labels, index entries (etc.) (in \ref post_macro)
+ * and output them later. This is used in particular to get
+ * labels and index entries (and potentially other fragile commands)
+ * outside of moving arguments (bug 2154)
+ */
+ bool postpone_fragile_stuff;
+
+ /** Stuff to be postponed and output after the current macro
+ * (if \ref postpone_fragile_stuff is true). Used for labels and index
+ * entries in commands with moving arguments (\\section, \\caption etc.)
+ */
+ mutable docstring post_macro;
+
/** Whether we are entering a display math inset.
* Needed to correctly strike out deleted math in change tracking.
*/
// such as Note that do not produce any output, so that no
// command is ever executed but its opening was recorded.
runparams.inulemcmd = rp.inulemcmd;
+
+ // And finally, pass the post_macros upstream
+ runparams.post_macro = rp.post_macro;
}
// If we have an open font definition, we have to close it
// \caption{...}, later we will make it take advantage
// of the one of the caption packages. (Lgb)
OutputParams runparams = runparams_in;
+ // Some fragile commands (labels, index entries)
+ // are output after the caption (#2154)
+ runparams.postpone_fragile_stuff = true;
InsetText::latex(os, runparams);
+ if (!runparams.post_macro.empty()) {
+ // Output the stored fragile commands (labels, indices etc.)
+ // that need to be output after the caption.
+ os << runparams.post_macro;
+ runparams.post_macro.clear();
+ }
// Backwards compatibility: We always had a linebreak after
// the caption (see #8514)
os << breakln;
{}
-void InsetIndex::latex(otexstream & os, OutputParams const & runparams_in) const
+void InsetIndex::latex(otexstream & ios, OutputParams const & runparams_in) const
{
OutputParams runparams(runparams_in);
runparams.inIndexEntry = true;
+ otexstringstream os;
+
if (buffer().masterBuffer()->params().use_indices && !params_.index.empty()
&& params_.index != "idx") {
os << "\\sindex[";
os << "|" << cmd;
}
os << '}';
+
+ // In macros with moving arguments, such as \section,
+ // we store the index and output it after the macro (#2154)
+ if (runparams_in.postpone_fragile_stuff)
+ runparams_in.post_macro += os.str();
+ else
+ ios << os.release();
}
#include "output_xhtml.h"
#include "ParIterator.h"
#include "sgml.h"
+#include "texstream.h"
#include "Text.h"
#include "TextClass.h"
#include "TocBackend.h"
}
+void InsetLabel::latex(otexstream & os, OutputParams const & runparams_in) const
+{
+ OutputParams runparams = runparams_in;
+ docstring command = getCommand(runparams);
+ // In macros with moving arguments, such as \section,
+ // we store the label and output it after the macro (#2154)
+ if (runparams_in.postpone_fragile_stuff)
+ runparams_in.post_macro += command;
+ else
+ os << command;
+}
+
+
int InsetLabel::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{
///
InsetCode lyxCode() const { return LABEL_CODE; }
///
+ void latex(otexstream & os, OutputParams const & runparams_in) const;
+ ///
int plaintext(odocstringstream & ods, OutputParams const & op,
size_t max_length = INT_MAX) const;
///
// Output the contents of the inset
latexParagraphs(buffer(), text_, os, rp);
runparams.encoding = rp.encoding;
+ // Pass the post_macros upstream
+ runparams.post_macro = rp.post_macro;
if (!il.rightdelim().empty())
os << il.rightdelim();
if (style.pass_thru) {
Font const outerfont = text.outerFont(pit);
parStartCommand(par, os, runparams, style);
+ if (style.isCommand() && style.needprotect)
+ // Due to the moving argument, some fragile
+ // commands (labels, index entries)
+ // are output after this command (#2154)
+ runparams.postpone_fragile_stuff = true;
if (intitle_command)
os << '{';
// (see #10849); thus open the command here.
if (intitle_command) {
parStartCommand(par, os, runparams, style);
+ if (style.isCommand() && style.needprotect)
+ // Due to the moving argument, some fragile
+ // commands (labels, index entries)
+ // are output after this command (#2154)
+ runparams.postpone_fragile_stuff = true;
os << '{';
}
// For InTitle commands, we already started the command before
// the language switch
- if (!intitle_command)
+ if (!intitle_command) {
parStartCommand(par, os, runparams, style);
+ if (style.isCommand() && style.needprotect)
+ // Due to the moving argument, some fragile
+ // commands (labels, index entries)
+ // are output after this command (#2154)
+ runparams.postpone_fragile_stuff = true;
+ }
Font const outerfont = text.outerFont(pit);
os << '}';
if (!style.postcommandargs().empty())
latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
+ if (!runparams.post_macro.empty()) {
+ // Output the stored fragile commands (labels, indices etc.)
+ // that need to be output after the command with moving argument.
+ os << runparams.post_macro;
+ runparams.post_macro.clear();
+ }
if (runparams.encoding != prev_encoding) {
runparams.encoding = prev_encoding;
os << setEncoding(prev_encoding->iconvName());
os << '}';
if (!style.postcommandargs().empty())
latexArgInsets(par, os, runparams, style.postcommandargs(), "post:");
+ if (!runparams.post_macro.empty()) {
+ // Output the stored fragile commands (labels, indices etc.)
+ // that need to be output after the command with moving argument.
+ os << runparams.post_macro;
+ runparams.post_macro.clear();
+ }
if (runparams.encoding != prev_encoding) {
runparams.encoding = prev_encoding;
os << setEncoding(prev_encoding->iconvName());
else
runparams_in.encoding = runparams.encoding;
+ // Also pass the post_macros upstream
+ runparams_in.post_macro = runparams.post_macro;
+
// we don't need a newline for the last paragraph!!!
// Note from JMarc: we will re-add a \n explicitly in