From fb2f7076a71db720f01843b02c96a447c20e4e9c Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sun, 29 Mar 2020 17:47:59 +0200 Subject: [PATCH] Prevent wrong reference to duplicated (but deleted) label Fixes #11803 --- src/insets/InsetLabel.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp index d8009adef5..30211b8e19 100644 --- a/src/insets/InsetLabel.cpp +++ b/src/insets/InsetLabel.cpp @@ -316,6 +316,20 @@ void InsetLabel::latex(otexstream & os, OutputParams const & runparams_in) const { OutputParams runparams = runparams_in; docstring command = getCommand(runparams); + docstring const label = getParam("name"); + if (buffer().params().output_changes + && buffer().activeLabel(label) + && buffer().insetLabel(label, true) != this) { + // this is a deleted label and we have a non-deleted with the same id + // rename it for output to prevent wrong references + docstring newlabel = label; + int i = 1; + while (buffer().insetLabel(newlabel)) { + newlabel = label + "-DELETED-" + convert(i); + ++i; + } + command = subst(command, label, newlabel); + } // 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) -- 2.39.5